More elf refactoring cleanups

This commit is contained in:
pancake 2023-05-30 18:29:47 +02:00 committed by GitHub
parent ae11bc6c84
commit 18237ab4f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 273 additions and 370 deletions

View File

@ -231,7 +231,7 @@ static bool init_ehdr(ELFOBJ *eo) {
// > pf `k bin/cur/info/elf_header.format` @ `k bin/cur/info/elf_header.offset`
}
ut64 Elf_(r_bin_elf_get_phnum)(ELFOBJ *obj) {
ut64 Elf_(get_phnum)(ELFOBJ *obj) {
r_return_val_if_fail (obj, 0);
if (obj->ehdr.e_phnum == UT16_MAX) {
@ -259,7 +259,7 @@ static bool read_phdr(ELFOBJ *eo, bool linux_kernel_hack) {
#else
const bool is_elf64 = false;
#endif
ut64 phnum = Elf_(r_bin_elf_get_phnum) (eo);
ut64 phnum = Elf_(get_phnum) (eo);
int i;
for (i = 0; i < phnum; i++) {
ut8 phdr[sizeof (Elf_(Phdr))] = {0};
@ -297,8 +297,8 @@ static bool read_phdr(ELFOBJ *eo, bool linux_kernel_hack) {
* So after the first read, we fix the address and read it again
*/
if (linux_kernel_hack && phdr_found) {
ut64 load_addr = Elf_(r_bin_elf_get_baddr) (eo);
eo->ehdr.e_phoff = Elf_(r_bin_elf_v2p) (eo, load_addr + eo->ehdr.e_phoff);
ut64 load_addr = Elf_(get_baddr) (eo);
eo->ehdr.e_phoff = Elf_(v2p) (eo, load_addr + eo->ehdr.e_phoff);
return read_phdr (eo, false);
}
@ -322,7 +322,7 @@ static int init_phdr(ELFOBJ *eo) {
if (eo->ehdr.e_phoff > eo->size || eo->ehdr.e_phoff + phdr_size > eo->size) {
return false;
}
ut64 phnum = Elf_(r_bin_elf_get_phnum) (eo);
ut64 phnum = Elf_(get_phnum) (eo);
if (!(eo->phdr = R_NEWS0 (Elf_(Phdr), phnum))) {
r_sys_perror ("malloc (phdr)");
return false;
@ -496,7 +496,7 @@ static Elf_(Phdr) *get_dynamic_segment(ELFOBJ *eo) {
}
static void init_dynamic_section_sdb(ELFOBJ *eo, Elf_(Addr) strtabaddr, size_t strsize) {
int r = Elf_(r_bin_elf_has_relro) (eo);
int r = Elf_(has_relro) (eo);
switch (r) {
case R_ELF_FULL_RELRO:
sdb_set (eo->kv, "elf.relro", "full", 0);
@ -677,7 +677,7 @@ static int init_dynamic_section(ELFOBJ *eo) {
return false;
}
ut64 loaded_offset = Elf_(r_bin_elf_v2p_new) (eo, dyn_phdr->p_vaddr);
ut64 loaded_offset = Elf_(v2p_new) (eo, dyn_phdr->p_vaddr);
if (loaded_offset == UT64_MAX) {
return false;
}
@ -691,7 +691,7 @@ static int init_dynamic_section(ELFOBJ *eo) {
ut64 strtabaddr = 0;
if (eo->dyn_info.dt_strtab != R_BIN_ELF_ADDR_MAX) {
strtabaddr = Elf_(r_bin_elf_v2p_new) (eo, eo->dyn_info.dt_strtab);
strtabaddr = Elf_(v2p_new) (eo, eo->dyn_info.dt_strtab);
}
size_t strsize = 0;
@ -783,7 +783,7 @@ static inline ut16 *_parse_edata(ELFOBJ *eo, EDataState *edata_state) {
return NULL;
}
ut64 off = Elf_(r_bin_elf_v2p) (eo, eo->version_info[DT_VERSIONTAGIDX (DT_VERSYM)]);
ut64 off = Elf_(v2p) (eo, eo->version_info[DT_VERSIONTAGIDX (DT_VERSYM)]);
const char *section_name = "";
if (eo->shstrtab && shdr->sh_name < eo->shstrtab_size) {
section_name = &eo->shstrtab[shdr->sh_name];
@ -827,7 +827,7 @@ static inline bool _maybe_parse_aux_ver_needed_info(ELFOBJ *eo, ParseVernauxStat
}
Elf_(Verneed) vn;
ut64 offset = Elf_(r_bin_elf_v2p) (eo, eo->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]);
ut64 offset = Elf_(v2p) (eo, eo->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]);
do {
if (offset > eo->size || offset + sizeof (vn) > eo->size) {
return false;
@ -908,7 +908,7 @@ static inline bool _maybe_parse_version_definition_info(ELFOBJ *eo, ParseVerDefS
Elf_(Verdef) vd;
ut8 svd[sizeof (Elf_(Verdef))] = {0};
ut64 offset = Elf_(r_bin_elf_v2p) (eo, vinfoaddr);
ut64 offset = Elf_(v2p) (eo, vinfoaddr);
if (offset > eo->size || offset + sizeof (vd) > eo->size) {
return false;
}
@ -1554,8 +1554,8 @@ static bool elf_init(ELFOBJ *eo) {
if (!init_dynstr (eo) && !is_bin_etrel (eo)) {
R_LOG_DEBUG ("Cannot initialize dynamic strings");
}
eo->baddr = Elf_(r_bin_elf_get_baddr) (eo);
if (!init_dynamic_section (eo) && !Elf_(r_bin_elf_is_static) (eo) && !is_bin_etrel (eo)) {
eo->baddr = Elf_(get_baddr) (eo);
if (!init_dynamic_section (eo) && !Elf_(is_static) (eo) && !is_bin_etrel (eo)) {
R_LOG_DEBUG ("Cannot initialize dynamic section");
}
}
@ -1565,25 +1565,25 @@ static bool elf_init(ELFOBJ *eo) {
eo->symbols_by_ord_size = 0;
eo->symbols_by_ord = NULL;
(void) _load_elf_sections (eo);
eo->boffset = Elf_(r_bin_elf_get_boffset) (eo);
eo->boffset = Elf_(get_boffset) (eo);
HtUUOptions opt = {0};
eo->rel_cache = ht_uu_new_opt (&opt);
(void) Elf_(r_bin_elf_load_relocs) (eo);
(void) Elf_(load_relocs) (eo);
sdb_ns_set (eo->kv, "versioninfo", store_versioninfo (eo));
return true;
}
ut64 Elf_(r_bin_elf_get_section_offset)(ELFOBJ *eo, const char *section_name) {
ut64 Elf_(get_section_offset)(ELFOBJ *eo, const char *section_name) {
RBinElfSection *section = get_section_by_name (eo, section_name);
return section? section->offset: UT64_MAX;
}
ut64 Elf_(r_bin_elf_get_section_addr)(ELFOBJ *eo, const char *section_name) {
ut64 Elf_(get_section_addr)(ELFOBJ *eo, const char *section_name) {
RBinElfSection *section = get_section_by_name (eo, section_name);
return section? section->rva: UT64_MAX;
}
ut64 Elf_(r_bin_elf_get_section_addr_end)(ELFOBJ *eo, const char *section_name) {
ut64 Elf_(get_section_addr_end)(ELFOBJ *eo, const char *section_name) {
RBinElfSection *section = get_section_by_name (eo, section_name);
return section? section->rva + section->size: UT64_MAX;
}
@ -1593,7 +1593,7 @@ static ut64 get_got_entry(ELFOBJ *eo, RBinElfReloc *rel) {
return UT64_MAX;
}
ut64 p_sym_got_addr = Elf_(r_bin_elf_v2p_new) (eo, rel->rva);
ut64 p_sym_got_addr = Elf_(v2p_new) (eo, rel->rva);
ut64 addr = R_BIN_ELF_BREADWORD (eo->b, p_sym_got_addr);
return (!addr || addr == R_BIN_ELF_WORD_MAX) ? UT64_MAX : addr;
@ -1648,7 +1648,7 @@ static ut64 get_import_addr_mips(ELFOBJ *bin, RBinElfReloc *rel) {
ut64 pos = COMPUTE_PLTGOT_POSITION (rel, got_addr, 0x2);
ut8 buf[128]; /// XXX why arbitrary 128
ut64 plt_addr = jmprel_addr + bin->dyn_info.dt_pltrelsz;
ut64 p_plt_addr = Elf_(r_bin_elf_v2p_new) (bin, plt_addr);
ut64 p_plt_addr = Elf_(v2p_new) (bin, plt_addr);
int res = r_buf_read_at (bin->b, p_plt_addr, buf, sizeof (buf));
if (res == sizeof (buf)) {
const ut8 *base = r_mem_mem_aligned (buf, sizeof (buf), (const ut8 *)"\x3c\x0f\x00", 3, 4);
@ -1713,7 +1713,7 @@ static ut64 get_import_addr_ppc(ELFOBJ *eo, RBinElfReloc *rel) {
return UT64_MAX;
}
ut64 p_plt_addr = Elf_(r_bin_elf_v2p_new) (eo, plt_addr);
ut64 p_plt_addr = Elf_(v2p_new) (eo, plt_addr);
if (p_plt_addr == UT64_MAX) {
return UT64_MAX;
}
@ -1743,7 +1743,7 @@ static ut64 get_import_addr_x86_manual(ELFOBJ *eo, RBinElfReloc *rel) {
return UT64_MAX;
}
ut64 got_offset = Elf_(r_bin_elf_v2p_new) (eo, got_addr);
ut64 got_offset = Elf_(v2p_new) (eo, got_addr);
if (got_offset == UT64_MAX) {
return UT64_MAX;
}
@ -1751,7 +1751,7 @@ static ut64 get_import_addr_x86_manual(ELFOBJ *eo, RBinElfReloc *rel) {
//XXX HACK ALERT!!!! full relro?? try to fix it
//will there always be .plt.got, what would happen if is .got.plt?
RBinElfSection *s = get_section_by_name (eo, ".plt.got");
if (Elf_(r_bin_elf_has_relro) (eo) < R_ELF_PART_RELRO || !s) {
if (Elf_(has_relro) (eo) < R_ELF_PART_RELRO || !s) {
return UT64_MAX;
}
@ -1783,7 +1783,7 @@ static ut64 get_import_addr_x86_manual(ELFOBJ *eo, RBinElfReloc *rel) {
plt_sym_addr = R_BIN_ELF_READWORD (buf, i);
//relative address
if ((plt_addr + 6 + Elf_(r_bin_elf_v2p) (eo, plt_sym_addr)) == rel->rva) {
if ((plt_addr + 6 + Elf_(v2p) (eo, plt_sym_addr)) == rel->rva) {
return plt_addr;
}
if (plt_sym_addr == rel->rva) {
@ -1859,7 +1859,7 @@ static ut64 get_import_addr(ELFOBJ *eo, int sym) {
}
/// XXX this is O(n) and can be cached to avoid walking the sections again
int Elf_(r_bin_elf_has_nx)(ELFOBJ *eo) {
int Elf_(has_nx)(ELFOBJ *eo) {
r_return_val_if_fail (eo, 0);
if (eo && eo->phdr) {
@ -1873,7 +1873,7 @@ int Elf_(r_bin_elf_has_nx)(ELFOBJ *eo) {
return 0;
}
int Elf_(r_bin_elf_has_relro)(ELFOBJ *bin) {
int Elf_(has_relro)(ELFOBJ *bin) {
r_return_val_if_fail (bin, R_ELF_NO_RELRO);
if (bin->phdr) {
bool have_bind_now = false;
@ -1900,7 +1900,7 @@ truncating the memory address to the nearest multiple
of the maximum page size
*/
ut64 Elf_(r_bin_elf_get_baddr)(ELFOBJ *eo) {
ut64 Elf_(get_baddr)(ELFOBJ *eo) {
r_return_val_if_fail (eo, 0);
ut64 base = UT64_MAX;
if (eo->phdr) {
@ -1925,7 +1925,7 @@ ut64 Elf_(r_bin_elf_get_baddr)(ELFOBJ *eo) {
return base;
}
ut64 Elf_(r_bin_elf_get_boffset)(ELFOBJ *eo) {
ut64 Elf_(get_boffset)(ELFOBJ *eo) {
r_return_val_if_fail (eo, 0);
if (!eo->phdr) {
@ -1946,10 +1946,10 @@ ut64 Elf_(r_bin_elf_get_boffset)(ELFOBJ *eo) {
return base;
}
ut64 Elf_(r_bin_elf_get_init_offset)(ELFOBJ *eo) {
ut64 Elf_(get_init_offset)(ELFOBJ *eo) {
r_return_val_if_fail (eo, UT64_MAX);
if (is_intel (eo)) { // push // x86 only
ut64 entry = Elf_(r_bin_elf_get_entry_offset) (eo);
ut64 entry = Elf_(get_entry_offset) (eo);
if (entry == UT64_MAX) {
return UT64_MAX;
}
@ -1958,17 +1958,17 @@ ut64 Elf_(r_bin_elf_get_init_offset)(ELFOBJ *eo) {
if (*buf == 0x68) {
memmove (buf, buf + 1, 4);
ut64 addr = (ut64) r_read_le32 (buf);
return Elf_(r_bin_elf_v2p) (eo, addr);
return Elf_(v2p) (eo, addr);
}
}
}
return 0;
}
ut64 Elf_(r_bin_elf_get_fini_offset)(ELFOBJ *eo) {
ut64 Elf_(get_fini_offset)(ELFOBJ *eo) {
r_return_val_if_fail (eo, UT64_MAX);
if (is_intel (eo)) { // push // x86 only
ut64 entry = Elf_(r_bin_elf_get_entry_offset) (eo);
ut64 entry = Elf_(get_entry_offset) (eo);
if (entry == UT64_MAX) {
return UT64_MAX;
}
@ -1980,29 +1980,29 @@ ut64 Elf_(r_bin_elf_get_fini_offset)(ELFOBJ *eo) {
if (*buf == 0x68) { // push // x86/32 only
memmove (buf, buf + 1, 4);
ut64 addr = (ut64) r_read_le32 (buf);
return Elf_(r_bin_elf_v2p) (eo, addr);
return Elf_(v2p) (eo, addr);
}
}
return 0;
}
static ut64 get_entry_offset_from_shdr(ELFOBJ *eo) {
ut64 sectionOffset = Elf_(r_bin_elf_get_section_offset)(eo, ".init.text");
ut64 sectionOffset = Elf_(get_section_offset)(eo, ".init.text");
if (sectionOffset != UT64_MAX) {
return sectionOffset;
}
sectionOffset = Elf_(r_bin_elf_get_section_offset)(eo, ".text");
sectionOffset = Elf_(get_section_offset)(eo, ".text");
if (sectionOffset != UT64_MAX) {
return sectionOffset;
}
sectionOffset = Elf_(r_bin_elf_get_section_offset)(eo, ".text");
sectionOffset = Elf_(get_section_offset)(eo, ".text");
if (sectionOffset != UT64_MAX) {
return sectionOffset;
}
return UT64_MAX;
}
ut64 Elf_(r_bin_elf_get_entry_offset)(ELFOBJ *eo) {
ut64 Elf_(get_entry_offset)(ELFOBJ *eo) {
r_return_val_if_fail (eo, UT64_MAX);
if (!Elf_(is_executable) (eo)) {
@ -2011,14 +2011,14 @@ ut64 Elf_(r_bin_elf_get_entry_offset)(ELFOBJ *eo) {
ut64 entry = eo->ehdr.e_entry;
if (entry) {
return Elf_(r_bin_elf_v2p) (eo, entry);
return Elf_(v2p) (eo, entry);
}
return get_entry_offset_from_shdr (eo);
}
static ut64 lookup_main_symbol_offset(ELFOBJ *eo) {
const RVector *symbols = Elf_(r_bin_elf_load_symbols) (eo);
const RVector *symbols = Elf_(load_symbols) (eo);
if (symbols) {
RBinElfSymbol *symbol;
r_vector_foreach (symbols, symbol) {
@ -2030,10 +2030,10 @@ static ut64 lookup_main_symbol_offset(ELFOBJ *eo) {
return UT64_MAX;
}
ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
ut64 Elf_(get_main_offset)(ELFOBJ *eo) {
r_return_val_if_fail (eo, UT64_MAX);
ut64 entry = Elf_(r_bin_elf_get_entry_offset) (eo);
ut64 entry = Elf_(get_entry_offset) (eo);
if (entry == UT64_MAX) {
return UT64_MAX;
}
@ -2051,10 +2051,10 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
// ARM64
if (buf[0x18 + 3] == 0x58 && buf[0x2f] == 0x00) {
ut32 entry_vaddr = Elf_(r_bin_elf_p2v) (eo, entry);
ut32 entry_vaddr = Elf_(p2v) (eo, entry);
ut32 main_addr = r_read_le32 (&buf[0x30]);
if ((main_addr >> 16) == (entry_vaddr >> 16)) {
return Elf_(r_bin_elf_v2p) (eo, main_addr);
return Elf_(v2p) (eo, main_addr);
}
}
@ -2072,7 +2072,7 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
delta = 0x30;
}
if (delta) {
ut64 pa = Elf_(r_bin_elf_v2p) (eo, r_read_le32 (&buf[delta - 1]) & ~1);
ut64 pa = Elf_(v2p) (eo, r_read_le32 (&buf[delta - 1]) & ~1);
if (pa < r_buf_size (eo->b)) {
return pa;
}
@ -2083,11 +2083,11 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
if (buf[0x40 + 2] == 0xff && buf[0x40 + 3] == 0xeb) {
// nothing may happen
} else if (!memcmp (buf + 0x28 + 2, "\xff\xeb", 2)) {
return Elf_(r_bin_elf_v2p) (eo, r_read_le32 (&buf[0x34]) & ~1);
return Elf_(v2p) (eo, r_read_le32 (&buf[0x34]) & ~1);
}
}
if (!memcmp (buf, "\x24\xc0\x9f\xe5\x00\xb0\xa0\xe3", 8)) {
return Elf_(r_bin_elf_v2p) (eo, r_read_le32 (&buf[0x30]) & ~1);
return Elf_(v2p) (eo, r_read_le32 (&buf[0x30]) & ~1);
}
}
@ -2104,8 +2104,8 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
*/
ut64 got_offset;
if ((got_offset = Elf_(r_bin_elf_get_section_offset) (eo, ".got")) != UT64_MAX ||
(got_offset = Elf_(r_bin_elf_get_section_offset) (eo, ".got.plt")) != UT64_MAX)
if ((got_offset = Elf_(get_section_offset) (eo, ".got")) != UT64_MAX ||
(got_offset = Elf_(get_section_offset) (eo, ".got.plt")) != UT64_MAX)
{
const ut64 gp = got_offset + 0x7ff0;
size_t len = sizeof (buf) / sizeof (buf[0]);
@ -2115,7 +2115,7 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
if ((instr & 0xffff0000) == 0x8f840000) { // lw a0, offset(gp)
const short delta = instr & 0x0000ffff;
r_buf_read_at (eo->b, /* got_entry_offset = */ gp + delta, buf, 4);
return Elf_(r_bin_elf_v2p) (eo, r_read_le32 (&buf[0]));
return Elf_(v2p) (eo, r_read_le32 (&buf[0]));
}
}
}
@ -2127,15 +2127,15 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
if (buf[0] == 0xe8 && !memcmp (buf + 5, "\x50\xe8\x00\x00\x00\x00\xb8\x01\x00\x00\x00\x53", 12)) {
size_t SIZEOF_CALL = 5;
ut64 rel_addr = (ut64)((int)(buf[1] + (buf[2] << 8) + (buf[3] << 16) + (buf[4] << 24)));
const ut64 addr = Elf_(r_bin_elf_p2v)(eo, entry + SIZEOF_CALL) + rel_addr;
return Elf_(r_bin_elf_v2p) (eo, addr);
const ut64 addr = Elf_(p2v)(eo, entry + SIZEOF_CALL) + rel_addr;
return Elf_(v2p) (eo, addr);
}
// X86-PIE
if (buf[0x00] == 0x48 && buf[0x1e] == 0x8d && buf[0x11] == 0xe8) {
ut32 *pmain = (ut32*)(buf + 0x30);
ut64 vmain = Elf_(r_bin_elf_p2v) (eo, (ut64)*pmain);
ut64 ventry = Elf_(r_bin_elf_p2v) (eo, entry);
ut64 vmain = Elf_(p2v) (eo, (ut64)*pmain);
ut64 ventry = Elf_(p2v) (eo, entry);
if (vmain >> 16 == ventry >> 16) {
return (ut64) vmain;
}
@ -2154,7 +2154,7 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
maddr = (ut64) r_read_le32 (&n32s[0]);
ut64 baddr = (eo->ehdr.e_entry >> 16) << 16;
if (eo->phdr) {
baddr = Elf_(r_bin_elf_get_baddr) (eo);
baddr = Elf_(get_baddr) (eo);
}
maddr += baddr;
return maddr;
@ -2168,12 +2168,12 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
}
if (!memcmp (buf + 29, "\x48\xc7\xc7", 3)) { // linux
ut64 addr = (ut64)r_read_le32 (&buf[29 + 3]);
return Elf_(r_bin_elf_v2p) (eo, addr);
return Elf_(v2p) (eo, addr);
}
#else
if (buf[23] == '\x68') {
ut64 addr = (ut64)r_read_le32 (&buf[23 + 1]);
return Elf_(r_bin_elf_v2p) (eo, addr);
return Elf_(v2p) (eo, addr);
}
#endif
// linux64 pie main -- probably buggy in some cases
@ -2192,7 +2192,7 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
ut8 *p = buf + bo + 3;
st32 maindelta = (st32)r_read_le32 (p);
ut64 vmain = (ut64)(entry + bo + maindelta) + 7;
ut64 ventry = Elf_(r_bin_elf_p2v) (eo, entry);
ut64 ventry = Elf_(p2v) (eo, entry);
if ((vmain >> 16) == (ventry >> 16)) {
return (ut64)vmain;
}
@ -2204,7 +2204,7 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *eo) {
return lookup_main_symbol_offset (eo);
}
bool Elf_(r_bin_elf_get_stripped)(ELFOBJ *eo) {
bool Elf_(get_stripped)(ELFOBJ *eo) {
if (!eo->shdr) {
return true;
}
@ -2223,7 +2223,7 @@ bool Elf_(r_bin_elf_get_stripped)(ELFOBJ *eo) {
return true;
}
char *Elf_(r_bin_elf_intrp)(ELFOBJ *eo) {
char *Elf_(intrp)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (!eo->phdr) {
return NULL;
@ -2261,7 +2261,7 @@ char *Elf_(r_bin_elf_intrp)(ELFOBJ *eo) {
return NULL;
}
bool Elf_(r_bin_elf_is_static)(ELFOBJ *eo) {
bool Elf_(is_static)(ELFOBJ *eo) {
if (!eo->phdr) {
return false;
}
@ -2274,7 +2274,7 @@ bool Elf_(r_bin_elf_is_static)(ELFOBJ *eo) {
return true;
}
char* Elf_(r_bin_elf_get_data_encoding)(ELFOBJ *eo) {
char* Elf_(get_data_encoding)(ELFOBJ *eo) {
switch (eo->ehdr.e_ident[EI_DATA]) {
case ELFDATANONE: return strdup ("none");
case ELFDATA2LSB: return strdup ("2's complement, little endian");
@ -2283,11 +2283,11 @@ char* Elf_(r_bin_elf_get_data_encoding)(ELFOBJ *eo) {
}
}
int Elf_(r_bin_elf_has_va)(ELFOBJ *eo) {
int Elf_(has_va)(ELFOBJ *eo) {
return true;
}
char* Elf_(r_bin_elf_get_arch)(ELFOBJ *eo) {
char* Elf_(get_arch)(ELFOBJ *eo) {
switch (eo->ehdr.e_machine) {
case EM_ARC:
case EM_ARC_A5:
@ -2364,7 +2364,7 @@ char* Elf_(r_bin_elf_get_arch)(ELFOBJ *eo) {
}
}
char* Elf_(r_bin_elf_get_abi)(ELFOBJ *eo) {
char* Elf_(get_abi)(ELFOBJ *eo) {
Elf_(Ehdr)* ehdr = &eo->ehdr;
ut32 eflags = eo->ehdr.e_flags;
@ -2459,7 +2459,7 @@ static const char *v850_flags_to_cpu(ut32 type) {
return NULL;
}
char* Elf_(r_bin_elf_get_cpu)(ELFOBJ *eo) {
char* Elf_(get_cpu)(ELFOBJ *eo) {
const char *cpu = NULL;
switch (eo->ehdr.e_machine) {
case EM_MIPS:
@ -2481,7 +2481,7 @@ char* Elf_(r_bin_elf_get_cpu)(ELFOBJ *eo) {
// http://www.sco.com/developers/gabi/latest/ch4.eheader.html
char* Elf_(r_bin_elf_get_machine_name)(ELFOBJ *eo) {
char* Elf_(get_machine_name)(ELFOBJ *eo) {
switch (eo->ehdr.e_machine) {
case EM_NONE: return strdup ("No machine");
case EM_M32: return strdup ("AT&T WE 32100");
@ -2645,7 +2645,7 @@ char* Elf_(r_bin_elf_get_machine_name)(ELFOBJ *eo) {
}
}
char* Elf_(r_bin_elf_get_file_type)(ELFOBJ *eo) {
char* Elf_(get_file_type)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
ut64 e_type = (ut64)eo->ehdr.e_type; // cast to avoid warn in iphone-gcc, must be ut16
@ -2668,7 +2668,7 @@ char* Elf_(r_bin_elf_get_file_type)(ELFOBJ *eo) {
return r_str_newf ("<unknown>: 0x%"PFMT64x, e_type);
}
char* Elf_(r_bin_elf_get_elf_class)(ELFOBJ *eo) {
char* Elf_(get_elf_class)(ELFOBJ *eo) {
switch (eo->ehdr.e_ident[EI_CLASS]) {
case ELFCLASSNONE: return strdup ("none");
case ELFCLASS32: return strdup ("ELF32");
@ -2677,7 +2677,7 @@ char* Elf_(r_bin_elf_get_elf_class)(ELFOBJ *eo) {
}
}
int Elf_(r_bin_elf_get_bits)(ELFOBJ *eo) {
int Elf_(get_bits)(ELFOBJ *eo) {
// Hack for ARCompact
if (eo->ehdr.e_machine == EM_ARC_A5) {
return 16;
@ -2723,7 +2723,7 @@ int Elf_(r_bin_elf_get_bits)(ELFOBJ *eo) {
// Hack for Thumb
if (eo->ehdr.e_machine == EM_ARM) {
if (eo->ehdr.e_type != ET_EXEC) {
const RVector *symbols = Elf_(r_bin_elf_load_symbols) (eo);
const RVector *symbols = Elf_(load_symbols) (eo);
if (symbols) {
RBinElfSymbol *symbol;
r_vector_foreach (symbols, symbol) {
@ -2735,7 +2735,7 @@ int Elf_(r_bin_elf_get_bits)(ELFOBJ *eo) {
}
}
ut64 entry = Elf_(r_bin_elf_get_entry_offset) (eo);
ut64 entry = Elf_(get_entry_offset) (eo);
if (entry & 1) {
return 16;
}
@ -2772,7 +2772,7 @@ static inline bool needle(ELFOBJ *eo, const char *s) {
}
// TODO: must return const char * all those strings must be const char os[LINUX] or so
char* Elf_(r_bin_elf_get_osabi_name)(ELFOBJ *eo) {
char* Elf_(get_osabi_name)(ELFOBJ *eo) {
switch (eo->ehdr.e_ident[EI_OSABI]) {
case ELFOSABI_LINUX: return strdup ("linux");
case ELFOSABI_SOLARIS: return strdup ("solaris");
@ -2847,7 +2847,7 @@ static inline bool _calculate_reg_offset(ELFOBJ *eo, RegOffsetState *state) {
return success;
}
ut8 *Elf_(r_bin_elf_grab_regstate)(ELFOBJ *eo, int *len) {
ut8 *Elf_(grab_regstate)(ELFOBJ *eo, int *len) {
if (!eo->phdr) {
R_LOG_DEBUG ("Cannot find NOTE section");
return NULL;
@ -2905,12 +2905,12 @@ ut8 *Elf_(r_bin_elf_grab_regstate)(ELFOBJ *eo, int *len) {
return NULL;
}
int Elf_(r_bin_elf_is_big_endian)(ELFOBJ *eo) {
int Elf_(is_big_endian)(ELFOBJ *eo) {
return eo->ehdr.e_ident[EI_DATA] == ELFDATA2MSB;
}
/* XXX Init dt_strtab? */
char *Elf_(r_bin_elf_get_rpath)(ELFOBJ *eo) {
char *Elf_(get_rpath)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (!eo->phdr || !eo->strtab) {
@ -2945,7 +2945,7 @@ static void fix_rva_and_offset_relocable_file(ELFOBJ *eo, RBinElfReloc *r, size_
if (idx < eo->ehdr.e_shnum) {
ut64 pa = eo->shdr[idx].sh_offset + r->offset;
r->offset = pa;
r->rva = Elf_(r_bin_elf_p2v) (eo, pa);
r->rva = Elf_(p2v) (eo, pa);
} else {
R_LOG_WARN ("fix_rva_and_offset_reloc have an invalid index");
}
@ -2957,7 +2957,7 @@ static void fix_rva_and_offset_relocable_file(ELFOBJ *eo, RBinElfReloc *r, size_
static void fix_rva_and_offset_exec_file(ELFOBJ *eo, RBinElfReloc *r) {
// read target and fix patch
r->rva = r->offset;
r->offset = Elf_(r_bin_elf_v2p) (eo, r->offset);
r->offset = Elf_(v2p) (eo, r->offset);
}
static void fix_rva_and_offset(ELFOBJ *eo, RBinElfReloc *r, size_t pos) {
@ -2969,7 +2969,7 @@ static void fix_rva_and_offset(ELFOBJ *eo, RBinElfReloc *r, size_t pos) {
}
static bool read_reloc(ELFOBJ *eo, RBinElfReloc *r, Elf_(Xword) rel_mode, ut64 vaddr) {
ut64 offset = Elf_(r_bin_elf_v2p_new) (eo, vaddr);
ut64 offset = Elf_(v2p_new) (eo, vaddr);
if (offset == UT64_MAX) {
return false;
}
@ -3190,7 +3190,7 @@ static bool populate_relocs_record(ELFOBJ *eo) {
return true;
}
const RVector *Elf_(r_bin_elf_load_relocs) (ELFOBJ *eo) {
const RVector *Elf_(load_relocs) (ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (eo->relocs_loaded) {
@ -3205,7 +3205,7 @@ const RVector *Elf_(r_bin_elf_load_relocs) (ELFOBJ *eo) {
return &eo->g_relocs;
}
const RVector* Elf_(r_bin_elf_load_libs)(ELFOBJ *eo) {
const RVector* Elf_(load_libs)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (eo->libs_loaded) {
@ -3247,7 +3247,7 @@ static void create_section_from_phdr(ELFOBJ *eo, const char *name, ut64 addr, ut
}
RBinElfSection *section = r_vector_end (&eo->g_sections);
section->offset = Elf_(r_bin_elf_v2p_new) (eo, addr);
section->offset = Elf_(v2p_new) (eo, addr);
section->rva = addr;
section->size = sz;
r_str_ncpy (section->name, name, R_ARRAY_SIZE (section->name) - 1);
@ -3413,9 +3413,9 @@ static void dtproceed(RBinFile *bf, ut64 preinit_addr, ut64 preinit_size, int sy
}
}
int big_endian = Elf_(r_bin_elf_is_big_endian) (obj);
ut64 from = Elf_(r_bin_elf_v2p) (obj, preinit_addr);
ut64 _baddr = Elf_(r_bin_elf_get_baddr) (bf->o->bin_obj);
int big_endian = Elf_(is_big_endian) (obj);
ut64 from = Elf_(v2p) (obj, preinit_addr);
ut64 _baddr = Elf_(get_baddr) (bf->o->bin_obj);
ut64 to = from + preinit_size;
ut64 at;
for (at = from; at < to ; at += R_BIN_ELF_WORDSIZE) {
@ -3429,7 +3429,7 @@ static void dtproceed(RBinFile *bf, ut64 preinit_addr, ut64 preinit_size, int sy
R_LOG_DEBUG ("invalid dynamic init address at 0x%08"PFMT64x, at);
break;
}
ut64 caddr = Elf_(r_bin_elf_v2p) (obj, addr);
ut64 caddr = Elf_(v2p) (obj, addr);
if (!caddr) {
R_LOG_DEBUG ("v2p failed for 0x%08"PFMT64x, caddr);
break;
@ -3449,7 +3449,7 @@ static void dtproceed(RBinFile *bf, ut64 preinit_addr, ut64 preinit_size, int sy
static bool parse_pt_dynamic(RBinFile *bf, RBinSection *ptr) {
ELFOBJ *obj = R_UNWRAP3 (bf, o, bin_obj);
int big_endian = Elf_(r_bin_elf_is_big_endian) (obj);
int big_endian = Elf_(is_big_endian) (obj);
Elf_(Dyn) entry;
ut64 preinit_addr = UT64_MAX;
ut64 preinit_size = UT64_MAX;
@ -3644,100 +3644,9 @@ static bool _add_sections_from_phdr(RBinFile *bf, ELFOBJ *eo, bool *found_load)
// program headers is another section
ut16 mach = eo->ehdr.e_machine;
ut64 num = Elf_(r_bin_elf_get_phnum) (eo);
ut64 num = Elf_(get_phnum) (eo);
r_vector_reserve (&eo->cached_sections, r_vector_length (&eo->cached_sections) + num);
#if 0
<<<<<<< HEAD
bool found_load = false;
if (phdr) {
ut64 num = Elf_(r_bin_elf_get_phnum) (bin);
r_vector_reserve (&bin->cached_sections, r_vector_length (&bin->cached_sections) + num);
int i = 0, n = 0;
for (i = 0; i < num; i++) {
RBinSection *ptr = r_vector_end (&bin->cached_sections);
if (!ptr) {
return;
}
ptr->add = false;
ptr->size = phdr[i].p_filesz;
ptr->vsize = phdr[i].p_memsz;
ptr->paddr = phdr[i].p_offset;
ptr->vaddr = phdr[i].p_vaddr;
ptr->perm = phdr[i].p_flags; // perm are rwx like x=1, w=2, r=4, aka no need to convert from r2's R_PERM
ptr->is_segment = true;
switch (phdr[i].p_type) {
case PT_DYNAMIC:
ptr->name = strdup ("DYNAMIC");
parse_pt_dynamic (bf, ptr);
break;
case PT_LOOS:
ptr->name = r_str_newf ("LOOS");
break;
case PT_LOAD:
ptr->name = r_str_newf ("LOAD%d", n++);
ptr->perm |= R_PERM_R;
found_load = true;
ptr->add = true;
break;
case PT_INTERP:
ptr->name = strdup ("INTERP");
break;
case PT_GNU_STACK:
ptr->name = strdup ("GNU_STACK");
break;
case PT_GNU_RELRO:
ptr->name = strdup ("GNU_RELRO");
break;
case PT_GNU_PROPERTY:
ptr->name = strdup ("GNU_PROPERTY");
break;
case PT_GNU_EH_FRAME:
ptr->name = strdup ("GNU_EH_FRAME");
break;
case PT_PHDR:
ptr->name = strdup ("PHDR");
break;
case PT_TLS:
ptr->name = strdup ("TLS");
break;
case PT_NOTE:
ptr->name = strdup ("NOTE");
break;
case PT_LOPROC:
ptr->name = strdup ("LOPROC");
break;
case PT_SUNWBSS:
ptr->name = strdup ("SUNWBSS");
break;
case PT_HISUNW:
ptr->name = strdup ("HISUNW");
break;
case PT_SUNWSTACK:
ptr->name = strdup ("SUNWSTACK");
break;
case PT_HIPROC:
ptr->name = strdup ("HIPROC");
break;
case PT_OPENBSD_RANDOMIZE:
ptr->name = strdup ("OPENBSD_RANDOMIZE");
break;
case PT_OPENBSD_WXNEEDED:
ptr->name = strdup ("OPENBSD_WXNEEDED");
break;
case PT_OPENBSD_BOOTDATA:
ptr->name = strdup ("OPENBSD_BOOTDATA");
break;
default:
if (ptr->size == 0 && ptr->vsize == 0) {
ptr->name = strdup ("NONE");
} else {
ptr->name = setphname (mach, phdr[i].p_type);
}
break;
#endif
int i = 0, n = 0;
for (i = 0; i < num; i++) {
RBinSection *ptr = r_vector_end (&eo->cached_sections);
@ -3895,7 +3804,7 @@ static void _fini_bin_section(RBinSection *section, void *user) {
}
}
const RVector* Elf_(r_bin_elf_load_sections)(RBinFile *bf, ELFOBJ *eo) {
const RVector* Elf_(load_sections)(RBinFile *bf, ELFOBJ *eo) {
r_return_val_if_fail (bf && eo, NULL);
if (!eo->sections_cached) {
const RVector *sections = _load_elf_sections (eo);
@ -4043,7 +3952,7 @@ static bool _read_symbols_from_phdr (ELFOBJ *eo, ReadPhdrSymbolState *state) {
break;
}
ut64 tmp_offset = Elf_(r_bin_elf_v2p_new) (eo, toffset);
ut64 tmp_offset = Elf_(v2p_new) (eo, toffset);
if (tmp_offset == UT64_MAX) {
tmp_offset = toffset;
is_vaddr = true;
@ -4056,36 +3965,36 @@ static bool _read_symbols_from_phdr (ELFOBJ *eo, ReadPhdrSymbolState *state) {
break;
}
RBinElfSymbol *new_phdr_symbol = r_vector_end (ret);
if (!new_phdr_symbol) {
RBinElfSymbol *psym = r_vector_end (ret);
if (!psym) {
return false;
}
new_phdr_symbol->offset = tmp_offset;
new_phdr_symbol->size = tsize;
psym->offset = tmp_offset;
psym->size = tsize;
int rest = ELF_STRING_LENGTH - 1;
int st_name = new_symbol->st_name;
int maxsize = R_MIN (eo->size, eo->strtab_size);
if (st_name < 0 || st_name >= maxsize) {
new_phdr_symbol->name[0] = 0;
psym->name[0] = 0;
} else {
const int len = r_str_nlen (eo->strtab + st_name, rest);
memcpy (new_phdr_symbol->name, &eo->strtab[st_name], len);
memcpy (psym->name, &eo->strtab[st_name], len);
}
new_phdr_symbol->ordinal = i;
new_phdr_symbol->in_shdr = false;
new_phdr_symbol->name[ELF_STRING_LENGTH - 2] = '\0';
if (!*new_phdr_symbol->name) {
R_LOG_DEBUG ("empty symbol name", new_phdr_symbol->name);
psym->ordinal = i;
psym->in_shdr = false;
psym->name[ELF_STRING_LENGTH - 2] = '\0';
if (!*psym->name) {
R_LOG_DEBUG ("empty symbol name", psym->name);
ret->len--;
continue;
}
fill_symbol_bind_and_type (eo, new_phdr_symbol, new_symbol);
new_phdr_symbol->is_sht_null = is_sht_null;
new_phdr_symbol->is_vaddr = is_vaddr;
fill_symbol_bind_and_type (eo, psym, new_symbol);
psym->is_sht_null = is_sht_null;
psym->is_vaddr = is_vaddr;
}
return true;
@ -4101,7 +4010,7 @@ static RVector* load_symbols_from_phdr(ELFOBJ *eo, int type) {
return NULL;
}
Elf_(Addr) addr_sym_table = Elf_(r_bin_elf_v2p) (eo, eo->dyn_info.dt_symtab);
Elf_(Addr) addr_sym_table = Elf_(v2p) (eo, eo->dyn_info.dt_symtab);
ut32 sym_size = eo->dyn_info.dt_syment;
if (!sym_size) {
return NULL;
@ -4163,7 +4072,7 @@ static RVector* load_symbols_from_phdr(ELFOBJ *eo, int type) {
return ret;
}
static RVector *Elf_(r_bin_elf_load_phdr_symbols)(ELFOBJ *eo) {
static RVector *Elf_(load_phdr_symbols)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (!eo->phdr_symbols) {
@ -4172,26 +4081,25 @@ static RVector *Elf_(r_bin_elf_load_phdr_symbols)(ELFOBJ *eo) {
return eo->phdr_symbols;
}
static RVector *Elf_(r_bin_elf_load_phdr_imports)(ELFOBJ *eo) {
static RVector *Elf_(load_phdr_imports)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (!eo->phdr_imports) {
eo->phdr_imports = load_symbols_from_phdr (eo, R_BIN_ELF_IMPORT_SYMBOLS);
}
return eo->phdr_imports;
}
static RVector *Elf_(load_phdr_symbols)(ELFOBJ *eo, int type) {
static RVector *Elf_(load_symbols_type)(ELFOBJ *eo, int type) {
return (type != R_BIN_ELF_IMPORT_SYMBOLS)
? Elf_(r_bin_elf_load_phdr_symbols) (eo)
: Elf_(r_bin_elf_load_phdr_imports) (eo);
? Elf_(load_phdr_symbols) (eo)
: Elf_(load_phdr_imports) (eo);
}
static int Elf_(fix_symbols)(ELFOBJ *eo, int nsym, int type, RVector *symbols) {
int result = -1;
HtUP *phd_offset_map = ht_up_new0 ();
HtUP *phd_ordinal_map = ht_up_new0 ();
const RVector *phdr_symbols = Elf_(load_phdr_symbols) (eo, type);
const RVector *phdr_symbols = Elf_(load_symbols_type) (eo, type);
if (phdr_symbols) {
RBinElfSymbol *symbol;
@ -4272,8 +4180,8 @@ static void setsymord(ELFOBJ* eobj, ut32 ord, RBinSymbol *ptr) {
eobj->symbols_by_ord[ord] = ptr;
}
static void _set_arm_thumb_bits(struct Elf_(r_bin_elf_obj_t) *eo, RBinSymbol **sym) {
int bin_bits = Elf_(r_bin_elf_get_bits) (eo);
static void _set_arm_thumb_bits(struct Elf_(obj_t) *eo, RBinSymbol **sym) {
int bin_bits = Elf_(get_bits) (eo);
RBinSymbol *ptr = *sym;
int len = strlen (ptr->name);
if (ptr->name[0] == '$' && (len >= 2 && !ptr->name[2])) {
@ -4314,14 +4222,14 @@ arm_symbol:
}
}
RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(r_bin_elf_obj_t) *eo, RBinElfSymbol *symbol, const char *namefmt) {
RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(obj_t) *eo, RBinElfSymbol *symbol, const char *namefmt) {
ut64 paddr, vaddr;
if (symbol->is_vaddr) {
paddr = UT64_MAX;
vaddr = symbol->offset;
} else {
paddr = symbol->offset;
vaddr = Elf_(r_bin_elf_p2v_new) (eo, paddr);
vaddr = Elf_(p2v_new) (eo, paddr);
}
RBinSymbol *ptr = R_NEW0 (RBinSymbol);
@ -4372,12 +4280,12 @@ static RVector* parse_gnu_debugdata(ELFOBJ *eo, size_t *ret_size) {
ut8 *odata = r_sys_unxz (data, size, &osize);
if (odata) {
RBuffer *newelf = r_buf_new_with_pointers (odata, osize, false);
ELFOBJ* newobj = Elf_(r_bin_elf_new_buf) (newelf, false);
ELFOBJ* newobj = Elf_(new_buf) (newelf, false);
RVector *symbols = NULL;
if (newobj) {
symbols = Elf_(r_bin_elf_load_symbols) (newobj);
symbols = Elf_(load_symbols) (newobj);
newobj->g_symbols = NULL;
Elf_(r_bin_elf_free)(newobj);
Elf_(free)(newobj);
}
if (ret_size) {
*ret_size = i;
@ -4489,7 +4397,7 @@ static RVector /* <RBinElfSymbol> */ *Elf_(_r_bin_elf_load_symbols_and_imports)(
if (!eo->shdr || !eo->ehdr.e_shnum || eo->ehdr.e_shnum == 0xffff) {
R_LOG_DEBUG ("invalid section header value");
return Elf_(load_phdr_symbols) (eo, type);
return Elf_(load_symbols_type) (eo, type);
}
ut32 shdr_size = 0;
@ -4663,7 +4571,7 @@ static RVector /* <RBinElfSymbol> */ *Elf_(_r_bin_elf_load_symbols_and_imports)(
es->offset = memory.sym[k].st_value + eo->shdr[memory.sym[k].st_shndx].sh_offset;
}
} else {
es->offset = Elf_(r_bin_elf_v2p_new) (eo, toffset);
es->offset = Elf_(v2p_new) (eo, toffset);
if (es->offset == UT64_MAX) {
es->offset = toffset;
is_vaddr = true;
@ -4709,7 +4617,7 @@ static RVector /* <RBinElfSymbol> */ *Elf_(_r_bin_elf_load_symbols_and_imports)(
}
if (!ret) {
return Elf_(load_phdr_symbols) (eo, type);
return Elf_(load_symbols_type) (eo, type);
}
int nsym = Elf_(fix_symbols) (eo, ret_ctr, type, ret);
@ -4731,7 +4639,7 @@ static RVector /* <RBinElfSymbol> */ *Elf_(_r_bin_elf_load_symbols_and_imports)(
return ret;
}
RVector *Elf_(r_bin_elf_load_symbols)(ELFOBJ *eo) {
RVector *Elf_(load_symbols)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (!eo->g_symbols) {
@ -4740,7 +4648,7 @@ RVector *Elf_(r_bin_elf_load_symbols)(ELFOBJ *eo) {
return eo->g_symbols;
}
RVector *Elf_(r_bin_elf_load_imports)(ELFOBJ *eo) {
RVector *Elf_(load_imports)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (!eo->g_imports) {
@ -4749,7 +4657,7 @@ RVector *Elf_(r_bin_elf_load_imports)(ELFOBJ *eo) {
return eo->g_imports;
}
const RVector* Elf_(r_bin_elf_load_fields)(ELFOBJ *eo) {
const RVector* Elf_(load_fields)(ELFOBJ *eo) {
r_return_val_if_fail (eo, NULL);
if (eo->fields_loaded) {
@ -4785,7 +4693,7 @@ const RVector* Elf_(r_bin_elf_load_fields)(ELFOBJ *eo) {
return &eo->g_fields;
}
void Elf_(r_bin_elf_free)(ELFOBJ* eo) {
void Elf_(free)(ELFOBJ* eo) {
if (!eo) {
return;
}
@ -4845,7 +4753,7 @@ void Elf_(r_bin_elf_free)(ELFOBJ* eo) {
free (eo);
}
ELFOBJ* Elf_(r_bin_elf_new_buf)(RBuffer *buf, bool verbose) {
ELFOBJ* Elf_(new_buf)(RBuffer *buf, bool verbose) {
ELFOBJ *eo = R_NEW0 (ELFOBJ);
if (eo) {
eo->kv = sdb_new0 ();
@ -4853,7 +4761,7 @@ ELFOBJ* Elf_(r_bin_elf_new_buf)(RBuffer *buf, bool verbose) {
eo->verbose = verbose;
eo->b = r_buf_ref (buf);
if (!elf_init (eo)) {
Elf_(r_bin_elf_free) (eo);
Elf_(free) (eo);
return NULL;
}
}
@ -4869,7 +4777,7 @@ static int is_in_vphdr(Elf_(Phdr) *p, ut64 addr) {
}
// Deprecated temporarily. Use r_bin_elf_p2v_new in new code for now.
ut64 Elf_(r_bin_elf_p2v) (ELFOBJ *eo, ut64 paddr) {
ut64 Elf_(p2v) (ELFOBJ *eo, ut64 paddr) {
r_return_val_if_fail (eo, 0);
if (!eo->phdr) {
@ -4894,7 +4802,7 @@ ut64 Elf_(r_bin_elf_p2v) (ELFOBJ *eo, ut64 paddr) {
}
// Deprecated temporarily. Use r_bin_elf_v2p_new in new code for now.
ut64 Elf_(r_bin_elf_v2p)(ELFOBJ *eo, ut64 vaddr) {
ut64 Elf_(v2p)(ELFOBJ *eo, ut64 vaddr) {
r_return_val_if_fail (eo, 0); // UT64_MAX or vaddr?
// r_return_val_if_fail (eo, UT64_MAX);
if (!eo->phdr) {
@ -4919,7 +4827,7 @@ ut64 Elf_(r_bin_elf_v2p)(ELFOBJ *eo, ut64 vaddr) {
/* converts a physical address to the virtual address, looking
* at the program headers in the binary bin */
ut64 Elf_(r_bin_elf_p2v_new) (ELFOBJ *eo, ut64 paddr) {
ut64 Elf_(p2v_new) (ELFOBJ *eo, ut64 paddr) {
r_return_val_if_fail (eo, UT64_MAX);
if (!eo->phdr) {
@ -4939,7 +4847,7 @@ ut64 Elf_(r_bin_elf_p2v_new) (ELFOBJ *eo, ut64 paddr) {
/* converts a virtual address to the relative physical address, looking
* at the program headers in the binary bin */
ut64 Elf_(r_bin_elf_v2p_new) (ELFOBJ *eo, ut64 vaddr) {
ut64 Elf_(v2p_new) (ELFOBJ *eo, ut64 vaddr) {
r_return_val_if_fail (eo, UT64_MAX);
if (!eo->phdr) {
@ -5031,7 +4939,7 @@ static void r_bin_elf_map_free(RBinMap *map) {
}
}
RList *Elf_(r_bin_elf_get_maps)(ELFOBJ *eo) {
RList *Elf_(get_maps)(ELFOBJ *eo) {
if (!eo->phdr) {
return NULL;
}
@ -5069,7 +4977,7 @@ RList *Elf_(r_bin_elf_get_maps)(ELFOBJ *eo) {
return maps;
}
char *Elf_(r_bin_elf_compiler)(ELFOBJ *eo) {
char *Elf_(compiler)(ELFOBJ *eo) {
RBinElfSection *section = get_section_by_name (eo, ".comment");
if (!section) {
return NULL;

View File

@ -17,7 +17,7 @@
#define R_BIN_ELF_DYNSYM_SYMBOLS 1 << 1
#define R_BIN_ELF_IMPORT_SYMBOLS (1 << 2 | (eo->ehdr.e_type == ET_REL ? R_BIN_ELF_SYMTAB_SYMBOLS : R_BIN_ELF_DYNSYM_SYMBOLS))
#define R_BIN_ELF_ALL_SYMBOLS (R_BIN_ELF_SYMTAB_SYMBOLS | R_BIN_ELF_DYNSYM_SYMBOLS)
#define ELFOBJ struct Elf_(r_bin_elf_obj_t)
#define ELFOBJ struct Elf_(obj_t)
#if R_BIN_ELF64
#define R_BIN_ELF_WORDSIZE 0x8
@ -77,7 +77,7 @@ typedef struct r_bin_elf_field_t {
char name[ELF_STRING_LENGTH];
} RBinElfField;
typedef struct Elf_(r_bin_elf_dynamic_info) {
typedef struct Elf_(dynamic_info) {
Elf_(Xword) dt_pltrelsz;
Elf_(Addr) dt_pltgot;
Elf_(Addr) dt_hash;
@ -107,7 +107,7 @@ typedef struct r_bin_elf_lib_t {
char name[ELF_STRING_LENGTH];
} RBinElfLib;
struct Elf_(r_bin_elf_obj_t) {
struct Elf_(obj_t) {
Elf_(Ehdr) ehdr;
Elf_(Phdr) *phdr;
Elf_(Shdr) *shdr;
@ -161,58 +161,58 @@ struct Elf_(r_bin_elf_obj_t) {
RVector g_fields; // RBinElfField
};
int Elf_(r_bin_elf_has_va)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_get_section_addr)(struct Elf_(r_bin_elf_obj_t) *bin, const char *section_name);
ut64 Elf_(r_bin_elf_get_section_offset)(struct Elf_(r_bin_elf_obj_t) *bin, const char *section_name);
ut64 Elf_(r_bin_elf_get_baddr)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_p2v)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 paddr);
ut64 Elf_(r_bin_elf_v2p)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 vaddr);
ut64 Elf_(r_bin_elf_p2v_new)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 paddr);
ut64 Elf_(r_bin_elf_v2p_new)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 vaddr);
ut64 Elf_(r_bin_elf_get_boffset)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_get_entry_offset)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_get_main_offset)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_get_init_offset)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_get_fini_offset)(struct Elf_(r_bin_elf_obj_t) *bin);
char *Elf_(r_bin_elf_intrp)(struct Elf_(r_bin_elf_obj_t) *bin);
char *Elf_(r_bin_elf_compiler)(ELFOBJ *bin);
bool Elf_(r_bin_elf_get_stripped)(struct Elf_(r_bin_elf_obj_t) *bin);
bool Elf_(r_bin_elf_is_static)(struct Elf_(r_bin_elf_obj_t) *bin);
char* Elf_(r_bin_elf_get_data_encoding)(struct Elf_(r_bin_elf_obj_t) *bin);
char* Elf_(r_bin_elf_get_arch)(struct Elf_(r_bin_elf_obj_t) *bin);
char* Elf_(r_bin_elf_get_machine_name)(struct Elf_(r_bin_elf_obj_t) *bin);
char* Elf_(r_bin_elf_get_head_flag)(ELFOBJ *bin); //yin
char* Elf_(r_bin_elf_get_abi)(ELFOBJ *bin);
char* Elf_(r_bin_elf_get_cpu)(ELFOBJ *bin);
char* Elf_(r_bin_elf_get_file_type)(struct Elf_(r_bin_elf_obj_t) *bin);
char* Elf_(r_bin_elf_get_elf_class)(struct Elf_(r_bin_elf_obj_t) *bin);
int Elf_(r_bin_elf_get_bits)(struct Elf_(r_bin_elf_obj_t) *bin);
char* Elf_(r_bin_elf_get_osabi_name)(struct Elf_(r_bin_elf_obj_t) *bin);
int Elf_(r_bin_elf_is_big_endian)(struct Elf_(r_bin_elf_obj_t) *bin);
const RVector *Elf_(r_bin_elf_load_relocs)(struct Elf_(r_bin_elf_obj_t) *bin); // RBinElfReloc
const RVector* Elf_(r_bin_elf_load_libs)(struct Elf_(r_bin_elf_obj_t) *bin); // RBinElfLib
const RVector* Elf_(r_bin_elf_load_sections)(RBinFile *bf, struct Elf_(r_bin_elf_obj_t) *bin);
RVector* Elf_(r_bin_elf_load_symbols)(struct Elf_(r_bin_elf_obj_t) *bin); // RBinElfSymbol
RVector* Elf_(r_bin_elf_load_imports)(struct Elf_(r_bin_elf_obj_t) *bin); // RBinElfSymbol
const RVector* Elf_(r_bin_elf_load_fields)(struct Elf_(r_bin_elf_obj_t) *bin); // RBinElfField
char *Elf_(r_bin_elf_get_rpath)(struct Elf_(r_bin_elf_obj_t) *bin);
int Elf_(has_va)(struct Elf_(obj_t) *bin);
ut64 Elf_(get_section_addr)(struct Elf_(obj_t) *bin, const char *section_name);
ut64 Elf_(get_section_offset)(struct Elf_(obj_t) *bin, const char *section_name);
ut64 Elf_(get_baddr)(struct Elf_(obj_t) *bin);
ut64 Elf_(p2v)(struct Elf_(obj_t) *bin, ut64 paddr);
ut64 Elf_(v2p)(struct Elf_(obj_t) *bin, ut64 vaddr);
ut64 Elf_(p2v_new)(struct Elf_(obj_t) *bin, ut64 paddr);
ut64 Elf_(v2p_new)(struct Elf_(obj_t) *bin, ut64 vaddr);
ut64 Elf_(get_boffset)(struct Elf_(obj_t) *bin);
ut64 Elf_(get_entry_offset)(struct Elf_(obj_t) *bin);
ut64 Elf_(get_main_offset)(struct Elf_(obj_t) *bin);
ut64 Elf_(get_init_offset)(struct Elf_(obj_t) *bin);
ut64 Elf_(get_fini_offset)(struct Elf_(obj_t) *bin);
char *Elf_(intrp)(struct Elf_(obj_t) *bin);
char *Elf_(compiler)(ELFOBJ *bin);
bool Elf_(get_stripped)(struct Elf_(obj_t) *bin);
bool Elf_(is_static)(struct Elf_(obj_t) *bin);
char* Elf_(get_data_encoding)(struct Elf_(obj_t) *bin);
char* Elf_(get_arch)(struct Elf_(obj_t) *bin);
char* Elf_(get_machine_name)(struct Elf_(obj_t) *bin);
char* Elf_(get_head_flag)(ELFOBJ *bin); //yin
char* Elf_(get_abi)(ELFOBJ *bin);
char* Elf_(get_cpu)(ELFOBJ *bin);
char* Elf_(get_file_type)(struct Elf_(obj_t) *bin);
char* Elf_(get_elf_class)(struct Elf_(obj_t) *bin);
int Elf_(get_bits)(struct Elf_(obj_t) *bin);
char* Elf_(get_osabi_name)(struct Elf_(obj_t) *bin);
int Elf_(is_big_endian)(struct Elf_(obj_t) *bin);
const RVector *Elf_(load_relocs)(struct Elf_(obj_t) *bin); // RBinElfReloc
const RVector* Elf_(load_libs)(struct Elf_(obj_t) *bin); // RBinElfLib
const RVector* Elf_(load_sections)(RBinFile *bf, struct Elf_(obj_t) *bin);
RVector* Elf_(load_symbols)(struct Elf_(obj_t) *bin); // RBinElfSymbol
RVector* Elf_(load_imports)(struct Elf_(obj_t) *bin); // RBinElfSymbol
const RVector* Elf_(load_fields)(struct Elf_(obj_t) *bin); // RBinElfField
char *Elf_(get_rpath)(struct Elf_(obj_t) *bin);
struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new)(const char* file, bool verbose);
struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new_buf)(RBuffer *buf, bool verbose);
void Elf_(r_bin_elf_free)(struct Elf_(r_bin_elf_obj_t)* bin);
struct Elf_(obj_t)* Elf_(new)(const char* file, bool verbose);
struct Elf_(obj_t)* Elf_(new_buf)(RBuffer *buf, bool verbose);
void Elf_(free)(struct Elf_(obj_t)* bin);
ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size);
bool Elf_(r_bin_elf_section_perms)(RBinFile *bf, const char *name, int perms);
bool Elf_(r_bin_elf_entry_write)(RBinFile *bf, ut64 addr);
bool Elf_(r_bin_elf_del_rpath)(RBinFile *bf);
ut64 Elf_(resize_section)(RBinFile *bf, const char *name, ut64 size);
bool Elf_(section_perms)(RBinFile *bf, const char *name, int perms);
bool Elf_(entry_write)(RBinFile *bf, ut64 addr);
bool Elf_(del_rpath)(RBinFile *bf);
ut64 Elf_(r_bin_elf_get_phnum)(ELFOBJ *bin);
ut64 Elf_(get_phnum)(ELFOBJ *bin);
bool Elf_(is_executable)(ELFOBJ *bin);
int Elf_(r_bin_elf_has_relro)(struct Elf_(r_bin_elf_obj_t) *bin);
int Elf_(r_bin_elf_has_nx)(struct Elf_(r_bin_elf_obj_t) *bin);
ut8 *Elf_(r_bin_elf_grab_regstate)(struct Elf_(r_bin_elf_obj_t) *bin, int *len);
RList *Elf_(r_bin_elf_get_maps)(ELFOBJ *bin);
RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(r_bin_elf_obj_t) *bin,
int Elf_(has_relro)(struct Elf_(obj_t) *bin);
int Elf_(has_nx)(struct Elf_(obj_t) *bin);
ut8 *Elf_(grab_regstate)(struct Elf_(obj_t) *bin, int *len);
RList *Elf_(get_maps)(ELFOBJ *bin);
RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(obj_t) *bin,
RBinElfSymbol *symbol,
const char *namefmt);
R_API RBinSection *r_bin_section_clone(RBinSection *s);

View File

@ -1,9 +1,5 @@
/* radare - LGPL - Copyright 2010-2019 pancake, nibble */
/* radare - LGPL - Copyright 2010-2023 pancake, nibble */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <r_types.h>
#include <r_util.h>
#include "elf.h"
@ -11,9 +7,8 @@
/* TODO: Take care of endianness */
/* TODO: Real error handling */
/* TODO: Resize sections before .init */
// ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const char *name, ut64 size) {
ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) {
struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj; // , const char *name, ut64 size) {
ut64 Elf_(resize_section)(RBinFile *bf, const char *name, ut64 size) {
struct Elf_(obj_t) *bin = bf->o->bin_obj; // , const char *name, ut64 size) {
Elf_(Ehdr) *ehdr = &bin->ehdr;
Elf_(Phdr) *phdr = bin->phdr, *phdrp;
Elf_(Shdr) *shdr = bin->shdr, *shdrp;
@ -63,7 +58,7 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) {
for (i = 0, shdrp = shdr; i < ehdr->e_shnum; i++, shdrp++) {
if (!strcmp (&strtab[shdrp->sh_name], ".rel.plt")) {
Elf_(Rel) *rel, *relp;
rel = (Elf_(Rel) *)malloc (1+shdrp->sh_size);
rel = (Elf_(Rel) *)malloc (1 + shdrp->sh_size);
if (!rel) {
r_sys_perror ("malloc");
return 0;
@ -171,11 +166,15 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) {
/* XXX Check when delta is negative */
rest_size = bin->size - (rsz_offset + rsz_osize);
buf = (ut8 *)malloc (1+bin->size);
buf = (ut8 *)malloc (1 + bin->size);
if (!buf) {
R_LOG_ERROR ("Cannot allocate %d", bin->size);
return 0;
}
r_buf_read_at (bin->b, 0, (ut8*)buf, bin->size);
r_buf_set_bytes (bin->b, (ut8*)buf, (int)(rsz_offset+rsz_size+rest_size));
r_buf_set_bytes (bin->b, (ut8*)buf, (int)(rsz_offset + rsz_size + rest_size));
printf ("COPY FROM 0x%08"PFMT64x"\n", (ut64)(rsz_offset+rsz_osize));
printf ("COPY FROM 0x%08"PFMT64x"\n", (ut64)(rsz_offset + rsz_osize));
r_buf_read_at (bin->b, rsz_offset + rsz_osize, (ut8*)buf, rest_size);
printf ("COPY TO 0x%08"PFMT64x"\n", (ut64)(rsz_offset+rsz_size));
r_buf_write_at (bin->b, rsz_offset + rsz_size, (ut8*)buf, rest_size);
@ -187,8 +186,8 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) {
}
/* XXX Endianness? */
bool Elf_(r_bin_elf_del_rpath)(RBinFile *bf) {
struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj;
bool Elf_(del_rpath)(RBinFile *bf) {
struct Elf_(obj_t) *bin = bf->o->bin_obj;
Elf_(Dyn) *dyn = NULL;
ut64 stroff = 0LL;
int ndyn, i, j;
@ -233,8 +232,8 @@ bool Elf_(r_bin_elf_del_rpath)(RBinFile *bf) {
return true;
}
bool Elf_(r_bin_elf_section_perms)(RBinFile *bf, const char *name, int perms) {
struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj;
bool Elf_(section_perms)(RBinFile *bf, const char *name, int perms) {
struct Elf_(obj_t) *bin = bf->o->bin_obj;
Elf_(Ehdr) *ehdr = &bin->ehdr;
Elf_(Shdr) *shdr = bin->shdr, *shdrp;
const char *strtab = bin->shstrtab;
@ -269,7 +268,7 @@ bool Elf_(r_bin_elf_section_perms)(RBinFile *bf, const char *name, int perms) {
return false;
}
bool Elf_(r_bin_elf_entry_write)(RBinFile *bf, ut64 addr) {
bool Elf_(entry_write)(RBinFile *bf, ut64 addr) {
const int patchoff = 0x18;
#if R_BIN_ELF64
printf ("wv8 0x%"PFMT64x" @ 0x%x\n", addr, patchoff);

View File

@ -15,7 +15,7 @@ static RBinInfo* info(RBinFile *bf);
static int get_file_type(RBinFile *bf) {
ELFOBJ *obj = bf->o->bin_obj;
char *type = Elf_(r_bin_elf_get_file_type (obj));
char *type = Elf_(get_file_type (obj));
int res = type? (r_str_startswith (type, "CORE") ? R_BIN_TYPE_CORE : R_BIN_TYPE_DEFAULT) : -1;
free (type);
return res;
@ -23,7 +23,7 @@ static int get_file_type(RBinFile *bf) {
static RList *maps(RBinFile *bf) {
r_return_val_if_fail (bf && bf->o, NULL);
return Elf_(r_bin_elf_get_maps)(bf->o->bin_obj);
return Elf_(get_maps)(bf->o->bin_obj);
}
static char* regstate(RBinFile *bf) {
@ -35,14 +35,14 @@ static char* regstate(RBinFile *bf) {
case EM_X86_64:
{
int len = 0;
ut8 *regs = Elf_(r_bin_elf_grab_regstate) (obj, &len);
ut8 *regs = Elf_(grab_regstate) (obj, &len);
char *hexregs = (regs && len > 0) ? r_hex_bin2strdup (regs, len) : NULL;
free (regs);
return hexregs;
}
}
R_LOG_ERROR ("Cannot retrieve regstate on: %s (not yet supported)",
Elf_(r_bin_elf_get_machine_name)(obj));
Elf_(get_machine_name)(obj));
return NULL;
}
@ -56,12 +56,12 @@ static void setimpord(ELFOBJ* eobj, ut32 ord, RBinImport *ptr) {
}
static Sdb* get_sdb(RBinFile *bf) {
ELFOBJ *bin = R_UNWRAP3 (bf, o, bin_obj);
return bin? bin->kv: NULL;
ELFOBJ *eo = R_UNWRAP3 (bf, o, bin_obj);
return eo? eo->kv: NULL;
}
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
ELFOBJ *res = Elf_(r_bin_elf_new_buf) (buf, bf->rbin->verbose);
ELFOBJ *res = Elf_(new_buf) (buf, bf->rbin->verbose);
if (res) {
// sdb_ns_set (sdb, "info", res->kv);
*bin_obj = res;
@ -84,15 +84,15 @@ static void destroy(RBinFile *bf) {
}
R_FREE (eobj->imports_by_ord);
}
Elf_(r_bin_elf_free) ((ELFOBJ*)bf->o->bin_obj);
Elf_(free) ((ELFOBJ*)bf->o->bin_obj);
}
static ut64 baddr(RBinFile *bf) {
return Elf_(r_bin_elf_get_baddr) (bf->o->bin_obj);
return Elf_(get_baddr) (bf->o->bin_obj);
}
static ut64 boffset(RBinFile *bf) {
return Elf_(r_bin_elf_get_boffset) (bf->o->bin_obj);
return Elf_(get_boffset) (bf->o->bin_obj);
}
static RBinAddr* binsym(RBinFile *bf, int sym) {
@ -102,23 +102,23 @@ static RBinAddr* binsym(RBinFile *bf, int sym) {
switch (sym) {
case R_BIN_SYM_ENTRY:
addr = Elf_(r_bin_elf_get_entry_offset) (bf->o->bin_obj);
addr = Elf_(get_entry_offset) (bf->o->bin_obj);
break;
case R_BIN_SYM_MAIN:
addr = Elf_(r_bin_elf_get_main_offset) (bf->o->bin_obj);
addr = Elf_(get_main_offset) (bf->o->bin_obj);
break;
case R_BIN_SYM_INIT:
addr = Elf_(r_bin_elf_get_init_offset) (bf->o->bin_obj);
addr = Elf_(get_init_offset) (bf->o->bin_obj);
break;
case R_BIN_SYM_FINI:
addr = Elf_(r_bin_elf_get_fini_offset) (bf->o->bin_obj);
addr = Elf_(get_fini_offset) (bf->o->bin_obj);
break;
}
if (addr && addr != UT64_MAX && (ret = R_NEW0 (RBinAddr))) {
ELFOBJ *eo = bf->o->bin_obj;
bool is_arm = eo->ehdr.e_machine == EM_ARM;
ret->paddr = addr;
ret->vaddr = Elf_(r_bin_elf_p2v) (obj, addr);
ret->vaddr = Elf_(p2v) (obj, addr);
if (is_arm && addr & 1) {
ret->bits = 16;
ret->vaddr--;
@ -135,8 +135,8 @@ static RList* sections(RBinFile *bf) {
}
// there is no leak here with sections since they are cached by elf.c
// and freed within Elf_(r_bin_elf_free)
const RVector *sections = Elf_(r_bin_elf_load_sections) (bf, obj);
// and freed within Elf_(free)
const RVector *sections = Elf_(load_sections) (bf, obj);
if (!sections) {
return NULL;
}
@ -160,7 +160,7 @@ static RBinAddr* newEntry(RBinFile *bf, ut64 hpaddr, ut64 hvaddr, ut64 vaddr, in
RBinAddr *ptr = R_NEW0 (RBinAddr);
if (ptr) {
ELFOBJ *eo = bf->o->bin_obj;
ptr->paddr = Elf_(r_bin_elf_v2p) (eo, vaddr);
ptr->paddr = Elf_(v2p) (eo, vaddr);
ptr->vaddr = vaddr;
ptr->hpaddr = hpaddr;
ptr->hvaddr = hvaddr;
@ -236,7 +236,7 @@ static RList* entries(RBinFile *bf) {
}
ELFOBJ* eo = bf->o->bin_obj;
ut64 paddr = Elf_(r_bin_elf_get_entry_offset) (eo);
ut64 paddr = Elf_(get_entry_offset) (eo);
if (paddr != UT64_MAX) {
RBinAddr *ptr = R_NEW0 (RBinAddr);
if (!ptr) {
@ -244,7 +244,7 @@ static RList* entries(RBinFile *bf) {
}
ptr->paddr = paddr;
ptr->vaddr = Elf_(r_bin_elf_p2v) (eo, ptr->paddr);
ptr->vaddr = Elf_(p2v) (eo, ptr->paddr);
ptr->hpaddr = 0x18; // e_entry offset in ELF header
ptr->hvaddr = UT64_MAX;
@ -264,11 +264,11 @@ static RList* entries(RBinFile *bf) {
}
}
if (ptr->hvaddr == UT64_MAX) {
Elf_(r_bin_elf_p2v_new) (eo, ptr->hpaddr);
Elf_(p2v_new) (eo, ptr->hpaddr);
}
if (eo->ehdr.e_machine == EM_ARM) {
int bin_bits = Elf_(r_bin_elf_get_bits) (eo);
int bin_bits = Elf_(get_bits) (eo);
if (bin_bits != 64) {
ptr->bits = 32;
if (ptr->vaddr & 1) {
@ -286,7 +286,7 @@ static RList* entries(RBinFile *bf) {
// add entrypoint for jni libraries
// NOTE: this is slow, we shouldnt find for java constructors here
const RVector *symbols = Elf_(r_bin_elf_load_symbols) (eo);
const RVector *symbols = Elf_(load_symbols) (eo);
if (!symbols) {
return ret;
}
@ -303,7 +303,7 @@ static RList* entries(RBinFile *bf) {
RBinAddr *ptr = R_NEW0 (RBinAddr);
if (ptr) {
ptr->paddr = symbol->offset;
ptr->vaddr = Elf_(r_bin_elf_p2v) (eo, ptr->paddr);
ptr->vaddr = Elf_(p2v) (eo, ptr->paddr);
ptr->hpaddr = UT64_MAX;
ptr->type = R_BIN_ENTRY_TYPE_INIT;
r_list_append (ret, ptr);
@ -311,7 +311,7 @@ static RList* entries(RBinFile *bf) {
break;
}
const int bin_bits = Elf_(r_bin_elf_get_bits) (eo);
const int bin_bits = Elf_(get_bits) (eo);
process_constructors (bf, ret, bin_bits < 32 ? 32: bin_bits);
RListIter *iter, *iter2;
RBinAddr *foo, *bar;
@ -350,7 +350,7 @@ static RList* symbols(RBinFile *bf) {
}
// traverse symbols
const RVector *symbols = Elf_(r_bin_elf_load_symbols) (bin);
const RVector *symbols = Elf_(load_symbols) (bin);
if (!symbols) {
return ret;
}
@ -365,7 +365,7 @@ static RList* symbols(RBinFile *bf) {
}
// traverse imports
const RVector *import_symbols = Elf_(r_bin_elf_load_imports) (bin);
const RVector *import_symbols = Elf_(load_imports) (bin);
if (!import_symbols) {
return ret;
}
@ -398,7 +398,7 @@ static RList* imports(RBinFile *bf) {
}
ELFOBJ *elf = bf->o->bin_obj;
const RVector *import_symbols = Elf_(r_bin_elf_load_imports) (elf);
const RVector *import_symbols = Elf_(load_imports) (elf);
if (!import_symbols) {
r_list_free (ret);
return NULL;
@ -429,7 +429,7 @@ static RList* libs(RBinFile *bf) {
}
// No leak, libs is automatically freed when r_bin_elf_free is called
const RVector *libs = Elf_(r_bin_elf_load_libs) (bf->o->bin_obj);
const RVector *libs = Elf_(load_libs) (bf->o->bin_obj);
if (libs) {
RBinElfLib *lib;
r_vector_foreach (libs, lib) {
@ -601,7 +601,6 @@ static RBinReloc *reloc_convert(ELFOBJ* bin, RBinElfReloc *rel, ut64 got_addr) {
static RList* relocs(RBinFile *bf) {
r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL);
RList *ret = NULL;
RBinReloc *ptr = NULL;
ELFOBJ *bin = bf->o->bin_obj;
if (!(ret = r_list_newf (free))) {
return NULL;
@ -609,41 +608,39 @@ static RList* relocs(RBinFile *bf) {
/* FIXME: This is a _temporary_ fix/workaround to prevent a use-after-
* free detected by ASan that would corrupt the relocation names */
r_list_free (imports (bf));
ut64 got_addr = Elf_(r_bin_elf_get_section_addr) (bin, ".got");
ut64 got_addr = Elf_(get_section_addr) (bin, ".got");
if (got_addr == UT64_MAX) {
got_addr = Elf_(r_bin_elf_get_section_addr) (bin, ".got.plt");
got_addr = Elf_(get_section_addr) (bin, ".got.plt");
}
if (got_addr == UT64_MAX && bin->ehdr.e_type == ET_REL) {
got_addr = Elf_(r_bin_elf_get_section_addr) (bin, ".got.r2");
got_addr = Elf_(get_section_addr) (bin, ".got.r2");
}
if (bf->o) {
const RVector *relocs = Elf_(r_bin_elf_load_relocs) (bin);
if (!relocs) {
return ret;
const RVector *relocs = Elf_(load_relocs) (bin);
if (!relocs) {
return ret;
}
RBinElfReloc *reloc, *r;
RListIter *iter;
r_vector_foreach (relocs, reloc) {
bool found = false;
// XXX this is slow
r_list_foreach (ret, iter, r) {
if (r->rva == reloc->rva) {
found = true;
}
}
RBinElfReloc *reloc, *r;
RListIter *iter;
r_vector_foreach (relocs, reloc) {
// XXX this is slow
r_list_foreach (ret, iter, r) {
if (r->rva == reloc->rva) {
goto another;
}
}
if (!(ptr = reloc_convert (bin, reloc, got_addr))) {
continue;
}
if (ptr->paddr != UT64_MAX) {
if (!found) {
RBinReloc *ptr = reloc_convert (bin, reloc, got_addr);
if (ptr && ptr->paddr != UT64_MAX) {
r_list_append (ret, ptr);
}
another:;
}
}
return ret;
}
// static void _patch_reloc(ELFOBJ *bo, ut16 e_machine, RIOBind *iob, RBinElfReloc *rel, ut64 S, ut64 B, ut64 L) {
static void _patch_reloc(RBinObject *binobj, struct Elf_(r_bin_elf_obj_t) *bo, ut16 e_machine, RIOBind *iob, RBinElfReloc *rel, ut64 S, ut64 B, ut64 L) {
static void _patch_reloc(RBinObject *binobj, struct Elf_(obj_t) *bo, ut16 e_machine, RIOBind *iob, RBinElfReloc *rel, ut64 S, ut64 B, ut64 L) {
ut64 V = 0;
ut64 A = rel->addend;
ut64 P = rel->rva;
@ -884,7 +881,7 @@ static RList* patch_relocs(RBin *b) {
}
gotr2map->name = strdup (".got.r2");
const RVector *relocs = Elf_(r_bin_elf_load_relocs) (bin);
const RVector *relocs = Elf_(load_relocs) (bin);
if (!relocs) {
return NULL;
}
@ -1014,13 +1011,13 @@ static RBinInfo* info(RBinFile *bf) {
: NULL;
void *obj = bf->o->bin_obj;
char *str;
if ((str = Elf_(r_bin_elf_get_rpath)(obj))) {
if ((str = Elf_(get_rpath)(obj))) {
ret->rpath = strdup (str);
free (str);
} else {
ret->rpath = strdup ("NONE");
}
if (!(str = Elf_(r_bin_elf_get_file_type) (obj))) {
if (!(str = Elf_(get_file_type) (obj))) {
free (ret);
return NULL;
}
@ -1028,55 +1025,55 @@ static RBinInfo* info(RBinFile *bf) {
ret->has_pi = (strstr (str, "DYN"))? 1: 0;
ret->has_lit = true;
ret->has_sanitizers = has_sanitizers (bf);
if (!(str = Elf_(r_bin_elf_get_elf_class) (obj))) {
if (!(str = Elf_(get_elf_class) (obj))) {
free (ret);
return NULL;
}
ret->bclass = str;
if (!(str = Elf_(r_bin_elf_get_osabi_name) (obj))) {
if (!(str = Elf_(get_osabi_name) (obj))) {
free (ret);
return NULL;
}
ret->os = str;
if (!(str = Elf_(r_bin_elf_get_osabi_name) (obj))) {
if (!(str = Elf_(get_osabi_name) (obj))) {
free (ret);
return NULL;
}
ret->subsystem = str;
if (!(str = Elf_(r_bin_elf_get_machine_name) (obj))) {
if (!(str = Elf_(get_machine_name) (obj))) {
free (ret);
return NULL;
}
ret->machine = str;
if (!(str = Elf_(r_bin_elf_get_arch) (obj))) {
if (!(str = Elf_(get_arch) (obj))) {
free (ret);
return NULL;
}
ret->arch = str;
ret->cpu = Elf_(r_bin_elf_get_cpu) (obj);
ret->cpu = Elf_(get_cpu) (obj);
ut32 elf_flags = ((ELFOBJ *)obj)->ehdr.e_flags;
if (elf_flags) {
ret->flags = r_str_newf ("0x%x", elf_flags);
}
ret->abi = Elf_(r_bin_elf_get_abi) (obj);
ret->abi = Elf_(get_abi) (obj);
ret->rclass = strdup ("elf");
ret->bits = Elf_(r_bin_elf_get_bits) (obj);
ret->bits = Elf_(get_bits) (obj);
if (!strcmp (ret->arch, "avr")) {
ret->bits = 16;
}
ret->big_endian = Elf_(r_bin_elf_is_big_endian) (obj);
ret->has_va = Elf_(r_bin_elf_has_va) (obj);
ret->has_nx = Elf_(r_bin_elf_has_nx) (obj);
ret->intrp = Elf_(r_bin_elf_intrp) (obj);
ret->compiler = Elf_(r_bin_elf_compiler) (obj);
ret->big_endian = Elf_(is_big_endian) (obj);
ret->has_va = Elf_(has_va) (obj);
ret->has_nx = Elf_(has_nx) (obj);
ret->intrp = Elf_(intrp) (obj);
ret->compiler = Elf_(compiler) (obj);
ret->dbg_info = 0;
if (!Elf_(r_bin_elf_get_stripped) (obj)) {
if (!Elf_(get_stripped) (obj)) {
ret->dbg_info |= R_BIN_DBG_LINENUMS | R_BIN_DBG_SYMS | R_BIN_DBG_RELOCS;
} else {
ret->dbg_info |= R_BIN_DBG_STRIPPED;
}
if (Elf_(r_bin_elf_is_static) (obj)) {
if (Elf_(is_static) (obj)) {
ret->dbg_info |= R_BIN_DBG_STATIC;
}
lookup_sections (bf, ret);

View File

@ -20,7 +20,7 @@ extern struct r_bin_write_t r_bin_write_elf64;
static ut64 get_elf_vaddr64(RBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr) {
//NOTE(aaSSfxxx): since RVA is vaddr - "official" image base, we just need to add imagebase to vaddr
struct Elf_(r_bin_elf_obj_t)* obj = bf->o->bin_obj;
struct Elf_(obj_t)* obj = bf->o->bin_obj;
return obj->baddr - obj->boffset + vaddr;
}

View File

@ -1,21 +1,20 @@
/* radare - LGPL - Copyright 2009-2019 - pancake */
/* radare - LGPL - Copyright 2009-2023 - pancake */
#include <r_types.h>
#include <r_bin.h>
#include "elf/elf.h"
static ut64 scn_resize(RBinFile *bf, const char *name, ut64 size) {
return Elf_(r_bin_elf_resize_section) (bf, name, size);
return Elf_(resize_section) (bf, name, size);
}
static bool scn_perms(RBinFile *bf, const char *name, int perms) {
return Elf_(r_bin_elf_section_perms) (bf, name, perms);
return Elf_(section_perms) (bf, name, perms);
}
static int rpath_del(RBinFile *bf) {
return Elf_(r_bin_elf_del_rpath) (bf);
return Elf_(del_rpath) (bf);
}
static bool chentry(RBinFile *bf, ut64 addr) {
return Elf_(r_bin_elf_entry_write) (bf, addr);
return Elf_(entry_write) (bf, addr);
}