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