From 40192fa7adbf7b53e9d45343b0ae1b47cc5fef86 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 29 Jul 2015 23:35:48 -0400 Subject: Show basic register data flow information on hover --- architecture.cpp | 6 +++++ binaryninjaapi.h | 11 +++++++++ binaryview.cpp | 6 +++++ function.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) diff --git a/architecture.cpp b/architecture.cpp index a3ec56b7..2399e102 100644 --- a/architecture.cpp +++ b/architecture.cpp @@ -416,6 +416,12 @@ vector Architecture::GetModifiedRegistersOnWrite(uint32_t reg) } +uint32_t Architecture::GetRegisterByName(const string& name) +{ + return BNGetArchitectureRegisterByName(m_arch, name.c_str()); +} + + bool Architecture::Assemble(const std::string&, uint64_t, DataBuffer&, std::string& errors) { errors = "Architecture does not implement an assembler.\n"; diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 2d230f6f..df2484df 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -562,6 +562,8 @@ namespace BinaryNinja bool AlwaysBranch(Architecture* arch, uint64_t addr); bool InvertBranch(Architecture* arch, uint64_t addr); bool SkipAndReturnValue(Architecture* arch, uint64_t addr, uint64_t value); + + size_t GetInstructionLength(Architecture* arch, uint64_t addr); }; class BinaryData: public BinaryView @@ -861,6 +863,7 @@ namespace BinaryNinja virtual BNRegisterInfo GetRegisterInfo(uint32_t reg); virtual uint32_t GetStackPointerRegister(); std::vector GetModifiedRegistersOnWrite(uint32_t reg); + uint32_t GetRegisterByName(const std::string& name); virtual bool Assemble(const std::string& code, uint64_t addr, DataBuffer& result, std::string& errors); @@ -1069,6 +1072,14 @@ namespace BinaryNinja Ref GetLowLevelIL() const; std::vector> GetLowLevelILBasicBlocks() const; + size_t GetLowLevelILForInstruction(Architecture* arch, uint64_t addr); + std::vector GetLowLevelILExitsForInstruction(Architecture* arch, uint64_t addr); + BNRegisterValue GetRegisterValueAtInstruction(Architecture* arch, uint64_t addr, uint32_t reg); + BNRegisterValue GetRegisterValueAfterInstruction(Architecture* arch, uint64_t addr, uint32_t reg); + BNRegisterValue GetRegisterValueAtLowLevelILInstruction(size_t i, uint32_t reg); + BNRegisterValue GetRegisterValueAfterLowLevelILInstruction(size_t i, uint32_t reg); + std::vector GetRegistersReadByInstruction(Architecture* arch, uint64_t addr); + std::vector GetRegistersWrittenByInstruction(Architecture* arch, uint64_t addr); Ref GetType() const; diff --git a/binaryview.cpp b/binaryview.cpp index 0e24f65e..12fa6548 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -829,6 +829,12 @@ bool BinaryView::SkipAndReturnValue(Architecture* arch, uint64_t addr, uint64_t } +size_t BinaryView::GetInstructionLength(Architecture* arch, uint64_t addr) +{ + return BNGetInstructionLength(m_view, arch->GetArchitectureObject(), addr); +} + + BinaryData::BinaryData(FileMetadata* file): BinaryView(BNCreateBinaryDataView(file->GetFileObject())) { } diff --git a/function.cpp b/function.cpp index 89b2dfbb..4e813916 100644 --- a/function.cpp +++ b/function.cpp @@ -99,6 +99,75 @@ vector> Function::GetLowLevelILBasicBlocks() const } +size_t Function::GetLowLevelILForInstruction(Architecture* arch, uint64_t addr) +{ + return BNGetLowLevelILForInstruction(m_func, arch->GetArchitectureObject(), addr); +} + + +vector Function::GetLowLevelILExitsForInstruction(Architecture* arch, uint64_t addr) +{ + size_t count; + size_t* exits = BNGetLowLevelILExitsForInstruction(m_func, arch->GetArchitectureObject(), addr, &count); + + vector result; + result.insert(result.end(), exits, &exits[count]); + + BNFreeLowLevelILInstructionList(exits); + return result; +} + + +BNRegisterValue Function::GetRegisterValueAtInstruction(Architecture* arch, uint64_t addr, uint32_t reg) +{ + return BNGetRegisterValueAtInstruction(m_func, arch->GetArchitectureObject(), addr, reg); +} + + +BNRegisterValue Function::GetRegisterValueAfterInstruction(Architecture* arch, uint64_t addr, uint32_t reg) +{ + return BNGetRegisterValueAfterInstruction(m_func, arch->GetArchitectureObject(), addr, reg); +} + + +BNRegisterValue Function::GetRegisterValueAtLowLevelILInstruction(size_t i, uint32_t reg) +{ + return BNGetRegisterValueAtLowLevelILInstruction(m_func, i, reg); +} + + +BNRegisterValue Function::GetRegisterValueAfterLowLevelILInstruction(size_t i, uint32_t reg) +{ + return BNGetRegisterValueAfterLowLevelILInstruction(m_func, i, reg); +} + + +vector Function::GetRegistersReadByInstruction(Architecture* arch, uint64_t addr) +{ + size_t count; + uint32_t* regs = BNGetRegistersReadByInstruction(m_func, arch->GetArchitectureObject(), addr, &count); + + vector result; + result.insert(result.end(), regs, ®s[count]); + + BNFreeRegisterList(regs); + return result; +} + + +vector Function::GetRegistersWrittenByInstruction(Architecture* arch, uint64_t addr) +{ + size_t count; + uint32_t* regs = BNGetRegistersWrittenByInstruction(m_func, arch->GetArchitectureObject(), addr, &count); + + vector result; + result.insert(result.end(), regs, ®s[count]); + + BNFreeRegisterList(regs); + return result; +} + + Ref Function::GetType() const { return new Type(BNGetFunctionType(m_func)); -- cgit v1.3.1