private static void decompile(AssemblyFile file) { string path = Path.GetDirectoryName(file.FullName); if (!Directory.Exists(string.Format(@"{0}\msil", path))) { Directory.CreateDirectory(string.Format(@"{0}\msil", path)); } Process process = new Process(); process.StartInfo.FileName = ILDASM; //process.StartInfo.UseShellExecute = false; //process.StartInfo.RedirectStandardOutput = true; process.StartInfo.Arguments = string.Format(@"/all /out={0}\msil\{1}.il {2}", path, file.ID, file.FullName); process.Start(); process.WaitForExit(); }
private static void recompile(AssemblyFile file) { string path = Path.GetDirectoryName(file.FullName); if (!Directory.Exists(string.Format(@"{0}\out", path))) { Directory.CreateDirectory(string.Format(@"{0}\out", path)); } string ilPath = string.Format(@"{0}\msil\{1}.il", path, file.ID); string resPath = string.Format(@"{0}\msil\{1}.res", path, file.ID); string extension = Path.GetExtension(file.FullName).Substring(1); Process process = new Process(); process.StartInfo.FileName = ILASM; //process.StartInfo.UseShellExecute = false; //process.StartInfo.RedirectStandardOutput = true; process.StartInfo.Arguments = string.Format(@"/{0} /resource={1} /key=key.snk {2} /output={3}\out\{4}", extension, resPath, ilPath, path, Path.GetFileName(file.FullName)); process.Start(); process.WaitForExit(); }
private static void rewrite(AssemblyFile file, string publicKey) { System.Console.WriteLine("Rewriting assembly..."); string path = Path.GetDirectoryName(file.FullName); string ilPath = string.Format(@"{0}\msil\{1}.il", path, file.ID); string ilText = File.ReadAllText(ilPath); foreach (var reference in file.References) { string format = string.Format(@"\.assembly extern.*{0}\r\n{{\r\n.*", reference); Regex regex = new Regex(format); var match = regex.Match(ilText).Groups[0].Value; //remove version Regex verRegex = new Regex(@"\.ver .*"); match = verRegex.Replace(match, ""); var refFile = ProcessContext.CurrentContext.Files.FirstOrDefault(f => f.ID == reference); var version = refFile.Version.Replace('.', ':'); if (!string.IsNullOrEmpty(match)) { match = match + string.Format(".publickeytoken = ({0} )\r\n .ver {1}\r\n", publicKey, version); ilText = regex.Replace(ilText, match); } } File.WriteAllText(ilPath, ilText); }
private static void decompile(AssemblyFile file, string publicKey) { decompile(file); rewrite(file, publicKey); }