Blame src/headers/pe_get_image_entry_point_addr.c

feffc7
/*****************************************************************************/
feffc7
/*  pemagination: a (virtual) tour into portable bits and executable bytes   */
6dda52
/*  Copyright (C) 2013--2020  SysDeer Technologies, LLC                      */
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
void * pe_get_image_entry_point_addr(const void * base)
feffc7
{
feffc7
	uint16_t *		magic;
fad23f
	union pe_raw_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:
6e18ff
			rva = (uint32_t *)hdr->opt_hdr_32.coh_entry_point;
feffc7
			break;
feffc7
feffc7
		case PE_MAGIC_PE32_PLUS:
6e18ff
			rva = (uint32_t *)hdr->opt_hdr_64.coh_entry_point;
feffc7
			break;
feffc7
feffc7
		default:
feffc7
			return 0;
feffc7
	}
feffc7
feffc7
	return pe_va_from_rva(base,*rva);
feffc7
}