summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-11-17 08:52:41 -0500
committermidipix <writeonce@midipix.org>2018-11-20 20:25:16 -0500
commit1ce71048e3b47573bc73b8276baca32132e2731f (patch)
treef7bcc6d6fc2d83b03bb9037425f94303d02572da
parent3827198893e5ffead609c09dbb96837511d0ded5 (diff)
downloadperk-1ce71048e3b47573bc73b8276baca32132e2731f.tar.bz2
perk-1ce71048e3b47573bc73b8276baca32132e2731f.tar.xz
output: header dump: added pe_hdrdump_sec_tbl().
-rw-r--r--include/perk/perk.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/hdrdump/pe_hdrdump_sec_tbl.c81
3 files changed, 83 insertions, 0 deletions
diff --git a/include/perk/perk.h b/include/perk/perk.h
index ad28822..5179ca7 100644
--- a/include/perk/perk.h
+++ b/include/perk/perk.h
@@ -208,6 +208,7 @@ perk_api int pe_hdrdump_image_dos_hdr (const struct pe_driver_ctx *, const str
perk_api int pe_hdrdump_coff_image_hdr (const struct pe_driver_ctx *, const struct pe_image_meta *);
perk_api int pe_hdrdump_coff_object_hdr(const struct pe_driver_ctx *, const struct pe_image_meta *);
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 *);
/* 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 322d1ce..9723cd0 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -6,6 +6,7 @@ API_SRCS = \
src/hdrdump/pe_hdrdump_coff_image_hdr.c \
src/hdrdump/pe_hdrdump_coff_object_hdr.c \
src/hdrdump/pe_hdrdump_opt_hdr.c \
+ src/hdrdump/pe_hdrdump_sec_tbl.c \
src/info/pe_get_image_abi.c \
src/info/pe_get_image_framework.c \
src/info/pe_get_image_subsystem.c \
diff --git a/src/hdrdump/pe_hdrdump_sec_tbl.c b/src/hdrdump/pe_hdrdump_sec_tbl.c
new file mode 100644
index 0000000..1254258
--- /dev/null
+++ b/src/hdrdump/pe_hdrdump_sec_tbl.c
@@ -0,0 +1,81 @@
+/***************************************************************/
+/* perk: PE Resource Kit */
+/* Copyright (C) 2015--2017 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.PERK. */
+/***************************************************************/
+
+#include <stdio.h>
+
+#include <perk/perk.h>
+#include <perk/perk_output.h>
+#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_sectbl[idx]
+#define PE_RAW_STRUCT sec_hdr
+#define PE_OUTPUT(x) PE_OUTPUT_TABLE(x)
+
+static int pe_hdrdump_sec_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_sec_hdr [%d]",
+ idx);
+
+ faddr = (char *)(PE_ADDR) - (char *)meta->r_image.map_addr;
+ vaddr = meta->m_opt.oh_mem.coh_image_base + faddr;
+
+ ch = buf;
+ ch += pe_output_hex_header(
+ ch,hdr,
+ faddr,vaddr,bits);
+
+ ch += PE_OUTPUT(sh_name);
+ ch += PE_OUTPUT(sh_virtual_size);
+ ch += PE_OUTPUT(sh_virtual_addr);
+ ch += PE_OUTPUT(sh_size_of_raw_data);
+ ch += PE_OUTPUT(sh_ptr_to_raw_data);
+ ch += PE_OUTPUT(sh_ptr_to_relocs);
+ ch += PE_OUTPUT(sh_ptr_to_line_nums);
+ ch += PE_OUTPUT(sh_num_of_relocs);
+ ch += PE_OUTPUT(sh_num_of_line_nums);
+ ch += PE_OUTPUT(sh_characteristics);
+
+ 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_sec_tbl(
+ const struct pe_driver_ctx * dctx,
+ const struct pe_image_meta * meta)
+{
+ uint32_t idx;
+
+ for (idx=0; idx<meta->m_coff.cfh_num_of_sections; idx++)
+ if (pe_hdrdump_sec_hdr_impl(dctx,meta,idx) < 0)
+ return PERK_NESTED_ERROR(dctx);
+
+ return 0;
+}