Contains the non-global locations accessed by the code inside a procedure.
Variables accessed by the procedure can live in many places: registers, stack, and temporaries.

The frame layout is particularly interesting. On the Intel x86 architecture in real mode we have the following:

Layout offset value +-----------------+ | arg3 | 6 +-----------------+ | arg2 | 4 +-----------------+ | arg1 | 2 +-----------------+ | return address | 0 +-----------------+ | frame pointer | -2 +-----------------+ | local1 | -4 +-----------------+ | local2 | -6 etc.

Note that variables that are stack arguments use offsets based on the state of stack _after_ the return address was pushed. The return address, if passed on the stack, is always considered to be at offset 0.

In addition, support has to be provided for architectures that have separate FPU stacks.

Пример #1
0
 public void Setup()
 {
     f = new Frame(PrimitiveType.Word16);
     argOff = f.EnsureStackArgument(4, PrimitiveType.Word16);
     argSeg = f.EnsureStackArgument(6, PrimitiveType.SegmentSelector);
     arg_alias = f.EnsureStackArgument(4, PrimitiveType.Pointer32);
 }
Пример #2
0
        public void W32Mips_Trampoline()
        {
            var instrs = new List<RtlInstructionCluster>();
            var frame = new Frame(PrimitiveType.Pointer32);
            var r9 = frame.EnsureRegister(new RegisterStorage("r9", 9, PrimitiveType.Word32));
            var rtl = new RtlTrace(0x123460)
            {
                m => m.Assign(r9, 0x00030000),
                m => m.Assign(r9, m.LoadDw(m.IAdd(r9, 0x1234))),
                m => m.Goto(r9)
            };

            var host = mr.Stub<IRewriterHost>();
            var services = mr.Stub<IServiceProvider>();
            var arch = mr.Stub<IProcessorArchitecture>();
            var state = mr.Stub<ProcessorState>();
            var addr = Address.Ptr32(0x00031234);
            arch.Stub(a => a.CreateFrame()).Return(frame);
            arch.Stub(a => a.CreateProcessorState()).Return(state);
            arch.Stub(a => a.CreateRewriter(null, null, null, null)).IgnoreArguments().Return(rtl);
            arch.Stub(a => a.MakeAddressFromConstant(Arg<Constant>.Is.NotNull)).Return(addr);
            host.Stub(h => h.GetImportedProcedure(
                Arg<Address>.Is.Equal(addr),
                Arg<Address>.Is.NotNull)).Return(new ExternalProcedure("foo", new ProcedureSignature()));
            mr.ReplayAll();

            var platform = new Win32MipsPlatform(services, arch);
            var result = platform.GetTrampolineDestination(new LeImageReader(new byte[0]), host);
            Assert.IsNotNull(result);
        }
Пример #3
0
		public void Setup()
		{
            var arch = new IntelArchitecture(ProcessorMode.Protected32);
			f = arch.CreateFrame();
            liveness = new IdentifierLiveness(arch);
			isLiveHelper = new RegisterLiveness.IsLiveHelper(arch);
		}
Пример #4
0
		public void Setup()
		{
            var arch = new X86ArchitectureFlat32();
			f = arch.CreateFrame();
            liveness = new IdentifierLiveness(arch);
			isLiveHelper = new RegisterLiveness.IsLiveHelper(arch);
		}
Пример #5
0
 private BlockFlow CreateBlockFlow(Block block, Frame frame)
 {
     return new BlockFlow(
         block,
         prog.Architecture.CreateRegisterBitset(),
         new SymbolicEvaluationContext(prog.Architecture, frame));
 }
Пример #6
0
        public override FunctionType Deserialize(SerializedSignature ss, Frame frame)
        {
            if (ss == null)
                return new FunctionType();
            if (ss == null)
                return null;
            var argser = new ArgumentDeserializer(this, Architecture, frame, 0, Architecture.WordWidth.Size);
            Identifier ret = null;

            if (ss.ReturnValue != null)
            {
                ret = argser.DeserializeReturnValue(ss.ReturnValue);
            }

            var args = new List<Identifier>();
            this.gr = 0;
            if (ss.Arguments != null)
            {
                for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg)
                {
                    var sArg = ss.Arguments[iArg];
                    Identifier arg = DeserializeArgument(argser, sArg);
                    args.Add(arg);
                }
            }

            var sig = new FunctionType(ret, args.ToArray());
            return sig;
        }
 private BlockFlow CreateBlockFlow(Block block, Frame frame)
 {
     return new BlockFlow(
         block,
         new HashSet<RegisterStorage>(),
         new SymbolicEvaluationContext(program.Architecture, frame));
 }
Пример #8
0
 public RtlStatementStream(uint address, Frame frame)
 {
     this.linAddress = address;
     this.arch = new FakeArchitecture();
     this.frame = frame;
     this.stms = new List<RtlInstructionCluster>();
 }
