Blame src/headers/pe_get_image_data_dirs_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_consts.h>
feffc7
#include <pemagine/pe_structs.h>
feffc7
#include <pemagine/pemagine.h>
feffc7
feffc7
pe_api
fb643b
struct pe_raw_data_dirs * pe_get_image_data_dirs_addr(const void * base)
feffc7
{
feffc7
	uint16_t *		magic;
fad23f
	union pe_raw_opt_hdr *	hdr;
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:
fb643b
			return (struct pe_raw_data_dirs *)hdr->opt_hdr_32.rva_and_sizes;
feffc7
feffc7
		case PE_MAGIC_PE32_PLUS:
fb643b
			return (struct pe_raw_data_dirs *)hdr->opt_hdr_64.rva_and_sizes;
feffc7
feffc7
		default:
feffc7
			return 0;
feffc7
	}
feffc7
}