Example #1
0
        public ImageSegment InitializeStack(IProcessorEmulator emulator, ProcessorState state)
        {
            var cs = ((Constant)state.GetValue(Registers.cs)).ToUInt16();
            var ss = ((Constant)state.GetValue(Registers.ss)).ToUInt16();
            var sp = ((Constant)state.GetValue(Registers.sp)).ToUInt16();
            var ds = ((Constant)state.GetValue(Registers.ds)).ToUInt16();

            emulator.WriteRegister(Registers.cs, cs);
            emulator.WriteRegister(Registers.ss, ss);
            emulator.WriteRegister(Registers.sp, sp);
            emulator.WriteRegister(Registers.ds, ds);
            return(null);
        }
Example #2
0
        private void TryHandlingZeroOverheadLoop()
        {
            // Check if we would hit the LP_END instruction set up by a prior LP instruction.
            var uAddrNext = instr.Address.ToUInt32() + (uint)instr.Length;
            var end       = state.GetValue(Registers.LpEnd);

            if (end is Constant cEnd && cEnd.IsValid && cEnd.ToUInt32() == uAddrNext)
            {
                var addrNext = Address.Ptr32(uAddrNext);

                var        lpCount = binder.EnsureRegister(Registers.LP_count);
                var        start   = state.GetValue(Registers.LpStart);
                Expression eBackEdgeTarget;
                if (start is Constant cStart && cStart.IsValid)
                {
                    eBackEdgeTarget = Address.Ptr32(cStart.ToUInt32());
                }
Example #3
0
 public ValueSet VisitIdentifier(Identifier id)
 {
     if (context.TryGetValue(id, out ValueSet vs))
     {
         return(vs);
     }
     if (state != null && state.GetValue(id) is Constant c && c.IsValid)
     {
         return(new ConcreteValueSet(c.DataType, c));
     }
     return(new IntervalValueSet(id.DataType, StridedInterval.Empty));
 }
Example #4
0
        public bool ProcessAlloca(CallSite site, ExternalProcedure impProc)
        {
            if (impProc.Signature == null)
            {
                throw new ApplicationException(string.Format("You must specify a procedure signature for {0} since it has been marked as 'alloca'.", impProc.Name));
            }
            var ab = CreateApplicationBuilder(new ProcedureConstant(program.Platform.PointerType, impProc), impProc.Signature, site);

            if (impProc.Signature.Parameters.Length != 1)
            {
                throw new ApplicationException(string.Format("An alloca function must have exactly one parameter, but {0} has {1}.", impProc.Name, impProc.Signature.Parameters.Length));
            }
            var target = ab.Bind(impProc.Signature.Parameters[0]);
            var id     = target as Identifier;

            if (id == null)
            {
                throw new ApplicationException(string.Format("The parameter of {0} wasn't a register.", impProc.Name));
            }
            if (state.GetValue(id) is Constant c && c.IsValid)
            {
                Emit(new Assignment(stackReg, new BinaryExpression(Operator.ISub, stackReg.DataType, stackReg, c)));
            }