private UserProcedure?LoadUserProcedure( Program program, Procedure_v1 sup) { if (!program.Architecture.TryParseAddress(sup.Address, out Address addr)) { return(null); } if (!sup.Decompile && sup.Signature == null && string.IsNullOrEmpty(sup.CSignature)) { listener.Warn( listener.CreateAddressNavigator(program, addr), "User procedure '{0}' has been marked 'no decompile' but its signature " + "has not been specified.", sup.Name ?? "<unnamed>"); } string name = sup.Name ?? NamingPolicy.Instance.ProcedureName(addr); var up = new UserProcedure(addr, name) { Ordinal = sup.Ordinal, Signature = sup.Signature, Characteristics = sup.Characteristics ?? new ProcedureCharacteristics(), Decompile = sup.Decompile, Assume = sup.Assume?.ToList() ?? new List <RegisterValue_v2>(), CSignature = sup.CSignature, OutputFile = sup.OutputFile }; return(up); }
private string GuessName(Procedure_v1 userProc, Procedure proc = null) { if (userProc != null) { if (!string.IsNullOrEmpty(userProc.Name)) return userProc.Name; if (!string.IsNullOrEmpty(userProc.CSignature)) { int i = userProc.CSignature.IndexOf('('); if (i > 0) { var name = userProc.CSignature.Remove(i); do { --i; } while (i > 0 && (char.IsLetterOrDigit(name[i]) || name[i] == '_')); return name.Substring(i + 1); } } } if (proc != null) { return proc.Name; } else { return null; } }
public ProcedureBase_v1 DeserializeSignature(Procedure_v1 userProc, Procedure proc) { if (!string.IsNullOrEmpty(userProc.CSignature)) { return ParseFunctionDeclaration(userProc.CSignature, proc.Frame); } return null; }
public ProcedureDialogInteractor(IProcessorArchitecture arch, Procedure_v1 proc) { this.arch = arch; this.proc = proc; if (proc.Signature != null && proc.Signature.Arguments == null) { proc.Signature.Arguments = new Argument_v1[0]; } }
public Procedure_v1 Serialize(Procedure proc, Address addr) { var sproc = new Procedure_v1 { Address = addr.ToString(), Name = proc.Name, Signature = Serialize(proc.Signature), }; return(sproc); }
public void Setup() { proc = new Procedure_v1(); var arch = new X86ArchitectureFlat32(); var platform = new Win32Platform(null, arch); var program = new Program { Architecture = arch, Platform = platform }; interactor = new ProcedureDialogInteractor(program, proc); }
public Procedure_v1 Serialize(Procedure proc, Address addr) { Procedure_v1 sproc = new Procedure_v1(); sproc.Address = addr.ToString(); sproc.Name = proc.Name; if (proc.Signature != null) { sproc.Signature = Serialize(proc.Signature); } return(sproc); }
public void Add(Procedure proc, Procedure_v1 userProc = null) { ++procCount; var addr = Address.Ptr32(procCount * 0x1000u); Program.Procedures[addr] = proc; Program.CallGraph.AddProcedure(proc); nameToProcedure[GuessName(userProc, proc)] = proc; if (userProc != null) { Program.User.Procedures[addr] = userProc; } }
public Serialization.Procedure_v1 EnsureUserProcedure(Address address, string name) { Serialization.Procedure_v1 up; if (!User.Procedures.TryGetValue(address, out up)) { up = new Serialization.Procedure_v1 { Address = address.ToString(), Name = name, }; User.Procedures.Add(address, up); } return(up); }
private KeyValuePair<Address, Procedure_v1> LoadUserProcedure_v1( Program program, Procedure_v1 sup) { program.Architecture.TryParseAddress(sup.Address, out Address addr); if (!sup.Decompile && sup.Signature == null && string.IsNullOrEmpty(sup.CSignature)) { listener.Warn( listener.CreateAddressNavigator(program, addr), "User procedure '{0}' has been marked 'no decompile' but its signature " + "has not been specified.", sup.Name ?? "<unnamed>"); } return new KeyValuePair<Address, Procedure_v1>(addr, sup); }
public void Mfi_Save() { Given_Loader(); Given_MainFormInteractor(); Given_LoadPreferences(); Given_DecompilerInstance(); Given_XmlWriter(); fsSvc.Stub(f => f.MakeRelativePath("foo.dcproject", "foo.exe")).Return("foo.exe"); fsSvc.Stub(f => f.MakeRelativePath(Arg <string> .Is.Equal("foo.dcproject"), Arg <string> .Is.Null)).Return(null); mr.ReplayAll(); When_CreateMainFormInteractor(); Assert.IsNotNull(loader); dcSvc.Decompiler.Load("foo.exe"); var p = new Reko.Core.Serialization.Procedure_v1 { Address = "12345", Name = "MyProc", }; var program = dcSvc.Decompiler.Project.Programs[0]; program.User.Procedures.Add(Address.Ptr32(0x12345), p); program.User.Heuristics.Add("shingle"); interactor.Save(); string s = @"<?xml version=""1.0"" encoding=""utf-8""?> <project xmlns=""http://schemata.jklnet.org/Reko/v4""> <arch>x86-protected-32</arch> <platform>TestPlatform</platform> <input> <filename>foo.exe</filename> <user> <processor /> <procedure name=""MyProc""> <address>00012345</address> </procedure> <heuristic name=""shingle"" /> <registerValues /> </user> </input> </project>"; Assert.AreEqual(s, Encoding.UTF8.GetString(xmlStm.ToArray())); mr.VerifyAll(); }
public override void DoIt() { var dlgFactory = Services.RequireService<IDialogFactory>(); var uiSvc = Services.RequireService<IDecompilerShellUiService>(); Procedure_v1 sProc; if (!program.User.Procedures.TryGetValue(address, out sProc)) sProc = new Procedure_v1 { Name = procedure.Name }; using (IProcedureDialog dlg = dlgFactory.CreateProcedureDialog(program, sProc)) { if (DialogResult.OK == uiSvc.ShowModalDialog(dlg)) { dlg.ApplyChanges(); program.User.Procedures[address] = sProc; if (procedure != null) procedure.Name = sProc.Name; } } }
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 void Mfi_Save() { Given_Loader(); Given_MainFormInteractor(); Given_LoadPreferences(); Given_DecompilerInstance(); mr.ReplayAll(); When_CreateMainFormInteractor(); Assert.IsNotNull(loader); dcSvc.Decompiler.Load("foo.exe"); var p = new Reko.Core.Serialization.Procedure_v1 { Address = "12345", Name = "MyProc", }; var program = dcSvc.Decompiler.Project.Programs[0]; program.UserProcedures.Add(Address.Ptr32(0x12345), p); interactor.Save(); string s = @"<?xml version=""1.0"" encoding=""utf-16""?> <project xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://schemata.jklnet.org/Decompiler/v2""> <input> <filename>foo.exe</filename> <address>00010000</address> <procedure name=""MyProc""> <address>00012345</address> </procedure> <options> <HeuristicScanning>false</HeuristicScanning> </options> </input> <output /> </project>"; Assert.AreEqual(s, interactor.Test_SavedProjectXml); mr.VerifyAll(); }
public Procedure Add(Procedure_v1 userProc, Action<ProcedureBuilder> testCodeBuilder) { var mock = new ProcedureBuilder(Program.Architecture, GuessName(userProc), null); mock.ProgramMock = this; mock.LinearAddress = (uint)((procCount + 1) * 0x1000); testCodeBuilder(mock); Add(mock.Procedure, userProc); unresolvedProcedures.AddRange(mock.UnresolvedProcedures); return mock.Procedure; }
private bool TryGetNoDecompiledProcedure(Address addr, out Procedure_v1 sProc) { if (!program.User.Procedures.TryGetValue(addr, out sProc) || sProc.Decompile) { sProc = null; return false; } return true; }
private bool TryGetNoDecompiledParsedProcedure(Address addr, out Procedure_v1 parsedProc) { Procedure_v1 sProc; if (!TryGetNoDecompiledProcedure(addr, out sProc)) { parsedProc = null; return false; } if (noDecompiledProcs.TryGetValue(addr, out parsedProc)) return true; parsedProc = new Procedure_v1() { Name = sProc.Name, }; noDecompiledProcs[addr] = parsedProc; if (string.IsNullOrEmpty(sProc.CSignature)) { Warn(addr, "The user-defined procedure at address {0} did not have a signature.", addr); return true; } var usb = new UserSignatureBuilder(program); var procDecl = usb.ParseFunctionDeclaration(sProc.CSignature); if (procDecl == null) { Warn(addr, "The user-defined procedure signature at address {0} could not be parsed.", addr); return true; } parsedProc.Signature = procDecl.Signature; return true; }
public void EnqueueUserProcedure(Procedure_v1 sp) { Address addr; if (!program.Architecture.TryParseAddress(sp.Address, out addr)) return; var proc = EnsureProcedure(addr, sp.Name); if (sp.Signature != null) { var sser = program.Platform.CreateProcedureSerializer( new TypeLibraryLoader(program.Platform, true), program.Platform.DefaultCallingConvention); proc.Signature = sser.Deserialize(sp.Signature, proc.Frame); } if (sp.Characteristics != null) { proc.Characteristics = sp.Characteristics; } queue.Enqueue(PriorityEntryPoint, new ProcedureWorkItem(this, program, addr, sp.Name)); }
public void Setup() { proc = new Procedure_v1(); interactor = new TestProcedureDialogInteractor(proc); }
public TestProcedureDialogInteractor(Procedure_v1 proc) : base(new IntelArchitecture(ProcessorMode.Protected32), proc) { }
private Procedure_v1 MkMalloc() { Procedure_v1 proc = new Procedure_v1 { Name = "malloc", Signature = new SerializedSignature { Convention = "cdecl", ReturnValue = new Argument_v1 { Kind = new Register_v1("eax"), }, Arguments = new Argument_v1[] { new Argument_v1 { Name = "cb", Kind = new StackVariable_v1(), } } } }; return proc; }
public Serialization.Procedure_v1 EnsureUserProcedure(Address address, string name) { Serialization.Procedure_v1 up; if (!UserProcedures.TryGetValue(address, out up)) { up = new Serialization.Procedure_v1 { Address = address.ToString(), Name = name, }; UserProcedures.Add(address, up); } return up; }
public void EnqueueUserProcedure(Procedure_v1 sp) { Address addr; if (!program.Architecture.TryParseAddress(sp.Address, out addr)) return; Procedure proc; if (program.Procedures.TryGetValue(addr, out proc)) return; // Already scanned. Do nothing. if (!sp.Decompile) return; proc = EnsureProcedure(addr, sp.Name); if (sp.Signature != null) { var sser = program.CreateProcedureSerializer(); proc.Signature = sser.Deserialize(sp.Signature, proc.Frame); } if (sp.Characteristics != null) { proc.Characteristics = sp.Characteristics; } queue.Enqueue(PriorityEntryPoint, new ProcedureWorkItem(this, program, addr, sp.Name)); }
public Procedure_v1 Serialize(Procedure proc, Address addr) { Procedure_v1 sproc = new Procedure_v1(); sproc.Address = addr.ToString(); sproc.Name = proc.Name; if (proc.Signature != null) sproc.Signature = Serialize(proc.Signature); return sproc; }
public Procedure_v1 EnsureUserProcedure(Address address, string name, bool decompile = true) { Procedure_v1 up; if (!User.Procedures.TryGetValue(address, out up)) { up = new Procedure_v1 { Address = address.ToString(), Name = name, Decompile = decompile, }; User.Procedures.Add(address, up); } return up; }
public ProcedureDialogInteractor(Program program, Procedure_v1 proc) { this.program = program; this.proc = proc; }