Пример #9
0
 public void Setup()
 {
     this.mr = new MockRepository();
     this.fsSvc = mr.StrictMock<IFileSystemService>();
     this.tllSvc = mr.Stub<ITypeLibraryLoaderService>();
     this.services = mr.StrictMock<IServiceProvider>();
     var cfgSvc = mr.Stub<IConfigurationService>();
     var env = mr.Stub<OperatingEnvironment>();
     this.arch = new M68kArchitecture();
     this.rtls = new List<RtlInstruction>();
     this.m = new RtlEmitter(rtls);
     cfgSvc.Stub(c => c.GetEnvironment("amigaOS")).Return(env);
     env.Stub(e => e.TypeLibraries).Return(new List<ITypeLibraryElement>());
     env.Stub(e => e.CharacteristicsLibraries).Return(new List<ITypeLibraryElement>());
     env.Stub(e => e.Options).Return(new Dictionary<string, object>
     {
         { "versionDependentLibraries", new Dictionary<string,object>
             {
                 { "33", new List<object> { "exec_v33", "dos_v33" } },
                 { "34", new List<object> { "exec_v34", "dos_v34" } },
             }
         }
     });
     this.services.Stub(s => s.GetService(typeof(IConfigurationService))).Return(cfgSvc);
     this.services.Stub(s => s.GetService(typeof(IFileSystemService))).Return(fsSvc);
     this.services.Stub(s => s.GetService(typeof(ITypeLibraryLoaderService))).Return(tllSvc);
     this.frame = new Frame(arch.FramePointerType);
 }
Пример #10
0
        public override ProcedureSignature Deserialize(SerializedSignature ss, Frame frame)
        {
            if (ss == null)
                return null;
            this.argser = new ArgumentSerializer(this, Architecture, frame, ss.Convention);
            Identifier ret = null;
            int fpuDelta = FpuStackOffset;

            FpuStackOffset = 0;
            if (ss.ReturnValue != null)
            {
                ret = argser.DeserializeReturnValue(ss.ReturnValue);
                fpuDelta += FpuStackOffset;
            }

            FpuStackOffset = 0;
            var args = new List<Identifier>();
            if (ss.Arguments != null)
            {
                for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg)
                {
                    var sArg = ss.Arguments[iArg];
                    var arg = DeserializeArgument(sArg, iArg, ss.Convention);
                    args.Add(arg);
                }
                fpuDelta -= FpuStackOffset;
            }
            FpuStackOffset = fpuDelta;

            var sig = new ProcedureSignature(ret, args.ToArray());
            ApplyConvention(ss, sig);
            return sig;
        }
Пример #11
0
        public override ProcedureSignature Deserialize(SerializedSignature ss, Frame frame)
        {
            if (ss == null)
                return null;
            var argser = new ArgumentSerializer(this, Architecture, frame, ss.Convention);
            Identifier ret = null;

            if (ss.ReturnValue != null)
            {
                ret = argser.DeserializeReturnValue(ss.ReturnValue);
            }

            var args = new List<Identifier>();
            if (ss.Arguments != null)
            {
                for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg)
                {
                    var sArg = ss.Arguments[iArg];
                    Identifier arg = argser.Deserialize(sArg);
                    args.Add(arg);
                }
            }

            var sig = new ProcedureSignature(ret, args.ToArray());
            return sig;
        }
Пример #12
0
 public OperandRewriter(IntelArchitecture arch, ExpressionEmitter emitter, Frame frame, IRewriterHost host)
 {
     this.arch = arch;
     this.m = emitter;
     this.frame = frame;
     this.host = host;
 }
Пример #13
0
 public OperandRewriter(M68kArchitecture arch, RtlEmitter emitter, Frame frame, PrimitiveType dataWidth)
 {
     this.arch = arch;
     this.m = emitter;
     this.frame = frame;
     this.DataWidth = dataWidth;
 }
Пример #14
0
 protected override IEnumerable<RtlInstructionCluster> GetInstructionStream(Frame frame, IRewriterHost host)
 {
     return arch.CreateRewriter(
         new LeImageReader(image, 0),
         arch.CreateProcessorState(),
         frame,
         this.host);
 }
Пример #15
0
		public void Setup()
		{
            arch = new IntelArchitecture(ProcessorMode.Real);
			f = new Frame(PrimitiveType.Word16);
			argOff = f.EnsureStackArgument(4, PrimitiveType.Word16);
			argSeg = f.EnsureStackArgument(6, PrimitiveType.SegmentSelector);
			arg_alias = f.EnsureStackArgument(4, PrimitiveType.Pointer32);
		}
