Skip to content

Commit ca28f78

Browse files
committed
Register functions from reloc targets
Rizin shows calls to reloc targets as their function names in disassembly. We do the same in the decompiler. Addresses #312
1 parent 9f8dd11 commit ca28f78

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/RizinScope.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,14 @@ FunctionSymbol *RizinScope::registerFunction(RzAnalysisFunction *fcn) const
410410
return dynamic_cast<FunctionSymbol *>(sym);
411411
}
412412

413+
FunctionSymbol *RizinScope::registerRelocTarget(RzBinReloc *reloc) const
414+
{
415+
RzCoreLock core(arch->getCore());
416+
if(!reloc->import || !reloc->import->name)
417+
return nullptr;
418+
return cache->addFunction(Address(arch->getDefaultCodeSpace(), reloc->target_vaddr), reloc->import->name);
419+
}
420+
413421
Symbol *RizinScope::registerFlag(RzFlagItem *flag) const
414422
{
415423
RzCoreLock core(arch->getCore());
@@ -516,6 +524,14 @@ Symbol *RizinScope::queryRizinAbsolute(ut64 addr, bool contain) const
516524
if(glob)
517525
return registerGlobalVar(glob);
518526

527+
RzBinReloc *reloc = rz_core_get_reloc_to(core, addr);
528+
if(reloc && reloc->import)
529+
{
530+
auto rsym = registerRelocTarget(reloc);
531+
if(rsym)
532+
return rsym;
533+
}
534+
519535
// TODO: register more things
520536

521537
// TODO: correctly handle contain for flags

src/RizinScope.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class RizinArchitecture;
1919
typedef struct rz_analysis_function_t RzAnalysisFunction;
2020
typedef struct rz_flag_item_t RzFlagItem;
2121
typedef struct rz_analysis_var_global_t RzAnalysisVarGlobal;
22+
typedef struct rz_bin_reloc_t RzBinReloc;
2223

2324
class RizinScope : public Scope
2425
{
@@ -30,6 +31,7 @@ class RizinScope : public Scope
3031
uint8 makeId() const { return (*next_id)++; }
3132

3233
FunctionSymbol *registerFunction(RzAnalysisFunction *fcn) const;
34+
FunctionSymbol *registerRelocTarget(RzBinReloc *reloc) const;
3335
Symbol *registerFlag(RzFlagItem *flag) const;
3436
Symbol *registerGlobalVar(RzAnalysisVarGlobal *glob) const;
3537
Symbol *queryRizinAbsolute(ut64 addr, bool contain) const;

test/db/extras/ghidra

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,3 +3262,22 @@ undefined8 entry0(int64_t arg1, int64_t arg2)
32623262
}
32633263
EOF
32643264
RUN
3265+
3266+
NAME=reloc target functions
3267+
FILE=rizin-testbins/elf/linux-example-x86-32.ko
3268+
CMDS=<<EOF
3269+
s sym.ko_example_init
3270+
af
3271+
pdg
3272+
EOF
3273+
EXPECT=<<EOF
3274+
3275+
undefined4 sym.ko_example_init(void)
3276+
{
3277+
// [04] -r-x section size 22 named .init.text
3278+
__fentry__();
3279+
printk("Hello, Rizin!\n");
3280+
return 0;
3281+
}
3282+
EOF
3283+
RUN

0 commit comments

Comments
 (0)