diff options
| author | Rusty Wagner <rusty@vector35.com> | 2016-05-30 04:20:27 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2016-05-30 04:20:27 -0400 |
| commit | 56d270363e63b45c2032f4e73d02f9e2a92c76c2 (patch) | |
| tree | 5a14ddd6954f1eff81e590f5961b07c7aa8093e7 | |
| parent | 0c3c4285a38d70bafb089b85e6764d0f4153ff9c (diff) | |
Add APIs for querying stack variable values and parameters by index
| -rw-r--r-- | binaryninjaapi.h | 6 | ||||
| -rw-r--r-- | binaryninjacore.h | 20 | ||||
| -rw-r--r-- | function.cpp | 44 | ||||
| -rw-r--r-- | python/__init__.py | 52 |
4 files changed, 116 insertions, 6 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 50def47f..7ece4c4d 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1358,6 +1358,12 @@ namespace BinaryNinja RegisterValue GetRegisterValueAfterInstruction(Architecture* arch, uint64_t addr, uint32_t reg); RegisterValue GetRegisterValueAtLowLevelILInstruction(size_t i, uint32_t reg); RegisterValue GetRegisterValueAfterLowLevelILInstruction(size_t i, uint32_t reg); + RegisterValue GetStackContentsAtInstruction(Architecture* arch, uint64_t addr, int64_t offset, size_t size); + RegisterValue GetStackContentsAfterInstruction(Architecture* arch, uint64_t addr, int64_t offset, size_t size); + RegisterValue GetStackContentsAtLowLevelILInstruction(size_t i, int64_t offset, size_t size); + RegisterValue GetStackContentsAfterLowLevelILInstruction(size_t i, int64_t offset, size_t size); + RegisterValue GetParameterValueAtInstruction(Architecture* arch, uint64_t addr, Type* functionType, size_t i); + RegisterValue GetParameterValueAtLowLevelILInstruction(size_t instr, Type* functionType, size_t i); std::vector<uint32_t> GetRegistersReadByInstruction(Architecture* arch, uint64_t addr); std::vector<uint32_t> GetRegistersWrittenByInstruction(Architecture* arch, uint64_t addr); std::vector<StackVariableReference> GetStackVariablesReferencedByInstruction(Architecture* arch, uint64_t addr); diff --git a/binaryninjacore.h b/binaryninjacore.h index db6f6f27..39ee7e98 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1115,12 +1115,24 @@ extern "C" BINARYNINJACOREAPI size_t* BNGetLowLevelILExitsForInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr, size_t* count); BINARYNINJACOREAPI void BNFreeLowLevelILInstructionList(size_t* list); - BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAtInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr, - uint32_t reg); - BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAfterInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr, - uint32_t reg); + BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAtInstruction(BNFunction* func, BNArchitecture* arch, + uint64_t addr, uint32_t reg); + BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAfterInstruction(BNFunction* func, BNArchitecture* arch, + uint64_t addr, uint32_t reg); BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAtLowLevelILInstruction(BNFunction* func, size_t i, uint32_t reg); BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAfterLowLevelILInstruction(BNFunction* func, size_t i, uint32_t reg); + BINARYNINJACOREAPI BNRegisterValue BNGetStackContentsAtInstruction(BNFunction* func, BNArchitecture* arch, + uint64_t addr, int64_t offset, size_t size); + BINARYNINJACOREAPI BNRegisterValue BNGetStackContentsAfterInstruction(BNFunction* func, BNArchitecture* arch, + uint64_t addr, int64_t offset, size_t size); + BINARYNINJACOREAPI BNRegisterValue BNGetStackContentsAtLowLevelILInstruction(BNFunction* func, size_t i, + int64_t offset, size_t size); + BINARYNINJACOREAPI BNRegisterValue BNGetStackContentsAfterLowLevelILInstruction(BNFunction* func, size_t i, + int64_t offset, size_t size); + BINARYNINJACOREAPI BNRegisterValue BNGetParameterValueAtInstruction(BNFunction* func, BNArchitecture* arch, + uint64_t addr, BNType* functionType, size_t i); + BINARYNINJACOREAPI BNRegisterValue BNGetParameterValueAtLowLevelILInstruction(BNFunction* func, size_t instr, + BNType* functionType, size_t i); BINARYNINJACOREAPI void BNFreeRegisterValue(BNRegisterValue* value); BINARYNINJACOREAPI uint32_t* BNGetRegistersReadByInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr, size_t* count); diff --git a/function.cpp b/function.cpp index 70cbfe2a..ea0fec86 100644 --- a/function.cpp +++ b/function.cpp @@ -196,6 +196,50 @@ RegisterValue Function::GetRegisterValueAfterLowLevelILInstruction(size_t i, uin } +RegisterValue Function::GetStackContentsAtInstruction(Architecture* arch, uint64_t addr, int64_t offset, size_t size) +{ + BNRegisterValue value = BNGetStackContentsAtInstruction(m_object, arch->GetObject(), addr, offset, size); + return GetRegisterValueFromAPIObject(value); +} + + +RegisterValue Function::GetStackContentsAfterInstruction(Architecture* arch, uint64_t addr, int64_t offset, size_t size) +{ + BNRegisterValue value = BNGetStackContentsAfterInstruction(m_object, arch->GetObject(), addr, offset, size); + return GetRegisterValueFromAPIObject(value); +} + + +RegisterValue Function::GetStackContentsAtLowLevelILInstruction(size_t i, int64_t offset, size_t size) +{ + BNRegisterValue value = BNGetStackContentsAtLowLevelILInstruction(m_object, i, offset, size); + return GetRegisterValueFromAPIObject(value); +} + + +RegisterValue Function::GetStackContentsAfterLowLevelILInstruction(size_t i, int64_t offset, size_t size) +{ + BNRegisterValue value = BNGetStackContentsAfterLowLevelILInstruction(m_object, i, offset, size); + return GetRegisterValueFromAPIObject(value); +} + + +RegisterValue Function::GetParameterValueAtInstruction(Architecture* arch, uint64_t addr, Type* functionType, size_t i) +{ + BNRegisterValue value = BNGetParameterValueAtInstruction(m_object, arch->GetObject(), addr, + functionType ? functionType->GetObject() : nullptr, i); + return GetRegisterValueFromAPIObject(value); +} + + +RegisterValue Function::GetParameterValueAtLowLevelILInstruction(size_t instr, Type* functionType, size_t i) +{ + BNRegisterValue value = BNGetParameterValueAtLowLevelILInstruction(m_object, instr, + functionType ? functionType->GetObject() : nullptr, i); + return GetRegisterValueFromAPIObject(value); +} + + vector<uint32_t> Function::GetRegistersReadByInstruction(Architecture* arch, uint64_t addr) { size_t count; diff --git a/python/__init__.py b/python/__init__.py index 821e3f41..6776ef09 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -2292,7 +2292,7 @@ class Function(object): def get_reg_value_at_low_level_il_instruction(self, i, reg): if isinstance(reg, str): reg = self.arch.regs[reg].index - value = core.BNGetRegisterValueAtInstruction(self.handle, self.arch.handle, i, reg) + value = core.BNGetRegisterValueAtLowLevelILInstruction(self.handle, i, reg) result = RegisterValue(self.arch, value) core.BNFreeRegisterValue(value) return result @@ -2300,7 +2300,55 @@ class Function(object): def get_reg_value_after_low_level_il_instruction(self, i, reg): if isinstance(reg, str): reg = self.arch.regs[reg].index - value = core.BNGetRegisterValueAfterInstruction(self.handle, self.arch.handle, i, reg) + value = core.BNGetRegisterValueAfterLowLevelILInstruction(self.handle, i, reg) + result = RegisterValue(self.arch, value) + core.BNFreeRegisterValue(value) + return result + + def get_stack_contents_at(self, arch, addr, offset, size): + if isinstance(reg, str): + reg = arch.regs[reg].index + value = core.BNGetStackContentsAtInstruction(self.handle, arch.handle, addr, offset, size) + result = RegisterValue(arch, value) + core.BNFreeRegisterValue(value) + return result + + def get_stack_contents_after(self, arch, addr, offset, size): + if isinstance(reg, str): + reg = arch.regs[reg].index + value = core.BNGetStackContentsAfterInstruction(self.handle, arch.handle, addr, reg) + result = RegisterValue(arch, value) + core.BNFreeRegisterValue(value) + return result + + def get_stack_contents_at_low_level_il_instruction(self, i, offset, size): + if isinstance(reg, str): + reg = self.arch.regs[reg].index + value = core.BNGetStackContentsAtLowLevelILInstruction(self.handle, i, offset, size) + result = RegisterValue(self.arch, value) + core.BNFreeRegisterValue(value) + return result + + def get_stack_contents_after_low_level_il_instruction(self, i, offset, size): + if isinstance(reg, str): + reg = self.arch.regs[reg].index + value = core.BNGetStackContentsAfterInstruction(self.handle, i, offset, size) + result = RegisterValue(self.arch, value) + core.BNFreeRegisterValue(value) + return result + + def get_parameter_at(self, arch, addr, func_type, i): + if func_type is not None: + func_type = func_type.handle + value = core.BNGetParameterValueAtInstruction(self.handle, arch.handle, addr, func_type, i) + result = RegisterValue(arch, value) + core.BNFreeRegisterValue(value) + return result + + def get_parameter_at_low_level_il_instruction(self, instr, func_type, i): + if func_type is not None: + func_type = func_type.handle + value = core.BNGetParameterValueAtLowLevelILInstruction(self.handle, instr, func_type, i) result = RegisterValue(self.arch, value) core.BNFreeRegisterValue(value) return result |
