public MakeAddressFromConstant ( Constant c ) : Address | ||
c | Constant | |
Résultat | Address |
/// <summary> /// Memory accesses are translated into expressions, performing simplifications /// where possible. /// </summary> public Expression EffectiveAddressExpression(X86Instruction instr, MemoryOperand mem) { Expression?eIndex = null; Expression?eBase = null; Expression?expr = null; bool ripRelative = false; if (mem.Base != RegisterStorage.None) { if (mem.Base == Registers.rip) { ripRelative = true; } else { eBase = AluRegister(mem.Base); if (expr != null) { expr = m.IAdd(eBase, expr); } else { expr = eBase; } } } if (mem.Offset !.IsValid) { if (ripRelative) { expr = instr.Address + (instr.Length + mem.Offset.ToInt64()); } else if (expr != null) { BinaryOperator op = Operator.IAdd; long l = mem.Offset.ToInt64(); if (l < 0 && l > -0x800) { l = -l; op = Operator.ISub; } DataType dt = (eBase != null) ? eBase.DataType : eIndex !.DataType; Constant cOffset = Constant.Create(dt, l); expr = new BinaryExpression(op, dt, expr, cOffset); } else { expr = mem.Offset; } } if (mem.Index != RegisterStorage.None) { eIndex = AluRegister(mem.Index); if (mem.Scale != 0 && mem.Scale != 1) { eIndex = m.IMul(eIndex, Constant.Create(mem.Index.DataType, mem.Scale)); } expr = m.IAdd(expr !, eIndex); } if (!IsSegmentedAccessRequired && expr is Constant c && mem.SegOverride == RegisterStorage.None) { return(arch.MakeAddressFromConstant(c, false) !); } return(expr !); }
/// <summary> /// Memory accesses are translated into expressions, performing simplifications /// where possible. /// </summary> public Expression EffectiveAddressExpression(X86Instruction instr, MemoryOperand mem) { Expression?eIndex = null; Expression?eBase = null; Expression?expr = null; bool ripRelative = false; if (mem.Base != RegisterStorage.None) { if (mem.Base == Registers.rip) { ripRelative = true; } else { eBase = AluRegister(mem.Base); if (expr != null) { expr = m.IAdd(eBase, expr); } else { expr = eBase; } } } if (mem.Offset != null) { if (ripRelative) { expr = instr.Address + (instr.Length + mem.Offset.ToInt64()); } else if (expr != null) { BinaryOperator op = Operator.IAdd; long l = mem.Offset.ToInt64(); if (l < 0 && l > -0x800) { l = -l; op = Operator.ISub; } DataType dt = (eBase != null) ? eBase.DataType : eIndex !.DataType; Constant cOffset = Constant.Create(dt, l); expr = new BinaryExpression(op, dt, expr, cOffset); } else { // expr is null, so there was no base register. But was there // an index register? If so extend the offset to the samesize. if (mem.Index != RegisterStorage.None && (int)mem.Index.BitSize != mem.Offset.DataType.BitSize) { var dt = PrimitiveType.Create(Domain.SignedInt, (int)mem.Index.BitSize); expr = Constant.Create(dt, mem.Offset.ToInt64()); } else { // There was no base or index. expr = mem.Offset; } } } if (mem.Index != RegisterStorage.None) { eIndex = AluRegister(mem.Index); if (mem.Scale != 0 && mem.Scale != 1) { eIndex = m.IMul(eIndex, Constant.Create(mem.Index.DataType, mem.Scale)); } expr = m.IAdd(expr !, eIndex); } if (!IsSegmentedAccessRequired && expr is Constant c && mem.SegOverride == RegisterStorage.None) { return(arch.MakeAddressFromConstant(c, false) !); } return(expr !); }