Пример #1
0
        private void CompileAssemblies(IList <Assembly> assemblies)
        {
            RecreateDirectory();

            foreach (var assembly in assemblies)
            {
                string resArguments = string.Empty;
                string ilPath       = ILReader.GetILPath(assembly.FilePath);
                string dir          = Path.GetDirectoryName(ilPath);
                string resName      = String.Format("{0}\\{1}.res", dir, assembly.FileNameWithoutExt);

                // fix resources filenames
                RenameResourcesFiles(assembly.FileName, dir);

                // verify if res file is available
                if (File.Exists(resName))
                {
                    resArguments = String.Format("{0} /res:\"{1}\"", resArguments, resName);
                }

                // save obfuscated IL code
                File.Delete(ilPath);
                File.WriteAllText(ilPath, assembly.ILCode);

                // prepare arguments
                string arguments = String.Format("{0}\"{1}\" {2}",
                                                 assembly.FileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ? "/DLL " : String.Empty,
                                                 ilPath,
                                                 resArguments);

                // run compilation
                Process.Start(new ProcessStartInfo()
                {
                    WindowStyle = ProcessWindowStyle.Hidden,
                    Arguments   = arguments,
                    FileName    = ilasmPath,
                });
            }

            // wait until compilation is finished
            while (Process.GetProcessesByName("ilasm").Any())
            {
                Task.Delay(100).Wait();
            }

            // move assemblies to another directory
            MoveAssembliesToDirectory(assemblies, ObfuscatedDirectory);

            // verify compilation
            VerifyAssemblies(assemblies);
        }
Пример #2
0
        private void MoveAssembliesToDirectory(IEnumerable <Assembly> assemblies, string directory)
        {
            foreach (var assembly in assemblies)
            {
                string path = Path.GetDirectoryName(ILReader.GetILPath(assembly.FilePath));

                foreach (var file in Directory.GetFiles(path).Where(x => x.EndsWith(".dll") || x.EndsWith(".exe")))
                {
                    var savePath = String.Format("{0}\\{1}", directory, Path.GetFileName(file));
                    File.Delete(savePath);
                    File.Move(file, savePath);
                }
            }
        }