diff options
| author | Brian Potchik <brian@vector35.com> | 2021-04-19 15:39:33 -0400 |
|---|---|---|
| committer | Brian Potchik <brian@vector35.com> | 2021-04-19 15:39:33 -0400 |
| commit | 224e24b283b8be99415431856e6b63dea7305996 (patch) | |
| tree | 96440f2c02cc012ad625bcded8b0c64c2759b785 | |
| parent | 0d52013908d977a12c35e6a03226a90107321c63 (diff) | |
Fix Mach-O duplicate symbol handling for external relocations.
| -rw-r--r-- | binaryninjaapi.h | 2 | ||||
| -rw-r--r-- | binaryninjacore.h | 7 | ||||
| -rw-r--r-- | binaryview.cpp | 8 | ||||
| -rw-r--r-- | python/binaryview.py | 5 | ||||
| -rw-r--r-- | rust/src/binaryview.rs | 8 |
5 files changed, 20 insertions, 10 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 4209b1b6..07d7ea83 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1625,7 +1625,7 @@ __attribute__ ((format (printf, 1, 2))) std::vector<Ref<Symbol>> GetVisibleSymbols(const NameSpace& nameSpace=NameSpace()); void DefineAutoSymbol(Ref<Symbol> sym); - void DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, Ref<Type> type); + Ref<Symbol> DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, Ref<Type> type); void UndefineAutoSymbol(Ref<Symbol> sym); void DefineUserSymbol(Ref<Symbol> sym); diff --git a/binaryninjacore.h b/binaryninjacore.h index 47e0d69d..0115eecf 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -28,14 +28,14 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 4 +#define BN_CURRENT_CORE_ABI_VERSION 5 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and // will require rebuilding. The minimum version is increased when there are // incompatible changes that break binary compatibility, such as changes to // existing types or functions. -#define BN_MINIMUM_CORE_ABI_VERSION 3 +#define BN_MINIMUM_CORE_ABI_VERSION 4 #ifdef __GNUC__ # ifdef BINARYNINJACORE_LIBRARY @@ -3836,8 +3836,7 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI void BNDefineUserSymbol(BNBinaryView* view, BNSymbol* sym); BINARYNINJACOREAPI void BNUndefineUserSymbol(BNBinaryView* view, BNSymbol* sym); BINARYNINJACOREAPI void BNDefineImportedFunction(BNBinaryView* view, BNSymbol* importAddressSym, BNFunction* func, BNType* type); - BINARYNINJACOREAPI void BNDefineAutoSymbolAndVariableOrFunction(BNBinaryView* view, BNPlatform* platform, - BNSymbol* sym, BNType* type); + BINARYNINJACOREAPI BNSymbol* BNDefineAutoSymbolAndVariableOrFunction(BNBinaryView* view, BNPlatform* platform, BNSymbol* sym, BNType* type); BINARYNINJACOREAPI BNSymbol* BNImportedFunctionFromImportAddressSymbol(BNSymbol* sym, uint64_t addr); diff --git a/binaryview.cpp b/binaryview.cpp index a803bf2e..f791090b 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -2211,10 +2211,12 @@ void BinaryView::DefineAutoSymbol(Ref<Symbol> sym) } -void BinaryView::DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, Ref<Type> type) +Ref<Symbol> BinaryView::DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, Ref<Type> type) { - BNDefineAutoSymbolAndVariableOrFunction(m_object, platform ? platform->GetObject() : nullptr, sym->GetObject(), - type ? type->GetObject() : nullptr); + BNSymbol* result = BNDefineAutoSymbolAndVariableOrFunction(m_object, platform ? platform->GetObject() : nullptr, sym->GetObject(), type ? type->GetObject() : nullptr); + if (!result) + return nullptr; + return new Symbol(result); } diff --git a/python/binaryview.py b/python/binaryview.py index 1fde4bcd..2af37321 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -3956,7 +3956,10 @@ class BinaryView(object): elif sym_type is not None: raise AttributeError("Provided sym_type is not of type `binaryninja.Type`") - core.BNDefineAutoSymbolAndVariableOrFunction(self.handle, plat.handle, sym.handle, sym_type) + sym = core.BNDefineAutoSymbolAndVariableOrFunction(self.handle, plat.handle, sym.handle, sym_type) + if sym is None: + return None + return types.Symbol(None, None, None, handle = sym) def undefine_auto_symbol(self, sym): """ diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 528e3374..c5df4f61 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -385,12 +385,18 @@ pub trait BinaryViewExt: BinaryViewBase { }; unsafe { - BNDefineAutoSymbolAndVariableOrFunction( + let raw_sym = BNDefineAutoSymbolAndVariableOrFunction( self.as_ref().handle, plat.handle, sym.handle, raw_type, ); + + if raw_sym.is_null() { + return Err(()); + } + + Ok(Ref::new(Symbol::from_raw(raw_sym))) } } |
