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
822ef0
int pe_read_coff_header(const struct pe_raw_coff_image_hdr * p, struct pe_meta_coff_file_hdr * m)
c0fbae
{
da15f0
	if ((p->cfh_signature[0] != 'P') || (p->cfh_signature[1] != 'E')
da15f0
			|| p->cfh_signature[2] || p->cfh_signature[3])
ff121d
		return PERK_ERR_BAD_COFF_HEADER;
c0fbae
da15f0
	m->cfh_signature[0] = p->cfh_signature[0];
da15f0
	m->cfh_signature[1] = p->cfh_signature[1];
da15f0
	m->cfh_signature[2] = p->cfh_signature[2];
da15f0
	m->cfh_signature[3] = p->cfh_signature[3];
c0fbae
da15f0
	m->cfh_machine		= pe_read_short(p->cfh_machine);
da15f0
	m->cfh_num_of_sections	= pe_read_short(p->cfh_num_of_sections);
c0fbae
da15f0
	m->cfh_time_date_stamp	= pe_read_long(p->cfh_time_date_stamp);
da15f0
	m->cfh_ptr_to_sym_tbl	= pe_read_long(p->cfh_ptr_to_sym_tbl);
da15f0
	m->cfh_num_of_syms	= pe_read_long(p->cfh_num_of_syms);
c0fbae
da15f0
	m->cfh_size_of_opt_hdr	= pe_read_short(p->cfh_size_of_opt_hdr);
da15f0
	m->cfh_characteristics	= pe_read_short(p->cfh_characteristics);
c0fbae
c0fbae
	return 0;
b5f7f5
}