Blame src/headers/pe_get_image_entry_point_addr.c

feffc7
/*****************************************************************************/
feffc7
/*  pemagination: a (virtual) tour into portable bits and executable bytes   */
feffc7
/*  Copyright (C) 2013,2014,2015  Z. Gilboa                                  */
feffc7
/*  Released under GPLv2 and GPLv3; see COPYING.PEMAGINE.                    */
feffc7
/*****************************************************************************/
feffc7
feffc7
#include <psxtypes/psxtypes.h>
feffc7
#include <pemagine/pe_structs.h>
feffc7
#include <pemagine/pe_consts.h>
feffc7
#include <pemagine/pemagine.h>
feffc7
feffc7
feffc7
pe_api
feffc7
void * pe_get_image_entry_point_addr(const void * base)
feffc7
{
feffc7
	uint16_t *		magic;
feffc7
	union pe_opt_hdr *	hdr;
feffc7
	uint32_t *		rva;
feffc7
feffc7
	if (!(hdr = pe_get_image_opt_hdr_addr(base)))
feffc7
		return 0;
feffc7
feffc7
	magic = (uint16_t *)hdr;
feffc7
feffc7
	switch (*magic) {
feffc7
		case PE_MAGIC_PE32:
feffc7
			rva = (uint32_t *)hdr->opt_hdr_32.entry_point;
feffc7
			break;
feffc7
feffc7
		case PE_MAGIC_PE32_PLUS:
feffc7
			rva = (uint32_t *)hdr->opt_hdr_64.entry_point;
feffc7
			break;
feffc7
feffc7
		default:
feffc7
			return 0;
feffc7
	}
feffc7
feffc7
	return pe_va_from_rva(base,*rva);
feffc7
}