summaryrefslogtreecommitdiffhomepage
path: root/src/reader/pe_read_dos_header.c
blob: f9864bedc6e78953c53ed64b67743efc6c93c40e (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
/***************************************************************/
/*  perk: PE Resource Kit                                      */
/*  Copyright (C) 2015--2017  Z. Gilboa                        */
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
/***************************************************************/

#include <string.h>

#include <perk/perk.h>
#include "perk_endian_impl.h"
#include "perk_reader_impl.h"

int pe_read_dos_header(const struct pe_raw_image_dos_hdr * p, struct pe_meta_image_dos_hdr * m)
{
	if ((p->dos_magic[0] != 'M') || (p->dos_magic[1] != 'Z'))
		return PERK_ERR_BAD_DOS_HEADER;

	int i;

	m->dos_magic[0] = p->dos_magic[0];
	m->dos_magic[1] = p->dos_magic[1];

	m->dos_cblp	= pe_read_short(p->dos_cblp);
	m->dos_cp	= pe_read_short(p->dos_cp);
	m->dos_crlc	= pe_read_short(p->dos_crlc);
	m->dos_cparhdr	= pe_read_short(p->dos_cparhdr);
	m->dos_minalloc	= pe_read_short(p->dos_minalloc);
	m->dos_maxalloc	= pe_read_short(p->dos_maxalloc);
	m->dos_ss	= pe_read_short(p->dos_ss);
	m->dos_sp	= pe_read_short(p->dos_sp);
	m->dos_csum	= pe_read_short(p->dos_csum);
	m->dos_ip	= pe_read_short(p->dos_ip);
	m->dos_cs	= pe_read_short(p->dos_cs);
	m->dos_lfarlc	= pe_read_short(p->dos_lfarlc);
	m->dos_ovno	= pe_read_short(p->dos_ovno);


	for (i=0; i<4; i++)
		m->dos_res[i] = pe_read_short(&p->dos_res[2*i]);

	m->dos_oemid	= pe_read_short(p->dos_oemid);
	m->dos_oeminfo	= pe_read_short(p->dos_oeminfo);

	for (i=0; i<10; i++)
		m->dos_res2[i] = pe_read_short(&p->dos_res2[2*i]);

	m->dos_lfanew	= pe_read_long(p->dos_lfanew);

	return 0;
}