Blame src/reader/pe_read_dos_header.c

c0fbae
#include <endian.h>
c0fbae
#include <string.h>
c0fbae
c0fbae
#include <perk/perk.h>
c0fbae
#include "perk_impl.h"
c0fbae
c0fbae
int pe_read_dos_header(const struct pe_image_dos_hdr * p, struct pe_meta_image_dos_hdr * m)
c0fbae
{
c0fbae
	if ((p->dos_magic[0] != 'M') || (p->dos_magic[1] != 'Z'))
c0fbae
		return PERK_BAD_DOS_HEADER;
c0fbae
c0fbae
	#if (BYTE_ORDER == LITTLE_ENDIAN)
c0fbae
c0fbae
	memcpy(m,p,sizeof(*p));
c0fbae
c0fbae
	#else
c0fbae
b5f7f5
	int i;
b5f7f5
c0fbae
	m->dos_magic[0] = p->dos_magic[0];
c0fbae
	m->dos_magic[1] = p->dos_magic[1];
c0fbae
c0fbae
	m->dos_cblp	= pe_read_short(p->dos_cblp);
c0fbae
	m->dos_cp	= pe_read_short(p->dos_cp);
c0fbae
	m->dos_crlc	= pe_read_short(p->dos_crlc);
c0fbae
	m->dos_cparhdr	= pe_read_short(p->dos_cparhdr);
c0fbae
	m->dos_minalloc	= pe_read_short(p->dos_minalloc);
c0fbae
	m->dos_maxalloc	= pe_read_short(p->dos_maxalloc);
c0fbae
	m->dos_ss	= pe_read_short(p->dos_ss);
c0fbae
	m->dos_sp	= pe_read_short(p->dos_sp);
c0fbae
	m->dos_csum	= pe_read_short(p->dos_csum);
c0fbae
	m->dos_ip	= pe_read_short(p->dos_ip);
c0fbae
	m->dos_cs	= pe_read_short(p->dos_cs);
c0fbae
	m->dos_lfarlc	= pe_read_short(p->dos_lfarlc);
c0fbae
	m->dos_ovno	= pe_read_short(p->dos_ovno);
c0fbae
c0fbae
c0fbae
	for (i=0; i<4; i++)
c0fbae
		m->dos_res[i] = pe_read_short(&p->dos_res[2*i]);
c0fbae
c0fbae
	m->dos_oemid	= pe_read_short(p->dos_oemid);
c0fbae
	m->dos_oeminfo	= pe_read_short(p->dos_oeminfo);
c0fbae
c0fbae
	for (i=0; i<10; i++)
c0fbae
		m->dos_res2[i] = pe_read_short(&p->dos_res2[2*i]);
c0fbae
c0fbae
	m->dos_lfanew	= pe_read_long(p->dos_lfanew);
c0fbae
c0fbae
	#endif
c0fbae
c0fbae
	return 0;
b5f7f5
}