Blame src/hdrdump/pe_hdrdump_coff_object_hdr.c

ec3678
/***************************************************************/
ec3678
/*  perk: PE Resource Kit                                      */
425fb8
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC        */
ec3678
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
ec3678
/***************************************************************/
ec3678
ec3678
#include <stdio.h>
ec3678
ec3678
#include <perk/perk.h>
d6e02b
#include <perk/perk_consts.h>
d6e02b
#include <perk/perk_structs.h>
ec3678
#include <perk/perk_output.h>
ec3678
#include "perk_driver_impl.h"
ec3678
#include "perk_hdrdump_impl.h"
ec3678
#include "perk_dprintf_impl.h"
ec3678
#include "perk_errinfo_impl.h"
ec3678
ec3678
#define PE_ADDR       meta->r_obj
ec3678
#define PE_RAW_STRUCT coff_object_hdr
ec3678
#define PE_OUTPUT(x)  PE_OUTPUT_TABLE(x)
ec3678
ec3678
int pe_hdrdump_coff_object_hdr(
ec3678
	const struct pe_driver_ctx *	dctx,
ec3678
	const struct pe_image_meta *	meta)
ec3678
{
ec3678
	int		bits;
ec3678
	uint64_t	faddr;
ec3678
	uint64_t	vaddr;
ec3678
	char *		ch;
ec3678
	char		buf[8192];
ec3678
ec3678
	if (!PE_ADDR)
ec3678
		return 0;
ec3678
ec3678
	if ((bits = pe_image_bits(meta)) < 0)
ec3678
		return PERK_CUSTOM_ERROR(
ec3678
			dctx,PERK_ERR_UNSUPPORTED_ABI);
ec3678
ec3678
	faddr = (char *)(PE_ADDR) - (char *)meta->r_image.map_addr;
ec3678
	vaddr = meta->m_opt.oh_mem.coh_image_base + faddr;
ec3678
ec3678
	ch  = buf;
ec3678
	ch += pe_output_hex_header(
ec3678
		ch,
ec3678
		"struct pe_raw_coff_object_hdr",
ec3678
		faddr,vaddr,bits);
ec3678
ec3678
	ch += PE_OUTPUT(cfh_machine);
ec3678
	ch += PE_OUTPUT(cfh_num_of_sections);
ec3678
	ch += PE_OUTPUT(cfh_time_date_stamp);
ec3678
	ch += PE_OUTPUT(cfh_ptr_to_sym_tbl);
ec3678
	ch += PE_OUTPUT(cfh_num_of_syms);
ec3678
	ch += PE_OUTPUT(cfh_size_of_opt_hdr);
ec3678
	ch += PE_OUTPUT(cfh_characteristics);
ec3678
ec3678
	ch += pe_output_hex_footer(ch);
ec3678
ec3678
	*ch = 0;
ec3678
ec3678
	if (pe_dprintf(pe_driver_fdout(dctx),"%s",buf) < 0)
ec3678
		return PERK_FILE_ERROR(dctx);
ec3678
ec3678
	return 0;
ec3678
}