Blame src/hdrdump/pe_hdrdump_image_dos_hdr.c

71ed2f
/***************************************************************/
71ed2f
/*  perk: PE Resource Kit                                      */
425fb8
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC        */
71ed2f
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
71ed2f
/***************************************************************/
71ed2f
71ed2f
#include <stdio.h>
71ed2f
71ed2f
#include <perk/perk.h>
d6e02b
#include <perk/perk_consts.h>
d6e02b
#include <perk/perk_structs.h>
71ed2f
#include <perk/perk_output.h>
71ed2f
#include "perk_driver_impl.h"
71ed2f
#include "perk_hdrdump_impl.h"
71ed2f
#include "perk_dprintf_impl.h"
71ed2f
#include "perk_errinfo_impl.h"
71ed2f
71ed2f
#define PE_ADDR       meta->r_dos
71ed2f
#define PE_RAW_STRUCT image_dos_hdr
71ed2f
#define PE_OUTPUT(x)  PE_OUTPUT_TABLE(x)
71ed2f
71ed2f
int pe_hdrdump_image_dos_hdr(
71ed2f
	const struct pe_driver_ctx *	dctx,
71ed2f
	const struct pe_image_meta *	meta)
71ed2f
{
71ed2f
	int		bits;
71ed2f
	uint64_t	faddr;
71ed2f
	uint64_t	vaddr;
71ed2f
	char *		ch;
71ed2f
	char		buf[8192];
71ed2f
71ed2f
	if (!PE_ADDR)
71ed2f
		return 0;
71ed2f
71ed2f
	if ((bits = pe_image_bits(meta)) < 0)
71ed2f
		return PERK_CUSTOM_ERROR(
71ed2f
			dctx,PERK_ERR_UNSUPPORTED_ABI);
71ed2f
71ed2f
	faddr = 0;
71ed2f
	vaddr = meta->m_opt.oh_mem.coh_image_base;
71ed2f
71ed2f
	ch  = buf;
71ed2f
	ch += pe_output_hex_header(
71ed2f
		ch,
71ed2f
		"struct pe_raw_image_dos_hdr",
71ed2f
		faddr,vaddr,bits);
71ed2f
71ed2f
	ch += PE_OUTPUT(dos_magic);
71ed2f
	ch += PE_OUTPUT(dos_cblp);
71ed2f
	ch += PE_OUTPUT(dos_cp);
71ed2f
	ch += PE_OUTPUT(dos_crlc);
71ed2f
	ch += PE_OUTPUT(dos_cparhdr);
71ed2f
	ch += PE_OUTPUT(dos_minalloc);
71ed2f
	ch += PE_OUTPUT(dos_maxalloc);
71ed2f
	ch += PE_OUTPUT(dos_ss);
71ed2f
	ch += PE_OUTPUT(dos_sp);
71ed2f
	ch += PE_OUTPUT(dos_csum);
71ed2f
	ch += PE_OUTPUT(dos_ip);
71ed2f
	ch += PE_OUTPUT(dos_cs);
71ed2f
	ch += PE_OUTPUT(dos_lfarlc);
71ed2f
	ch += PE_OUTPUT(dos_ovno);
71ed2f
	ch += PE_OUTPUT(dos_res);
71ed2f
	ch += PE_OUTPUT(dos_oemid);
71ed2f
	ch += PE_OUTPUT(dos_oeminfo);
71ed2f
	ch += PE_OUTPUT(dos_res2);
71ed2f
	ch += PE_OUTPUT(dos_lfanew);
71ed2f
71ed2f
	ch += pe_output_hex_footer(ch);
71ed2f
71ed2f
	*ch = 0;
71ed2f
71ed2f
	if (pe_dprintf(pe_driver_fdout(dctx),"%s",buf) < 0)
71ed2f
		return PERK_FILE_ERROR(dctx);
71ed2f
71ed2f
	return 0;
71ed2f
}