summaryrefslogtreecommitdiffhomepage
path: root/src/internal/perk_hdrdump_impl.h
blob: 379d427301823ac4c2548d87e8c87024b7762129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/***************************************************************/
/*  perk: PE Resource Kit                                      */
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC        */
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
/***************************************************************/

#ifndef PERK_HDRDUMP_IMPL_H
#define PERK_HDRDUMP_IMPL_H

#include <stddef.h>

#define PE_QUOTE(s)	#s
#define PE_STRING(s)	PE_QUOTE(s)
#define PE_TYPE(t)	struct pe_raw_ ## t
#define PE_OFFSET(t,x)	offsetof(PE_TYPE(t),x)
#define PE_SIZE(p,x)	sizeof((p)->x)

#define PE_OUTPUT_RAW_ELEMENT_TABLE(ch,p,t,x)   \
	pe_output_raw_element(                  \
		ch,p,                           \
		PE_STRING(x),                   \
		PE_OFFSET(t,x),                 \
		PE_SIZE(p,x))

#define PE_OUTPUT_TABLE(x)              \
	PE_OUTPUT_RAW_ELEMENT_TABLE(    \
		ch,                     \
		PE_ADDR,                \
		PE_RAW_STRUCT,          \
		x)

size_t pe_output_hex_header(
	char *		buf,
	const char * 	sname,
	uint64_t	faddr,
	uint64_t	vaddr,
	int		bits);

size_t pe_output_hex_footer(
	char *		buf);

size_t pe_output_raw_element(
	char *		ch,
	const void *	rdata,
	const char *	mname,
	uint32_t	moffset,
	uint32_t	msize);

static inline int pe_image_bits(const struct pe_image_meta * m)
{
	switch (m->m_abi) {
		case PE_ABI_PE32:
			return 32;

		case PE_ABI_PE64:
			return 64;

		default:
			return -1;
	}
}

#endif