summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexWhiter <a.whiter@yandex.ru>2018-03-30 15:51:31 (GMT)
committerAlexWhiter <a.whiter@yandex.ru>2018-03-30 15:51:31 (GMT)
commit6dd1bb797c2d74052def1ba869961caa6dce3661 (patch)
tree7bc0f8613295c2cbb51fcca3e63d3819dea8d665
parenta0930e367b39e7a7d0d2f8803cb6e7b983c2def5 (diff)
downloadcv2pdb-6dd1bb797c2d74052def1ba869961caa6dce3661.zip
cv2pdb-6dd1bb797c2d74052def1ba869961caa6dce3661.tar.gz
cv2pdb-6dd1bb797c2d74052def1ba869961caa6dce3661.tar.bz2
RSDS section writing into EXE with symbols in DBG file.
-rw-r--r--src/PEImage.h2
-rw-r--r--src/cv2pdb.cpp10
-rw-r--r--src/cv2pdb.h2
-rw-r--r--src/main.cpp42
4 files changed, 39 insertions, 17 deletions
diff --git a/src/PEImage.h b/src/PEImage.h
index 5ebfa16..ce8e804 100644
--- a/src/PEImage.h
+++ b/src/PEImage.h
@@ -90,7 +90,7 @@ public:
unsigned long long getImageBase() const { return IMGHDR(OptionalHeader.ImageBase); }
int getRelocationInLineSegment(unsigned int offset) const;
int getRelocationInSegment(int segment, unsigned int offset) const;
-
+ bool areDebugSymbolsStripped() const { return (IMGHDR(FileHeader.Characteristics) & IMAGE_FILE_DEBUG_STRIPPED) != 0; }
int dumpDebugLineInfoCOFF();
int dumpDebugLineInfoOMF();
diff --git a/src/cv2pdb.cpp b/src/cv2pdb.cpp
index 95749bc..84cf5f2 100644
--- a/src/cv2pdb.cpp
+++ b/src/cv2pdb.cpp
@@ -3432,14 +3432,14 @@ bool CV2PDB::addSymbols()
return rc;
}
-bool CV2PDB::writeImage(const TCHAR* opath)
+bool CV2PDB::writeImage(const TCHAR* opath, PEImage& exeImage)
{
int len = sizeof(*rsds) + strlen((char*)(rsds + 1)) + 1;
- if (!img.replaceDebugSection(rsds, len, true))
- return setError(img.getLastError());
+ if (!exeImage.replaceDebugSection(rsds, len, true))
+ return setError(exeImage.getLastError());
- if (!img.save(opath))
- return setError(img.getLastError());
+ if (!exeImage.save(opath))
+ return setError(exeImage.getLastError());
return true;
}
diff --git a/src/cv2pdb.h b/src/cv2pdb.h
index 558ce21..9e5e5d1 100644
--- a/src/cv2pdb.h
+++ b/src/cv2pdb.h
@@ -160,7 +160,7 @@ public:
bool createSrcLineBitmap();
int getNextSrcLine(int seg, unsigned int off);
- bool writeImage(const TCHAR* opath);
+ bool writeImage(const TCHAR* opath, PEImage& exeImage);
mspdb::Mod* globalMod();
diff --git a/src/main.cpp b/src/main.cpp
index cf7260f..0e4cf3d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -145,13 +145,35 @@ int T_main(int argc, TCHAR* argv[])
return -1;
}
- PEImage img;
- if (!img.loadExe(argv[1]))
- fatal(SARG ": %s", argv[1], img.getLastError());
- if (img.countCVEntries() == 0 && !img.hasDWARF())
- fatal(SARG ": no codeview debug entries found", argv[1]);
+ PEImage exe, dbg, *img = NULL;
+ TCHAR dbgname[MAX_PATH];
- CV2PDB cv2pdb(img);
+ if (!exe.loadExe(argv[1]))
+ fatal(SARG ": %s", argv[1], exe.getLastError());
+ if (exe.countCVEntries() || exe.hasDWARF())
+ img = &exe;
+ else
+ if (exe.areDebugSymbolsStripped())
+ {
+ T_strcpy(dbgname, argv[1]);
+ TCHAR *pDot = T_strrchr(dbgname, '.');
+ if (!pDot || pDot <= T_strrchr(dbgname, '/') || pDot <= T_strrchr(dbgname, '\\'))
+ T_strcat(dbgname, TEXT(".dbg"));
+ else
+ T_strcpy(pDot, TEXT(".dbg"));
+
+ if (!dbg.loadExe(dbgname))
+ fatal(SARG ": %s", dbgname, dbg.getLastError());
+
+ if (dbg.countCVEntries())
+ img = &dbg;
+ else
+ fatal(SARG ": no codeview debug entries found", dbgname);
+ }
+ else
+ fatal(SARG ": no codeview debug entries found", argv[1]);
+
+ CV2PDB cv2pdb(*img);
cv2pdb.Dversion = Dversion;
cv2pdb.debug = debug;
cv2pdb.initLibraries();
@@ -179,9 +201,9 @@ int T_main(int argc, TCHAR* argv[])
if(!cv2pdb.openPDB(pdbname, pdbref))
fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
- if(img.hasDWARF())
+ if(exe.hasDWARF())
{
- if(!img.relocateDebugLineInfo(0x400000))
+ if(!exe.relocateDebugLineInfo(0x400000))
fatal(SARG ": %s", argv[1], cv2pdb.getLastError());
if(!cv2pdb.createDWARFModules())
@@ -225,8 +247,8 @@ int T_main(int argc, TCHAR* argv[])
if (!cv2pdb.addPublics())
fatal(SARG ": %s", pdbname, cv2pdb.getLastError());
- if (!img.isDBG())
- if (!cv2pdb.writeImage(outname))
+ if (!exe.isDBG())
+ if (!cv2pdb.writeImage(outname, exe))
fatal(SARG ": %s", outname, cv2pdb.getLastError());
}