Пример #16
0
 public void EnsureOutRegister()
 {
     Frame f = new Frame(PrimitiveType.Word32);
     Identifier r = f.EnsureRegister(new Mocks.MockMachineRegister("r1", 1, PrimitiveType.Word32));
     Identifier arg = f.EnsureOutArgument(r, PrimitiveType.Pointer32);
     Assert.AreEqual("r1Out", arg.Name);
     Assert.AreSame(PrimitiveType.Pointer32, arg.DataType);
 }
Пример #17
0
		public void RegisterTest()
		{
			Frame f = new Frame(PrimitiveType.Word16);
			Identifier id0 = f.EnsureRegister(Registers.ax);
			Identifier id1 = f.EnsureRegister(Registers.bx);
			Identifier id2 = f.EnsureRegister(Registers.ax);
			Assert.AreEqual(id0, id2);
		}
Пример #18
0
 public override IEnumerable<RtlInstructionCluster> CreateRewriter(ImageReader rdr, ProcessorState state, Frame frame, IRewriterHost host)
 {
     return new MipsRewriter(
         this,
         new MipsDisassembler(this, rdr, IsVersion6OrLater),
         frame,
         host);
 }
Пример #19
0
 public IEnumerable<RtlInstructionCluster> CreateRewriter(ImageReader rdr, ProcessorState state, Frame frame, IRewriterHost host)
 {
     var linAddr = rdr.Address.ToLinear();
     RtlTrace trace;
     if (!rewriters.Traces.TryGetValue(rdr.Address, out trace))
         NUnit.Framework.Assert.Fail(string.Format("Unexpected request for a rewriter at address {0}", rdr.Address));
     return trace;
 }
Пример #20
0
 private void CreateSymbolicEvaluator(Frame frame)
 {
     ctx = new SymbolicEvaluationContext(arch, frame);
     se = new SymbolicEvaluator(ctx);
     if (esp == null)
         esp = Tmp32("esp");
     ctx.SetValue(esp, frame.FramePointer);
 }
Пример #21
0
 protected override IEnumerable<RtlInstructionCluster> GetInstructionStream(Frame frame, IRewriterHost host)
 {
     return new X86Rewriter(
         arch,
         host, 
         new X86State(arch),
         asmResult.SegmentMap.Segments.Values.First().MemoryArea.CreateLeReader(0), frame);
 }
Пример #22
0
        public override FunctionType Deserialize(SerializedSignature ss, Frame frame)
        {
            int ncrn = 0;
            int nsaa = 0;
            // mem arg forb ret val

            var argser = new ArgumentDeserializer(
               this,
               Architecture,
               frame,
               Architecture.PointerType.Size,
               Architecture.WordWidth.Size);

            Identifier ret = null;
            if (ss.ReturnValue != null)
            {
                ret = argser.DeserializeReturnValue(ss.ReturnValue);
            }

            var args = new List<Identifier>();
            if (ss.Arguments != null)
            {
                foreach (var sArg in ss.Arguments)
                {
                    var dt = sArg.Type.Accept(TypeLoader);
                    var sizeInWords = (dt.Size + 3) / 4;

                    if (sizeInWords == 2 && (ncrn & 1) == 1)
                        ++ncrn;
                    Identifier arg;
                    if (sizeInWords <= 4 - ncrn)
                    {
                        if (sizeInWords == 2)
                        {
                            arg = frame.EnsureSequence(
                                Architecture.GetRegister(argRegs[ncrn]),
                                Architecture.GetRegister(argRegs[ncrn + 1]),
                                dt);
                            ncrn += 2;
                        }
                        else
                        {
                            arg = frame.EnsureRegister(
                                Architecture.GetRegister(argRegs[ncrn]));
                            ncrn += 1;
                        }
                    }
                    else
                    {
                        arg = frame.EnsureStackArgument(nsaa, dt);
                        nsaa += AlignedStackArgumentSize(dt);
                    }
                    args.Add(arg);
                }
            }
            return new FunctionType(ret, args.ToArray());
        }
Пример #23
0
        public override FunctionType Deserialize(SerializedSignature ss, Frame frame)
        {
            if (ss == null)
                return null;
            this.argDeser = new ArgumentDeserializer(
                this,
                Architecture,
                frame,
                Architecture.PointerType.Size, //$BUG: x86 real mode?
                Architecture.WordWidth.Size);
            Identifier ret = null;
            int fpuDelta = FpuStackOffset;

            FpuStackOffset = 0;
            if (ss.ReturnValue != null)
            {
                ret = argDeser.DeserializeReturnValue(ss.ReturnValue);
                fpuDelta += FpuStackOffset;
            }

            FpuStackOffset = 0;
            var args = new List<Identifier>();
            if (ss.EnclosingType != null)
            {
                var arg = DeserializeImplicitThisArgument(ss);
                args.Add(arg);
            }
            if (ss.Arguments != null)
            {
                if (ss.Convention == "pascal")
                {
                    for (int iArg = ss.Arguments.Length -1; iArg >= 0; --iArg)
                    {
                        var sArg = ss.Arguments[iArg];
                        var arg = DeserializeArgument(sArg, iArg, ss.Convention);
                        args.Add(arg);
                    }
                    args.Reverse();
                }
                else
                {
                    for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg)
                    {
                        var sArg = ss.Arguments[iArg];
                        var arg = DeserializeArgument(sArg, iArg, ss.Convention);
                        args.Add(arg);
                    }
                }
                fpuDelta -= FpuStackOffset;
            }
            FpuStackOffset = fpuDelta;
            var sig = new FunctionType(ret, args.ToArray());
            sig.IsInstanceMetod = ss.IsInstanceMethod;
            ApplyConvention(ss, sig);
            return sig;
        }
