summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Schuetze <r.sagitario@gmx.de>2018-03-31 06:24:53 (GMT)
committerGitHub <noreply@github.com>2018-03-31 06:24:53 (GMT)
commitdf1a89bef43e5c62ecfac896002717993fe8a758 (patch)
tree0162a00bd2b35b1f18ca4f402b51e9f65f063aae
parentd67da0ec9481ca3ffe878ca68dfb64909040e231 (diff)
parentb78a52328e5d943fdc824468861a7fb0f6fe65b0 (diff)
downloadcv2pdb-df1a89bef43e5c62ecfac896002717993fe8a758.zip
cv2pdb-df1a89bef43e5c62ecfac896002717993fe8a758.tar.gz
cv2pdb-df1a89bef43e5c62ecfac896002717993fe8a758.tar.bz2
Merge pull request #26 from AlexWhiter/master
Writing of RSDS section to EXE with symbols in DBG.
-rw-r--r--src/PEImage.cpp3
-rw-r--r--src/cv2pdb.cpp10
-rw-r--r--src/cv2pdb.h2
-rw-r--r--src/main.cpp47
4 files changed, 44 insertions, 18 deletions
diff --git a/src/PEImage.cpp b/src/PEImage.cpp
index 4cd3675..9a61c3a 100644
--- a/src/PEImage.cpp
+++ b/src/PEImage.cpp
@@ -330,8 +330,7 @@ bool PEImage::initDbgPtr(bool initDbgDir)
nsec = dbg->NumberOfSections;
symtable = (char*)(sec + nsec);
- nsym = dbg->ExportedNamesSize;
- strtable = symtable + nsym * IMAGE_SIZEOF_SYMBOL;
+ strtable = symtable + dbg->ExportedNamesSize;
if(dbg->DebugDirectorySize <= IMAGE_DIRECTORY_ENTRY_DEBUG)
return setError("too few entries in data directory");
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..8163f6b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -26,6 +26,7 @@ double
#define T_unlink _wremove
#define T_main wmain
#define SARG "%S"
+#define T_stat _wstat
#else
#define T_toupper toupper
#define T_getdcwd _getdcwd
@@ -38,6 +39,7 @@ double
#define T_unlink unlink
#define T_main main
#define SARG "%s"
+#define T_stat stat
#endif
void fatal(const char *message, ...)
@@ -145,13 +147,38 @@ 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
+ {
+ 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"));
+
+ struct _stat buffer;
+ if (T_stat(dbgname, &buffer) == 0)
+ {
+ 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 +206,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 +252,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());
}