Blame src/internal/perk_hdrdump_impl.h

b73ae8
/***************************************************************/
b73ae8
/*  perk: PE Resource Kit                                      */
425fb8
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC        */
b73ae8
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
b73ae8
/***************************************************************/
b73ae8
b73ae8
#ifndef PERK_HDRDUMP_IMPL_H
b73ae8
#define PERK_HDRDUMP_IMPL_H
b73ae8
b73ae8
#include <stddef.h>
b73ae8
b73ae8
#define PE_QUOTE(s)	#s
b73ae8
#define PE_STRING(s)	PE_QUOTE(s)
b73ae8
#define PE_TYPE(t)	struct pe_raw_ ## t
b73ae8
#define PE_OFFSET(t,x)	offsetof(PE_TYPE(t),x)
b73ae8
#define PE_SIZE(p,x)	sizeof((p)->x)
b73ae8
b73ae8
#define PE_OUTPUT_RAW_ELEMENT_TABLE(ch,p,t,x)   \
b73ae8
	pe_output_raw_element(                  \
b73ae8
		ch,p,                           \
b73ae8
		PE_STRING(x),                   \
b73ae8
		PE_OFFSET(t,x),                 \
b73ae8
		PE_SIZE(p,x))
b73ae8
b73ae8
#define PE_OUTPUT_TABLE(x)              \
b73ae8
	PE_OUTPUT_RAW_ELEMENT_TABLE(    \
b73ae8
		ch,                     \
b73ae8
		PE_ADDR,                \
b73ae8
		PE_RAW_STRUCT,          \
b73ae8
		x)
b73ae8
b73ae8
size_t pe_output_hex_header(
b73ae8
	char *		buf,
b73ae8
	const char * 	sname,
b73ae8
	uint64_t	faddr,
b73ae8
	uint64_t	vaddr,
b73ae8
	int		bits);
b73ae8
b73ae8
size_t pe_output_hex_footer(
b73ae8
	char *		buf);
b73ae8
b73ae8
size_t pe_output_raw_element(
b73ae8
	char *		ch,
b73ae8
	const void *	rdata,
b73ae8
	const char *	mname,
b73ae8
	uint32_t	moffset,
b73ae8
	uint32_t	msize);
b73ae8
71ed2f
static inline int pe_image_bits(const struct pe_image_meta * m)
71ed2f
{
71ed2f
	switch (m->m_abi) {
71ed2f
		case PE_ABI_PE32:
71ed2f
			return 32;
71ed2f
71ed2f
		case PE_ABI_PE64:
71ed2f
			return 64;
71ed2f
71ed2f
		default:
71ed2f
			return -1;
71ed2f
	}
71ed2f
}
71ed2f
b73ae8
#endif