コード例 #1
0
ファイル: TypingTestBase.cs プロジェクト: gitter-badger/reko
		protected Program RewriteFile(string relativePath, Address addrBase)
		{
            var sc = new ServiceContainer();
            var config = new FakeDecompilerConfiguration();
            sc.AddService<IConfigurationService>(config);
            sc.AddService<DecompilerHost>(new FakeDecompilerHost());
            sc.AddService<DecompilerEventListener>(new FakeDecompilerEventListener());
            sc.AddService<IFileSystemService>(new FileSystemServiceImpl());
            ILoader ldr = new Loader(sc);
            var program = ldr.AssembleExecutable(
                FileUnitTester.MapTestPath(relativePath),
                new X86TextAssembler(sc, new IntelArchitecture(ProcessorMode.Real)),
                addrBase);
            program.Platform = new DefaultPlatform(sc, program.Architecture);
            var ep = new EntryPoint(program.Image.BaseAddress, program.Architecture.CreateProcessorState());
            var project = new Project { Programs = { program } };
            var scan = new Scanner(
                program,
                new Dictionary<Address, ProcedureSignature>(),
                new ImportResolver(project),
                sc);
			scan.EnqueueEntryPoint(ep);
			scan.ScanImage();

			var dfa = new DataFlowAnalysis(program, new FakeDecompilerEventListener());
			dfa.AnalyzeProgram();
            return program;
		}
コード例 #2
0
ファイル: RewriterTests.cs プロジェクト: gh0std4ncer/reko
 private void DoRewriteCore()
 {
     Project project = LoadProject();
     project.Programs.Add(prog);
     scanner = new Scanner(prog, new Dictionary<Address, ProcedureSignature>(),
         new ImportResolver(project),
         new FakeDecompilerEventListener());
     EntryPoint ep = new EntryPoint(baseAddress, prog.Architecture.CreateProcessorState());
     scanner.EnqueueEntryPoint(ep);
     var program =  project.Programs[0];
     foreach (Procedure_v1 sp in program.UserProcedures.Values)
     {
         scanner.EnqueueUserProcedure(sp);
     }
     scanner.ScanImage();
 }
コード例 #3
0
ファイル: TypingTestBase.cs プロジェクト: gh0std4ncer/reko
        protected void RunHexTest(string hexFile, string outputFile)
        {
            var svc = new ServiceContainer();
            var cfg = new FakeDecompilerConfiguration();
            svc.AddService<IConfigurationService>(cfg);
            ILoader ldr = new Loader(svc);
            var imgLoader = new DchexLoader(FileUnitTester.MapTestPath( hexFile), svc, null);
            var img = imgLoader.Load(null);
            var program = new Program(img.Image, img.Image.CreateImageMap(), img.Architecture, img.Platform);
            var project = new Project { Programs = { program } };
            var ep = new EntryPoint(program.Image.BaseAddress, program.Architecture.CreateProcessorState());
            var scan = new Scanner(program, new Dictionary<Address, ProcedureSignature>(), new ImportResolver(project), new FakeDecompilerEventListener());
            scan.EnqueueEntryPoint(ep);
            scan.ScanImage();

            var dfa = new DataFlowAnalysis(program, new FakeDecompilerEventListener());
            dfa.AnalyzeProgram();
            RunTest(program, outputFile);
        }
コード例 #4
0
ファイル: ScannerTests.cs プロジェクト: gitter-badger/reko
        public void Scanner_CallGraphTree()
        {
            Program prog = new Program();
            var addr = Address.SegPtr(0xC00, 0);
            var m = new X86Assembler(sc, new DefaultPlatform(sc, new X86ArchitectureReal()), addr, new List<EntryPoint>());
            m.i86();

            m.Proc("main");
            m.Call("baz");
            m.Ret();
            m.Endp("main");

            m.Proc("foo");
            m.Ret();
            m.Endp("foo");

            m.Proc("bar");
            m.Ret();
            m.Endp("bar");

            m.Proc("baz");
            m.Call("foo");
            m.Call("bar");
            m.Jmp("foo");
            m.Endp("baz");

            var lr = m.GetImage();
            prog.Image = lr.Image;
            prog.ImageMap = lr.ImageMap;
            prog.Architecture = lr.Architecture;
            prog.Platform = new FakePlatform(null, arch);
            var proj = new Project { Programs = { prog } };
            var scan = new Scanner(prog, new Dictionary<Address, ProcedureSignature>(), new ImportResolver(proj), sc);
            EntryPoint ep = new EntryPoint(addr, prog.Architecture.CreateProcessorState());
            scan.EnqueueEntryPoint(ep);
            scan.ScanImage();

            Assert.AreEqual(4, prog.Procedures.Count);
        }
コード例 #5
0
ファイル: ScannerTests.cs プロジェクト: gitter-badger/reko
 private void BuildX86RealTest(Action<X86Assembler> test)
 {
     var addr = Address.SegPtr(0x0C00, 0);
     var m = new X86Assembler(sc, new FakePlatform(null, new X86ArchitectureReal()), addr, new List<EntryPoint>());
     test(m);
     var lr = m.GetImage();
     program = new Program(
         lr.Image,
         lr.ImageMap,
         lr.Architecture,
         lr.Platform);
     scan = CreateScanner(program);
     EntryPoint ep = new EntryPoint(addr, program.Architecture.CreateProcessorState());
     scan.EnqueueEntryPoint(ep);
 }
