상속: ProcedureBase_v1
예제 #1
0
        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);
        }
예제 #2
0
 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;
     }
 }
예제 #3
0
 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];
     }
 }
예제 #5
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);
 }
예제 #7
0
        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);
        }
예제 #8
0
 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;
     }
 }
예제 #9
0
파일: Program.cs 프로젝트: Godzil/reko
 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);
 }
예제 #10
0
파일: ProjectLoader.cs 프로젝트: ntzwq/reko
 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);
 }
예제 #11
0
        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();
        }
예제 #12
0
 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;
         }
     }
 }
예제 #13
0
		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();
			}
		}
예제 #14
0
        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();
        }
예제 #15
0
 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;
 }
예제 #16
0
파일: Scanner.cs 프로젝트: uxmal/reko
 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;
 }
예제 #17
0
파일: Scanner.cs 프로젝트: uxmal/reko
 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;
 }
예제 #18
0
파일: Scanner.cs 프로젝트: MavenRain/reko
 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)
 {
 }
예제 #21
0
		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;
		}
예제 #22
0
파일: Program.cs 프로젝트: MavenRain/reko
 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;
 }
예제 #23
0
파일: Scanner.cs 프로젝트: uxmal/reko
 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));
 }
예제 #24
0
 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;
 }
예제 #25
0
파일: Program.cs 프로젝트: relaxar/reko
 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;
 }
예제 #26
0
 public ProcedureDialogInteractor(Program program, Procedure_v1 proc)
 {
     this.program = program;
     this.proc = proc;
 }