diff options
| author | Brandon Miller <brandon@vector35.com> | 2026-05-27 08:56:19 -0400 |
|---|---|---|
| committer | Brandon Miller <brandon@vector35.com> | 2026-05-27 08:56:19 -0400 |
| commit | 83e945296c9fd54c1cb5f28a3f41b5477418393d (patch) | |
| tree | a1556a2d1b41166d77e0636513c0a58564ff5335 | |
| parent | 8fbf9ca9c0c32c600008dc6d85cacf84276736f8 (diff) | |
Apply symbols and types to TMS320C6x ELFs
| -rw-r--r-- | binaryninjacore.h | 4 | ||||
| -rw-r--r-- | rust/src/architecture.rs | 36 | ||||
| -rw-r--r-- | view/elf/elfview.cpp | 16 |
3 files changed, 38 insertions, 18 deletions
diff --git a/binaryninjacore.h b/binaryninjacore.h index 033d3c29..178312b2 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -37,14 +37,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 169 +#define BN_CURRENT_CORE_ABI_VERSION 170 // 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 169 +#define BN_MINIMUM_CORE_ABI_VERSION 170 #ifdef __GNUC__ #ifdef BINARYNINJACORE_LIBRARY diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index 3d081b9f..df2e66b7 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -595,7 +595,7 @@ pub trait ArchitectureWithFunctionContext: Architecture { pub struct FunctionLifterContext { pub(crate) handle: *mut BNFunctionLifterContext, - pub function: *mut BNLowLevelILFunction, + pub function: Ref<LowLevelILMutableFunction>, pub platform: Ref<Platform>, pub logger: Ref<Logger>, pub blocks: Vec<Ref<BasicBlock<NativeBlock>>>, @@ -604,7 +604,7 @@ pub struct FunctionLifterContext { pub inlined_remapping: HashMap<Location, Location>, pub user_indirect_branches: HashMap<Location, HashSet<Location>>, pub auto_indirect_branches: HashMap<Location, HashSet<Location>>, - //pub inlined_calls: HashSet<u64>, + pub inlined_calls: HashSet<u64>, } unsafe fn lifter_context_slice<'a, T>(ptr: *const T, len: usize) -> &'a [T] { @@ -621,6 +621,14 @@ impl FunctionLifterContext { function: *mut BNLowLevelILFunction, handle: *mut BNFunctionLifterContext, ) -> Self { + Self::from_raw_with_arch(function, handle, None) + } + + pub(crate) unsafe fn from_raw_with_arch( + function: *mut BNLowLevelILFunction, + handle: *mut BNFunctionLifterContext, + arch: Option<CoreArchitecture>, + ) -> Self { debug_assert!(!function.is_null()); debug_assert!(!handle.is_null()); let flc_ref = &*handle; @@ -699,9 +707,18 @@ impl FunctionLifterContext { } } + let inlined_calls: HashSet<u64> = + lifter_context_slice(flc_ref.inlinedCalls, flc_ref.inlinedCallsCount) + .iter() + .copied() + .collect(); + FunctionLifterContext { handle, - function: BNNewLowLevelILFunctionReference(function), + function: LowLevelILMutableFunction::ref_from_raw_with_arch( + BNNewLowLevelILFunctionReference(function), + arch, + ), platform, logger, blocks, @@ -710,6 +727,7 @@ impl FunctionLifterContext { inlined_remapping, user_indirect_branches, auto_indirect_branches, + inlined_calls, } } @@ -739,14 +757,6 @@ impl FunctionLifterContext { } } -impl Drop for FunctionLifterContext { - fn drop(&mut self) { - if !self.function.is_null() { - unsafe { BNFreeLowLevelILFunction(self.function) }; - } - } -} - // TODO: WTF?!?!?!? pub struct CoreArchitectureList(*mut *mut BNArchitecture, usize); @@ -1765,7 +1775,9 @@ where LowLevelILMutableFunction::from_raw_with_arch(function, Some(*custom_arch.as_ref())) }; - let mut ctx = unsafe { FunctionLifterContext::from_raw(function, context) }; + let mut ctx = unsafe { + FunctionLifterContext::from_raw_with_arch(function, context, Some(*custom_arch.as_ref())) + }; custom_arch.lift_function(llil, &mut ctx) } diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp index abf860a2..c54663d4 100644 --- a/view/elf/elfview.cpp +++ b/view/elf/elfview.cpp @@ -1338,8 +1338,16 @@ bool ElfView::Init() DefineElfSymbol(FunctionSymbol, entry->name, entry->value, false, entry->binding); break; case ELF_STT_FUNC: - DefineElfSymbol(FunctionSymbol, entry->name, entry->value, false, entry->binding); - break; + { + auto symbolType = FunctionSymbol; + if (m_plat && m_plat->GetName() == "tms320c6x" && + (entry->name.find('$') != std::string::npos || entry->name == "LOOP")) { + // TMS320C6x ELFs use ELF_STT_FUNC *$* and LOOP symbols for labeling blocks + symbolType = LocalLabelSymbol; + } + DefineElfSymbol(symbolType, entry->name, entry->value, false, entry->binding); + break; + } case ELF_STT_TLS: /* - only create Binja symbols for .symtab (not .dynsym) symbols - ignore mapping symbols, all is assumed data @@ -2617,9 +2625,9 @@ void ElfView::DefineElfSymbol(BNSymbolType type, const string& incomingName, uin } } - if (!typeRef && m_arch && m_arch->GetName() == "hexagon") + if (!typeRef && m_arch && (m_arch->GetName() == "hexagon" || m_arch->GetName() == "tms320c6x")) { - // Apply platform types for statically linked Hexagon binaries + // Apply platform types for statically linked Hexagon and TMS320C6x binaries typeRef = GetDefaultPlatform()->GetFunctionByName(rawName); } |
