Blame src/reader/pe_read_import_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_import_header(const struct pe_import_hdr * p, struct pe_meta_import_hdr * m)
c0fbae
{
c0fbae
	#if (BYTE_ORDER == LITTLE_ENDIAN)
c0fbae
c0fbae
	memcpy(m,p,sizeof(*p));
c0fbae
c0fbae
	#else
c0fbae
c0fbae
	m->import_lookup_tbl_rva	= pe_read_long(p->import_lookup_tbl_rva);
c0fbae
	m->time_date_stamp		= pe_read_long(p->time_date_stamp);
c0fbae
	m->forwarder_chain		= pe_read_long(p>forwarder_chain);
c0fbae
	m->name_rva			= pe_read_long(p->name_rva);
c0fbae
	m->import_addr_tbl_rva		= pe_read_long(p>import_addr_tbl_rva);
c0fbae
c0fbae
	#endif
c0fbae
c0fbae
	m->name  = 0;
c0fbae
	m->aitems = 0;
c0fbae
c0fbae
	return 0;
c0fbae
};
c0fbae
c0fbae
int pe_read_import_lookup_item(
c0fbae
	const struct 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:
c0fbae
			m->u.import_lookup_entry_64 = pe_read_long(p->u.import_lookup_entry_32);
c0fbae
			return 0;
c0fbae
c0fbae
		case PE_MAGIC_PE32_PLUS:
c0fbae
			m->u.import_lookup_entry_64 = pe_read_quad(p->u.import_lookup_entry_64);
c0fbae
			return 0;
c0fbae
c0fbae
		default:
c0fbae
			return PERK_BAD_IMAGE_TYPE;
c0fbae
	}
c0fbae
};