diff options
Diffstat (limited to 'lowlevelil.cpp')
| -rw-r--r-- | lowlevelil.cpp | 122 |
1 files changed, 93 insertions, 29 deletions
diff --git a/lowlevelil.cpp b/lowlevelil.cpp index 9764445e..c48b5b92 100644 --- a/lowlevelil.cpp +++ b/lowlevelil.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2016 Vector 35 LLC +// Copyright (c) 2015-2017 Vector 35 LLC // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to @@ -152,6 +152,12 @@ ExprId LowLevelILFunction::Const(size_t size, uint64_t val) } +ExprId LowLevelILFunction::ConstPointer(size_t size, uint64_t val) +{ + return AddExpr(LLIL_CONST_PTR, size, 0, val); +} + + ExprId LowLevelILFunction::Flag(uint32_t reg) { return AddExpr(LLIL_FLAG, 0, 0, reg); @@ -170,9 +176,9 @@ ExprId LowLevelILFunction::Add(size_t size, ExprId a, ExprId b, uint32_t flags) } -ExprId LowLevelILFunction::AddCarry(size_t size, ExprId a, ExprId b, uint32_t flags) +ExprId LowLevelILFunction::AddCarry(size_t size, ExprId a, ExprId b, ExprId carry, uint32_t flags) { - return AddExpr(LLIL_ADC, size, flags, a, b); + return AddExpr(LLIL_ADC, size, flags, a, b, carry); } @@ -182,9 +188,9 @@ ExprId LowLevelILFunction::Sub(size_t size, ExprId a, ExprId b, uint32_t flags) } -ExprId LowLevelILFunction::SubBorrow(size_t size, ExprId a, ExprId b, uint32_t flags) +ExprId LowLevelILFunction::SubBorrow(size_t size, ExprId a, ExprId b, ExprId carry, uint32_t flags) { - return AddExpr(LLIL_SBB, size, flags, a, b); + return AddExpr(LLIL_SBB, size, flags, a, b, carry); } @@ -230,9 +236,9 @@ ExprId LowLevelILFunction::RotateLeft(size_t size, ExprId a, ExprId b, uint32_t } -ExprId LowLevelILFunction::RotateLeftCarry(size_t size, ExprId a, ExprId b, uint32_t flags) +ExprId LowLevelILFunction::RotateLeftCarry(size_t size, ExprId a, ExprId b, ExprId carry, uint32_t flags) { - return AddExpr(LLIL_RLC, size, flags, a, b); + return AddExpr(LLIL_RLC, size, flags, a, b, carry); } @@ -242,9 +248,9 @@ ExprId LowLevelILFunction::RotateRight(size_t size, ExprId a, ExprId b, uint32_t } -ExprId LowLevelILFunction::RotateRightCarry(size_t size, ExprId a, ExprId b, uint32_t flags) +ExprId LowLevelILFunction::RotateRightCarry(size_t size, ExprId a, ExprId b, ExprId carry, uint32_t flags) { - return AddExpr(LLIL_RRC, size, flags, a, b); + return AddExpr(LLIL_RRC, size, flags, a, b, carry); } @@ -326,15 +332,21 @@ ExprId LowLevelILFunction::Not(size_t size, ExprId a, uint32_t flags) } -ExprId LowLevelILFunction::SignExtend(size_t size, ExprId a) +ExprId LowLevelILFunction::SignExtend(size_t size, ExprId a, uint32_t flags) +{ + return AddExpr(LLIL_SX, size, flags, a); +} + + +ExprId LowLevelILFunction::ZeroExtend(size_t size, ExprId a, uint32_t flags) { - return AddExpr(LLIL_SX, size, 0, a); + return AddExpr(LLIL_ZX, size, flags, a); } -ExprId LowLevelILFunction::ZeroExtend(size_t size, ExprId a) +ExprId LowLevelILFunction::LowPart(size_t size, ExprId a, uint32_t flags) { - return AddExpr(LLIL_ZX, size, 0, a); + return AddExpr(LLIL_LOW_PART, size, flags, a); } @@ -528,6 +540,58 @@ ExprId LowLevelILFunction::AddOperandList(const vector<ExprId> operands) } +ExprId LowLevelILFunction::GetExprForRegisterOrConstant(const BNRegisterOrConstant& operand, size_t size) +{ + if (operand.constant) + return AddExpr(LLIL_CONST, size, 0, operand.value); + return AddExpr(LLIL_REG, size, 0, operand.reg); +} + + +ExprId LowLevelILFunction::GetNegExprForRegisterOrConstant(const BNRegisterOrConstant& operand, size_t size) +{ + if (operand.constant) + return AddExpr(LLIL_CONST, size, 0, -(int64_t)operand.value); + return AddExpr(LLIL_NEG, size, 0, AddExpr(LLIL_REG, size, 0, operand.reg)); +} + + +ExprId LowLevelILFunction::GetExprForFlagOrConstant(const BNRegisterOrConstant& operand) +{ + if (operand.constant) + return AddExpr(LLIL_CONST, 0, 0, operand.value); + return AddExpr(LLIL_FLAG, 0, 0, operand.reg); +} + + +ExprId LowLevelILFunction::GetExprForRegisterOrConstantOperation(BNLowLevelILOperation op, size_t size, + BNRegisterOrConstant* operands, size_t operandCount) +{ + if (operandCount == 0) + return AddExpr(op, size, 0); + if (operandCount == 1) + return AddExpr(op, size, 0, GetExprForRegisterOrConstant(operands[0], size)); + if (operandCount == 2) + { + return AddExpr(op, size, 0, GetExprForRegisterOrConstant(operands[0], size), + GetExprForRegisterOrConstant(operands[1], size)); + } + if (operandCount == 3) + { + if ((op == LLIL_ADC) || (op == LLIL_SBB) || (op == LLIL_RLC) || (op == LLIL_RRC)) + { + return AddExpr(op, size, 0, GetExprForRegisterOrConstant(operands[0], size), + GetExprForRegisterOrConstant(operands[1], size), GetExprForFlagOrConstant(operands[2])); + } + return AddExpr(op, size, 0, GetExprForRegisterOrConstant(operands[0], size), + GetExprForRegisterOrConstant(operands[1], size), GetExprForRegisterOrConstant(operands[2], size)); + } + return AddExpr(op, size, 0, GetExprForRegisterOrConstant(operands[0], size), + GetExprForRegisterOrConstant(operands[1], size), GetExprForRegisterOrConstant(operands[2], size), + GetExprForRegisterOrConstant(operands[3], size)); +} + + ExprId LowLevelILFunction::Operand(uint32_t n, ExprId expr) { BNLowLevelILSetExprSourceOperand(m_object, expr, n); @@ -699,28 +763,28 @@ size_t LowLevelILFunction::GetNonSSAExprIndex(size_t expr) const } -size_t LowLevelILFunction::GetSSARegisterDefinition(uint32_t reg, size_t idx) const +size_t LowLevelILFunction::GetSSARegisterDefinition(uint32_t reg, size_t version) const { - return BNGetLowLevelILSSARegisterDefinition(m_object, reg, idx); + return BNGetLowLevelILSSARegisterDefinition(m_object, reg, version); } -size_t LowLevelILFunction::GetSSAFlagDefinition(uint32_t flag, size_t idx) const +size_t LowLevelILFunction::GetSSAFlagDefinition(uint32_t flag, size_t version) const { - return BNGetLowLevelILSSAFlagDefinition(m_object, flag, idx); + return BNGetLowLevelILSSAFlagDefinition(m_object, flag, version); } -size_t LowLevelILFunction::GetSSAMemoryDefinition(size_t idx) const +size_t LowLevelILFunction::GetSSAMemoryDefinition(size_t version) const { - return BNGetLowLevelILSSAMemoryDefinition(m_object, idx); + return BNGetLowLevelILSSAMemoryDefinition(m_object, version); } -set<size_t> LowLevelILFunction::GetSSARegisterUses(uint32_t reg, size_t idx) const +set<size_t> LowLevelILFunction::GetSSARegisterUses(uint32_t reg, size_t version) const { size_t count; - size_t* instrs = BNGetLowLevelILSSARegisterUses(m_object, reg, idx, &count); + size_t* instrs = BNGetLowLevelILSSARegisterUses(m_object, reg, version, &count); set<size_t> result; for (size_t i = 0; i < count; i++) @@ -731,10 +795,10 @@ set<size_t> LowLevelILFunction::GetSSARegisterUses(uint32_t reg, size_t idx) con } -set<size_t> LowLevelILFunction::GetSSAFlagUses(uint32_t flag, size_t idx) const +set<size_t> LowLevelILFunction::GetSSAFlagUses(uint32_t flag, size_t version) const { size_t count; - size_t* instrs = BNGetLowLevelILSSAFlagUses(m_object, flag, idx, &count); + size_t* instrs = BNGetLowLevelILSSAFlagUses(m_object, flag, version, &count); set<size_t> result; for (size_t i = 0; i < count; i++) @@ -745,10 +809,10 @@ set<size_t> LowLevelILFunction::GetSSAFlagUses(uint32_t flag, size_t idx) const } -set<size_t> LowLevelILFunction::GetSSAMemoryUses(size_t idx) const +set<size_t> LowLevelILFunction::GetSSAMemoryUses(size_t version) const { size_t count; - size_t* instrs = BNGetLowLevelILSSAMemoryUses(m_object, idx, &count); + size_t* instrs = BNGetLowLevelILSSAMemoryUses(m_object, version, &count); set<size_t> result; for (size_t i = 0; i < count; i++) @@ -759,16 +823,16 @@ set<size_t> LowLevelILFunction::GetSSAMemoryUses(size_t idx) const } -RegisterValue LowLevelILFunction::GetSSARegisterValue(uint32_t reg, size_t idx) +RegisterValue LowLevelILFunction::GetSSARegisterValue(uint32_t reg, size_t version) { - BNRegisterValue value = BNGetLowLevelILSSARegisterValue(m_object, reg, idx); + BNRegisterValue value = BNGetLowLevelILSSARegisterValue(m_object, reg, version); return RegisterValue::FromAPIObject(value); } -RegisterValue LowLevelILFunction::GetSSAFlagValue(uint32_t flag, size_t idx) +RegisterValue LowLevelILFunction::GetSSAFlagValue(uint32_t flag, size_t version) { - BNRegisterValue value = BNGetLowLevelILSSAFlagValue(m_object, flag, idx); + BNRegisterValue value = BNGetLowLevelILSSAFlagValue(m_object, flag, version); return RegisterValue::FromAPIObject(value); } |
