/// <summary> /// Shows UI and allows the user to edit the project properties. /// </summary> /// <param name="project"></param> public bool EditProjectProperties( IDecompilerShellUiService uiSvc, Project_v1 project, Action<Project_v1> updater) { using (var dlg = new EditProjectDialog()) { Attach(dlg); LoadFieldsFromProject(project); if (uiSvc.ShowModalDialog(dlg) == DialogResult.OK) { updater(CreateProjectFromFields()); return true; } } return false; }
public Project LoadProject(Project_v1 sp) { Program program; if (sp.Input != null && !string.IsNullOrEmpty(sp.Input.Filename)) { var bytes = loader.LoadImageBytes(sp.Input.Filename, 0); // Address.Parse(sp.Input.Address, 16)); program = loader.LoadExecutable(sp.Input.Filename, bytes, null); program.Filename = sp.Input.Filename; } else { program = new Program(); } if (sp.Output != null) { program.DisassemblyFilename = sp.Output.DisassemblyFilename; program.IntermediateFilename = sp.Output.IntermediateFilename; program.OutputFilename = sp.Output.OutputFilename; program.TypesFilename = sp.Output.TypesFilename; program.GlobalsFilename = sp.Output.GlobalsFilename; } program.UserProcedures = sp.UserProcedures .Select(sup => { Address addr; program.Architecture.TryParseAddress(sup.Address, out addr); return(new KeyValuePair <Address, Procedure_v1>(addr, sup)); }) .Where(kv => kv.Key != null) .ToSortedList(kv => kv.Key, kv => kv.Value); foreach (var uc in sp.UserCalls) { Address addr; if (!program.Architecture.TryParseAddress(uc.InstructionAddress, out addr)) { program.UserCalls.Add(addr, uc); } } return(new Project { Programs = { program } }); }
public void SudWrite() { Project_v1 ud = new Project_v1(); ud.Input.Address = "0x1000:0x0"; ud.Output.DisassemblyFilename = "foo.asm"; ud.Output.IntermediateFilename = "foo.cod"; Procedure_v1 proc = new Procedure_v1(); proc.Name = "foo"; proc.Signature = new SerializedSignature { ReturnValue = new Argument_v1 { Kind = new Register_v1("eax") }, Arguments = new Argument_v1[] { new Argument_v1 { Kind = new StackVariable_v1(), Type = new PrimitiveType_v1(Domain.SignedInt, 4) }, new Argument_v1 { Kind = new StackVariable_v1(), Type = new PrimitiveType_v1(Domain.SignedInt, 4) } } }; ud.UserProcedures.Add(proc); using (FileUnitTester fut = new FileUnitTester("Core/SudWrite.txt")) { var writer = new FilteringXmlWriter(fut.TextWriter); writer.Formatting = System.Xml.Formatting.Indented; XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(Project_v1)); ser.Serialize(writer, ud); fut.AssertFilesEqual(); } }
public Project LoadProject(Project_v1 sp) { Program program; if (sp.Input != null && !string.IsNullOrEmpty(sp.Input.Filename)) { var bytes = loader.LoadImageBytes(sp.Input.Filename, 0); // Address.Parse(sp.Input.Address, 16)); program = loader.LoadExecutable(sp.Input.Filename, bytes, null); program.Filename = sp.Input.Filename; } else { program = new Program(); } if (sp.Output != null) { program.DisassemblyFilename = sp.Output.DisassemblyFilename; program.IntermediateFilename = sp.Output.IntermediateFilename; program.OutputFilename = sp.Output.OutputFilename; program.TypesFilename = sp.Output.TypesFilename; program.GlobalsFilename = sp.Output.GlobalsFilename; } program.UserProcedures = sp.UserProcedures .Select(sup => { Address addr; program.Architecture.TryParseAddress(sup.Address, out addr); return new KeyValuePair<Address, Procedure_v1>(addr, sup); }) .Where(kv => kv.Key != null) .ToSortedList(kv => kv.Key, kv => kv.Value); foreach (var uc in sp.UserCalls) { Address addr; if (!program.Architecture.TryParseAddress(uc.InstructionAddress, out addr)) program.UserCalls.Add(addr, uc); } return new Project { Programs = { program } }; }
private Project_v1 CreateTestProject() { var project = new Project_v1(); project.Input.Filename = "test.exe"; project.Input.Address = "10000"; project.Output.DisassemblyFilename = "test.asm"; project.Output.IntermediateFilename = "test.dis"; project.Output.TypesFilename = "test.h"; project.Output.OutputFilename = "test.c"; return project; }
public void Ps_Load_v1() { var bytes = new byte[100]; loader.Stub(l => l.LoadImageBytes(null, 0)).IgnoreArguments().Return(bytes); loader.Stub(l => l.LoadExecutable(null, null, null)).IgnoreArguments().Return( new Program { Architecture = arch }); mr.ReplayAll(); var sp = new Project_v1 { Input = new DecompilerInput_v1 { Filename = "f.exe", }, UserProcedures = { new Procedure_v1 { Name = "Fn", Decompile = true, Characteristics = new ProcedureCharacteristics { Terminates = true, }, Address = "113300", Signature = new SerializedSignature { ReturnValue = new Argument_v1 { Type = new PrimitiveType_v1(Domain.SignedInt, 4), }, Arguments = new Argument_v1[] { new Argument_v1 { Name = "a", Kind = new StackVariable_v1(), Type = new PrimitiveType_v1(Domain.Character, 2) }, new Argument_v1 { Name = "b", Kind = new StackVariable_v1(), Type = new PointerType_v1 { DataType = new PrimitiveType_v1(Domain.Character, 2) } } } } } } }; var ps = new ProjectLoader(loader); var p = ps.LoadProject(sp); Assert.AreEqual(1, p.Programs.Count); var inputFile = p.Programs[0]; Assert.AreEqual(1, inputFile.UserProcedures.Count); Assert.AreEqual("Fn", inputFile.UserProcedures.First().Value.Name); }
private void LoadFieldsFromProject(Project_v1 project) { dlg.BinaryFilename.Text = project.Input.Filename; dlg.BaseAddress.Text = project.Input.Address; dlg.Disassembly.Text = project.Output.DisassemblyFilename; dlg.IntermediateFilename.Text = project.Output.IntermediateFilename; dlg.TypesFilename.Text = project.Output.TypesFilename; dlg.OutputFilename.Text = project.Output.OutputFilename; // dlg.OutputFilename.Text = project.Output.GloblalsFilename }
private Project_v1 CreateProjectFromFields() { Project_v1 project = new Project_v1(); project.Input.Filename = dlg.BinaryFilename.Text; project.Input.Address = dlg.BaseAddress.Text; project.Output.DisassemblyFilename = dlg.Disassembly.Text; project.Output.IntermediateFilename = dlg.IntermediateFilename.Text; project.Output.TypesFilename = dlg.TypesFilename.Text; project.Output.OutputFilename = dlg.OutputFilename.Text; //project.Output.GloblalsFilename = dlg.OutputFilename.Text; return project; }