Ejemplo n.º 1
0
		protected Program RewriteFile(string relativePath, Address addrBase)
		{
            var services = new ServiceContainer();
            var config = new FakeDecompilerConfiguration();
            services.AddService<IConfigurationService>(config);
            ILoader ldr = new Loader(services);
            var program = ldr.AssembleExecutable(
                FileUnitTester.MapTestPath(relativePath),
                new X86TextAssembler(new IntelArchitecture(ProcessorMode.Real)),
                addrBase);
            program.Platform = new DefaultPlatform(services, 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),
                new FakeDecompilerEventListener());
			scan.EnqueueEntryPoint(ep);
			scan.ScanImage();

			var dfa = new DataFlowAnalysis(program, new FakeDecompilerEventListener());
			dfa.AnalyzeProgram();
            return program;
		}
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public void EnqueueEntryPoint(EntryPoint ep)
 {
     queue.Enqueue(PriorityEntryPoint, new EntryPointWorkitem(this, program, ep));
 }
Ejemplo n.º 4
0
 public override RelocationResults Relocate(Address addrLoad)
 {
     if (image == null)
         throw new InvalidOperationException(); // No file loaded
     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
     {
         switch (Header32.e_machine)
         {
         case EM_386: RelocateI386(); break;
         case EM_PPC: RelocatePpc32(); break;
         case EM_ARM: RelocateArm(); break;
         default: throw new NotImplementedException(string.Format("ELF relocation for {0} is not implemented yet.", arch.GetType().Name));
         }
     }
     return new RelocationResults(entryPoints, relocations);
 }
Ejemplo n.º 5
0
 private void BuildX86RealTest(Action<X86Assembler> test)
 {
     var addr = Address.SegPtr(0x0C00, 0);
     var m = new X86Assembler(new IntelArchitecture(ProcessorMode.Real), addr, new List<EntryPoint>());
     test(m);
     var lr = m.GetImage();
     program = new Program(
         lr.Image,
         lr.ImageMap,
         lr.Architecture,
         new FakePlatform(null, arch));
     scan = CreateScanner(program);
     EntryPoint ep = new EntryPoint(addr, program.Architecture.CreateProcessorState());
     scan.EnqueueEntryPoint(ep);
 }
Ejemplo n.º 6
0
        public void Scanner_CallGraphTree()
        {
            Program prog = new Program();
            var addr = Address.SegPtr(0xC00, 0);
            var m = new X86Assembler(new IntelArchitecture(ProcessorMode.Real), 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), new FakeDecompilerEventListener());
            EntryPoint ep = new EntryPoint(addr, prog.Architecture.CreateProcessorState());
            scan.EnqueueEntryPoint(ep);
            scan.ScanImage();

            Assert.AreEqual(4, prog.Procedures.Count);
        }
Ejemplo n.º 7
0
 public EntryPointWorkitem(IScanner scanner, Program program, EntryPoint ep)
 {
     this.scanner = scanner;
     this.program = program;
     this.ep = ep;
 }