Blame src/headers/pe_get_image_coff_hdr_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_consts.h>
feffc7
#include <pemagine/pe_structs.h>
feffc7
#include <pemagine/pemagine.h>
feffc7
b8d16a
02863d
struct pe_raw_coff_image_hdr * pe_get_image_coff_hdr_addr(const void * base)
feffc7
{
de5b30
	struct pe_raw_image_dos_hdr *	dos;
02863d
	struct pe_raw_coff_image_hdr *	coff;
feffc7
	uint32_t *			offset;
feffc7
feffc7
	if (!(dos = pe_get_image_dos_hdr_addr(base)))
feffc7
		return 0;
feffc7
b8d16a
	offset = (uint32_t *)(dos->dos_lfanew);
02863d
	coff   = (struct pe_raw_coff_image_hdr *)pe_va_from_rva(base,*offset);
feffc7
12bebb
	return ((coff->cfh_signature[0] == 'P')
12bebb
			&& (coff->cfh_signature[1] == 'E')
12bebb
			&& (coff->cfh_signature[2] == '\0')
12bebb
			&& (coff->cfh_signature[3] == '\0'))
b8d16a
		? coff : 0;
feffc7
}