Blame src/reader/pe_read_coff_header.c

e2e2c2
/***************************************************************/
e2e2c2
/*  perk: PE Resource Kit                                      */
e2e2c2
/*  Copyright (C) 2015--2016  Z. Gilboa                        */
e2e2c2
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
e2e2c2
/***************************************************************/
e2e2c2
c0fbae
#include <string.h>
c0fbae
c0fbae
#include <perk/perk.h>
01439f
#include "perk_endian_impl.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
{
7d801c
	uint16_t * pzero = (uint16_t *)&p->signature[2];
7d801c
7d801c
	if ((p->signature[0] != 'P') || (p->signature[1] != 'E') || *pzero)
ff121d
		return PERK_ERR_BAD_COFF_HEADER;
c0fbae
01439f
	if (PERK_LITTLE_ENDIAN) {
c0fbae
01439f
		memcpy(m,p,sizeof(*p));
c0fbae
01439f
	}  else {
c0fbae
01439f
		m->signature[0] = p->signature[0];
01439f
		m->signature[1] = p->signature[1];
01439f
		m->signature[2] = p->signature[2];
01439f
		m->signature[3] = p->signature[3];
c0fbae
01439f
		m->machine		= pe_read_short(p->machine);
01439f
		m->num_of_sections	= pe_read_short(p->num_of_sections);
c0fbae
01439f
		m->time_date_stamp	= pe_read_long(p->time_date_stamp);
01439f
		m->ptr_to_sym_tbl	= pe_read_long(p->ptr_to_sym_tbl);
01439f
		m->num_of_syms		= pe_read_long(p->num_of_syms);
c0fbae
01439f
		m->size_of_opt_hdr	= pe_read_short(p->size_of_opt_hdr);
01439f
		m->characteristics	= pe_read_short(p->characteristics);
c0fbae
01439f
	}
c0fbae
c0fbae
	return 0;
b5f7f5
}