mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-29 09:13:19 +00:00
Haddr entrypoints for ELF, PE and mach0 (#6167)
This commit is contained in:
parent
24e08bb23d
commit
c4428f088d
@ -740,10 +740,12 @@ static int parse_thread(struct MACH0_(obj_t)* bin, struct load_command *lc, ut64
|
||||
|
||||
if (is_first_thread) {
|
||||
bin->main_cmd = *lc;
|
||||
if (pc != UT64_MAX)
|
||||
if (pc != UT64_MAX) {
|
||||
bin->entry = pc;
|
||||
if (pc_offset != UT64_MAX)
|
||||
}
|
||||
if (pc_offset != UT64_MAX) {
|
||||
sdb_num_set (bin->kv, "mach0.entry.offset", pc_offset, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -1861,6 +1863,7 @@ struct addr_t* MACH0_(get_entrypoint)(struct MACH0_(obj_t)* bin) {
|
||||
if (bin->entry) {
|
||||
entry->addr = entry_to_vaddr(bin);
|
||||
entry->offset = addr_to_offset (bin, entry->addr);
|
||||
entry->haddr = sdb_num_get (bin->kv, "mach0.entry.offset", 0);
|
||||
}
|
||||
|
||||
if (!bin->entry || entry->offset == 0) {
|
||||
|
@ -56,6 +56,7 @@ struct reloc_t {
|
||||
struct addr_t {
|
||||
ut64 offset;
|
||||
ut64 addr;
|
||||
ut64 haddr;
|
||||
int last;
|
||||
};
|
||||
|
||||
|
@ -736,7 +736,7 @@ static int bin_pe_init_resource(struct PE_(r_bin_pe_obj_t)* bin) {
|
||||
}
|
||||
|
||||
static void bin_pe_store_tls_callbacks(struct PE_(r_bin_pe_obj_t) *bin, PE_DWord callbacks) {
|
||||
PE_DWord paddr;
|
||||
PE_DWord paddr, haddr;
|
||||
int count = 0;
|
||||
PE_DWord addressOfTLSCallback = 1;
|
||||
char *key;
|
||||
@ -758,6 +758,9 @@ static void bin_pe_store_tls_callbacks(struct PE_(r_bin_pe_obj_t) *bin, PE_DWord
|
||||
key = sdb_fmt (0, "pe.tls_callback%d_paddr", count);
|
||||
paddr = bin_pe_rva_to_paddr (bin, bin_pe_va_to_rva(bin, (PE_DWord) addressOfTLSCallback));
|
||||
sdb_num_set (bin->kv, key, paddr, 0);
|
||||
key = sdb_fmt (0, "pe.tls_callback%d_haddr", count);
|
||||
haddr = callbacks;
|
||||
sdb_num_set (bin->kv, key, haddr, 0);
|
||||
count++;
|
||||
callbacks += sizeof (addressOfTLSCallback);
|
||||
}
|
||||
@ -1735,6 +1738,8 @@ struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)*
|
||||
pe_entry = bin->optional_header->AddressOfEntryPoint;
|
||||
entry->vaddr = bin_pe_rva_to_va (bin, pe_entry);
|
||||
entry->paddr = bin_pe_rva_to_paddr (bin, pe_entry);
|
||||
// haddr is the address of AddressOfEntryPoint in header.
|
||||
entry->haddr = bin->dos_header->e_lfanew + 4 + sizeof (PE_(image_file_header)) + 16;
|
||||
|
||||
if (entry->paddr >= bin->size) {
|
||||
struct r_bin_pe_section_t *sections = PE_(r_bin_pe_get_sections) (bin);
|
||||
|
@ -17,6 +17,7 @@
|
||||
struct r_bin_pe_addr_t {
|
||||
ut64 vaddr;
|
||||
ut64 paddr;
|
||||
ut64 haddr;
|
||||
};
|
||||
|
||||
struct r_bin_pe_section_t {
|
||||
@ -66,7 +67,7 @@ struct r_bin_pe_lib_t {
|
||||
struct PE_(r_bin_pe_obj_t) {
|
||||
// these pointers contain a copy of the headers and sections!
|
||||
PE_(image_dos_header) *dos_header;
|
||||
PE_(image_nt_headers) *nt_headers;
|
||||
PE_(image_nt_headers) *nt_headers;
|
||||
PE_(image_optional_header) *optional_header; //not free this just pointer into nt_headers
|
||||
PE_(image_data_directory) *data_directory; //not free this just pointer into nt_headers
|
||||
PE_(image_section_header) *section_header;
|
||||
|
@ -158,6 +158,7 @@ static RList* entries(RBinFile *arch) {
|
||||
}
|
||||
ptr->paddr = Elf_(r_bin_elf_get_entry_offset) (obj);
|
||||
ptr->vaddr = Elf_(r_bin_elf_p2v) (obj, ptr->paddr);
|
||||
ptr->haddr = 0x18;
|
||||
|
||||
if (obj->ehdr.e_machine == EM_ARM) {
|
||||
int bin_bits = Elf_(r_bin_elf_get_bits) (obj);
|
||||
|
@ -96,7 +96,8 @@ static RList* entries(RBinFile *arch) {
|
||||
}
|
||||
if ((ptr = R_NEW0 (RBinAddr))) {
|
||||
ptr->paddr = entry->offset + obj->boffset;
|
||||
ptr->vaddr = entry->addr; //
|
||||
ptr->vaddr = entry->addr;
|
||||
ptr->haddr = entry->haddr;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
free (entry);
|
||||
|
@ -80,7 +80,7 @@ static RBinAddr* binsym(RBinFile *arch, int type) {
|
||||
}
|
||||
|
||||
static void add_tls_callbacks(RBinFile *arch, RList* list) {
|
||||
PE_DWord paddr, vaddr;
|
||||
PE_DWord paddr, vaddr, haddr;
|
||||
int count = 0;
|
||||
RBinAddr *ptr = NULL;
|
||||
struct PE_(r_bin_pe_obj_t) *bin = (struct PE_(r_bin_pe_obj_t) *) (arch->o->bin_obj);
|
||||
@ -98,9 +98,16 @@ static void add_tls_callbacks(RBinFile *arch, RList* list) {
|
||||
if (!vaddr) {
|
||||
break;
|
||||
}
|
||||
|
||||
key = sdb_fmt (0, "pe.tls_callback%d_haddr", count);
|
||||
haddr = sdb_num_get (bin->kv, key, 0);
|
||||
if (!haddr) {
|
||||
break;
|
||||
}
|
||||
if ((ptr = R_NEW0 (RBinAddr))) {
|
||||
ptr->paddr = paddr;
|
||||
ptr->vaddr = vaddr;
|
||||
ptr->haddr = haddr;
|
||||
ptr->type = R_BIN_ENTRY_TYPE_TLS;
|
||||
r_list_append (list, ptr);
|
||||
}
|
||||
@ -122,6 +129,7 @@ static RList* entries(RBinFile *arch) {
|
||||
if ((ptr = R_NEW0 (RBinAddr))) {
|
||||
ptr->paddr = entry->paddr;
|
||||
ptr->vaddr = entry->vaddr;
|
||||
ptr->haddr = entry->haddr;
|
||||
ptr->type = R_BIN_ENTRY_TYPE_PROGRAM;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -858,6 +858,10 @@ static int bin_entry(RCore *r, int mode, ut64 laddr, int va) {
|
||||
|
||||
r_list_foreach (entries, iter, entry) {
|
||||
ut64 paddr = entry->paddr;
|
||||
ut64 haddr = UT64_MAX;
|
||||
if (entry->haddr) {
|
||||
haddr = entry->haddr;
|
||||
}
|
||||
ut64 at = rva (r->bin, paddr, entry->vaddr, va);
|
||||
const char *type = r_bin_entry_type_string (entry->type);
|
||||
if (!type) type = "unknown";
|
||||
@ -872,19 +876,31 @@ static int bin_entry(RCore *r, int mode, ut64 laddr, int va) {
|
||||
"\"paddr\":%" PFMT64d ","
|
||||
"\"baddr\":%" PFMT64d ","
|
||||
"\"laddr\":%" PFMT64d ","
|
||||
"\"haddr\":%" PFMT64d ","
|
||||
"\"type\":\"%s\"}",
|
||||
iter->p ? "," : "", at, paddr, baddr, laddr, type);
|
||||
iter->p ? "," : "", at, paddr, baddr, laddr, haddr, type);
|
||||
} else if (IS_MODE_RAD (mode)) {
|
||||
r_cons_printf ("f entry%i 1 @ 0x%08"PFMT64x"\n", i, at);
|
||||
r_cons_printf ("f entry%i_haddr 1 @ 0x%08"PFMT64x"\n", i, haddr);
|
||||
r_cons_printf ("s entry%i\n", i);
|
||||
} else {
|
||||
r_cons_printf (
|
||||
"vaddr=0x%08"PFMT64x
|
||||
" paddr=0x%08"PFMT64x
|
||||
" baddr=0x%08"PFMT64x
|
||||
" laddr=0x%08"PFMT64x
|
||||
" type=%s\n",
|
||||
at, paddr, baddr, laddr, type);
|
||||
" laddr=0x%08"PFMT64x,
|
||||
at, paddr, baddr, laddr);
|
||||
if (haddr == UT64_MAX) {
|
||||
r_cons_printf (
|
||||
" haddr=%"PFMT64d
|
||||
" type=%s\n",
|
||||
haddr, type);
|
||||
} else {
|
||||
r_cons_printf (
|
||||
" haddr=0x%08"PFMT64x
|
||||
" type=%s\n",
|
||||
haddr, type);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -103,6 +103,7 @@ enum {
|
||||
typedef struct r_bin_addr_t {
|
||||
ut64 vaddr;
|
||||
ut64 paddr;
|
||||
ut64 haddr;
|
||||
int type;
|
||||
int bits;
|
||||
} RBinAddr;
|
||||
|
Loading…
Reference in New Issue
Block a user