bindexplib: Teach DumpFile to return errors

This will allow callers to know if it worked.
This commit is contained in:
Bill Hoffman 2015-06-19 16:12:43 -04:00 committed by Brad King
parent 8ea69dfef1
commit de70c922d9
1 changed files with 10 additions and 7 deletions

View File

@ -296,7 +296,8 @@ DumpObjFile(PIMAGE_FILE_HEADER pImageFileHeader, FILE *fout)
* dumping routine
*----------------------------------------------------------------------
*/
void
bool
DumpFile(const char* filename, FILE *fout)
{
HANDLE hFile;
@ -309,15 +310,15 @@ DumpFile(const char* filename, FILE *fout)
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Couldn't open file with CreateFile()\n");
return;
fprintf(stderr, "Couldn't open file '%s' with CreateFile()\n", filename);
return false;
}
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (hFileMapping == 0) {
CloseHandle(hFile);
fprintf(stderr, "Couldn't open file mapping with CreateFileMapping()\n");
return;
return false;
}
lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
@ -325,13 +326,13 @@ DumpFile(const char* filename, FILE *fout)
CloseHandle(hFileMapping);
CloseHandle(hFile);
fprintf(stderr, "Couldn't map view of file with MapViewOfFile()\n");
return;
return false;
}
dosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
fprintf(stderr, "File is an executable. I don't dump those.\n");
return;
return false;
}
/* Does it look like a i386 COFF OBJ file??? */
else if (
@ -346,9 +347,11 @@ DumpFile(const char* filename, FILE *fout)
*/
DumpObjFile((PIMAGE_FILE_HEADER) lpFileBase, fout);
} else {
printf("unrecognized file format\n");
printf("unrecognized file format in '%s'\n", filename);
return false;
}
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return true;
}