Example #1
0
        public override void Build(X86Assembler m)
        {
            m.i86();
            // A straight-forward factorial function + a driver program to ensure the return value
            // is USE'd.

            m.Mov(cx, 0x100);
            m.Push(cx);
            m.Call("factorial");
            m.Add(Registers.sp, 2);
            m.Mov(m.WordPtr(0x0100), ax);
            m.Ret();

            m.Proc("factorial");
            m.Push(bp);
            m.Mov(bp, sp);

            m.Mov(ax, m.WordPtr(bp, 4));
            m.Dec(ax);
            m.Jz("base_case");

            m.Push(ax);
            m.Call("factorial");
            m.Inc(sp);
            m.Inc(sp);
            m.Mov(dx, m.WordPtr(bp, 4));
            m.Imul(dx);
            m.Jmp("done");

            m.Label("base_case");
            m.Mov(ax, 1);

            m.Label("done");
            m.Pop(bp);
            m.Ret();
            m.Endp("factorial");
        }
Example #2
0
        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);
        }
Example #3
0
        public void Scanner_CallGraphTree()
        {
            program = new Program();
            var addr = Address.SegPtr(0xC00, 0);
            var m = new X86Assembler(sc, new DefaultPlatform(sc, new X86ArchitectureReal()), addr, new List<ImageSymbol>());
            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");

            program = m.GetImage();
            program.Platform = new FakePlatform(null, arch);
            Given_Project();

            var scan = new Scanner(
                program, 
                new ImportResolver(project, program, eventListener),
                sc);
            var sym = new ImageSymbol(addr);
            scan.EnqueueImageSymbol(sym, true);
            scan.ScanImage();

            Assert.AreEqual(4, program.Procedures.Count);
        }