summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRainer Schuetze <r.sagitario@gmx.de>2018-03-30 09:40:26 (GMT)
committerRainer Schuetze <r.sagitario@gmx.de>2018-03-30 09:40:26 (GMT)
commitd67da0ec9481ca3ffe878ca68dfb64909040e231 (patch)
tree2819e269661a9ee6a0a7654ff49c7225806459b1 /src
parentab4b0b1946295f9762ec3ed83a7c84cc8b7aa975 (diff)
downloadcv2pdb-d67da0ec9481ca3ffe878ca68dfb64909040e231.zip
cv2pdb-d67da0ec9481ca3ffe878ca68dfb64909040e231.tar.gz
cv2pdb-d67da0ec9481ca3ffe878ca68dfb64909040e231.tar.bz2
add partial support to convert DBG to PDB
Diffstat (limited to 'src')
-rw-r--r--src/PEImage.cpp62
-rw-r--r--src/PEImage.h3
-rw-r--r--src/main.cpp5
3 files changed, 67 insertions, 3 deletions
diff --git a/src/PEImage.cpp b/src/PEImage.cpp
index a8fd11f..4cd3675 100644
--- a/src/PEImage.cpp
+++ b/src/PEImage.cpp
@@ -53,6 +53,7 @@ PEImage::PEImage(const TCHAR* iname)
, symtable(0)
, strtable(0)
, bigobj(false)
+, dbgfile(false)
{
if(iname)
loadExe(iname);
@@ -98,7 +99,7 @@ bool PEImage::loadExe(const TCHAR* iname)
if (!readAll(iname))
return false;
- return initCVPtr(true) || initDWARFPtr(true);
+ return initCVPtr(true) || initDbgPtr(true) || initDWARFPtr(true);
}
///////////////////////////////////////////////////////////////////////
@@ -317,6 +318,65 @@ bool PEImage::initCVPtr(bool initDbgDir)
}
///////////////////////////////////////////////////////////////////////
+bool PEImage::initDbgPtr(bool initDbgDir)
+{
+ auto dbg = DPV<IMAGE_SEPARATE_DEBUG_HEADER> (0);
+ if(!dbg)
+ return setError("file too small for DBG header");
+ if(dbg->Signature != IMAGE_SEPARATE_DEBUG_SIGNATURE)
+ return setError("this is not a DBG file");
+
+ sec = (PIMAGE_SECTION_HEADER)(dbg + 1);
+ nsec = dbg->NumberOfSections;
+
+ symtable = (char*)(sec + nsec);
+ nsym = dbg->ExportedNamesSize;
+ strtable = symtable + nsym * IMAGE_SIZEOF_SYMBOL;
+
+ if(dbg->DebugDirectorySize <= IMAGE_DIRECTORY_ENTRY_DEBUG)
+ return setError("too few entries in data directory");
+
+ dbgDir = 0;
+ dirHeader = 0;
+ dirEntry = 0;
+ if (!initDbgDir)
+ return true;
+
+ unsigned int dbgDirOff = strtable - (char*) dbg;
+ unsigned int i;
+ int found = false;
+ for(i = 0; i < dbg->DebugDirectorySize/sizeof(IMAGE_DEBUG_DIRECTORY); i++)
+ {
+ int off = dbgDirOff + i*sizeof(IMAGE_DEBUG_DIRECTORY);
+ dbgDir = DPV<IMAGE_DEBUG_DIRECTORY>(off, sizeof(IMAGE_DEBUG_DIRECTORY));
+ if (!dbgDir)
+ continue; //return setError("debug directory not placed in image");
+ if (dbgDir->Type != IMAGE_DEBUG_TYPE_CODEVIEW)
+ continue; //return setError("debug directory not of type CodeView");
+
+ cv_base = dbgDir->PointerToRawData;
+ OMFSignature* sig = DPV<OMFSignature>(cv_base, dbgDir->SizeOfData);
+ if (!sig)
+ return setError("invalid debug data base address and size");
+ if (memcmp(sig->Signature, "NB09", 4) != 0 && memcmp(sig->Signature, "NB11", 4) != 0)
+ {
+ // return setError("can only handle debug info of type NB09 and NB11");
+ return false;
+ }
+ dirHeader = CVP<OMFDirHeader>(sig->filepos);
+ if (!dirHeader)
+ return setError("invalid CodeView dir header data base address");
+ dirEntry = CVP<OMFDirEntry>(sig->filepos + dirHeader->cbDirHeader);
+ if (!dirEntry)
+ return setError("CodeView debug dir entries invalid");
+
+ dbgfile = true;
+ return true;
+ }
+ return setError("no CodeView debug info data found");
+}
+
+///////////////////////////////////////////////////////////////////////
bool PEImage::initDWARFPtr(bool initDbgDir)
{
dos = DPV<IMAGE_DOS_HEADER> (0);
diff --git a/src/PEImage.h b/src/PEImage.h
index 05e3d9e..5ebfa16 100644
--- a/src/PEImage.h
+++ b/src/PEImage.h
@@ -63,6 +63,7 @@ public:
bool replaceDebugSection (const void* data, int datalen, bool initCV);
bool initCVPtr(bool initDbgDir);
+ bool initDbgPtr(bool initDbgDir);
bool initDWARFPtr(bool initDbgDir);
bool initDWARFObject();
void initDWARFSegments();
@@ -70,6 +71,7 @@ public:
bool hasDWARF() const { return debug_line != 0; }
bool isX64() const { return hdr64 != 0; }
+ bool isDBG() const { return dbgfile; }
int countCVEntries() const;
OMFDirEntry* getCVEntry(int i) const;
@@ -112,6 +114,7 @@ private:
const char* symtable;
const char* strtable;
bool bigobj;
+ bool dbgfile; // is DBG file
public:
//dwarf
diff --git a/src/main.cpp b/src/main.cpp
index b832d72..cf7260f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -225,8 +225,9 @@ int T_main(int argc, TCHAR* argv[])
if (!cv2pdb.addPublics())
fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
- if (!cv2pdb.writeImage(outname))
- fatal(SARG ": %s", outname, cv2pdb.getLastError());
+ if (!img.isDBG())
+ if (!cv2pdb.writeImage(outname))
+ fatal(SARG ": %s", outname, cv2pdb.getLastError());
}
return 0;