Blame src/reader/pe_read_import_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>
ff2363
#include "perk_endian_impl.h"
413f56
#include "perk_reader_impl.h"
c0fbae
c0fbae
int pe_read_import_header(const struct pe_import_hdr * p, struct pe_meta_import_hdr * m)
c0fbae
{
ff2363
	if (PERK_LITTLE_ENDIAN) {
c0fbae
ff2363
		memcpy(m,p,sizeof(*p));
c0fbae
ff2363
	} else {
c0fbae
ff2363
		m->import_lookup_tbl_rva	= pe_read_long(p->import_lookup_tbl_rva);
ff2363
		m->time_date_stamp		= pe_read_long(p->time_date_stamp);
ff2363
		m->forwarder_chain		= pe_read_long(p->forwarder_chain);
ff2363
		m->name_rva			= pe_read_long(p->name_rva);
ff2363
		m->import_addr_tbl_rva		= pe_read_long(p->import_addr_tbl_rva);
c0fbae
ff2363
	}
c0fbae
c0fbae
	m->name  = 0;
c0fbae
	m->aitems = 0;
c0fbae
c0fbae
	return 0;
b5f7f5
}
c0fbae
c0fbae
int pe_read_import_lookup_item(
7d4d3d
	const union pe_import_lookup_item * p,
c0fbae
	struct pe_meta_import_lookup_item * m,
c0fbae
	uint32_t magic)
c0fbae
{
c0fbae
	switch (magic) {
c0fbae
		case PE_MAGIC_PE32:
7d4d3d
			m->u.import_lookup_entry_64 = pe_read_long(p->import_lookup_entry_32);
c0fbae
			return 0;
c0fbae
c0fbae
		case PE_MAGIC_PE32_PLUS:
7d4d3d
			m->u.import_lookup_entry_64 = pe_read_quad(p->import_lookup_entry_64);
c0fbae
			return 0;
c0fbae
c0fbae
		default:
ff121d
			return PERK_ERR_BAD_IMAGE_TYPE;
c0fbae
	}
b5f7f5
}