Initial pavement for RCorePriv opaque struct ##api

This commit is contained in:
pancake 2024-08-19 13:04:04 +02:00
parent 0d8ed01c9b
commit e382b998a7
5 changed files with 47 additions and 56 deletions

View File

@ -2086,22 +2086,18 @@ static bool bin_relocs(RCore *r, PJ *pj, int mode, int va) {
return true;
}
#define MYDB 1
/* R2_590 - this is a VERY VERY VERY hacky and bad workaround that needs proper refactoring in Rbin to use Sdb */
#if MYDB
/* R2_600 - avoid using globals to resolve symbols and imports without making it expensive */
R_DEPRECATE static R_TH_LOCAL Sdb *mydb = NULL;
R_DEPRECATE static R_TH_LOCAL RVecRBinSymbol *osymbols = NULL;
R_DEPRECATE static RBinSymbol *get_import(RBin *bin, RVecRBinSymbol *symbols, const char *name, ut64 addr) {
r_strf_buffer(64);
RBinSymbol *symbol, *res = NULL;
#if 1
if (mydb && symbols && symbols != osymbols) {
sdb_free (mydb);
mydb = NULL;
osymbols = symbols;
}
#endif
if (mydb) {
if (name) {
res = (RBinSymbol*)(void*)(size_t)
@ -2138,25 +2134,6 @@ R_DEPRECATE static RBinSymbol *get_import(RBin *bin, RVecRBinSymbol *symbols, co
}
return res;
}
#else
static R_TH_LOCAL RList *osymbols = NULL;
static RBinSymbol *get_symbol(RBin *bin, RList *symbols, const char *name, ut64 addr) {
RBinSymbol *symbol;
RListIter *iter;
// XXX this is slow, we should use a hashtable here
r_list_foreach (symbols, iter, symbol) {
if (name) {
if (!strcmp (symbol->name, name))
return symbol;
} else {
if (symbol->vaddr == addr) {
return symbol;
}
}
}
return NULL;
}
#endif
/* XXX: This is a hack to get PLT references in rabin2 -i */
R_API ut64 r_core_bin_impaddr(RBin *bin, int va, const char *name) {
@ -2307,13 +2284,11 @@ static bool bin_imports(RCore *r, PJ *pj, int mode, int va, const char *name) {
}
r_table_free (table);
#if MYDB
// NOTE: if we comment out this, it will leak.. but it will be faster
// because it will keep the cache across multiple RBin calls
osymbols = NULL;
sdb_free (mydb);
mydb = NULL;
#endif
return true;
}

View File

@ -302,6 +302,10 @@ typedef struct {
int y;
} VisualMark;
#if R2_USE_NEW_ABI
typedef struct RCorePriv RCorePriv;
#endif
struct r_core_t {
RBin *bin;
RConfig *config;

View File

@ -0,0 +1,14 @@
/* radare - LGPL - Copyright 2024 - pancake */
#include <r_core.h>
#ifndef R2_CORE_PRIV_H
#define R2_CORE_PRIV_H
#if R2_USE_NEW_ABI
typedef struct {
int old_bits;
char *old_arch;
} RCorePriv;
#endif
#endif

View File

@ -1,21 +1,19 @@
// script to symbolicate iOS kernels with IPSW by pancake
// ref: https://blacktop.github.io/ipsw/blog/kernel-symbolication/
const jsonFiles = r2.cmdj("ls -j *.js").map((x) => x.name);
function filterFlag(symName) {
return "sym." + symName.replace(/[^a-zA-Z0-9]/g, '_');
}
function loadFlagsFromIpswKsym(jsonFiles) {
function filterFlag(symName) {
return "sym." + symName.replace(/[^a-zA-Z0-9]/g, '_');
}
const script = [];
for (const jf of jsonFiles) {
const data = JSON.parse(r2.cmd("cat " + jf));
const flagName = filterFlag(jf.sym);
script.push("'f ksym." + flagName + " = " + jf.addr);
for (const item of data) {
script.push("'f ksym." + filterFlag(item.sym) + " = " + item.addr);
}
}
script.map(r2.cmd0);
}
const jsonFiles = r2.cmdj("ls -j *.js").map((x) => x.name);
loadFlagsFromIpswKsym(jsonFiles);

View File

@ -721,28 +721,28 @@ colu: 12
addr: 0x00001149
EOF
EXPECT_ERR=<<EOF
DEBUG: [cbin.c:3375] (section .dynsym) Cd 8[21] @ 0x3d8
DEBUG: [cbin.c:3375] (section .dynstr) Css 141 @ 0x480
DEBUG: [cbin.c:3375] (section .rela.dyn) Cd 8[24] @ 0x550
DEBUG: [cbin.c:3375] (section .rela.plt) Cd 8[3] @ 0x610
DEBUG: [cbin.c:3375] (section .init_array) Cd 8[1] @ 0x3db8
DEBUG: [cbin.c:3375] (section .fini_array) Cd 8[1] @ 0x3dc0
DEBUG: [cbin.c:3375] (section .dynamic) Cd 8[62] @ 0x3dc8
DEBUG: [cbin.c:3375] (section .got) Cd 8[9] @ 0x3fb8
DEBUG: [cbin.c:3375] (section .dynsym) Cd 8[21] @ 0x3d8
DEBUG: [cbin.c:3375] (section .dynstr) Css 141 @ 0x480
DEBUG: [cbin.c:3375] (section .rela.dyn) Cd 8[24] @ 0x550
DEBUG: [cbin.c:3375] (section .rela.plt) Cd 8[3] @ 0x610
DEBUG: [cbin.c:3375] (section .init_array) Cd 8[1] @ 0x3db8
DEBUG: [cbin.c:3375] (section .fini_array) Cd 8[1] @ 0x3dc0
DEBUG: [cbin.c:3375] (section .dynamic) Cd 8[62] @ 0x3dc8
DEBUG: [cbin.c:3375] (section .got) Cd 8[9] @ 0x3fb8
DEBUG: [cbin.c:3350] (section .dynsym) Cd 8[21] @ 0x3d8
DEBUG: [cbin.c:3350] (section .dynstr) Css 141 @ 0x480
DEBUG: [cbin.c:3350] (section .rela.dyn) Cd 8[24] @ 0x550
DEBUG: [cbin.c:3350] (section .rela.plt) Cd 8[3] @ 0x610
DEBUG: [cbin.c:3350] (section .init_array) Cd 8[1] @ 0x3db8
DEBUG: [cbin.c:3350] (section .fini_array) Cd 8[1] @ 0x3dc0
DEBUG: [cbin.c:3350] (section .dynamic) Cd 8[62] @ 0x3dc8
DEBUG: [cbin.c:3350] (section .got) Cd 8[9] @ 0x3fb8
DEBUG: [cbin.c:3350] (section .dynsym) Cd 8[21] @ 0x3d8
DEBUG: [cbin.c:3350] (section .dynstr) Css 141 @ 0x480
DEBUG: [cbin.c:3350] (section .rela.dyn) Cd 8[24] @ 0x550
DEBUG: [cbin.c:3350] (section .rela.plt) Cd 8[3] @ 0x610
DEBUG: [cbin.c:3350] (section .init_array) Cd 8[1] @ 0x3db8
DEBUG: [cbin.c:3350] (section .fini_array) Cd 8[1] @ 0x3dc0
DEBUG: [cbin.c:3350] (section .dynamic) Cd 8[62] @ 0x3dc8
DEBUG: [cbin.c:3350] (section .got) Cd 8[9] @ 0x3fb8
WARN: [cbin.c:1904] Relocs has not been applied. Please use `-e bin.relocs.apply=true` or `-e bin.cache=true` next time
DEBUG: [cbin.c:2620] Cannot resolve symbol address __libc_start_main
DEBUG: [cbin.c:2620] Cannot resolve symbol address _ITM_deregisterTMCloneTable
DEBUG: [cbin.c:2620] Cannot resolve symbol address __gmon_start__
DEBUG: [cbin.c:2620] Cannot resolve symbol address _ITM_registerTMCloneTable
DEBUG: [cbin.c:2620] Cannot resolve symbol address __cxa_finalize
DEBUG: [cbin.c:2595] Cannot resolve symbol address __libc_start_main
DEBUG: [cbin.c:2595] Cannot resolve symbol address _ITM_deregisterTMCloneTable
DEBUG: [cbin.c:2595] Cannot resolve symbol address __gmon_start__
DEBUG: [cbin.c:2595] Cannot resolve symbol address _ITM_registerTMCloneTable
DEBUG: [cbin.c:2595] Cannot resolve symbol address __cxa_finalize
EOF
RUN