summaryrefslogtreecommitdiffhomepage
path: root/src/hdrdump/pe_hdrdump_image_dos_hdr.c
blob: c290079a93591b01a16f9264d4513eb4b2ef27ff (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
64
65
66
67
68
69
70
71
72
73
74
75
76
/***************************************************************/
/*  perk: PE Resource Kit                                      */
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC        */
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
/***************************************************************/

#include <stdio.h>

#include <perk/perk.h>
#include <perk/perk_consts.h>
#include <perk/perk_structs.h>
#include <perk/perk_output.h>
#include "perk_driver_impl.h"
#include "perk_hdrdump_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_hdrdump_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;
}