summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-11-13 15:06:20 -0500
committermidipix <writeonce@midipix.org>2016-11-13 15:06:20 -0500
commitcf4adcd6a9a857eb9d33c6f0235eed071be7e434 (patch)
treee3cfa883746b149238304307235f2fb9baa35164
parent902a22167b52d38de153cc95abaeab955d41e0e7 (diff)
downloadperk-cf4adcd6a9a857eb9d33c6f0235eed071be7e434.tar.bz2
perk-cf4adcd6a9a857eb9d33c6f0235eed071be7e434.tar.xz
logic: pe_get_expsym_by_name(), pe_get_expsym_by_index(): improved interface.
-rw-r--r--include/perk/perk.h15
-rw-r--r--src/logic/pe_get_image_meta.c43
-rw-r--r--src/output/pe_output_image_type.c2
3 files changed, 40 insertions, 20 deletions
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; i<m->edata.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)