summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-11-12 22:23:08 -0500
committermidipix <writeonce@midipix.org>2016-11-12 22:23:08 -0500
commitc7ca52f4ec6005315ac2a2374f4f05fb1ae62ad2 (patch)
tree0a47b264a987c41620f76fb8d71823e20bbaa274
parenta5cc53c9e31a213da5ef8779ebca4de034e3b96f (diff)
downloadperk-c7ca52f4ec6005315ac2a2374f4f05fb1ae62ad2.tar.bz2
perk-c7ca52f4ec6005315ac2a2374f4f05fb1ae62ad2.tar.xz
logic: added pe_get_expsym_by_name(), pe_get_expsym_by_index().
-rw-r--r--include/perk/perk.h6
-rw-r--r--src/logic/pe_get_image_meta.c40
2 files changed, 46 insertions, 0 deletions
diff --git a/include/perk/perk.h b/include/perk/perk.h
index 5e6010d..9412173 100644
--- a/include/perk/perk.h
+++ b/include/perk/perk.h
@@ -210,6 +210,12 @@ 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);
+
/* low-level api */
perk_api int pe_read_dos_header (const struct pe_image_dos_hdr *, struct pe_meta_image_dos_hdr *);
perk_api int pe_read_coff_header (const struct pe_coff_file_hdr *, struct pe_meta_coff_file_hdr *);
diff --git a/src/logic/pe_get_image_meta.c b/src/logic/pe_get_image_meta.c
index 6302f70..b4b21d3 100644
--- a/src/logic/pe_get_image_meta.c
+++ b/src/logic/pe_get_image_meta.c
@@ -59,6 +59,46 @@ 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(
+ const struct pe_image_meta * m,
+ const char * name)
+{
+ uint32_t offset;
+ uint32_t * symrva;
+ const char * sym;
+ unsigned i;
+
+ 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));
+
+ 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;
+ }
+
+ return 0;
+}
+
+const char * pe_get_expsym_by_index(
+ const struct pe_image_meta * m,
+ unsigned index)
+{
+ uint32_t offset;
+ uint32_t * symrva;
+ uintptr_t addr;
+
+ if (index >= m->edata.num_of_name_ptrs)
+ return 0;
+
+ 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;
+
+ return (const char *)addr;
+}
+
int pe_get_image_meta(
const struct pe_driver_ctx * dctx,
const struct pe_raw_image * image,