예제 #1
0
 public void TestLoadSave()
 {
     string atldll = Path.Combine(Environment.SystemDirectory, "atl.dll");
     Assert.IsTrue(File.Exists(atldll));
     string targetFilename = Path.Combine(Path.GetTempPath(), "genericResourceTestLoadSave.dll");
     Console.WriteLine(targetFilename);
     File.Copy(atldll, targetFilename, true);
     // write the resource to a binary
     GenericResource genericResource = new GenericResource(
         new ResourceId("TESTTYPE"), new ResourceId("TESTNAME"), ResourceUtil.USENGLISHLANGID);
     genericResource.Data = Guid.NewGuid().ToByteArray();
     genericResource.SaveTo(targetFilename);
     // reload and compare
     GenericResource newGenericResource = new GenericResource(
         new ResourceId("TESTTYPE"), new ResourceId("TESTNAME"), ResourceUtil.USENGLISHLANGID);
     newGenericResource.LoadFrom(targetFilename);
     ByteUtils.CompareBytes(newGenericResource.Data, genericResource.Data);
 }
예제 #2
0
 public void TestReadWriteMenuMixedResourceBytes()
 {
     string filename = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe");
     using (ResourceInfo ri = new ResourceInfo())
     {
         ri.Load(filename);
         foreach (MenuResource rc in ri[Kernel32.ResourceTypes.RT_MENU])
         {
             GenericResource genericResource = new GenericResource(
                 rc.Type,
                 rc.Name,
                 rc.Language);
             genericResource.LoadFrom(filename);
             byte[] data = rc.WriteAndGetBytes();
             ByteUtils.CompareBytes(genericResource.Data, data);
         }
     }
 }
 public void TestLoadSave(string binaryName)
 {
     Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
     string filename = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\" + binaryName);
     Assert.IsTrue(File.Exists(filename));
     string targetFilename = Path.Combine(Path.GetTempPath(), "genericResourceTestLoadSave.dll");
     Console.WriteLine(targetFilename);
     File.Copy(filename, targetFilename, true);
     // write the resource to a binary
     GenericResource genericResource = new GenericResource(
         new ResourceId("TESTTYPE"), new ResourceId("TESTNAME"), ResourceUtil.USENGLISHLANGID);
     genericResource.Data = Guid.NewGuid().ToByteArray();
     genericResource.SaveTo(targetFilename);
     // reload and compare
     GenericResource newGenericResource = new GenericResource(
         new ResourceId("TESTTYPE"), new ResourceId("TESTNAME"), ResourceUtil.USENGLISHLANGID);
     newGenericResource.LoadFrom(targetFilename);
     ByteUtils.CompareBytes(newGenericResource.Data, genericResource.Data);
 }
예제 #4
0
 public void TestReadWriteResourceBytes()
 {
     Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
     string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
     foreach (string filename in Directory.GetFiles(Path.Combine(uriPath, "Binaries")))
     {
         Console.WriteLine(filename);
         using (ResourceInfo ri = new ResourceInfo())
         {
             ri.Load(filename);
             foreach (Resource rc in ri)
             {
                 Console.WriteLine("Resource: {0} - {1}", rc.TypeName, rc.Name);
                 GenericResource genericResource = new GenericResource(rc.Type, rc.Name, rc.Language);
                 genericResource.LoadFrom(filename);
                 byte[] data = rc.WriteAndGetBytes();
                 ByteUtils.CompareBytes(genericResource.Data, data);
             }
         }
     }
 }
예제 #5
0
 public void TestReadWriteMenuMixedResourceBytes()
 {
     Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
     string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
     string filename = Path.Combine(uriPath, @"Binaries\custom.exe");
     using (ResourceInfo ri = new ResourceInfo())
     {
         ri.Load(filename);
         foreach (MenuResource rc in ri[Kernel32.ResourceTypes.RT_MENU])
         {
             Console.WriteLine(rc.Name);
             GenericResource genericResource = new GenericResource(
                 rc.Type,
                 rc.Name,
                 rc.Language);
             genericResource.LoadFrom(filename);
             byte[] data = rc.WriteAndGetBytes();
             ByteUtils.CompareBytes(genericResource.Data, data);
         }
     }
 }
예제 #6
0
        public void TestReadWriteResourceBytes(string filename)
        {
            if (Path.GetFileName(filename).StartsWith("ClassLibrary_NET"))
            {
                Assert.Ignore(".NET assemblies will fail because they use a padding different from the specification");
            }

            using (ResourceInfo ri = new ResourceInfo())
            {
                ri.Load(filename);
                foreach (Resource rc in ri)
                {
                    Console.WriteLine("Resource: {0} - {1}", rc.TypeName, rc.Name);
                    GenericResource genericResource = new GenericResource(rc.Type, rc.Name, rc.Language);
                    genericResource.LoadFrom(filename);
                    byte[] data = rc.WriteAndGetBytes();
                    ByteUtils.CompareBytes(genericResource.Data, data);
                }
            }
        }
예제 #7
0
        public static void injectResources()
        {
            if(isCreateBackup)
                File.Copy(dll, dll + ".bak", false);    // Don't overwrite

            DirectoryInfo d = new DirectoryInfo(workingDir);
            foreach (var file in d.GetFiles())
            {
                try
                {
                    // The resource ID MUST be parsed as a uint to replace the current resource, otherwise
                    // it will be added as a new resource which will be ignored by iTunes.
                    var res = new GenericResource
                        (RT_RCDATA, new ResourceId(uint.Parse(Path.GetFileNameWithoutExtension(file.Name))), LANG_ENGLISH);

                    res.Data = File.ReadAllBytes(file.FullName);
                    res.SaveTo(dll);

                    Console.WriteLine("Injection Successful: " + file.Name);
                }
                catch
                {
                    Console.WriteLine("Injection Failed: " + file.Name);
                }
            }
        }