Skip to content

Commit 83e9452

Browse files
committed
Apply symbols and types to TMS320C6x ELFs
1 parent 8fbf9ca commit 83e9452

3 files changed

Lines changed: 38 additions & 18 deletions

File tree

binaryninjacore.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
// Current ABI version for linking to the core. This is incremented any time
3838
// there are changes to the API that affect linking, including new functions,
3939
// new types, or modifications to existing functions or types.
40-
#define BN_CURRENT_CORE_ABI_VERSION 169
40+
#define BN_CURRENT_CORE_ABI_VERSION 170
4141

4242
// Minimum ABI version that is supported for loading of plugins. Plugins that
4343
// are linked to an ABI version less than this will not be able to load and
4444
// will require rebuilding. The minimum version is increased when there are
4545
// incompatible changes that break binary compatibility, such as changes to
4646
// existing types or functions.
47-
#define BN_MINIMUM_CORE_ABI_VERSION 169
47+
#define BN_MINIMUM_CORE_ABI_VERSION 170
4848

4949
#ifdef __GNUC__
5050
#ifdef BINARYNINJACORE_LIBRARY

rust/src/architecture.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ pub trait ArchitectureWithFunctionContext: Architecture {
595595

596596
pub struct FunctionLifterContext {
597597
pub(crate) handle: *mut BNFunctionLifterContext,
598-
pub function: *mut BNLowLevelILFunction,
598+
pub function: Ref<LowLevelILMutableFunction>,
599599
pub platform: Ref<Platform>,
600600
pub logger: Ref<Logger>,
601601
pub blocks: Vec<Ref<BasicBlock<NativeBlock>>>,
@@ -604,7 +604,7 @@ pub struct FunctionLifterContext {
604604
pub inlined_remapping: HashMap<Location, Location>,
605605
pub user_indirect_branches: HashMap<Location, HashSet<Location>>,
606606
pub auto_indirect_branches: HashMap<Location, HashSet<Location>>,
607-
//pub inlined_calls: HashSet<u64>,
607+
pub inlined_calls: HashSet<u64>,
608608
}
609609

610610
unsafe fn lifter_context_slice<'a, T>(ptr: *const T, len: usize) -> &'a [T] {
@@ -620,6 +620,14 @@ impl FunctionLifterContext {
620620
pub unsafe fn from_raw(
621621
function: *mut BNLowLevelILFunction,
622622
handle: *mut BNFunctionLifterContext,
623+
) -> Self {
624+
Self::from_raw_with_arch(function, handle, None)
625+
}
626+
627+
pub(crate) unsafe fn from_raw_with_arch(
628+
function: *mut BNLowLevelILFunction,
629+
handle: *mut BNFunctionLifterContext,
630+
arch: Option<CoreArchitecture>,
623631
) -> Self {
624632
debug_assert!(!function.is_null());
625633
debug_assert!(!handle.is_null());
@@ -699,9 +707,18 @@ impl FunctionLifterContext {
699707
}
700708
}
701709

710+
let inlined_calls: HashSet<u64> =
711+
lifter_context_slice(flc_ref.inlinedCalls, flc_ref.inlinedCallsCount)
712+
.iter()
713+
.copied()
714+
.collect();
715+
702716
FunctionLifterContext {
703717
handle,
704-
function: BNNewLowLevelILFunctionReference(function),
718+
function: LowLevelILMutableFunction::ref_from_raw_with_arch(
719+
BNNewLowLevelILFunctionReference(function),
720+
arch,
721+
),
705722
platform,
706723
logger,
707724
blocks,
@@ -710,6 +727,7 @@ impl FunctionLifterContext {
710727
inlined_remapping,
711728
user_indirect_branches,
712729
auto_indirect_branches,
730+
inlined_calls,
713731
}
714732
}
715733

@@ -739,14 +757,6 @@ impl FunctionLifterContext {
739757
}
740758
}
741759

742-
impl Drop for FunctionLifterContext {
743-
fn drop(&mut self) {
744-
if !self.function.is_null() {
745-
unsafe { BNFreeLowLevelILFunction(self.function) };
746-
}
747-
}
748-
}
749-
750760
// TODO: WTF?!?!?!?
751761
pub struct CoreArchitectureList(*mut *mut BNArchitecture, usize);
752762

@@ -1765,7 +1775,9 @@ where
17651775
LowLevelILMutableFunction::from_raw_with_arch(function, Some(*custom_arch.as_ref()))
17661776
};
17671777

1768-
let mut ctx = unsafe { FunctionLifterContext::from_raw(function, context) };
1778+
let mut ctx = unsafe {
1779+
FunctionLifterContext::from_raw_with_arch(function, context, Some(*custom_arch.as_ref()))
1780+
};
17691781
custom_arch.lift_function(llil, &mut ctx)
17701782
}
17711783

view/elf/elfview.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,8 +1338,16 @@ bool ElfView::Init()
13381338
DefineElfSymbol(FunctionSymbol, entry->name, entry->value, false, entry->binding);
13391339
break;
13401340
case ELF_STT_FUNC:
1341-
DefineElfSymbol(FunctionSymbol, entry->name, entry->value, false, entry->binding);
1342-
break;
1341+
{
1342+
auto symbolType = FunctionSymbol;
1343+
if (m_plat && m_plat->GetName() == "tms320c6x" &&
1344+
(entry->name.find('$') != std::string::npos || entry->name == "LOOP")) {
1345+
// TMS320C6x ELFs use ELF_STT_FUNC *$* and LOOP symbols for labeling blocks
1346+
symbolType = LocalLabelSymbol;
1347+
}
1348+
DefineElfSymbol(symbolType, entry->name, entry->value, false, entry->binding);
1349+
break;
1350+
}
13431351
case ELF_STT_TLS:
13441352
/* - only create Binja symbols for .symtab (not .dynsym) symbols
13451353
- ignore mapping symbols, all is assumed data
@@ -2617,9 +2625,9 @@ void ElfView::DefineElfSymbol(BNSymbolType type, const string& incomingName, uin
26172625
}
26182626
}
26192627

2620-
if (!typeRef && m_arch && m_arch->GetName() == "hexagon")
2628+
if (!typeRef && m_arch && (m_arch->GetName() == "hexagon" || m_arch->GetName() == "tms320c6x"))
26212629
{
2622-
// Apply platform types for statically linked Hexagon binaries
2630+
// Apply platform types for statically linked Hexagon and TMS320C6x binaries
26232631
typeRef = GetDefaultPlatform()->GetFunctionByName(rawName);
26242632
}
26252633

0 commit comments

Comments
 (0)