Пример #24
0
 protected override IEnumerable<RtlInstructionCluster> GetInstructionStream(Frame frame, IRewriterHost host)
 {
     var addr = Address.Ptr16(10);
     var image = new LoadedImage(addr, new byte[1]);
     return arch.CreateRewriter(
         arch.CreateImageReader(image, addr),
         arch.CreateProcessorState(),
         frame,
         host);
 }
Пример #25
0
 public void Setup()
 {
     this.mr = new MockRepository();
     this.fsSvc = mr.StrictMock<IFileSystemService>();
     this.services = mr.StrictMock<IServiceProvider>();
     this.arch = new M68kArchitecture();
     this.rtls = new List<RtlInstruction>();
     this.m = new RtlEmitter(rtls);
     this.services.Stub(s => s.GetService(typeof(IFileSystemService))).Return(fsSvc);
     this.frame = new Frame(arch.FramePointerType);
 }
Пример #26
0
 private BlockFlow CreateBlockFlow(Block block, Frame frame)
 {
     var bflow = new BlockFlow(
         block,
         prog.Architecture.CreateRegisterBitset(),
         new SymbolicEvaluationContext(
             prog.Architecture,
             frame));
     flow[block] = bflow;
     return bflow;
 }
Пример #27
0
		public void FrGrfTest()
		{
			IntelArchitecture arch = new IntelArchitecture(ProcessorMode.Real);
			Frame f = new Frame(PrimitiveType.Word16);
			uint iSz = (uint) (FlagM.ZF|FlagM.SF);
			Identifier grfSz = f.EnsureFlagGroup(Registers.eflags, iSz, arch.GrfToString(iSz), PrimitiveType.Byte);
			using (FileUnitTester fut = new FileUnitTester("Core/FrGrfTest.txt"))
			{
				f.Write(fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Пример #28
0
 public VarargsFormatScanner(
     Program program,
     Frame frame,
     EvaluationContext ctx,
     IServiceProvider services)
 {
     this.program = program;
     this.arch = program.Architecture;
     this.frame = frame;
     this.eval = new ExpressionSimplifier(ctx);
     this.services = services;
 }
Пример #29
0
 public ApplicationBuilderTests()
 {
     arch = new IntelArchitecture(ProcessorMode.Protected32);
     frame = arch.CreateFrame();
     ret = frame.EnsureRegister(Registers.eax);
     arg04 = new Identifier("arg04",   PrimitiveType.Word32, new StackArgumentStorage(4, PrimitiveType.Word32));
     arg08 = new Identifier("arg08",   PrimitiveType.Word16, new StackArgumentStorage(8, PrimitiveType.Word16));
     arg0C = new Identifier("arg0C",   PrimitiveType.Byte, new StackArgumentStorage(0x0C, PrimitiveType.Byte));
     regOut = new Identifier("edxOut", PrimitiveType.Word32, new OutArgumentStorage(frame.EnsureRegister(Registers.edx)));
     sig = new ProcedureSignature(ret,
         new Identifier[] { arg04, arg08, arg0C, regOut });
 }
Пример #30
0
 public void Setup()
 {
     m = new ProcedureBuilder(arch);
     frame = m.Frame;
     ax = frame.EnsureRegister(new RegisterStorage("ax", 0, 0, PrimitiveType.Word16));
     bx = frame.EnsureRegister(new RegisterStorage("bx", 3, 0, PrimitiveType.Word16));
     cx = frame.EnsureRegister(new RegisterStorage("cx", 1, 0, PrimitiveType.Word16));
     dx = frame.EnsureRegister(new RegisterStorage("dx", 2, 0, PrimitiveType.Word16));
     flags = new FlagRegister("flags", PrimitiveType.Word16);
     SCZ = frame.EnsureFlagGroup(flags, 7, "SCZ", PrimitiveType.Byte);
     CF = frame.EnsureFlagGroup(flags, arch.CarryFlagMask, "C", PrimitiveType.Bool);
     rw = new LongAddRewriter(m.Procedure, arch);
 }