summaryrefslogtreecommitdiffhomepage
path: root/src/exports
diff options
context:
space:
mode:
Diffstat (limited to 'src/exports')
-rw-r--r--src/exports/pe_get_export_symbol_info.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/exports/pe_get_export_symbol_info.c b/src/exports/pe_get_export_symbol_info.c
index 831b7e5..e3d0e8d 100644
--- a/src/exports/pe_get_export_symbol_info.c
+++ b/src/exports/pe_get_export_symbol_info.c
@@ -15,17 +15,17 @@ static __inline__ int pe_addr_within_bounds(void * addr, void * bottom, void * t
return (((uintptr_t)addr >= (uintptr_t)bottom) && ((uintptr_t)addr < (uintptr_t)top));
}
-pe_api
int pe_get_export_symbol_info(
const void * base,
const char * name,
struct pe_export_sym * sym)
{
- struct pe_raw_export_hdr*exp_hdr;
+ struct pe_raw_export_hdr * exp_hdr;
ssize_t len;
uint32_t * rva_offset;
uintptr_t * addr_offset;
+ uintptr_t addr;
uint32_t sec_size;
void * sec_addr_cap;
@@ -45,12 +45,12 @@ int pe_get_export_symbol_info(
uint32_t upper;
uint32_t idx;
- /* initialize pe_exp_item */
- sym->ordinal_base = (uint32_t *)0;
- sym->ordinal = (uint16_t *)0;
- sym->addr = (void *)0;
- sym->forwarder_rva = (void *)0;
- sym->name = (char *)0;
+ /* init */
+ sym->ordinal_base = 0;
+ sym->ordinal = 0;
+ sym->addr = 0;
+ sym->forwarder_rva = 0;
+ sym->name = 0;
sym->status = 0;
if (!(exp_hdr = pe_get_image_export_hdr_addr(base,&sec_size)))
@@ -60,15 +60,16 @@ int pe_get_export_symbol_info(
rva_offset = (uint32_t *)(exp_hdr->export_addr_tbl_rva);
fn_addr = (uint32_t *)pe_va_from_rva(base,*rva_offset);
- rva_offset = (uint32_t *)(exp_hdr->name_ptr_rva);
- fn_names = (uint32_t *)pe_va_from_rva(base,*rva_offset);
+ rva_offset = (uint32_t *)(exp_hdr->name_ptr_rva);
+ fn_names = (uint32_t *)pe_va_from_rva(base,*rva_offset);
- rva_offset = (uint32_t *)(exp_hdr->ordinal_tbl_rva);
- fn_ordinals = (uint16_t *)pe_va_from_rva(base,*rva_offset);
+ rva_offset = (uint32_t *)(exp_hdr->ordinal_tbl_rva);
+ fn_ordinals = (uint16_t *)pe_va_from_rva(base,*rva_offset);
addr_entries = (uint32_t *)exp_hdr->addr_tbl_entries;
name_entries = (uint32_t *)exp_hdr->num_of_name_ptrs;
+
/* by ordinal? */
if ((intptr_t)name < 0x10000) {
sym->ordinal_base = (uint32_t *)exp_hdr->ordinal_base;
@@ -77,7 +78,8 @@ int pe_get_export_symbol_info(
if (((intptr_t)name - *sym->ordinal_base + 1) > *addr_entries)
return -1;
- rva_offset = (uint32_t *)pe_va_from_rva(fn_addr,((uintptr_t)name-*sym->ordinal_base)*sizeof(uint32_t));
+ addr = ((uintptr_t)name - *sym->ordinal_base) * sizeof(uint32_t);
+ rva_offset = (uint32_t *)pe_va_from_rva(fn_addr,addr);
addr_offset = (uintptr_t *)pe_va_from_rva(base,*rva_offset);
if (pe_addr_within_bounds(addr_offset,exp_hdr,sec_addr_cap)) {
@@ -98,7 +100,7 @@ int pe_get_export_symbol_info(
upper = *name_entries;
while (lower < upper) {
- idx = (lower + upper) / 2;
+ idx = (lower + upper) / 2;
rva_offset = (uint32_t *)pe_va_from_rva(fn_names,idx*sizeof(uint32_t));
exp_name = (char *)pe_va_from_rva(base,*rva_offset);
@@ -137,6 +139,5 @@ int pe_get_export_symbol_info(
}
}
- /* export name not found */
return -1;
}