summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-11-12 00:26:35 -0500
committermidipix <writeonce@midipix.org>2018-11-20 20:25:15 -0500
commit153cea12f066ec60d625449765e28fc112085546 (patch)
tree311667c6d7f18c3e28b45bf8388bd4c799602ccd /src
parent71ed2fda0285acf148a38f443490435350df6b4e (diff)
downloadperk-153cea12f066ec60d625449765e28fc112085546.tar.bz2
perk-153cea12f066ec60d625449765e28fc112085546.tar.xz
output: header dump: added pe_hdrdump_coff_image_hdr().
Diffstat (limited to 'src')
-rw-r--r--src/hdrdump/pe_hdrdump_coff_image_hdr.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/hdrdump/pe_hdrdump_coff_image_hdr.c b/src/hdrdump/pe_hdrdump_coff_image_hdr.c
new file mode 100644
index 0000000..04b47f7
--- /dev/null
+++ b/src/hdrdump/pe_hdrdump_coff_image_hdr.c
@@ -0,0 +1,63 @@
+/***************************************************************/
+/* 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_coff
+#define PE_RAW_STRUCT coff_image_hdr
+#define PE_OUTPUT(x) PE_OUTPUT_TABLE(x)
+
+int pe_hdrdump_coff_image_hdr(
+ const struct pe_driver_ctx * dctx,
+ const struct pe_image_meta * meta)
+{
+ int bits;
+ uint64_t faddr;
+ uint64_t vaddr;
+ char * ch;
+ char buf[8192];
+
+ if (!PE_ADDR)
+ return 0;
+
+ if ((bits = pe_image_bits(meta)) < 0)
+ return PERK_CUSTOM_ERROR(
+ dctx,PERK_ERR_UNSUPPORTED_ABI);
+
+ 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,
+ "struct pe_raw_coff_image_hdr",
+ faddr,vaddr,bits);
+
+ ch += PE_OUTPUT(cfh_signature);
+ ch += PE_OUTPUT(cfh_machine);
+ ch += PE_OUTPUT(cfh_num_of_sections);
+ ch += PE_OUTPUT(cfh_time_date_stamp);
+ ch += PE_OUTPUT(cfh_ptr_to_sym_tbl);
+ ch += PE_OUTPUT(cfh_num_of_syms);
+ ch += PE_OUTPUT(cfh_size_of_opt_hdr);
+ ch += PE_OUTPUT(cfh_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;
+}