diff options
| -rw-r--r-- | binaryninjaapi.h | 23 | ||||
| -rw-r--r-- | binaryninjacore.h | 5 | ||||
| -rw-r--r-- | mediumlevelil.cpp | 129 | ||||
| -rw-r--r-- | python/mediumlevelil.py | 27 |
4 files changed, 14 insertions, 170 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 0371c4ff..072bfb5a 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2251,28 +2251,9 @@ namespace BinaryNinja size_t GetInstructionStart(Architecture* arch, uint64_t addr); ExprId AddExpr(BNMediumLevelILOperation operation, size_t size, - ExprId a = 0, ExprId b = 0, ExprId c = 0, ExprId d = 0, ExprId e = 0, ExprId f = 0); + ExprId a = 0, ExprId b = 0, ExprId c = 0, ExprId d = 0, ExprId e = 0); ExprId AddInstruction(ExprId expr); - ExprId SetVar(size_t size, const Variable& var, ExprId src); - ExprId SetVarField(size_t size, const Variable& var, int64_t offset, ExprId src); - ExprId SetVarSplit(size_t size, const Variable& high, const Variable& low, ExprId src); - ExprId SetVarSSA(size_t size, const Variable& var, size_t index, ExprId src); - ExprId SetVarFieldSSA(size_t size, const Variable& var, size_t varIndex, int64_t offset, ExprId src); - ExprId SetVarSplitSSA(size_t size, const Variable& high, size_t highIndex, - const Variable& low, size_t lowIndex, ExprId src); - ExprId SetVarAliased(size_t size, const Variable& var, size_t destIndex, size_t srcIndex, ExprId src); - ExprId SetVarFieldAliased(size_t size, const Variable& var, size_t destIndex, size_t srcIndex, - int64_t offset, ExprId src); - ExprId Var(size_t size, const Variable& var); - ExprId VarField(size_t size, const Variable& var, int64_t offset); - ExprId VarSSA(size_t size, const Variable& var, size_t index); - ExprId VarFieldSSA(size_t size, const Variable& var, int64_t offset, size_t varIndex); - ExprId VarAliased(size_t size, const Variable& var, size_t memIndex); - ExprId VarFieldAliased(size_t size, const Variable& var, int64_t offset, size_t memIndex); - ExprId AddressOf(size_t size, const Variable& var); - ExprId AddressOfField(size_t size, const Variable& var, int64_t offset); - ExprId Goto(BNMediumLevelILLabel& label); ExprId If(ExprId operand, BNMediumLevelILLabel& t, BNMediumLevelILLabel& f); void MarkLabel(BNMediumLevelILLabel& label); @@ -2281,8 +2262,6 @@ namespace BinaryNinja ExprId AddLabelList(const std::vector<BNMediumLevelILLabel*>& labels); ExprId AddOperandList(const std::vector<ExprId> operands); - Variable GetVariable(ExprId i, size_t varOperand); - BNMediumLevelILInstruction operator[](size_t i) const; size_t GetIndexForInstruction(size_t i) const; size_t GetInstructionForExpr(size_t expr) const; diff --git a/binaryninjacore.h b/binaryninjacore.h index 1bd97cde..21592772 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -735,7 +735,6 @@ extern "C" MLIL_SET_VAR_SSA, MLIL_SET_VAR_SSA_FIELD, MLIL_SET_VAR_SPLIT_SSA, - MLIL_VAR_SPLIT_DEST_SSA, MLIL_SET_VAR_ALIASED, MLIL_SET_VAR_ALIASED_FIELD, MLIL_VAR_SSA, @@ -758,7 +757,7 @@ extern "C" { BNMediumLevelILOperation operation; size_t size; - uint64_t operands[6]; + uint64_t operands[5]; uint64_t address; }; @@ -2250,7 +2249,7 @@ extern "C" BINARYNINJACOREAPI size_t BNMediumLevelILGetInstructionStart(BNMediumLevelILFunction* func, BNArchitecture* arch, uint64_t addr); BINARYNINJACOREAPI size_t BNMediumLevelILAddExpr(BNMediumLevelILFunction* func, BNMediumLevelILOperation operation, - size_t size, uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e, uint64_t f); + size_t size, uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e); BINARYNINJACOREAPI size_t BNMediumLevelILAddInstruction(BNMediumLevelILFunction* func, size_t expr); BINARYNINJACOREAPI size_t BNMediumLevelILGoto(BNMediumLevelILFunction* func, BNMediumLevelILLabel* label); BINARYNINJACOREAPI size_t BNMediumLevelILIf(BNMediumLevelILFunction* func, uint64_t op, diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp index 0b420a82..868f3f75 100644 --- a/mediumlevelil.cpp +++ b/mediumlevelil.cpp @@ -61,9 +61,9 @@ size_t MediumLevelILFunction::GetInstructionStart(Architecture* arch, uint64_t a ExprId MediumLevelILFunction::AddExpr(BNMediumLevelILOperation operation, size_t size, - ExprId a, ExprId b, ExprId c, ExprId d, ExprId e, ExprId f) + ExprId a, ExprId b, ExprId c, ExprId d, ExprId e) { - return BNMediumLevelILAddExpr(m_object, operation, size, a, b, c, d, e, f); + return BNMediumLevelILAddExpr(m_object, operation, size, a, b, c, d, e); } @@ -73,120 +73,6 @@ ExprId MediumLevelILFunction::AddInstruction(size_t expr) } -ExprId MediumLevelILFunction::SetVar(size_t size, const Variable& var, ExprId src) -{ - return AddExpr(MLIL_SET_VAR, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, src); -} - - -ExprId MediumLevelILFunction::SetVarField(size_t size, const Variable& var, int64_t offset, ExprId src) -{ - return AddExpr(MLIL_SET_VAR_FIELD, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, - offset, src); -} - - -ExprId MediumLevelILFunction::SetVarSplit(size_t size, const Variable& high, const Variable& low, ExprId src) -{ - return AddExpr(MLIL_SET_VAR_SPLIT, size, ((uint64_t)high.type << 32) | (uint64_t)high.index, high.storage, - ((uint64_t)low.type << 32) | (uint64_t)low.index, low.storage, src); -} - - -ExprId MediumLevelILFunction::SetVarSSA(size_t size, const Variable& var, size_t varIndex, ExprId src) -{ - return AddExpr(MLIL_SET_VAR_SSA, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, - varIndex, src); -} - - -ExprId MediumLevelILFunction::SetVarFieldSSA(size_t size, const Variable& var, size_t varIndex, - int64_t offset, ExprId src) -{ - return AddExpr(MLIL_SET_VAR_SSA_FIELD, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, - varIndex, offset, src); -} - - -ExprId MediumLevelILFunction::SetVarSplitSSA(size_t size, const Variable& high, size_t highIndex, - const Variable& low, size_t lowIndex, ExprId src) -{ - return AddExpr(MLIL_SET_VAR_SPLIT_SSA, size, - AddExpr(MLIL_VAR_SPLIT_DEST_SSA, size, ((uint64_t)high.type << 32) | (uint64_t)high.index, - high.storage, highIndex), - AddExpr(MLIL_VAR_SPLIT_DEST_SSA, size, ((uint64_t)low.type << 32) | (uint64_t)low.index, - low.storage, lowIndex), src); -} - - -ExprId MediumLevelILFunction::SetVarAliased(size_t size, const Variable& var, size_t destIndex, - size_t srcIndex, ExprId src) -{ - return AddExpr(MLIL_SET_VAR_ALIASED, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, - destIndex, srcIndex, src); -} - - -ExprId MediumLevelILFunction::SetVarFieldAliased(size_t size, const Variable& var, size_t destIndex, - size_t srcIndex, int64_t offset, ExprId src) -{ - return AddExpr(MLIL_SET_VAR_ALIASED_FIELD, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, - destIndex, srcIndex, offset, src); -} - - -ExprId MediumLevelILFunction::Var(size_t size, const Variable& var) -{ - return AddExpr(MLIL_VAR, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage); -} - - -ExprId MediumLevelILFunction::VarField(size_t size, const Variable& var, int64_t offset) -{ - return AddExpr(MLIL_VAR_FIELD, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, offset); -} - - -ExprId MediumLevelILFunction::VarSSA(size_t size, const Variable& var, size_t varIndex) -{ - return AddExpr(MLIL_VAR_SSA, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, varIndex); -} - - -ExprId MediumLevelILFunction::VarFieldSSA(size_t size, const Variable& var, int64_t offset, - size_t varIndex) -{ - return AddExpr(MLIL_VAR_SSA_FIELD, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, - offset, varIndex); -} - - -ExprId MediumLevelILFunction::VarAliased(size_t size, const Variable& var, size_t memIndex) -{ - return AddExpr(MLIL_VAR_ALIASED, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, memIndex); -} - - -ExprId MediumLevelILFunction::VarFieldAliased(size_t size, const Variable& var, int64_t offset, size_t memIndex) -{ - return AddExpr(MLIL_VAR_ALIASED_FIELD, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage, - offset, memIndex); -} - - -ExprId MediumLevelILFunction::AddressOf(size_t size, const Variable& var) -{ - return AddExpr(MLIL_ADDRESS_OF, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.storage); -} - - -ExprId MediumLevelILFunction::AddressOfField(size_t size, const Variable& var, int64_t offset) -{ - return AddExpr(MLIL_ADDRESS_OF_FIELD, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, - var.storage, offset); -} - - ExprId MediumLevelILFunction::Goto(BNMediumLevelILLabel& label) { return BNMediumLevelILGoto(m_object, &label); @@ -239,17 +125,6 @@ ExprId MediumLevelILFunction::AddOperandList(const vector<ExprId> operands) } -Variable MediumLevelILFunction::GetVariable(ExprId i, size_t varOperand) -{ - BNMediumLevelILInstruction instr = (*this)[i]; - Variable result; - result.type = (BNVariableSourceType)(instr.operands[varOperand] >> 32); - result.index = (uint32_t)instr.operands[varOperand]; - result.storage = instr.operands[varOperand + 1]; - return result; -} - - BNMediumLevelILInstruction MediumLevelILFunction::operator[](size_t i) const { return BNGetMediumLevelILByIndex(m_object, i); diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index e959e480..316e45b7 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -22,7 +22,7 @@ import ctypes # Binary Ninja components import _binaryninjacore as core -from .enums import MediumLevelILOperation, InstructionTextTokenType, VariableSourceType, ILBranchDependence +from .enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDependence import function import basicblock import lowlevelil @@ -119,7 +119,6 @@ class MediumLevelILInstruction(object): MediumLevelILOperation.MLIL_SET_VAR_SPLIT_SSA: [("high", "expr"), ("low", "expr"), ("src", "expr")], MediumLevelILOperation.MLIL_SET_VAR_ALIASED: [("dest", "var"), ("dest_memory", "int"), ("src_memory", "int"), ("src", "exor")], MediumLevelILOperation.MLIL_SET_VAR_ALIASED_FIELD: [("dest", "var"), ("dest_memory", "int"), ("src_memory", "int"), ("offset", "int"), ("src", "exor")], - MediumLevelILOperation.MLIL_VAR_SPLIT_DEST_SSA: [("dest", "var"), ("index", "int")], MediumLevelILOperation.MLIL_VAR_SSA: [("src", "var"), ("index", "int")], MediumLevelILOperation.MLIL_VAR_SSA_FIELD: [("src", "var"), ("index", "int"), ("offset", "int")], MediumLevelILOperation.MLIL_VAR_ALIASED: [("src", "var"), ("src_memory", "int")], @@ -157,11 +156,7 @@ class MediumLevelILInstruction(object): elif operand_type == "expr": value = MediumLevelILInstruction(func, instr.operands[i]) elif operand_type == "var": - var_type = VariableSourceType(instr.operands[i] >> 32) - index = instr.operands[i] & 0xffffffff - storage = instr.operands[i + 1] - i += 1 - value = function.Variable(self.function.source_function, var_type, index, storage) + value = function.Variable.from_identifier(self.function.source_function, instr.operands[i]) elif operand_type == "int_list": count = ctypes.c_ulonglong() operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count) @@ -174,23 +169,19 @@ class MediumLevelILInstruction(object): operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count) i += 1 value = [] - for j in xrange(count.value / 2): - var_type = VariableSourceType(operand_list[j * 2] >> 32) - index = operand_list[j * 2] & 0xffffffff - storage = operand_list[(j * 2) + 1] - value.append(function.Variable(self.function.source_function, var_type, index, storage)) + for j in operand_list: + value.append(function.Variable.from_identifier(self.function.source_function, j)) core.BNMediumLevelILFreeOperandList(operand_list) elif operand_type == "var_ssa_list": count = ctypes.c_ulonglong() operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count) i += 1 value = [] - for j in xrange(count.value / 3): - var_type = VariableSourceType(operand_list[j * 3] >> 32) - index = operand_list[j * 3] & 0xffffffff - storage = operand_list[(j * 3) + 1] - var_index = operand_list[(j * 3) + 2] - value.append((function.Variable(self.function.source_function, var_type, index, storage), var_index)) + for j in xrange(count.value / 2): + var_id = operand_list[j * 2] + var_index = operand_list[(j * 2) + 2] + value.append((function.Variable.from_identifier(self.function.source_function, + var_id), var_index)) core.BNMediumLevelILFreeOperandList(operand_list) elif operand_type == "expr_list": count = ctypes.c_ulonglong() |
