diff options
| author | Rusty Wagner <rusty@vector35.com> | 2017-03-02 00:37:46 -0500 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2017-03-02 00:37:46 -0500 |
| commit | 7aab4e4a3f8f2daadd1fbd00259da5b01090d84c (patch) | |
| tree | 7b9db291c184b44b6b2a4a9f2af66e5d9bc6b464 | |
| parent | 94b38cee51eff16f1e79945806088c7ae60016d7 (diff) | |
Adding MLIL instructions, moving stack contents data flow to a later stage
| -rw-r--r-- | binaryninjaapi.h | 6 | ||||
| -rw-r--r-- | binaryninjacore.h | 7 | ||||
| -rw-r--r-- | lowlevelil.cpp | 7 | ||||
| -rw-r--r-- | mediumlevelil.cpp | 31 | ||||
| -rw-r--r-- | python/lowlevelil.py | 6 | ||||
| -rw-r--r-- | python/mediumlevelil.py | 5 |
6 files changed, 45 insertions, 17 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 1367e7c1..e3ba4968 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2180,7 +2180,6 @@ namespace BinaryNinja RegisterValue GetSSARegisterValue(uint32_t reg, size_t idx); RegisterValue GetSSAFlagValue(uint32_t flag, size_t idx); - RegisterValue GetSSAStackContents(size_t memoryIndex, int64_t offset, size_t size); RegisterValue GetExprValue(size_t expr); }; @@ -2207,12 +2206,17 @@ namespace BinaryNinja ExprId SetVar(size_t size, const BNILVariable& var, ExprId src); ExprId SetVarField(size_t size, const BNILVariable& var, int64_t offset, ExprId src); + ExprId SetVarSplit(size_t size, const BNILVariable& high, const BNILVariable& low, ExprId src); ExprId SetVarSSA(size_t size, const BNILVariable& var, size_t index, ExprId src); ExprId SetVarFieldSSA(size_t size, const BNILVariable& var, int64_t offset, size_t varIndex, ExprId src); + ExprId SetVarSplitSSA(size_t size, const BNILVariable& high, size_t highIndex, + const BNILVariable& low, size_t lowIndex, ExprId src); ExprId Var(size_t size, const BNILVariable& var); ExprId VarField(size_t size, const BNILVariable& var, int64_t offset); ExprId VarSSA(size_t size, const BNILVariable& var, size_t index); ExprId VarFieldSSA(size_t size, const BNILVariable& var, int64_t offset, size_t varIndex); + ExprId AddressOf(size_t size, const BNILVariable& var); + ExprId AddressOfField(size_t size, const BNILVariable& var, int64_t offset); ExprId Goto(BNMediumLevelILLabel& label); ExprId If(ExprId operand, BNMediumLevelILLabel& t, BNMediumLevelILLabel& f); diff --git a/binaryninjacore.h b/binaryninjacore.h index aa9bb49b..d35f806c 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -645,10 +645,13 @@ extern "C" MLIL_NOP, MLIL_SET_VAR, // Not valid in SSA form (see MLIL_SET_VAR_SSA) MLIL_SET_VAR_FIELD, // Not valid in SSA form (see MLIL_SET_VAR_FIELD) + MLIL_SET_VAR_SPLIT, // Not valid in SSA form (see MLIL_SET_VAR_SPLIT_SSA) MLIL_LOAD, // Not valid in SSA form (see MLIL_LOAD_SSA) MLIL_STORE, // Not valid in SSA form (see MLIL_STORE_SSA) MLIL_VAR, // Not valid in SSA form (see MLIL_VAR_SSA) MLIL_VAR_FIELD, // Not valid in SSA form (see MLIL_VAR_SSA_FIELD) + MLIL_ADDRESS_OF, + MLIL_ADDRESS_OF_FIELD, MLIL_CONST, MLIL_ADD, MLIL_ADC, @@ -708,6 +711,8 @@ extern "C" // The following instructions are only used in SSA form MLIL_SET_VAR_SSA, MLIL_SET_VAR_SSA_FIELD, + MLIL_SET_VAR_SPLIT_SSA, + MLIL_VAR_SPLIT_DEST_SSA, MLIL_VAR_SSA, MLIL_VAR_SSA_FIELD, MLIL_CALL_SSA, @@ -2151,8 +2156,6 @@ extern "C" uint32_t reg, size_t idx); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILSSAFlagValue(BNLowLevelILFunction* func, uint32_t flag, size_t idx); - BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILSSAStackContents(BNLowLevelILFunction* func, - size_t memoryIndex, int64_t offset, size_t size); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILExprValue(BNLowLevelILFunction* func, size_t expr); diff --git a/lowlevelil.cpp b/lowlevelil.cpp index 5a789981..342effea 100644 --- a/lowlevelil.cpp +++ b/lowlevelil.cpp @@ -767,13 +767,6 @@ RegisterValue LowLevelILFunction::GetSSAFlagValue(uint32_t flag, size_t idx) } -RegisterValue LowLevelILFunction::GetSSAStackContents(size_t memoryIndex, int64_t offset, size_t size) -{ - BNRegisterValue value = BNGetLowLevelILSSAStackContents(m_object, memoryIndex, offset, size); - return RegisterValue::FromAPIObject(value); -} - - RegisterValue LowLevelILFunction::GetExprValue(size_t expr) { BNRegisterValue value = BNGetLowLevelILExprValue(m_object, expr); diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp index f6ad5bfd..8c97db61 100644 --- a/mediumlevelil.cpp +++ b/mediumlevelil.cpp @@ -86,6 +86,13 @@ ExprId MediumLevelILFunction::SetVarField(size_t size, const BNILVariable& var, } +ExprId MediumLevelILFunction::SetVarSplit(size_t size, const BNILVariable& high, const BNILVariable& low, ExprId src) +{ + return AddExpr(MLIL_SET_VAR_SPLIT, size, ((uint64_t)high.type << 32) | (uint64_t)high.index, high.identifier, + ((uint64_t)low.type << 32) | (uint64_t)low.index, low.identifier, src); +} + + ExprId MediumLevelILFunction::SetVarSSA(size_t size, const BNILVariable& var, size_t varIndex, ExprId src) { return AddExpr(MLIL_SET_VAR_SSA, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.identifier, @@ -101,6 +108,17 @@ ExprId MediumLevelILFunction::SetVarFieldSSA(size_t size, const BNILVariable& va } +ExprId MediumLevelILFunction::SetVarSplitSSA(size_t size, const BNILVariable& high, size_t highIndex, + const BNILVariable& 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.identifier, highIndex), + AddExpr(MLIL_VAR_SPLIT_DEST_SSA, size, ((uint64_t)low.type << 32) | (uint64_t)low.index, + low.identifier, lowIndex), src); +} + + ExprId MediumLevelILFunction::Var(size_t size, const BNILVariable& var) { return AddExpr(MLIL_VAR, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.identifier); @@ -127,6 +145,19 @@ ExprId MediumLevelILFunction::VarFieldSSA(size_t size, const BNILVariable& var, } +ExprId MediumLevelILFunction::AddressOf(size_t size, const BNILVariable& var) +{ + return AddExpr(MLIL_ADDRESS_OF, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, var.identifier); +} + + +ExprId MediumLevelILFunction::AddressOfField(size_t size, const BNILVariable& var, int64_t offset) +{ + return AddExpr(MLIL_ADDRESS_OF_FIELD, size, ((uint64_t)var.type << 32) | (uint64_t)var.index, + var.identifier, offset); +} + + ExprId MediumLevelILFunction::Goto(BNMediumLevelILLabel& label) { return BNMediumLevelILGoto(m_object, &label); diff --git a/python/lowlevelil.py b/python/lowlevelil.py index ed1cedd4..40cb964c 100644 --- a/python/lowlevelil.py +++ b/python/lowlevelil.py @@ -1422,12 +1422,6 @@ class LowLevelILFunction(object): core.BNFreeRegisterValue(value) return result - def get_ssa_stack_contents(self, memory_index, offset, size): - value = core.BNGetLowLevelILSSAStackContents(self.handle, memory_index, offset, size) - result = function.RegisterValue(self.arch, value) - core.BNFreeRegisterValue(value) - return result - class LowLevelILBasicBlock(basicblock.BasicBlock): def __init__(self, view, handle, owner): diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index c4c4aa23..839c45ce 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -47,6 +47,7 @@ class MediumLevelILInstruction(object): MediumLevelILOperation.MLIL_NOP: [], MediumLevelILOperation.MLIL_SET_VAR: [("dest", "var"), ("src", "expr")], MediumLevelILOperation.MLIL_SET_VAR_FIELD: [("dest", "var"), ("offset", "int"), ("src", "expr")], + MediumLevelILOperation.MLIL_SET_VAR_SPLIT: [("high", "var"), ("low", "var"), ("src", "expr")], MediumLevelILOperation.MLIL_LOAD: [("src", "expr")], MediumLevelILOperation.MLIL_STORE: [("dest", "expr"), ("src", "expr")], MediumLevelILOperation.MLIL_VAR: [("src", "var")], @@ -108,12 +109,14 @@ class MediumLevelILInstruction(object): MediumLevelILOperation.MLIL_UNIMPL_MEM: [("src", "expr")], MediumLevelILOperation.MLIL_SET_VAR_SSA: [("dest", "var"), ("index", "int"), ("src", "expr")], MediumLevelILOperation.MLIL_SET_VAR_SSA_FIELD: [("dest", "var"), ("index", "int"), ("offset", "int"), ("src", "expr")], + MediumLevelILOperation.MLIL_SET_VAR_SPLIT_SSA: [("high", "expr"), ("low", "expr"), ("src", "expr")], + 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_CALL_SSA: [("output", "expr"), ("dest", "expr"), ("param", "expr")], MediumLevelILOperation.MLIL_SYSCALL_SSA: [("output", "expr"), ("param", "expr")], MediumLevelILOperation.MLIL_CALL_OUTPUT_SSA: [("dest_memory", "int"), ("dest", "var_ssa_list")], - MediumLevelILOperation.MLIL_CALL_PARAM_SSA: [("src", "var_ssa_list")], + MediumLevelILOperation.MLIL_CALL_PARAM_SSA: [("src_memory", "int"), ("src", "var_ssa_list")], MediumLevelILOperation.MLIL_LOAD_SSA: [("src", "expr"), ("src_memory", "int")], MediumLevelILOperation.MLIL_STORE_SSA: [("dest", "expr"), ("dest_memory", "int"), ("src_memory", "int"), ("src", "expr")], MediumLevelILOperation.MLIL_VAR_PHI: [("dest", "var"), ("index", "int"), ("src", "var_ssa_list")], |
