From 8f30d9ab0402bb17814059c9e8df809c36edb437 Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 17 Nov 2018 19:41:58 -0500 Subject: output: header dump: added pe_hdrdump_import_tbl(). --- include/perk/perk.h | 1 + project/common.mk | 1 + src/hdrdump/pe_hdrdump_import_tbl.c | 76 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/hdrdump/pe_hdrdump_import_tbl.c diff --git a/include/perk/perk.h b/include/perk/perk.h index 28914cc..0eed0a3 100644 --- a/include/perk/perk.h +++ b/include/perk/perk.h @@ -210,6 +210,7 @@ perk_api int pe_hdrdump_coff_object_hdr(const struct pe_driver_ctx *, const str perk_api int pe_hdrdump_opt_hdr (const struct pe_driver_ctx *, const struct pe_image_meta *); perk_api int pe_hdrdump_sec_tbl (const struct pe_driver_ctx *, const struct pe_image_meta *); perk_api int pe_hdrdump_export_hdr (const struct pe_driver_ctx *, const struct pe_image_meta *); +perk_api int pe_hdrdump_import_tbl (const struct pe_driver_ctx *, const struct pe_image_meta *); /* error trace api */ perk_api int pe_output_error_record (const struct pe_driver_ctx *, const struct pe_error_info *); diff --git a/project/common.mk b/project/common.mk index 13c1cd7..befd77d 100644 --- a/project/common.mk +++ b/project/common.mk @@ -4,6 +4,7 @@ API_SRCS = \ src/driver/pe_unit_ctx.c \ src/hdrdump/pe_hdrdump_export_hdr.c \ src/hdrdump/pe_hdrdump_image_dos_hdr.c \ + src/hdrdump/pe_hdrdump_import_tbl.c \ src/hdrdump/pe_hdrdump_coff_image_hdr.c \ src/hdrdump/pe_hdrdump_coff_object_hdr.c \ src/hdrdump/pe_hdrdump_opt_hdr.c \ diff --git a/src/hdrdump/pe_hdrdump_import_tbl.c b/src/hdrdump/pe_hdrdump_import_tbl.c new file mode 100644 index 0000000..a6d872e --- /dev/null +++ b/src/hdrdump/pe_hdrdump_import_tbl.c @@ -0,0 +1,76 @@ +/***************************************************************/ +/* perk: PE Resource Kit */ +/* Copyright (C) 2015--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ +/***************************************************************/ + +#include + +#include +#include +#include "perk_driver_impl.h" +#include "perk_hdrdump_impl.h" +#include "perk_dprintf_impl.h" +#include "perk_errinfo_impl.h" + +#define PE_ADDR &meta->r_idata[idx] +#define PE_RAW_STRUCT import_hdr +#define PE_OUTPUT(x) PE_OUTPUT_TABLE(x) + +static int pe_hdrdump_import_hdr_impl( + const struct pe_driver_ctx * dctx, + const struct pe_image_meta * meta, + uint32_t idx) +{ + int bits; + uint64_t faddr; + uint64_t vaddr; + char * ch; + char hdr[64]; + char buf[8192]; + + if ((bits = pe_image_bits(meta)) < 0) + return PERK_CUSTOM_ERROR( + dctx,PERK_ERR_UNSUPPORTED_ABI); + + sprintf( + hdr, + "struct pe_raw_import_hdr [%d]", + idx); + + faddr = (char *)(PE_ADDR) - (char *)meta->r_image.map_addr; + vaddr = meta->m_opt.oh_mem.coh_image_base + meta->m_idata[idx].ih_virtual_addr; + + ch = buf; + ch += pe_output_hex_header( + ch,hdr, + faddr,vaddr,bits); + + ch += PE_OUTPUT(ih_import_lookup_tbl_rva); + ch += PE_OUTPUT(ih_time_date_stamp); + ch += PE_OUTPUT(ih_forwarder_chain); + ch += PE_OUTPUT(ih_name_rva); + ch += PE_OUTPUT(ih_import_addr_tbl_rva); + + ch += pe_output_hex_footer(ch); + + *ch = 0; + + if (pe_dprintf(pe_driver_fdout(dctx),"%s",buf) < 0) + return PERK_FILE_ERROR(dctx); + + return 0; +} + +int pe_hdrdump_import_tbl( + const struct pe_driver_ctx * dctx, + const struct pe_image_meta * meta) +{ + int idx; + + for (idx=0; idxm_stats.t_nimplibs; idx++) + if (pe_hdrdump_import_hdr_impl(dctx,meta,idx) < 0) + return PERK_NESTED_ERROR(dctx); + + return 0; +} -- cgit v1.2.3