From 9e2275f12aea1d90c206ea597f42cdd82f9a38ae Mon Sep 17 00:00:00 2001 From: midipix Date: Fri, 30 May 2025 22:16:01 +0000 Subject: library api: _hexdump_ (header and section pretty printing) namespace overhaul. --- src/hexdump/pe_hexdump_image_dos_hdr.c | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/hexdump/pe_hexdump_image_dos_hdr.c (limited to 'src/hexdump/pe_hexdump_image_dos_hdr.c') diff --git a/src/hexdump/pe_hexdump_image_dos_hdr.c b/src/hexdump/pe_hexdump_image_dos_hdr.c new file mode 100644 index 0000000..9579279 --- /dev/null +++ b/src/hexdump/pe_hexdump_image_dos_hdr.c @@ -0,0 +1,76 @@ +/***************************************************************/ +/* perk: PE Resource Kit */ +/* Copyright (C) 2015--2021 SysDeer Technologies, LLC */ +/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ +/***************************************************************/ + +#include + +#include +#include +#include +#include +#include "perk_driver_impl.h" +#include "perk_hexdump_impl.h" +#include "perk_dprintf_impl.h" +#include "perk_errinfo_impl.h" + +#define PE_ADDR meta->r_dos +#define PE_RAW_STRUCT image_dos_hdr +#define PE_OUTPUT(x) PE_OUTPUT_TABLE(x) + +int pe_hexdump_image_dos_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 = 0; + vaddr = meta->m_opt.oh_mem.coh_image_base; + + ch = buf; + ch += pe_output_hex_header( + ch, + "struct pe_raw_image_dos_hdr", + faddr,vaddr,bits); + + ch += PE_OUTPUT(dos_magic); + ch += PE_OUTPUT(dos_cblp); + ch += PE_OUTPUT(dos_cp); + ch += PE_OUTPUT(dos_crlc); + ch += PE_OUTPUT(dos_cparhdr); + ch += PE_OUTPUT(dos_minalloc); + ch += PE_OUTPUT(dos_maxalloc); + ch += PE_OUTPUT(dos_ss); + ch += PE_OUTPUT(dos_sp); + ch += PE_OUTPUT(dos_csum); + ch += PE_OUTPUT(dos_ip); + ch += PE_OUTPUT(dos_cs); + ch += PE_OUTPUT(dos_lfarlc); + ch += PE_OUTPUT(dos_ovno); + ch += PE_OUTPUT(dos_res); + ch += PE_OUTPUT(dos_oemid); + ch += PE_OUTPUT(dos_oeminfo); + ch += PE_OUTPUT(dos_res2); + ch += PE_OUTPUT(dos_lfanew); + + 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; +} -- cgit v1.2.3