From 902ef4d9ca892e3de23355c3c0fc7b49bf1d9726 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 12 Feb 2021 13:58:24 -0500 Subject: Add unresolved control-flow tracking and associated tag support. --- binaryninjaapi.h | 3 +++ binaryninjacore.h | 3 +++ function.cpp | 17 +++++++++++++++++ python/function.py | 16 ++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index d7911b96..5be370c0 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3135,6 +3135,9 @@ __attribute__ ((format (printf, 1, 2))) std::vector GetIndirectBranches(); std::vector GetIndirectBranchesAt(Architecture* arch, uint64_t addr); + std::vector GetUnresolvedIndirectBranches(); + bool HasUnresolvedIndirectBranches(); + void SetAutoCallTypeAdjustment(Architecture* arch, uint64_t addr, const Confidence>& adjust); void SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust); void SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, diff --git a/binaryninjacore.h b/binaryninjacore.h index a857bd79..c64adc23 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -3336,6 +3336,9 @@ __attribute__ ((format (printf, 1, 2))) uint64_t addr, size_t* count); BINARYNINJACOREAPI void BNFreeIndirectBranchList(BNIndirectBranchInfo* branches); + BINARYNINJACOREAPI uint64_t* BNGetUnresolvedIndirectBranches(BNFunction* func, size_t* count); + BINARYNINJACOREAPI bool BNHasUnresolvedIndirectBranches(BNFunction* func); + BINARYNINJACOREAPI void BNSetAutoCallTypeAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTypeWithConfidence* type); BINARYNINJACOREAPI void BNSetUserCallTypeAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, diff --git a/function.cpp b/function.cpp index 80f55fe6..50799191 100644 --- a/function.cpp +++ b/function.cpp @@ -1192,6 +1192,23 @@ vector Function::GetIndirectBranchesAt(Architecture* arch, u } +vector Function::GetUnresolvedIndirectBranches() +{ + size_t count; + uint64_t* addrs = BNGetUnresolvedIndirectBranches(m_object, &count); + vector result; + result.insert(result.end(), addrs, &addrs[count]); + BNFreeAddressList(addrs); + return result; +} + + +bool Function::HasUnresolvedIndirectBranches() +{ + return BNHasUnresolvedIndirectBranches(m_object); +} + + void Function::SetAutoCallTypeAdjustment(Architecture* arch, uint64_t addr, const Confidence>& adjust) { BNTypeWithConfidence apiObject; diff --git a/python/function.py b/python/function.py index 53a0ec57..15bbf251 100644 --- a/python/function.py +++ b/python/function.py @@ -1659,6 +1659,22 @@ class Function(object): core.BNFreeIndirectBranchList(branches) return result + @property + def unresolved_indirect_branches(self): + """List of unresolved indirect branches (read-only)""" + count = ctypes.c_ulonglong() + addrs = core.BNGetUnresolvedIndirectBranches(self.handle, count) + result = [] + for i in range(0, count.value): + result.append(addrs[i]) + core.BNFreeAddressList(addrs) + return result + + @property + def has_unresolved_indirect_branches(self): + """Has unresolved indirect branches (read-only)""" + return core.BNHasUnresolvedIndirectBranches(self.handle) + @property def session_data(self): """Dictionary object where plugins can store arbitrary data associated with the function""" -- cgit v1.3.1