Blame src/reader/pe_read_import_header.c

e2e2c2
/***************************************************************/
e2e2c2
/*  perk: PE Resource Kit                                      */
ced38a
/*  Copyright (C) 2015--2017  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
34ee9e
int pe_read_import_header(const struct pe_raw_import_hdr * p, struct pe_meta_import_hdr * m)
c0fbae
{
982672
	m->ih_import_lookup_tbl_rva = pe_read_long(p->ih_import_lookup_tbl_rva);
982672
	m->ih_time_date_stamp       = pe_read_long(p->ih_time_date_stamp);
982672
	m->ih_forwarder_chain       = pe_read_long(p->ih_forwarder_chain);
982672
	m->ih_name_rva              = pe_read_long(p->ih_name_rva);
982672
	m->ih_import_addr_tbl_rva   = pe_read_long(p->ih_import_addr_tbl_rva);
982672
982672
	m->ih_name   = 0;
982672
	m->ih_aitems = 0;
c0fbae
c0fbae
	return 0;
b5f7f5
}
c0fbae
9770d4
int pe_read_import_lookup(
91d87e
	const unsigned char * p,
3161de
	struct pe_meta_import_lookup * m,
c0fbae
	uint32_t magic)
c0fbae
{
c0fbae
	switch (magic) {
c0fbae
		case PE_MAGIC_PE32:
91d87e
			m->u.ii_import_lookup_entry_64 = pe_read_long(p);
4ae524
			m->ii_flag = (uint32_t)m->u.ii_import_lookup_entry_64 >> 31;
4ae524
			break;
c0fbae
c0fbae
		case PE_MAGIC_PE32_PLUS:
91d87e
			m->u.ii_import_lookup_entry_64 = pe_read_quad(p);
4ae524
			m->ii_flag = m->u.ii_import_lookup_entry_64 >> 63;
4ae524
			break;
c0fbae
c0fbae
		default:
ff121d
			return PERK_ERR_BAD_IMAGE_TYPE;
c0fbae
	}
4ae524
4ae524
	if (m->ii_flag) {
994c64
		m->ii_ordinal           = m->u.ii_import_lookup_entry_32 & 0xffff;
4ae524
		m->ii_hint_name_tbl_rva = 0;
4ae524
	} else {
4ae524
		m->ii_ordinal           = 0;
4ae524
		m->ii_hint_name_tbl_rva = m->u.ii_import_lookup_entry_32 & 0x7fffffff;
4ae524
	}
4ae524
4ae524
	m->ii_hint = 0;
4ae524
	m->ii_name = 0;
4ae524
4ae524
	return 0;
b5f7f5
}