Blame src/headers/pe_get_image_coff_hdr_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
feffc7
struct pe_coff_file_hdr * pe_get_image_coff_hdr_addr(const void * base)
feffc7
{
feffc7
	struct pe_image_dos_hdr *	dos;
feffc7
	struct pe_coff_file_hdr *	coff;
feffc7
	uint32_t *			offset;
feffc7
feffc7
	if (!(dos = pe_get_image_dos_hdr_addr(base)))
feffc7
		return 0;
feffc7
feffc7
	offset   = (uint32_t *)(dos->dos_lfanew);
feffc7
	coff = (struct pe_coff_file_hdr *)pe_va_from_rva(base,*offset);
feffc7
feffc7
	if ((coff->signature[0] == 'P') && (coff->signature[1] == 'E')
feffc7
			&& (coff->signature[2] == '\0') && (coff->signature[3] == '\0'))
feffc7
		return coff;
feffc7
	else
feffc7
		return 0;
feffc7
}