From cf4adcd6a9a857eb9d33c6f0235eed071be7e434 Mon Sep 17 00:00:00 2001 From: midipix Date: Nov 13 2016 20:06:20 +0000 Subject: logic: pe_get_expsym_by_name(), pe_get_expsym_by_index(): improved interface. --- diff --git a/include/perk/perk.h b/include/perk/perk.h index 9412173..988e0f6 100644 --- a/include/perk/perk.h +++ b/include/perk/perk.h @@ -76,6 +76,13 @@ struct pe_raw_image { size_t size; }; +struct pe_expsym { + const char * name; + void * eaddr; + void * maddr; + uint32_t roffset; +}; + struct pe_image_summary { int32_t nexpsyms; int32_t nimplibs; @@ -209,12 +216,8 @@ perk_api void pe_free_image_meta (struct pe_image_meta *); perk_api int pe_get_named_section_index(const struct pe_image_meta *, const char * name); perk_api int pe_get_block_section_index(const struct pe_image_meta *, const struct pe_block *); - -perk_api -const char * pe_get_expsym_by_name (const struct pe_image_meta *, const char * name); - -perk_api -const char * pe_get_expsym_by_index (const struct pe_image_meta *, unsigned index); +perk_api int pe_get_expsym_by_name (const struct pe_image_meta *, const char * name, struct pe_expsym * optional); +perk_api int pe_get_expsym_by_index (const struct pe_image_meta *, unsigned index, struct pe_expsym * optional); /* low-level api */ perk_api int pe_read_dos_header (const struct pe_image_dos_hdr *, struct pe_meta_image_dos_hdr *); diff --git a/src/logic/pe_get_image_meta.c b/src/logic/pe_get_image_meta.c index b4b21d3..ee2b632 100644 --- a/src/logic/pe_get_image_meta.c +++ b/src/logic/pe_get_image_meta.c @@ -59,9 +59,10 @@ int pe_get_block_section_index(const struct pe_image_meta * m, const struct pe_b return -1; } -const char * pe_get_expsym_by_name( +int pe_get_expsym_by_name( const struct pe_image_meta * m, - const char * name) + const char * name, + struct pe_expsym * expsym) { uint32_t offset; uint32_t * symrva; @@ -74,29 +75,45 @@ const char * pe_get_expsym_by_name( for (i=0; iedata.num_of_name_ptrs; i++) { sym = (const char *)m->image.addr + symrva[i] - offset; - if (!(strcmp(sym,name))) - return sym; + if (!(strcmp(sym,name))) { + if (expsym) { + expsym->name = sym; + expsym->eaddr = 0; + expsym->maddr = 0; + expsym->roffset = 0; + } + + return 0; + } } - return 0; + return -1; } -const char * pe_get_expsym_by_index( +int pe_get_expsym_by_index( const struct pe_image_meta * m, - unsigned index) + unsigned index, + struct pe_expsym * expsym) { uint32_t offset; uint32_t * symrva; - uintptr_t addr; + uintptr_t symaddr; if (index >= m->edata.num_of_name_ptrs) - return 0; + return -1; + + if (expsym) { + offset = m->hedata->virtual_addr - m->hedata->ptr_to_raw_data; + symrva = (uint32_t *)((uintptr_t)m->image.addr + (m->edata.name_ptr_rva - offset)); + symaddr = (uintptr_t)m->image.addr + symrva[index] - offset; - offset = m->hedata->virtual_addr - m->hedata->ptr_to_raw_data; - symrva = (uint32_t *)((uintptr_t)m->image.addr + (m->edata.name_ptr_rva - offset)); - addr = (uintptr_t)m->image.addr + symrva[index] - offset; + expsym->name = (const char *)symaddr; + expsym->eaddr = 0; + expsym->maddr = 0; + expsym->roffset = 0; + } - return (const char *)addr; + return 0; } int pe_get_image_meta( diff --git a/src/output/pe_output_image_type.c b/src/output/pe_output_image_type.c index b2a0bd7..21ae925 100644 --- a/src/output/pe_output_image_type.c +++ b/src/output/pe_output_image_type.c @@ -66,7 +66,7 @@ static const char * pretty_subsystem(const struct pe_unit_ctx * uctx) static bool pe_image_is_psxscl(const struct pe_unit_ctx * uctx) { return (!uctx->meta->summary.nimplibs - && pe_get_expsym_by_name(uctx->meta,"__psx_init")); + && !pe_get_expsym_by_name(uctx->meta,"__psx_init",0)); } static const char * pretty_framework(const struct pe_unit_ctx * uctx)