2015-09-07 Keith Marshall <keithmarshall@users.sourceforge.net>
+ Avoid uint32_t difference overflow in 64-bit pointer adjustment.
+
+ * pexports.c (rva_to_ptr): Do not compute uint32_t offset differences;
+ apply each offset adjustment individually to the base pointer.
+
+ * pexports.h: Add '#pragma ms_struct on', to keep structures aligned
+ per MSVC convention.
+
+2015-09-07 Keith Marshall <keithmarshall@users.sourceforge.net>
+
Eliminate Microsoft inspired obfuscated typedef insanity.
* pexports.c pexports.h (BYTE, WORD, DWORD): Delete typedefs;
exports = RVA_TO_PTR(exports_rva, IMAGE_EXPORT_DIRECTORY *);
/* set up various pointers */
- export_name = RVA_TO_PTR(exports->Name,char*);
- ordinal_table = RVA_TO_PTR(exports->AddressOfNameOrdinals, uint16_t *);
+ export_name = RVA_TO_PTR(exports->Name, char *);
name_table = RVA_TO_PTR(exports->AddressOfNames, uint32_t *);
- function_table = RVA_TO_PTR(exports->AddressOfFunctions,void*);
+ ordinal_table = RVA_TO_PTR(exports->AddressOfNameOrdinals, uint16_t *);
+ function_table = RVA_TO_PTR(exports->AddressOfFunctions, void *);
if (verbose)
{
rva_to_ptr(uint32_t rva)
{
IMAGE_SECTION_HEADER *section = find_section(rva);
- if (section->PointerToRawData == 0)
- return NULL;
- else
- return ((char *) dos_hdr + rva - (section->VirtualAddress - section->PointerToRawData));
+ return (section->PointerToRawData != 0)
+ ? (char *)(dos_hdr) + rva - section->VirtualAddress + section->PointerToRawData
+ : NULL;
}
/* Load a portable executable into memory */