summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmds/pe_cmd_perk.c2
-rw-r--r--src/driver/pe_driver_ctx.c1
-rw-r--r--src/logic/pe_image_meta_data.c395
-rw-r--r--src/output/pe_output_pecoff_symbols.c (renamed from src/output/pe_output_image_symbols.c)6
4 files changed, 299 insertions, 105 deletions
diff --git a/src/cmds/pe_cmd_perk.c b/src/cmds/pe_cmd_perk.c
index b22643e..bdb6364 100644
--- a/src/cmds/pe_cmd_perk.c
+++ b/src/cmds/pe_cmd_perk.c
@@ -50,7 +50,7 @@ static void pe_perform_unit_actions_impl(
pe_output_pecoff_sections(dctx,meta);
if (flags & PERK_OUTPUT_IMAGE_SYMBOLS)
- pe_output_image_symbols(dctx,meta);
+ pe_output_pecoff_symbols(dctx,meta);
if (flags & PERK_OUTPUT_IMAGE_STRINGS)
pe_output_pecoff_strings(dctx,meta);
diff --git a/src/driver/pe_driver_ctx.c b/src/driver/pe_driver_ctx.c
index 279527d..6a260bd 100644
--- a/src/driver/pe_driver_ctx.c
+++ b/src/driver/pe_driver_ctx.c
@@ -195,6 +195,7 @@ static int pe_cctx_update(
const char * pretty;
pretty = 0;
+ fmtarg = 0;
/* get options, count units */
for (entry=meta->entries; entry->fopt || entry->arg; entry++) {
diff --git a/src/logic/pe_image_meta_data.c b/src/logic/pe_image_meta_data.c
index b789100..b433cff 100644
--- a/src/logic/pe_image_meta_data.c
+++ b/src/logic/pe_image_meta_data.c
@@ -15,6 +15,7 @@
#include <perk/perk.h>
#include <perk/perk_consts.h>
#include <perk/perk_structs.h>
+#include "perk_endian_impl.h"
#include "perk_reader_impl.h"
#include "perk_errinfo_impl.h"
@@ -62,7 +63,9 @@ static int pe_symrec_crc64_compare(const void * a, const void * b)
return eqor * (syma->cs_crc64 > symb->cs_crc64 ? (1) : (-1));
}
-static int pe_get_named_section_index(const struct pe_image_meta * m, const char * name)
+static int pe_get_named_section_index(
+ const struct pe_image_meta * m,
+ const char * name)
{
int i; for (i=0; i<m->m_coff.cfh_num_of_sections; i++)
if (!(strcmp(name,m->m_sectbl[i].sh_name)))
@@ -71,12 +74,16 @@ static int pe_get_named_section_index(const struct pe_image_meta * m, const char
return -1;
}
-int pe_meta_get_named_section_index(const struct pe_image_meta * m, const char * name)
+int pe_meta_get_named_section_index(
+ const struct pe_image_meta * m,
+ const char * name)
{
return pe_get_named_section_index(m,name);
}
-static int pe_get_block_section_index(const struct pe_image_meta * m, const struct pe_block * block)
+static int pe_get_block_section_index(
+ const struct pe_image_meta * m,
+ const struct pe_block * block)
{
int i;
uint32_t low,high;
@@ -88,21 +95,28 @@ static int pe_get_block_section_index(const struct pe_image_meta * m, const stru
low = m->m_sectbl[i].sh_virtual_addr;
high = low + m->m_sectbl[i].sh_virtual_size;
- if ((block->dh_rva >= low) && (block->dh_rva + block->dh_size <= high))
- return i;
+ if (block->dh_rva >= low)
+ if (block->dh_rva + block->dh_size <= high)
+ return i;
}
return -1;
}
-int pe_meta_get_block_section_index(const struct pe_image_meta * m, const struct pe_block * block)
+int pe_meta_get_block_section_index(
+ const struct pe_image_meta * m,
+ const struct pe_block * block)
{
return pe_get_block_section_index(m,block);
}
-int pe_meta_get_roffset_from_rva(const struct pe_image_meta * m, uint32_t rva, uint32_t * roffset)
+int pe_meta_get_roffset_from_rva(
+ const struct pe_image_meta * m,
+ uint32_t rva,
+ uint32_t * roffset)
{
- int i;
+ int i;
+ uint32_t offset;
uint32_t low,high;
for (i=0; i<m->m_coff.cfh_num_of_sections; i++) {
@@ -110,7 +124,11 @@ int pe_meta_get_roffset_from_rva(const struct pe_image_meta * m, uint32_t rva, u
high = low + m->m_sectbl[i].sh_virtual_size;
if ((rva >= low) && (rva < high)) {
- *roffset = (rva - low) + m->m_sectbl[i].sh_ptr_to_raw_data;
+ offset = m->m_sectbl[i].sh_ptr_to_raw_data;
+ offset += rva - low;
+
+ *roffset = offset;
+
return 0;
}
}
@@ -118,9 +136,12 @@ int pe_meta_get_roffset_from_rva(const struct pe_image_meta * m, uint32_t rva, u
return -1;
}
-int pe_meta_get_rva_from_roffset(const struct pe_image_meta * m, uint32_t roffset, uint32_t * rva)
+int pe_meta_get_rva_from_roffset(
+ const struct pe_image_meta * m,
+ uint32_t roffset,
+ uint32_t * rva)
{
- int i;
+ int i;
uint32_t low,high,ref;
for (i=0, ref=~0; i<m->m_coff.cfh_num_of_sections; i++) {
@@ -128,8 +149,13 @@ int pe_meta_get_rva_from_roffset(const struct pe_image_meta * m, uint32_t roffse
high = low + m->m_sectbl[i].sh_virtual_size;
if ((roffset >= low) && (roffset < high)) {
- *rva = (roffset - low) + m->m_sectbl[i].sh_virtual_addr;
+ roffset -= low;
+ roffset += m->m_sectbl[i].sh_virtual_addr;
+
+ *rva = roffset;
+
return 0;
+
} else if (ref > low) {
ref = low;
}
@@ -148,19 +174,24 @@ static int pe_get_expsym_by_name(
const char * name,
struct pe_expsym * expsym)
{
- uint32_t offset;
- uint32_t * symrva;
- const char * sym;
- unsigned i;
+ uint32_t offset;
+ const unsigned char * ptrtbl;
+ const char * sym;
+ unsigned i;
if (m->r_obj || !m->h_edata)
return -1;
- offset = m->h_edata->sh_virtual_addr - m->h_edata->sh_ptr_to_raw_data;
- symrva = (uint32_t *)((uintptr_t)m->r_image.map_addr + (m->m_edata.eh_name_ptr_rva - offset));
+ offset = m->h_edata->sh_virtual_addr;
+ offset -= m->h_edata->sh_ptr_to_raw_data;
+
+ ptrtbl = m->r_image.map_addr;
+ ptrtbl += m->m_edata.eh_name_ptr_rva;
+ ptrtbl -= offset;
for (i=0; i<m->m_edata.eh_num_of_name_ptrs; i++) {
- sym = (const char *)m->r_image.map_addr + symrva[i] - offset;
+ sym = m->r_image.map_addr;
+ sym += pe_read_long(ptrtbl) - offset;
if (!(strcmp(sym,name))) {
if (expsym) {
@@ -172,6 +203,8 @@ static int pe_get_expsym_by_name(
return 0;
}
+
+ ptrtbl += sizeof(uint32_t);
}
return -1;
@@ -190,9 +223,9 @@ static int pe_get_expsym_by_index(
unsigned index,
struct pe_expsym * expsym)
{
- uint32_t offset;
- uint32_t * symrva;
- uintptr_t symaddr;
+ uint32_t offset;
+ const unsigned char * symptr;
+ const char * sym;
if (m->r_obj)
return -1;
@@ -201,11 +234,17 @@ static int pe_get_expsym_by_index(
return -1;
if (expsym) {
- offset = m->h_edata->sh_virtual_addr - m->h_edata->sh_ptr_to_raw_data;
- symrva = (uint32_t *)((uintptr_t)m->r_image.map_addr + (m->m_edata.eh_name_ptr_rva - offset));
- symaddr = (uintptr_t)m->r_image.map_addr + symrva[index] - offset;
+ offset = m->h_edata->sh_virtual_addr;
+ offset -= m->h_edata->sh_ptr_to_raw_data;
- expsym->s_name = (const char *)symaddr;
+ symptr = m->r_image.map_addr;
+ symptr += m->m_edata.eh_name_ptr_rva - offset;
+ symptr += index * sizeof(uint32_t);
+
+ sym = m->r_image.map_addr;
+ sym += pe_read_long(symptr) - offset;
+
+ expsym->s_name = sym;
expsym->s_eaddr = 0;
expsym->s_maddr = 0;
expsym->s_roffset = 0;
@@ -363,20 +402,36 @@ int pe_meta_get_image_meta(
unsigned j;
void * addr;
- char * base;
+ char * sptr;
+ unsigned char * base;
const unsigned char * mark;
+ const unsigned char * cap;
uint64_t vaddr;
+ uint32_t strtbl;
+ uint32_t symtbl;
+ uint32_t arroff;
+
+ uint32_t tbllen;
+ uint32_t reclen;
struct pe_image_meta * m;
struct pe_meta_coff_symbol * symrec;
+ union pe_raw_import_lookup * imptbl;
int nrecs;
int nsyms;
+
+ /* mapped pe/coff or archive member data */
base = image->map_addr;
+ sptr = image->map_addr;
+
+ /* context allocation */
if (!(m = calloc(1,sizeof(*m))))
return PERK_SYSTEM_ERROR(dctx);
+
+ /* image dos header, coff object header */
m->r_obj = (struct pe_raw_coff_object_hdr *)base;
if (pe_read_object_header(m->r_obj,&m->m_coff)) {
@@ -387,32 +442,44 @@ int pe_meta_get_image_meta(
return pe_free_image_meta_impl(
m,PERK_CUSTOM_ERROR(dctx,ret));
- m->r_coff = (struct pe_raw_coff_image_hdr *)(base + m->m_dos.dos_lfanew);
+ mark = &base[m->m_dos.dos_lfanew];
+ m->r_coff = (struct pe_raw_coff_image_hdr *)mark;
if ((ret = (pe_read_coff_header(m->r_coff,&m->m_coff))))
return pe_free_image_meta_impl(
m,PERK_CUSTOM_ERROR(dctx,ret));
}
- if (m->m_coff.cfh_ptr_to_sym_tbl) {
- mark = (const unsigned char *)base+ + m->m_coff.cfh_ptr_to_sym_tbl;
- m->r_symtbl = (struct pe_raw_coff_symbol *)mark;
- mark += m->m_coff.cfh_size_of_sym_tbl;
- m->m_coff.cfh_ptr_to_str_tbl = m->m_coff.cfh_ptr_to_sym_tbl;
- m->m_coff.cfh_ptr_to_str_tbl += m->m_coff.cfh_size_of_sym_tbl;
- m->m_coff.cfh_size_of_str_tbl = pe_read_long(mark);
+ /* symbol table & string table */
+ symtbl = m->m_coff.cfh_ptr_to_sym_tbl;
+ tbllen = m->m_coff.cfh_size_of_sym_tbl;
+ reclen = sizeof(struct pe_raw_coff_symbol);
+ strtbl = symtbl + tbllen;
+
+
+ if (symtbl) {
+ mark = &base[symtbl];
+ m->r_symtbl = (struct pe_raw_coff_symbol *)mark;
+ m->m_coff.cfh_ptr_to_str_tbl = strtbl;
+ m->m_coff.cfh_size_of_str_tbl = pe_read_long(&base[strtbl]);
}
- if ((nrecs = m->m_coff.cfh_size_of_sym_tbl/sizeof(struct pe_raw_coff_symbol))) {
- if (!(m->m_symtbl = calloc(nrecs+1,sizeof(struct pe_meta_coff_symbol))))
+
+ if ((nrecs = tbllen/reclen)) {
+ if (!(m->m_symtbl = calloc(
+ nrecs+1,
+ sizeof(struct pe_meta_coff_symbol))))
return PERK_SYSTEM_ERROR(dctx);
- if (!(m->m_symvec_symidx = calloc(nrecs,sizeof(struct pe_meta_coff_symbol *))))
+ if (!(m->m_symvec_symidx = calloc(
+ nrecs,
+ sizeof(struct pe_meta_coff_symbol *))))
return PERK_SYSTEM_ERROR(dctx);
}
+
for (i=0,symrec=m->m_symtbl; i<nrecs; i++,symrec++) {
m->m_symvec_symidx[i] = symrec;
@@ -432,45 +499,58 @@ int pe_meta_get_image_meta(
m->m_stats.t_nsymbols = symrec - m->m_symtbl;
if ((nsyms = m->m_stats.t_nsymbols) && true) {
- if (!(m->m_symvec_crc32 = calloc(nsyms,sizeof(*m->m_symvec_crc32))))
+ if (!(m->m_symvec_crc32 = calloc(
+ nsyms,
+ sizeof(m->m_symvec_crc32[0]))))
return PERK_SYSTEM_ERROR(dctx);
for (i=0; i<nsyms; i++)
m->m_symvec_crc32[i] = &m->m_symtbl[i];
- qsort(&m->m_symvec_crc32[0],nsyms,
- sizeof(*m->m_symvec_crc32),
+ qsort(
+ m->m_symvec_crc32,nsyms,
+ sizeof(m->m_symvec_crc32[0]),
pe_symrec_crc32_compare);
}
if (nsyms && true) {
- if (!(m->m_symvec_crc64 = calloc(nsyms,sizeof(*m->m_symvec_crc64))))
+ if (!(m->m_symvec_crc64 = calloc(
+ nsyms,
+ sizeof(m->m_symvec_crc64[0]))))
return PERK_SYSTEM_ERROR(dctx);
for (i=0; i<nsyms; i++)
m->m_symvec_crc64[i] = &m->m_symtbl[i];
- qsort(m->m_symvec_crc64,nsyms,
- sizeof(*m->m_symvec_crc64),
+ qsort(
+ m->m_symvec_crc64,nsyms,
+ sizeof(m->m_symvec_crc64[0]),
pe_symrec_crc64_compare);
}
+
+ /* optional header & section table */
if (m->r_dos) {
- mark = &m->r_coff->cfh_signature[0];
- m->r_opt = (union pe_raw_opt_hdr *)(mark + sizeof(*m->r_coff));
+ mark = &m->r_coff->cfh_signature[0];
+ mark += sizeof(m->r_coff[0]);
+ m->r_opt = (union pe_raw_opt_hdr *)mark;
if ((ret = (pe_read_optional_header(m->r_opt,&m->m_opt))))
return pe_free_image_meta_impl(
m,PERK_CUSTOM_ERROR(dctx,ret));
- mark = &m->r_opt->opt_hdr_32.coh_magic[0];
- m->r_sectbl = (struct pe_raw_sec_hdr *)(mark + m->m_coff.cfh_size_of_opt_hdr);
+ mark = &m->r_opt->opt_hdr_32.coh_magic[0];
+ mark += m->m_coff.cfh_size_of_opt_hdr;
+ m->r_sectbl = (struct pe_raw_sec_hdr *)mark;
} else {
- mark = &m->r_obj->cfh_machine[0];
- m->r_sectbl = (struct pe_raw_sec_hdr *)(mark + sizeof(*m->r_obj));
+ mark = &m->r_obj->cfh_machine[0];
+ mark += sizeof(m->r_obj[0]);
+ m->r_sectbl = (struct pe_raw_sec_hdr *)mark;
}
- if (!(m->m_sectbl = calloc(m->m_coff.cfh_num_of_sections,sizeof(*(m->m_sectbl)))))
+ if (!(m->m_sectbl = calloc(
+ m->m_coff.cfh_num_of_sections,
+ sizeof(m->m_sectbl[0]))))
return pe_free_image_meta_impl(
m,PERK_SYSTEM_ERROR(dctx));
@@ -480,25 +560,90 @@ int pe_meta_get_image_meta(
if (m->m_sectbl[i].sh_name_buf[0] == '/')
if ((l = strtol(&m->m_sectbl[i].sh_name_buf[1],0,10)) > 0)
if (l < m->m_coff.cfh_size_of_str_tbl)
- m->m_sectbl[i].sh_name = base + m->m_coff.cfh_ptr_to_str_tbl + l;
+ m->m_sectbl[i].sh_name = &sptr[strtbl+l];
}
+
+ /* .relocs */
+ struct pe_raw_base_reloc_block * r;
+ struct pe_block b;
+
+ i = pe_get_named_section_index(m,".reloc");
+ s = pe_get_block_section_index(m,&m->m_opt.oh_dirs.coh_base_reloc_tbl);
+
+ if ((i >= 0) && (i != s))
+ return pe_free_image_meta_impl(
+ m,PERK_CUSTOM_ERROR(
+ dctx,
+ PERK_ERR_IMAGE_MALFORMED));
+
+
+ if (s >= 0) {
+ mark = image->map_addr;
+ mark += m->m_sectbl[s].sh_ptr_to_raw_data;
+ mark += m->m_opt.oh_dirs.coh_base_reloc_tbl.dh_rva;
+ mark -= m->m_sectbl[s].sh_virtual_addr;
+ cap = &mark[m->m_sectbl[s].sh_virtual_size];
+
+ } else if (i >= 0) {
+ mark = image->map_addr;
+ mark += m->m_sectbl[i].sh_ptr_to_raw_data;
+ cap = &mark[m->m_sectbl[s].sh_virtual_size];
+
+ } else {
+ mark = 0;
+ cap = 0;
+ }
+
+
+
+ for (; mark < cap; ) {
+ r = (struct pe_raw_base_reloc_block *)mark;
+
+ b.dh_rva = pe_read_long(r->blk_rva);
+ b.dh_size = pe_read_long(r->blk_size);
+
+ if ((b.dh_rva == 0) && (b.dh_size == 0)) {
+ mark = cap;
+
+ } else {
+ mark += b.dh_size;
+ b.dh_size -= offsetof(struct pe_raw_base_reloc_block,blk_data);
+
+ m->m_stats.t_nrelocs += b.dh_size / sizeof(uint16_t);
+ m->m_stats.t_nrelblks++;
+ }
+ }
+
+
/* .edata */
i = pe_get_named_section_index(m,".edata");
s = pe_get_block_section_index(m,&m->m_opt.oh_dirs.coh_export_tbl);
if ((i >= 0) && (i != s))
return pe_free_image_meta_impl(
- m,PERK_CUSTOM_ERROR(dctx,PERK_ERR_IMAGE_MALFORMED));
+ m,PERK_CUSTOM_ERROR(
+ dctx,
+ PERK_ERR_IMAGE_MALFORMED));
if (s >= 0) {
+ mark = base;
+ mark += m->m_sectbl[s].sh_ptr_to_raw_data;
+ mark += m->m_opt.oh_dirs.coh_export_tbl.dh_rva;
+ mark -= m->m_sectbl[s].sh_virtual_addr;
+
m->h_edata = &m->m_sectbl[s];
- m->r_edata = (struct pe_raw_export_hdr *)(base + m->m_sectbl[s].sh_ptr_to_raw_data
- + m->m_opt.oh_dirs.coh_export_tbl.dh_rva - m->m_sectbl[s].sh_virtual_addr);
+ m->r_edata = (struct pe_raw_export_hdr *)mark;
+
m->m_edata.eh_virtual_addr = m->m_opt.oh_dirs.coh_export_tbl.dh_rva;
+
} else if (i >= 0) {
+ mark = base;
+ mark += m->m_sectbl[i].sh_ptr_to_raw_data;
+
m->h_edata = &m->m_sectbl[i];
- m->r_edata = (struct pe_raw_export_hdr *)(base + m->m_sectbl[i].sh_ptr_to_raw_data);
+ m->r_edata = (struct pe_raw_export_hdr *)mark;
+
m->m_edata.eh_virtual_addr = m->m_sectbl[i].sh_virtual_addr;
}
@@ -507,6 +652,7 @@ int pe_meta_get_image_meta(
m->m_stats.t_nexpsyms = m->m_edata.eh_num_of_name_ptrs;
}
+
/* .idata */
struct pe_raw_import_hdr * pidata;
unsigned char * pitem;
@@ -517,92 +663,134 @@ int pe_meta_get_image_meta(
if ((i >= 0) && (i != s))
return pe_free_image_meta_impl(
- m,PERK_CUSTOM_ERROR(dctx,PERK_ERR_IMAGE_MALFORMED));
+ m,PERK_CUSTOM_ERROR(
+ dctx,
+ PERK_ERR_IMAGE_MALFORMED));
+
if (s >= 0) {
+ mark = base;
+ mark += m->m_sectbl[s].sh_ptr_to_raw_data;
+ mark += m->m_opt.oh_dirs.coh_import_tbl.dh_rva;
+ mark -= m->m_sectbl[s].sh_virtual_addr;
+
m->h_idata = &m->m_sectbl[s];
- m->r_idata = (struct pe_raw_import_hdr *)(base + m->m_sectbl[s].sh_ptr_to_raw_data
- + m->m_opt.oh_dirs.coh_import_tbl.dh_rva - m->m_sectbl[s].sh_virtual_addr);
- vaddr = m->m_opt.oh_dirs.coh_import_tbl.dh_rva;
+ m->r_idata = (struct pe_raw_import_hdr *)mark;
+ vaddr = m->m_opt.oh_dirs.coh_import_tbl.dh_rva;
+
} else if (i >= 0) {
+ mark = base;
+ mark += m->m_sectbl[i].sh_ptr_to_raw_data;
+
m->h_idata = &m->m_sectbl[i];
- m->r_idata = (struct pe_raw_import_hdr *)(base + m->m_sectbl[i].sh_ptr_to_raw_data);
- vaddr = m->m_sectbl[i].sh_virtual_addr;
+ m->r_idata = (struct pe_raw_import_hdr *)mark;
+ vaddr = m->m_sectbl[i].sh_virtual_addr;
}
- if (m->r_idata) {
- /* num of implibs */
- for (pidata=m->r_idata; pe_read_long(pidata->ih_name_rva); pidata++)
+
+ if ((pidata = m->r_idata)) {
+ for (; pe_read_long(pidata->ih_name_rva); ) {
m->m_stats.t_nimplibs++;
+ pidata++;
+ }
+
- /* import headers */
- if (!(m->m_idata = calloc(m->m_stats.t_nimplibs,sizeof(*m->m_idata))))
+ if (!(m->m_idata = calloc(
+ m->m_stats.t_nimplibs,
+ sizeof(m->m_idata[0]))))
return pe_free_image_meta_impl(
m,PERK_SYSTEM_ERROR(dctx));
+
for (i=0; i<m->m_stats.t_nimplibs; i++) {
- m->m_idata[i].ih_virtual_addr = vaddr + (i * sizeof(*m->r_idata));
+ arroff = i * sizeof(m->r_idata[0]);
+ m->m_idata[i].ih_virtual_addr = vaddr + arroff;
+
pe_read_import_header(&m->r_idata[i],&m->m_idata[i]);
- m->m_idata[i].ih_name = base + m->h_idata->sh_ptr_to_raw_data
- + m->m_idata[i].ih_name_rva
- - m->h_idata->sh_virtual_addr;
+ arroff = m->h_idata->sh_ptr_to_raw_data;
+ arroff += m->m_idata[i].ih_name_rva;
+ arroff -= m->h_idata->sh_virtual_addr;
- if (m->m_idata[i].ih_import_lookup_tbl_rva)
- m->m_idata[i].ih_aitems = (union pe_raw_import_lookup *)(base + m->h_idata->sh_ptr_to_raw_data
- + m->m_idata[i].ih_import_lookup_tbl_rva
- - m->h_idata->sh_virtual_addr);
+ m->m_idata[i].ih_name = &sptr[arroff];
- /* items */
if (m->m_idata[i].ih_import_lookup_tbl_rva) {
+ mark = base;
+ mark += m->h_idata->sh_ptr_to_raw_data;
+ mark += m->m_idata[i].ih_import_lookup_tbl_rva;
+ mark -= m->h_idata->sh_virtual_addr;
+ imptbl = (union pe_raw_import_lookup *)mark;
+
+ m->m_idata[i].ih_aitems = imptbl;
+
+
if (m->m_opt.oh_std.coh_magic == PE_MAGIC_PE32) {
- pitem = m->m_idata[i].ih_aitems->ii_import_lookup_entry_32;
+ pitem = imptbl->ii_import_lookup_entry_32;
- for (; pe_read_long(pitem); m->m_idata[i].ih_count++)
+ for (; pe_read_long(pitem); ) {
pitem += sizeof(uint32_t);
+ m->m_idata[i].ih_count++;
+ }
+
} else if (m->m_opt.oh_std.coh_magic == PE_MAGIC_PE32_PLUS) {
- pitem = m->m_idata[i].ih_aitems->ii_import_lookup_entry_64;
+ pitem = imptbl->ii_import_lookup_entry_64;
- for (; pe_read_quad(pitem); m->m_idata[i].ih_count++)
+ for (; pe_read_quad(pitem); ) {
pitem += sizeof(uint64_t);
+ m->m_idata[i].ih_count++;
+ }
+
} else {
return pe_free_image_meta_impl(
m,PERK_CUSTOM_ERROR(
- dctx,PERK_ERR_UNSUPPORTED_ABI));
+ dctx,
+ PERK_ERR_UNSUPPORTED_ABI));
}
- if (!(m->m_idata[i].ih_items = calloc(m->m_idata[i].ih_count,sizeof(*(m->m_idata[i].ih_items)))))
+ if (!(m->m_idata[i].ih_items = calloc(
+ m->m_idata[i].ih_count,
+ sizeof(m->m_idata[i].ih_items[0]))))
return pe_free_image_meta_impl(
m,PERK_SYSTEM_ERROR(dctx));
}
+
switch (m->m_opt.oh_std.coh_magic) {
case PE_MAGIC_PE32:
- pitem = m->m_idata[i].ih_aitems->ii_import_lookup_entry_32;
+ pitem = imptbl->ii_import_lookup_entry_32;
psize = sizeof(uint32_t);
break;
case PE_MAGIC_PE32_PLUS:
- pitem = m->m_idata[i].ih_aitems->ii_import_lookup_entry_64;
+ pitem = imptbl->ii_import_lookup_entry_64;
psize = sizeof(uint64_t);
break;
}
+
for (j=0; j<m->m_idata[i].ih_count; j++) {
+ struct pe_raw_hint_name_entry * pentry;
+ struct pe_meta_import_lookup * ihitem;
+
+ ihitem = &m->m_idata[i].ih_items[j];
+
if ((ret = pe_read_import_lookup(
- pitem + j*psize,
- &(m->m_idata[i].ih_items[j]),
+ &pitem[j*psize],ihitem,
m->m_opt.oh_std.coh_magic)))
return pe_free_image_meta_impl(
- m,PERK_CUSTOM_ERROR(dctx,ret));
+ m,PERK_CUSTOM_ERROR(
+ dctx,ret));
+
+ if (!ihitem->ii_flag) {
+ mark = base;
+ mark += m->h_idata->sh_ptr_to_raw_data;
+ mark += ihitem->ii_hint_name_tbl_rva;
+ mark -= m->h_idata->sh_virtual_addr;
- if (!m->m_idata[i].ih_items[j].ii_flag) {
- struct pe_raw_hint_name_entry * pentry =
- (struct pe_raw_hint_name_entry *)(base + m->h_idata->sh_ptr_to_raw_data
- + m->m_idata[i].ih_items[j].ii_hint_name_tbl_rva - m->h_idata->sh_virtual_addr);
+ pentry = (struct pe_raw_hint_name_entry *)mark;
- m->m_idata[i].ih_items[j].ii_hint = pe_read_short(pentry->ii_hint);
- m->m_idata[i].ih_items[j].ii_name = (char *)pentry->ii_name;
+ ihitem->ii_hint = pe_read_short(pentry->ii_hint);
+ ihitem->ii_name = &sptr[pentry->ii_name - base];
}
}
}
@@ -613,9 +801,11 @@ int pe_meta_get_image_meta(
m->h_dsometa = &m->m_sectbl[i];
m->r_dsometa = base + m->m_sectbl[i].sh_ptr_to_raw_data;
- m->m_stats.t_ndsolibs = (m->m_opt.oh_std.coh_magic == PE_MAGIC_PE32_PLUS)
- ? m->h_dsometa->sh_virtual_size / sizeof(struct mdso_raw_meta_record_m64)
- : m->h_dsometa->sh_virtual_size / sizeof(struct mdso_raw_meta_record_m32);
+ psize = (m->m_opt.oh_std.coh_magic == PE_MAGIC_PE32_PLUS)
+ ? sizeof(struct mdso_raw_meta_record_m64)
+ : sizeof(struct mdso_raw_meta_record_m32);
+
+ m->m_stats.t_ndsolibs = m->h_dsometa->sh_virtual_size / psize;
}
/* .dsosyms */
@@ -623,15 +813,17 @@ int pe_meta_get_image_meta(
m->h_dsosyms = &m->m_sectbl[i];
m->r_dsosyms = base + m->m_sectbl[i].sh_ptr_to_raw_data;
- m->m_stats.t_ndsosyms = (m->m_opt.oh_std.coh_magic == PE_MAGIC_PE32_PLUS)
- ? m->h_dsosyms->sh_virtual_size / sizeof(struct mdso_raw_sym_entry_m64)
- : m->h_dsosyms->sh_virtual_size / sizeof(struct mdso_raw_sym_entry_m32);
+ psize = (m->m_opt.oh_std.coh_magic == PE_MAGIC_PE32_PLUS)
+ ? sizeof(struct mdso_raw_sym_entry_m64)
+ : sizeof(struct mdso_raw_sym_entry_m32);
+
+ m->m_stats.t_ndsosyms = m->h_dsosyms->sh_virtual_size / psize;
}
/* .dsostrs */
if ((i = pe_get_named_section_index(m,MDSO_STRS_SECTION)) >= 0) {
m->h_dsostrs = &m->m_sectbl[i];
- m->r_dsostrs = base + m->m_sectbl[i].sh_ptr_to_raw_data;
+ m->r_dsostrs = sptr + m->m_sectbl[i].sh_ptr_to_raw_data;
}
/* .dsodata */
@@ -654,7 +846,8 @@ int pe_meta_get_image_meta(
if (m->m_abi == PE_ABI_UNSUPPORTED)
return pe_free_image_meta_impl(
m,PERK_CUSTOM_ERROR(
- dctx,PERK_ERR_UNSUPPORTED_ABI));
+ dctx,
+ PERK_ERR_UNSUPPORTED_ABI));
/* all done */
diff --git a/src/output/pe_output_image_symbols.c b/src/output/pe_output_pecoff_symbols.c
index 7e5e640..0c2eaa1 100644
--- a/src/output/pe_output_image_symbols.c
+++ b/src/output/pe_output_pecoff_symbols.c
@@ -261,7 +261,7 @@ static int pe_output_symbol_records_yaml(
return 0;
}
-static int pe_output_image_symbols_yaml(
+static int pe_output_pecoff_symbols_yaml(
const struct pe_driver_ctx * dctx,
const struct pe_image_meta * meta,
int fdout)
@@ -277,7 +277,7 @@ static int pe_output_image_symbols_yaml(
return 0;
}
-int pe_output_image_symbols(
+int pe_output_pecoff_symbols(
const struct pe_driver_ctx * dctx,
const struct pe_image_meta * meta)
{
@@ -287,7 +287,7 @@ int pe_output_image_symbols(
return 0;
if (dctx->cctx->fmtflags & PERK_PRETTY_YAML) {
- if (pe_output_image_symbols_yaml(dctx,meta,fdout) < 0)
+ if (pe_output_pecoff_symbols_yaml(dctx,meta,fdout) < 0)
return PERK_NESTED_ERROR(dctx);
} else {