diff options
author | sagitario <sagitario@fc51e93f-b9fe-4711-8d8d-3ae870c5f7d8> | 2009-05-08 15:54:32 (GMT) |
---|---|---|
committer | sagitario <sagitario@fc51e93f-b9fe-4711-8d8d-3ae870c5f7d8> | 2009-05-08 15:54:32 (GMT) |
commit | d3adcbbc0c51ab693e7fcbd95569ffd548128d02 (patch) | |
tree | 2d821e16fcb0b09ae7c43629366499bd1a4dc33a /src/PEImage.h | |
download | cv2pdb-d3adcbbc0c51ab693e7fcbd95569ffd548128d02.zip cv2pdb-d3adcbbc0c51ab693e7fcbd95569ffd548128d02.tar.gz cv2pdb-d3adcbbc0c51ab693e7fcbd95569ffd548128d02.tar.bz2 |
Diffstat (limited to 'src/PEImage.h')
-rw-r--r-- | src/PEImage.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/PEImage.h b/src/PEImage.h new file mode 100644 index 0000000..bbc2eb9 --- /dev/null +++ b/src/PEImage.h @@ -0,0 +1,86 @@ +// Convert DMD CodeView debug information to PDB files
+// Copyright (c) 2009 by Rainer Schuetze, All Rights Reserved
+//
+// License for redistribution is given by the Artistic License 2.0
+// see file LICENSE for further details
+
+#ifndef __PEIMAGE_H__
+#define __PEIMAGE_H__
+
+#include "LastError.h"
+
+#include <windows.h>
+
+struct OMFDirHeader;
+struct OMFDirEntry;
+
+class PEImage : public LastError
+{
+public:
+ PEImage(const char* iname = 0);
+ ~PEImage();
+
+ template<class P> P* DP(int off)
+ {
+ return (P*) ((char*) dump_base + off);
+ }
+ template<class P> P* DPV(int off, int size)
+ {
+ if(off < 0 || off + size > dump_total_len)
+ return 0;
+ return (P*) ((char*) dump_base + off);
+ }
+ template<class P> P* DPV(int off)
+ {
+ return DPV<P>(off, sizeof(P));
+ }
+ template<class P> P* CVP(int off)
+ {
+ return DPV<P>(cv_base + off, sizeof(P));
+ }
+
+ template<class P> P* RVA(unsigned long rva, int len) + { + IMAGE_DOS_HEADER *dos = DPV<IMAGE_DOS_HEADER> (0);
+ IMAGE_NT_HEADERS32* hdr = DPV<IMAGE_NT_HEADERS32> (dos->e_lfanew);
+ IMAGE_SECTION_HEADER* sec = IMAGE_FIRST_SECTION(hdr);
+ + for (int i = 0; i < hdr->FileHeader.NumberOfSections; i++) + { + if (rva >= sec[i].VirtualAddress && + rva + len <= sec[i].VirtualAddress + sec[i].SizeOfRawData) + return DPV<P>(sec[i].PointerToRawData + rva - sec[i].VirtualAddress, len); + } + return 0; + } +
+ bool load(const char* iname);
+ bool save(const char* oname);
+
+ bool replaceDebugSection (const void* data, int datalen);
+ bool initPtr();
+
+ int countCVEntries() const;
+ OMFDirEntry* getCVEntry(int i) const;
+
+ // utilities
+ static void* alloc_aligned(unsigned int size, unsigned int align, unsigned int alignoff = 0);
+ static void free_aligned(void* p);
+
+private:
+ int fd;
+ void* dump_base; + int dump_total_len;
+
+ IMAGE_DOS_HEADER *dos;
+ IMAGE_NT_HEADERS32* hdr;
+ IMAGE_SECTION_HEADER* sec;
+ IMAGE_DEBUG_DIRECTORY* dbgDir;
+ OMFDirHeader* dirHeader;
+ OMFDirEntry* dirEntry;
+
+ int cv_base;
+};
+
+
+#endif //__PEIMAGE_H__
\ No newline at end of file |