Blame src/reader/pe_read_coff_header.c

c0fbae
#include <endian.h>
c0fbae
#include <string.h>
c0fbae
c0fbae
#include <perk/perk.h>
413f56
#include "perk_reader_impl.h"
c0fbae
c0fbae
int pe_read_coff_header(const struct pe_coff_file_hdr * p, struct pe_meta_coff_file_hdr * m)
c0fbae
{
c0fbae
	if ((p->signature[0] != 'P') || (p->signature[1] != 'E')
c0fbae
			|| *(uint16_t *)&p->signature[2])
c0fbae
		return PERK_BAD_COFF_HEADER;
c0fbae
c0fbae
	#if (BYTE_ORDER == LITTLE_ENDIAN)
c0fbae
c0fbae
	memcpy(m,p,sizeof(*p));
c0fbae
c0fbae
	#else
c0fbae
c0fbae
	m->signature[0] = p->signature[0];
c0fbae
	m->signature[1] = p->signature[1];
c0fbae
	m->signature[2] = p->signature[2];
c0fbae
	m->signature[3] = p->signature[3];
c0fbae
c0fbae
	m->machine		= pe_read_short(p->machine);
c0fbae
	m->num_of_sections	= pe_read_short(p->num_of_sections);
c0fbae
c0fbae
	m->time_date_stamp	= pe_read_long(p->time_date_stamp);
c0fbae
	m->ptr_to_sym_tbl	= pe_read_long(p->ptr_to_sym_tbl);
c0fbae
	m->num_of_syms		= pe_read_long(p->num_of_syms);
c0fbae
c0fbae
	m->size_of_opt_hdr	= pe_read_short(p->size_of_opt_hdr);
c0fbae
	m->characteristics	= pe_read_short(p->characteristics);
c0fbae
c0fbae
	#endif
c0fbae
c0fbae
	return 0;
b5f7f5
}