コード例 #6
0
ファイル: NeImageLoader.cs プロジェクト: nemerle/reko
 public List<EntryPoint> LoadEntryPoints(Dictionary<int, string> names)
 {
     var rdr = new LeImageReader(RawImage, this.lfaNew + this.offEntryTable);
     var entries = new List<EntryPoint>();
     for (;;)
     {
         var cEntries = rdr.ReadByte();
         if (cEntries == 0)
             break;
         var segNum = rdr.ReadByte();
         var seg = this.segments[segNum - 1];
         for (int i = 0; i < cEntries; ++i)
         {
             var flags = rdr.ReadByte();
             var offset = rdr.ReadUInt16();
             string name;
             var addr = seg.Address + offset;
             var state = arch.CreateProcessorState();
             EntryPoint ep;
             if (names.TryGetValue(entries.Count, out name))
             {
                 ep = new EntryPoint(addr, name, state);
             }
             else
             {
                 ep = new EntryPoint(addr, state);
             }
             entries.Add(ep);
         }
     }
     return entries;
 }
コード例 #7
0
ファイル: ElfImageLoader.cs プロジェクト: gitter-badger/reko
 public override RelocationResults Relocate(Program program, Address addrLoad)
 {
     if (image == null)
         throw new InvalidOperationException(); // No file loaded
     var entryPoints = new List<EntryPoint>();
     var relocations = new RelocationDictionary();
     var addrEntry = GetEntryPointAddress();
     if (addrEntry != null)
     {
         var ep = new EntryPoint(addrEntry, arch.CreateProcessorState());
         entryPoints.Add(ep);
     }
     if (fileClass == ELFCLASS64)
     {
         if (Header64.e_machine == EM_PPC64)
         {
             //$TODO
         }
         else if (Header64.e_machine == EM_X86_64)
         {
             RelocateX86_64();
         }
         else
             throw new NotImplementedException(string.Format("Relocations for architecture {0} not implemented.", Header64.e_machine));
     }
     else
     {
         switch (Header32.e_machine)
         {
         case EM_386:
             RelocateI386();
             break;
         case EM_PPC:
             RelocatePpc32();
             break;
         case EM_MIPS:
         case EM_ARM:
             break;
         default:
             throw new NotImplementedException();
         }
     }
     return new RelocationResults(entryPoints, relocations, new List<Address>());
 }
コード例 #8
0
 public EntryPointWorkitem(IScanner scanner, Program program, EntryPoint ep)
 {
     this.scanner = scanner;
     this.program = program;
     this.ep = ep;
 }
コード例 #9
0
ファイル: ElfImageLoader.cs プロジェクト: melbcat/reko
 public override RelocationResults Relocate(Address addrLoad)
 {
     if (image == null)
         throw new InvalidOperationException(); // No file loaded
     List<EntryPoint> entryPoints = new List<EntryPoint>();
     RelocationDictionary relocations = new RelocationDictionary();
     var addrEntry = GetEntryPointAddress();
     if (addrEntry != null)
     {
         var ep = new EntryPoint(addrEntry, arch.CreateProcessorState());
         entryPoints.Add(ep);
     }
     if (fileClass == ELFCLASS64)
     {
         if (Header64.e_machine == EM_PPC64)
         {
             //$TODO
         }
         else
             throw new NotImplementedException(string.Format("Relocations for architecture {0} not implemented.", Header64.e_machine));
     }
     else
     {
         if (Header32.e_machine == EM_386)
         {
             RelocateI386();
         }
         else if (Header32.e_machine == EM_PPC)
         {
             RelocatePpc32();
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     return new RelocationResults(entryPoints, relocations);
 }
コード例 #10
0
ファイル: RewriterTests.cs プロジェクト: gitter-badger/reko
        private void DoRewriteCore()
        {
            var cfgSvc = MockRepository.GenerateStub<IConfigurationService>();
            var env = MockRepository.GenerateStub<OperatingEnvironment>();
            var tlSvc = MockRepository.GenerateStub<ITypeLibraryLoaderService>();
            cfgSvc.Stub(c => c.GetEnvironment("ms-dos")).Return(env);
            cfgSvc.Replay();
            env.Stub(e => e.TypeLibraries).Return(new TypeLibraryElementCollection());
            env.CharacteristicsLibraries = new TypeLibraryElementCollection();
            env.Replay();
            tlSvc.Replay();
            sc.AddService<DecompilerHost>(new FakeDecompilerHost());
            sc.AddService<DecompilerEventListener>(new FakeDecompilerEventListener());
            sc.AddService<IConfigurationService>(cfgSvc);
            sc.AddService<ITypeLibraryLoaderService>(tlSvc);

            Project project = LoadProject();
            project.Programs.Add(this.program);
            scanner = new Scanner(this.program, new Dictionary<Address, ProcedureSignature>(),
                new ImportResolver(project),
                sc);
            EntryPoint ep = new EntryPoint(baseAddress, this.program.Architecture.CreateProcessorState());
            scanner.EnqueueEntryPoint(ep);
            var program =  project.Programs[0];
            foreach (Procedure_v1 sp in program.User.Procedures.Values)
            {
                scanner.EnqueueUserProcedure(sp);
            }
            scanner.ScanImage();
        }
コード例 #11
0
ファイル: Scanner.cs プロジェクト: MavenRain/reko
 public void EnqueueEntryPoint(EntryPoint ep)
 {
     queue.Enqueue(PriorityEntryPoint, new EntryPointWorkitem(this, program, ep));
 }