Be more strict about checks (especially in RVA translations).
diff --git a/tools/winedump/main.c b/tools/winedump/main.c
index 5807622..d3c1a04 100644
--- a/tools/winedump/main.c
+++ b/tools/winedump/main.c
@@ -404,7 +404,8 @@
if (globals.input_name == NULL)
fatal("No file name has been given\n");
set_module_name(1);
- dll_open (globals.input_name);
+ if (!dll_open (globals.input_name))
+ break;
output_spec_preamble ();
output_header_preamble ();
diff --git a/tools/winedump/pe.c b/tools/winedump/pe.c
index ca78762..1e02da6 100644
--- a/tools/winedump/pe.c
+++ b/tools/winedump/pe.c
@@ -111,27 +111,23 @@
IMAGE_SECTION_HEADER* sectHead;
int i;
+ if (rva == 0) return NULL;
+
sectHead = (IMAGE_SECTION_HEADER*)((char*)PE_nt_headers + sizeof(DWORD) +
sizeof(IMAGE_FILE_HEADER) +
PE_nt_headers->FileHeader.SizeOfOptionalHeader);
- if (rva == 0) return NULL;
-
for (i = PE_nt_headers->FileHeader.NumberOfSections - 1; i >= 0; i--)
{
if (sectHead[i].VirtualAddress <= rva &&
rva + len <= (DWORD)sectHead[i].VirtualAddress + sectHead[i].SizeOfRawData)
- break;
+ {
+ /* return image import directory offset */
+ return PRD(sectHead[i].PointerToRawData + rva - sectHead[i].VirtualAddress, len);
+ }
}
- if (i < 0)
- {
- printf("rva not found in any section (%lu)\n", rva);
- return NULL;
- }
-
- /* return image import directory offset */
- return PRD(sectHead[i].PointerToRawData + rva - sectHead[i].VirtualAddress, len);
+ return NULL;
}
static void* get_dir(unsigned idx)
@@ -170,7 +166,7 @@
printf(" Machine: %04X (%s)\n",
fileHeader->Machine, get_machine_str(fileHeader->Machine));
printf(" Number of Sections: %d\n", fileHeader->NumberOfSections);
- printf(" TimeDateStamp: %08lX (%s) offset %ld\n",
+ printf(" TimeDateStamp: %08lX (%s) offset %lu\n",
fileHeader->TimeDateStamp, get_time_str(fileHeader->TimeDateStamp),
Offset(&(fileHeader->TimeDateStamp)));
printf(" PointerToSymbolTable: %08lX\n", fileHeader->PointerToSymbolTable);
@@ -591,8 +587,12 @@
printf( " Callbacks %08lx -> {", (DWORD)dir->AddressOfCallBacks );
if (dir->AddressOfCallBacks)
{
- callbacks = RVA((DWORD)dir->AddressOfCallBacks - PE_nt_headers->OptionalHeader.ImageBase,0);
- while (*callbacks) printf( " %08lx", *callbacks++ );
+ DWORD addr = (DWORD)dir->AddressOfCallBacks - PE_nt_headers->OptionalHeader.ImageBase;
+ while ((callbacks = RVA(addr, sizeof(DWORD))) && *callbacks)
+ {
+ printf( " %08lx", *callbacks );
+ addr += sizeof(DWORD);
+ }
}
printf(" }\n\n");
}
@@ -704,6 +704,11 @@
unsigned int i, j;
printf( "%s", prefix );
+ if (!ptr)
+ {
+ printf("NULL\n");
+ return;
+ }
for (i = 0; i < size; i++)
{
printf( "%02x%c", ptr[i], (i % 16 == 7) ? '-' : ' ' );
@@ -1224,9 +1229,9 @@
*
* Open a DLL and read in exported symbols
*/
-void dll_open (const char *dll_name)
+int dll_open (const char *dll_name)
{
- pe_analysis(dll_name, do_grab_sym, SIG_PE);
+ return pe_analysis(dll_name, do_grab_sym, SIG_PE);
}
/*******************************************************************
diff --git a/tools/winedump/winedump.h b/tools/winedump/winedump.h
index c65e012..3188a81 100644
--- a/tools/winedump/winedump.h
+++ b/tools/winedump/winedump.h
@@ -157,9 +157,9 @@
void dump_file(const char* name);
/* DLL functions */
-void dll_open (const char *dll_name);
+int dll_open (const char *dll_name);
-int dll_next_symbol (parsed_symbol * sym);
+int dll_next_symbol (parsed_symbol * sym);
/* Symbol functions */
int symbol_init(parsed_symbol* symbol, const char* name);