Minor cleanups, plus fixed a couple bugs in .DBG parsing code.
Added dump for MISC section.
This commit is contained in:
parent
3676c17646
commit
b741cc0f52
|
@ -25,7 +25,7 @@
|
||||||
* other structs.
|
* other structs.
|
||||||
*
|
*
|
||||||
* The contents of this section look like this (the first two fields are
|
* The contents of this section look like this (the first two fields are
|
||||||
* already extracted and passed in as parameters):
|
* extracted and passed back out):
|
||||||
*
|
*
|
||||||
* unsigned short cFile
|
* unsigned short cFile
|
||||||
* unsigned short cSeg
|
* unsigned short cSeg
|
||||||
|
|
|
@ -49,7 +49,7 @@ DWORD GetOffsetFromRVA (DWORD rva)
|
||||||
/* Assumes all RVA's in the section headers are sorted in increasing
|
/* Assumes all RVA's in the section headers are sorted in increasing
|
||||||
* order (which should be the case).
|
* order (which should be the case).
|
||||||
*/
|
*/
|
||||||
for (i = g_dbg_dircount - 1; i >= 0; i--)
|
for (i = g_numsects - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
sectbegin = g_secthdrs[i].VirtualAddress;
|
sectbegin = g_secthdrs[i].VirtualAddress;
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
|
@ -330,8 +330,8 @@ int DumpDebugDir (FILE *debugfile)
|
||||||
|
|
||||||
PrintFilePos (debugfile);
|
PrintFilePos (debugfile);
|
||||||
|
|
||||||
printf ("Found %d CodeView subsection%c...\n", g_dbg_dircount,
|
printf ("Found %d Debug director%s...\n", g_dbg_dircount,
|
||||||
(g_dbg_dircount == 1) ? '.' : 's');
|
(g_dbg_dircount == 1) ? "y" : "ies");
|
||||||
|
|
||||||
if (g_dbg_dircount == 0)
|
if (g_dbg_dircount == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -347,20 +347,11 @@ int DumpDebugDir (FILE *debugfile)
|
||||||
fseek (debugfile, filepos, SEEK_SET);
|
fseek (debugfile, filepos, SEEK_SET);
|
||||||
PrintFilePos (debugfile);
|
PrintFilePos (debugfile);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i;
|
fseek( debugfile, g_dbghdr.ExportedNamesSize, SEEK_CUR);
|
||||||
|
PrintFilePos (debugfile);
|
||||||
/* Find the .rdata section.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < g_numsects; i++)
|
|
||||||
if (strcmp (g_secthdrs[i].Name, ".rdata") == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
filepos = g_secthdrs[i].PointerToRawData;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!ReadDebugDir (debugfile, g_dbg_dircount, &g_debugdirs))
|
if (!ReadDebugDir (debugfile, g_dbg_dircount, &g_debugdirs))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -387,6 +378,22 @@ int DumpDebugDir (FILE *debugfile)
|
||||||
printf (" SizeOfData = [0x%8lx]\n", g_debugdirs[i].SizeOfData);
|
printf (" SizeOfData = [0x%8lx]\n", g_debugdirs[i].SizeOfData);
|
||||||
printf (" AddressOfRawData = [0x%8lx]\n", g_debugdirs[i].AddressOfRawData);
|
printf (" AddressOfRawData = [0x%8lx]\n", g_debugdirs[i].AddressOfRawData);
|
||||||
printf (" PointerToRawData = [0x%8lx]\n", g_debugdirs[i].PointerToRawData);
|
printf (" PointerToRawData = [0x%8lx]\n", g_debugdirs[i].PointerToRawData);
|
||||||
|
|
||||||
|
if (g_debugdirs[i].Type == IMAGE_DEBUG_TYPE_MISC)
|
||||||
|
{
|
||||||
|
IMAGE_DEBUG_DIRECTORY_MISC misc;
|
||||||
|
int lastpos = ftell (debugfile);
|
||||||
|
size_t bytes_read;
|
||||||
|
|
||||||
|
/* FIXME: Not sure exactly what the contents are supposed to be. */
|
||||||
|
fseek (debugfile, g_debugdirs[i].PointerToRawData, SEEK_SET);
|
||||||
|
bytes_read = fread (&misc, 1, sizeof (IMAGE_DEBUG_DIRECTORY_MISC), debugfile);
|
||||||
|
printf ("\n [0x%8lx]\n [0x%8lx]\n [0x%4x]\n [0x%4x]\n '%s'\n",
|
||||||
|
misc.unknown1, misc.SizeOfData, misc.unknown2,
|
||||||
|
misc.unknown3, misc.Name);
|
||||||
|
|
||||||
|
fseek (debugfile, lastpos, SEEK_SET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free (g_debugdirs);
|
free (g_debugdirs);
|
||||||
|
@ -782,8 +789,8 @@ int DumpSrcModuleInfo (int index, FILE *debugfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read in the entire sstSrcModule from the .DBG file. We'll process it
|
/* Read in the entire sstSrcModule from the .DBG file. We'll process it
|
||||||
* bit by bit, but passing memory pointers into the various functions in
|
* bit by bit, by passing memory pointers into the various functions in
|
||||||
* cvprint.c.
|
* cvcrunch.c.
|
||||||
*/
|
*/
|
||||||
if (!ReadChunk (debugfile, (void*)rawdata, g_cvEntries[index].cb, fileoffset))
|
if (!ReadChunk (debugfile, (void*)rawdata, g_cvEntries[index].cb, fileoffset))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -831,7 +838,7 @@ int DumpAlignSymInfo (int index, FILE *debugfile)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print out the info of all related modules (e.g. sstAlignSym, sstSrcModule)
|
* Print out the info of all related modules (e.g. sstAlignSym, sstSrcModule)
|
||||||
* for the desired sub-section (i.e. sstModule).
|
* for the given sub-section index (i.e. sstModule).
|
||||||
*/
|
*/
|
||||||
int DumpRelatedSections (int index, FILE *debugfile)
|
int DumpRelatedSections (int index, FILE *debugfile)
|
||||||
{
|
{
|
||||||
|
@ -925,9 +932,15 @@ int DumpAllModules (FILE *debugfile)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (g_cvHeader.cDir == 0 || g_cvEntries == NULL)
|
if (g_cvHeader.cDir == 0)
|
||||||
{
|
{
|
||||||
printf ("ERROR: Bailing out of Module Data Dump\n");
|
printf ("\nStrange...found CodeView header, but no module entries\n\n");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_cvEntries == NULL)
|
||||||
|
{
|
||||||
|
printf ("ERROR: Invalid entry table, bailing out of Module Data Dump\n");
|
||||||
printf ("%ld %p\n", g_cvHeader.cDir, g_cvEntries);
|
printf ("%ld %p\n", g_cvHeader.cDir, g_cvEntries);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,16 @@
|
||||||
|
|
||||||
#include "pshpack1.h"
|
#include "pshpack1.h"
|
||||||
|
|
||||||
|
/* FIXME: no idea if this is correct */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
DWORD unknown1;
|
||||||
|
DWORD SizeOfData;
|
||||||
|
WORD unknown2;
|
||||||
|
WORD unknown3;
|
||||||
|
char Name[MAX_PATH];
|
||||||
|
} IMAGE_DEBUG_DIRECTORY_MISC;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CodeView headers
|
* CodeView headers
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -318,7 +318,7 @@ int ReadCodeViewDirectory (FILE *debugfile, int entrynum, OMFDirEntry **entries)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load in the data contents of all CodeView sstModule sub-sections in the file (likely a
|
* Load in the data contents of all CodeView sstModule sub-sections in the file (likely a
|
||||||
* large array, as there is one sub-section for every module... > 100 modules is normal).
|
* large array, as there is one sub-section for every code module... > 100 modules is normal).
|
||||||
* 'entrynum' should hold the total number of CV sub-sections, not the number of sstModule
|
* 'entrynum' should hold the total number of CV sub-sections, not the number of sstModule
|
||||||
* subsections. The function will ignore anything that isn't a sstModule.
|
* subsections. The function will ignore anything that isn't a sstModule.
|
||||||
*
|
*
|
||||||
|
@ -408,7 +408,7 @@ int ReadModuleData (FILE *debugfile, int entrynum, OMFDirEntry *entries,
|
||||||
if (pad)
|
if (pad)
|
||||||
namelen += (4 - pad);
|
namelen += (4 - pad);
|
||||||
|
|
||||||
module->Name = calloc (namelen, sizeof (char) + 1);
|
module->Name = calloc (namelen + 1, sizeof (char));
|
||||||
bytes_read = fread (module->Name, sizeof (char), namelen, debugfile);
|
bytes_read = fread (module->Name, sizeof (char), namelen, debugfile);
|
||||||
if (bytes_read < namelen)
|
if (bytes_read < namelen)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue