/*****************************************************************************/ /* pemagination: a (virtual) tour into portable bits and executable bytes */ /* Copyright (C) 2013--2016 Z. Gilboa */ /* Released under GPLv2 and GPLv3; see COPYING.PEMAGINE. */ /*****************************************************************************/ #include #include #include #include struct pe_raw_coff_file_hdr * pe_get_image_coff_hdr_addr(const void * base) { struct pe_raw_image_dos_hdr * dos; struct pe_raw_coff_file_hdr * coff; uint32_t * offset; if (!(dos = pe_get_image_dos_hdr_addr(base))) return 0; offset = (uint32_t *)(dos->dos_lfanew); coff = (struct pe_raw_coff_file_hdr *)pe_va_from_rva(base,*offset); return ((coff->signature[0] == 'P') && (coff->signature[1] == 'E') && (coff->signature[2] == '\0') && (coff->signature[3] == '\0')) ? coff : 0; }