private Decompile ( string exePath, string destinationDir ) : void | ||
exePath | string | |
destinationDir | string | |
return | void |
public void Recompile(bool test) { if (Files.Count == 0) { return; } BuildStatus = ""; BuildError = ""; BuildSuccess = false; BuildThread = new Thread(() => { string stepname = ""; long linesAdded = 0; long trackedObjects = 0; try { BuildStatus = "Checking"; if (XDecompile.CheckIfAlreadyXRayed(Files) && !TryRestoreBackups()) { return; } BuildStatus = "Preparing"; // copy XLibrary to final destination CopyLocalToOutputDir("XLibrary.dll", OutputDir); if (EnableLocalViewer) { CopyLocalToOutputDir("OpenTK.dll", OutputDir); CopyLocalToOutputDir("OpenTK.GLControl.dll", OutputDir); CopyLocalToOutputDir("QuickFont.dll", OutputDir); } string errorLog = ""; XNodeOut.NextID = 0; XNodeOut root = new XNodeOut(null, "root", XObjType.Root); XNodeOut extRoot = root.AddNode("Not XRayed", XObjType.External); XNodeOut intRoot = root.AddNode("XRayed", XObjType.Internal); // init root file nodes so links can be made for processed fields before they are directly xrayed foreach (var item in Files) { item.FileNode = intRoot.AddNode(Path.GetFileName(item.FilePath), XObjType.File); } foreach (var item in Files) { var decompile = new XDecompile(intRoot, extRoot, item, this); try { if (CompileWithMS) { BuildStatus = "Decompiling " + item.FileName; decompile.MsDecompile(); // used for debugging tricky ilasm errors //for (int i = 0; i < int.MaxValue; i++) // { decompile.AllowedAdds = int.MaxValue; // i; decompile.AddsDone = 0; BuildStatus = "Scanning " + item.FileName; decompile.ScanLines(test); BuildStatus = "Recompiling " + item.FileName; item.RecompiledPath = decompile.Compile(); // } } else { BuildStatus = "Recompiling " + item.FileName; decompile.MonoRecompile(); } // remove signature // files that arent signed are coming up as signed meaning this would probably corrupt a file // also not sure if checked anymore - http://msdn.microsoft.com/en-us/library/cc713694.aspx //var meta = new MetaInfo(item.RecompiledPath); //if (meta.Load()) // meta.RemoveSignature(); // decompile to check if (DecompileAgain) { string filename = Path.GetFileName(item.FilePath); string compiler = CompileWithMS ? "MS" : "Mono"; // create directories var dir = Path.Combine(Application.StartupPath, "recompile", filename, compiler + "_original"); var originalPath = decompile.BackupPath != null ? decompile.BackupPath : item.FilePath; decompile.Decompile(originalPath, dir); dir = Path.Combine(Application.StartupPath, "recompile", filename, compiler + "_new"); decompile.Decompile(item.RecompiledPath, dir); } } catch (CompileError ex) { errorLog += item.FileName + "\r\n" + ex.Summary + "\r\n--------------------------------------------------------\r\n"; } catch (Exception ex) { BuildError = "Error recompiling: " + ex.Message + "\r\n" + ex.StackTrace; BuildStatus = "Error on " + item.FileName; return; } linesAdded += decompile.LinesAdded; } // save node map before verifying because we dont want bogus verify // errors from preventing the dat file form being made BuildStatus = "Saving Map"; var settings = new Dictionary <string, string>(); settings["Version"] = XRay.BuilderVersion; if (Pro.Verified) { settings["Pro"] = Pro.SignedFile; } if (EnableLocalViewer) { settings["EnableLocalViewer"] = EnableLocalViewer.ToString(); settings["EnableIpcServer"] = EnableIpcServer.ToString(); settings["ShowViewerOnStart"] = ShowViewerOnStart.ToString(); } if (EnableTcpServer) { settings["EnableTcpServer"] = EnableTcpServer.ToString(); settings["TcpListenPort"] = TcpListenPort.ToString(); settings["EncryptionKey"] = EncryptionKey; } var writePath = Path.Combine(OutputDir, "XRay.dat"); trackedObjects = root.SaveTree(writePath, settings); if (errorLog.Length > 0) { string logPath = Path.Combine(Application.StartupPath, "errorlog.txt"); File.WriteAllText(logPath, errorLog); Process.Start(logPath); } } catch (Exception ex) { BuildError = "Error during " + stepname + ": " + ex.Message; } BuildStatus = String.Format("Success! {0:#,#} instructions added, {1:#,#} objects tracked", linesAdded, trackedObjects); BuildSuccess = true; }); BuildThread.Start(); }
public void Recompile(bool test) { if (Files.Count == 0) return; BuildStatus = ""; BuildError = ""; BuildSuccess = false; BuildThread = new Thread(() => { string stepname = ""; long linesAdded = 0; long trackedObjects = 0; try { BuildStatus = "Checking"; if (XDecompile.CheckIfAlreadyXRayed(Files) && !TryRestoreBackups()) { return; } BuildStatus = "Preparing"; // copy XLibrary to final destination CopyLocalToOutputDir("XLibrary.dll", OutputDir); if (EnableLocalViewer) { CopyLocalToOutputDir("OpenTK.dll", OutputDir); CopyLocalToOutputDir("OpenTK.GLControl.dll", OutputDir); CopyLocalToOutputDir("QuickFont.dll", OutputDir); } string errorLog = ""; XNodeOut.NextID = 0; XNodeOut root = new XNodeOut(null, "root", XObjType.Root); XNodeOut extRoot = root.AddNode("Not XRayed", XObjType.External); XNodeOut intRoot = root.AddNode("XRayed", XObjType.Internal); // init root file nodes so links can be made for processed fields before they are directly xrayed foreach (var item in Files) item.FileNode = intRoot.AddNode(Path.GetFileName(item.FilePath), XObjType.File); var callMap = new Dictionary<int, FunctionCall>(); var initMap = new Dictionary<int, FunctionCall>(); foreach (var item in Files) { var decompile = new XDecompile(this, intRoot, extRoot, item, callMap, initMap); try { if (CompileWithMS) { BuildStatus = "Decompiling " + item.FileName; decompile.MsDecompile(); // used for debugging tricky ilasm errors //for (int i = 0; i < int.MaxValue; i++) // { decompile.AllowedAdds = int.MaxValue; // i; decompile.AddsDone = 0; BuildStatus = "Scanning " + item.FileName; decompile.ScanLines(test); BuildStatus = "Recompiling " + item.FileName; item.RecompiledPath = decompile.Compile(); // } } else { BuildStatus = "Recompiling " + item.FileName; decompile.MonoRecompile(); } // remove signature // files that arent signed are coming up as signed meaning this would probably corrupt a file // also not sure if checked anymore - http://msdn.microsoft.com/en-us/library/cc713694.aspx //var meta = new MetaInfo(item.RecompiledPath); //if (meta.Load()) // meta.RemoveSignature(); // decompile to check if (DecompileAgain) { string filename = Path.GetFileName(item.FilePath); string compiler = CompileWithMS ? "MS" : "Mono"; // create directories var dir = Path.Combine(Application.StartupPath, "recompile", filename, compiler + "_original"); var originalPath = decompile.BackupPath != null ? decompile.BackupPath : item.FilePath; decompile.Decompile(originalPath, dir); dir = Path.Combine(Application.StartupPath, "recompile", filename, compiler + "_new"); decompile.Decompile(item.RecompiledPath, dir); } } catch (CompileError ex) { errorLog += item.FileName + "\r\n" + ex.Summary + "\r\n--------------------------------------------------------\r\n"; } catch (Exception ex) { BuildError = "Error recompiling: " + ex.Message + "\r\n" + ex.StackTrace; BuildStatus = "Error on " + item.FileName; return; } linesAdded += decompile.LinesAdded; } // save node map before verifying because we dont want bogus verify // errors from preventing the dat file form being made BuildStatus = "Saving Map"; var settings = new Dictionary<string, string>(); settings["Version"] = XRay.BuilderVersion; if (Pro.Verified) settings["Pro"] = Pro.SignedFile; if (EnableLocalViewer) { settings["EnableLocalViewer"] = EnableLocalViewer.ToString(); settings["EnableIpcServer"] = EnableIpcServer.ToString(); settings["ShowViewerOnStart"] = ShowViewerOnStart.ToString(); } if (EnableTcpServer) { settings["EnableTcpServer"] = EnableTcpServer.ToString(); settings["TcpListenPort"] = TcpListenPort.ToString(); settings["EncryptionKey"] = EncryptionKey; } settings["FunctionCount"] = XNodeOut.NextID.ToString(); var writePath = Path.Combine(OutputDir, "XRay.dat"); trackedObjects = SaveDat(writePath, settings, root, callMap, initMap); if (errorLog.Length > 0) { string logPath = Path.Combine(Application.StartupPath, "errorlog.txt"); File.WriteAllText(logPath, errorLog); Process.Start(logPath); } } catch (Exception ex) { BuildError = "Error during " + stepname + ": " + ex.Message; } BuildStatus = String.Format("Success! {0:#,#} instructions added, {1:#,#} objects tracked", linesAdded, trackedObjects); BuildSuccess = true; }); BuildThread.Start(); }
private void ReCompile(bool test) { XRayedFile[] files = FileList.Items.Cast<XRayedFile>().ToArray(); if (files.Length == 0) return; OptionsPanel.Enabled = false; // have to extract out because thread cant access gui elements bool trackFlow = TrackFlowCheckBox.Checked; bool trackExternal = TrackExternalCheckBox.Checked; bool trackAnon = TrackAnonCheckBox.Checked; bool trackFields = TrackFieldsCheckBox.Checked; bool trackInstances = TrackInstancesCheckBox.Checked; bool replaceOriginal = ReplaceOriginalCheckBox.Checked; bool doVerify = RunVerifyCheckbox.Checked; bool compileWithMS = MsToolsCheckbox.Checked; bool decompileAgain = DecompileAgainCheckbox.Checked; bool showUiOnStart = ShowOnStartCheckBox.Checked; bool saveMsil = SaveMsilCheckBox.Checked; bool decompileCSharp = DecompileCSharpCheckBox.Checked; new Thread(() => { string stepname = ""; var status = new Action<string, string>((step, name) => { stepname = step; RunInGui(() => StatusLabel.Text = step + " " + name); }); long linesAdded = 0; long trackedObjects = 0; try { status("checking", ""); if (XDecompile.CheckIfAlreadyXRayed(files) && !TryRestoreBackups(files)) { RunInGui(() => OptionsPanel.Enabled = true); return; } status("Preparing", ""); XDecompile.PrepareOutputDir(SourceDir, OutputDir); string errorLog = ""; XNodeOut.NextID = 0; XNodeOut root = new XNodeOut(null, "root", XObjType.Root); XNodeOut extRoot = root.AddNode("Not XRayed", XObjType.External); XNodeOut intRoot = root.AddNode("XRayed", XObjType.Internal); // init root file nodes so links can be made for processed fields before they are directly xrayed foreach (XRayedFile item in files) item.FileNode = intRoot.AddNode(Path.GetFileName(item.FilePath), XObjType.File); foreach (XRayedFile item in files) { XDecompile decompile = new XDecompile(intRoot, extRoot, item, OutputDir, DatPath, files, !replaceOriginal) { TrackFlow = trackFlow, TrackExternal = trackExternal, TrackAnon = trackAnon, TrackFields = trackFields, TrackInstances = trackInstances, ShowUIonStart = showUiOnStart, SaveMsil = saveMsil, DecompileCSharp = decompileCSharp }; try { if (compileWithMS) { status("Decompiling", item.FileName); decompile.MsDecompile(); // used for debugging tricky ilasm errors //for (int i = 0; i < int.MaxValue; i++) // { decompile.AllowedAdds = int.MaxValue; // i; decompile.AddsDone = 0; status("Scanning", item.FileName); decompile.ScanLines(test); status("Recompiling", item.FileName); item.RecompiledPath = decompile.Compile(); // } } else { status("Recompiling", item.FileName); decompile.MonoRecompile(); } // remove signature // files that arent signed are coming up as signed meaning this would probably corrupt a file // also not sure if checked anymore - http://msdn.microsoft.com/en-us/library/cc713694.aspx //var meta = new MetaInfo(item.RecompiledPath); //if (meta.Load()) // meta.RemoveSignature(); // decompile to check if (decompileAgain) { string filename = Path.GetFileName(item.FilePath); string compiler = compileWithMS ? "MS" : "Mono"; // create directories var dir = Path.Combine(Application.StartupPath, "recompile", filename, compiler + "_original"); var originalPath = decompile.BackupPath != null ? decompile.BackupPath : item.FilePath; decompile.Decompile(originalPath, dir); dir = Path.Combine(Application.StartupPath, "recompile", filename, compiler + "_new"); decompile.Decompile(item.RecompiledPath, dir); } } catch (CompileError ex) { errorLog += item.FileName + "\r\n" + ex.Summary + "\r\n--------------------------------------------------------\r\n"; } catch (Exception ex) { RunInGui(() => { MessageBox.Show("Error recompiling: " + ex.Message + "\r\n" + ex.StackTrace); StatusLabel.Text = "Error on " + item.FileName; OptionsPanel.Enabled = true; }); return; } linesAdded += decompile.LinesAdded; } // save node map before verifying because we dont want bogus verify // errors from preventing the dat file form being made status("Saving Map", ""); var settings = new Dictionary<string, string>(); settings["Version"] = XRay.BuilderVersion; if (Pro.Verified) settings["Pro"] = Pro.SignedFile; trackedObjects = root.SaveTree(DatPath, settings); // verify last and aggregate errors' if (doVerify) foreach (XRayedFile item in files) { try { status("Verifying", item.FileName); XDecompile.Verify(item.RecompiledPath); } catch (CompileError ex) { errorLog += item.FileName + "\r\n" + ex.Summary + "\r\n--------------------------------------------------------\r\n"; } } if (errorLog.Length > 0) throw new CompileError(errorLog); } catch (CompileError ex) { string summary = ex.Summary; summary = summary.Replace("Unexpected type on the stack.", "Unexpected type on the stack. (Ignore)"); summary = summary.Replace("Unmanaged pointers are not a verifiable type.", "Unmanaged pointers are not a verifiable type. (Ignore)"); if (!replaceOriginal) summary = summary.Replace("Unable to resolve token.", "Unable to resolve token. (Try turning off side by side)"); //todo token error - turn off side by side string logPath = Path.Combine(Application.StartupPath, "errorlog.txt"); File.WriteAllText(logPath, summary); Process.Start(logPath); } catch (Exception ex) { RunInGui(() => MessageBox.Show("Error during " + stepname + ": " + ex.Message)); } status(String.Format("Ready to Launch - {0:#,#} instructions added, {1:#,#} objects tracked", linesAdded, trackedObjects), ""); RunInGui(() => { OptionsPanel.Enabled = true; }); }).Start(); }