From ec3678eef66f4957ad7bbf40d4d2f61f5d2ac371 Mon Sep 17 00:00:00 2001 From: midipix Date: Nov 21 2018 01:25:15 +0000 Subject: output: header dump: added pe_hdrdump_coff_object_hdr(). --- diff --git a/include/perk/perk.h b/include/perk/perk.h index 0693066..73be4ee 100644 --- a/include/perk/perk.h +++ b/include/perk/perk.h @@ -206,6 +206,7 @@ perk_api int pe_output_mdso_libraries (const struct pe_driver_ctx *, const str /* header dump api */ perk_api int pe_hdrdump_image_dos_hdr (const struct pe_driver_ctx *, const struct pe_image_meta *); 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 *); /* 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 2a2ed7b..15ad27d 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_image_dos_hdr.c \ src/hdrdump/pe_hdrdump_coff_image_hdr.c \ + src/hdrdump/pe_hdrdump_coff_object_hdr.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_coff_object_hdr.c b/src/hdrdump/pe_hdrdump_coff_object_hdr.c new file mode 100644 index 0000000..ee3b870 --- /dev/null +++ b/src/hdrdump/pe_hdrdump_coff_object_hdr.c @@ -0,0 +1,62 @@ +/***************************************************************/ +/* 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_obj +#define PE_RAW_STRUCT coff_object_hdr +#define PE_OUTPUT(x) PE_OUTPUT_TABLE(x) + +int pe_hdrdump_coff_object_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_object_hdr", + faddr,vaddr,bits); + + 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; +}