BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
PEFile.cpp
Go to the documentation of this file.
1#include "pe/PEFile.h"
2#include "FileBuffer.h"
3
5{
6 if (buf == NULL) return false;
7
9 WORD *magic = (WORD*) buf->getContentAt(dosOffset, sizeof(WORD));
10 if (magic == NULL) return false;
11
12 if ((*magic) != pe::S_DOS) {
13 return false;
14 }
15 offset_t newOffset = dosOffset + (sizeof(IMAGE_DOS_HEADER) - sizeof(LONG));
16 LONG* lfnew = (LONG*) buf->getContentAt(newOffset, sizeof(LONG));
17 if (lfnew == NULL) {
18 return false;
19 }
20 offset_t peOffset = static_cast<offset_t>(*lfnew);
21 DWORD *peMagic = (DWORD*) buf->getContentAt(peOffset, sizeof(DWORD));
22 if (peMagic == NULL) {
23 return false;
24 }
25 if (*peMagic == pe::S_NT) {
26 return true;
27 }
28 return false;
29}
30
32{
34 if (signatureMatches(buf) == false) return NULL;
35
36 try {
37 exe = new PEFile(buf);
38 } catch (ExeException &e) {
39 exe = NULL;
40 }
41 return exe;
42}
43
44//-------------------------------------------------------------
46{
47 if (!buffer || !bufferSize) return 0;
48
49 WORD* wordsBuff = reinterpret_cast<WORD*>(buffer);
50 const size_t wordsCount = bufferSize / sizeof(WORD);
51 const size_t remainingBytes = bufferSize % sizeof(WORD);
52
53 size_t checksumBgn = 0;
54 size_t checksumEnd = 0;
57 checksumEnd = checksumBgn + sizeof(DWORD);
58 }
59
60 const long long maxVal = ((long long)1) << 32;
61 long long checksum = 0;
62
63 for (int i = 0; i < wordsCount; i++) {
65
66 size_t bI = i * sizeof(WORD);
68 size_t mask = (checksumEnd - bI) % sizeof(WORD);
69 size_t shift = (sizeof(WORD) - mask) * 8;
70 chunk = (chunk >> shift) << shift;
71 }
72
73 checksum = (checksum & 0xffffffff) + chunk + (checksum >> 32);
74 if (checksum > maxVal) {
75 checksum = (checksum & 0xffffffff) + (checksum >> 32);
76 }
77 }
78
79 // Handle the remaining bytes
80 if (remainingBytes > 0) {
81 WORD chunk = 0;
83
84 size_t bI = wordsCount * sizeof(WORD);
86 size_t mask = (checksumEnd - bI) % sizeof(WORD);
87 size_t shift = (sizeof(WORD) - mask) * 8;
88 chunk = (chunk >> shift) << shift;
89 }
90
91 checksum = (checksum & 0xffffffff) + chunk + (checksum >> 32);
92 if (checksum > maxVal) {
93 checksum = (checksum & 0xffffffff) + (checksum >> 32);
94 }
95 }
96 checksum = (checksum & 0xffff) + (checksum >> 16);
97 checksum = (checksum)+(checksum >> 16);
98 checksum = checksum & 0xffff;
100 return checksum;
101}
102
104
106 : MappedExe(v_buf, Executable::BITS_32), dosHdrWrapper(NULL), fHdr(NULL), optHdr(NULL), sects(NULL),
107 album(NULL)
108{
109 album = new ResourcesAlbum(this);
110 wrap(v_buf);
112}
113
115{
118
119 this->dosHdrWrapper = NULL;
120 this->fHdr = NULL;
121 this->optHdr = NULL;
122 this->sects = NULL;
123}
124
126{
127 for (size_t i = 0 ; i < pe::DIR_ENTRIES_COUNT; i++) {
129 }
130}
131
133{
134 PEFile::wrap(this->buf);
135}
136
138{
139 //erase all existing wrappers:
141
142 // rewrao the core:
143 core.wrap(v_buf);
144
145 //regenerate the wrappers:
146 this->dosHdrWrapper = new DosHdrWrapper(this);
147 this->wrappers[WR_DOS_HDR] = this->dosHdrWrapper;
148
149 this->fHdr = new FileHdrWrapper(this);
150 if (fHdr->getPtr() == NULL) throw ExeException("Cannot parse FileHdr: It is not PE File!");
151 this->wrappers[WR_FILE_HDR] = fHdr;
152 this->wrappers[WR_RICH_HDR] = new RichHdrWrapper(this);
153
154 this->optHdr = new OptHdrWrapper(this);
155 if (optHdr->getPtr() == NULL) throw ExeException("Cannot parse OptionalHeader: It is not PE File!");
157
158 this->wrappers[WR_DATADIR] = new DataDirWrapper(this);
159
160 bool isOk = false;
162 if (isOk && secNum){
163 this->sects = new SectHdrsWrapper(this);
164 this->wrappers[WR_SECTIONS] = sects;
165 }
166 else {
167 this->sects = NULL;
168 }
169 // map Data Dirs
171 dataDirEntries[pe::DIR_IMPORT] = new ImportDirWrapper(this);
172 dataDirEntries[pe::DIR_DELAY_IMPORT] = new DelayImpDirWrapper(this);
173 dataDirEntries[pe::DIR_BOUND_IMPORT] = new BoundImpDirWrapper(this);
174 dataDirEntries[pe::DIR_DEBUG] = new DebugDirWrapper(this);
175 dataDirEntries[pe::DIR_EXPORT] = new ExportDirWrapper(this);
176 dataDirEntries[pe::DIR_SECURITY] = new SecurityDirWrapper(this);
177 dataDirEntries[pe::DIR_TLS] = new TlsDirWrapper(this);
178 dataDirEntries[pe::DIR_LOAD_CONFIG] = new LdConfigDirWrapper(this);
179 dataDirEntries[pe::DIR_BASERELOC] = new RelocDirWrapper(this);
180 dataDirEntries[pe::DIR_EXCEPTION] = new ExceptionDirWrapper(this);
181 dataDirEntries[pe::DIR_RESOURCE] = new ResourceDirWrapper(this, album);
182 dataDirEntries[pe::DIR_COM_DESCRIPTOR] = new ClrDirWrapper(this);
183
184 for (int i = 0; i < pe::DIR_ENTRIES_COUNT; i++) {
186 }
187
188 if (this->album) {
189 this->album->wrapLeafsContent();
190 }
191}
192
193pe::RICH_DANS_HEADER* PEFile::getRichHeaderBgn(pe::RICH_SIGNATURE* richSign)
194{
195 if (!richSign) return NULL;
196
197 DWORD xorkey = richSign->checksum;
198 const offset_t richOffset = this->getOffset(richSign);
199
200 pe::RICH_DANS_HEADER* dansHdr = NULL;
201
202 offset_t offset = richOffset - sizeof(pe::RICH_DANS_HEADER);
203 while (offset > 0) {
204 dansHdr = (pe::RICH_DANS_HEADER*) this->getContentAt(offset, sizeof(pe::RICH_DANS_HEADER));
205 if (!dansHdr) {
206 break;
207 }
208 if (dansHdr->dansId == (pe::DANS_HDR_MAGIC ^ xorkey)) {
209 break; //got it!
210 }
211 //walking back
212 offset -= sizeof(DWORD);
213 }
214 if (!dansHdr || dansHdr->dansId != (pe::DANS_HDR_MAGIC ^ xorkey)) {
215 return NULL; //not found
216 }
217 return dansHdr;
218}
219
220pe::RICH_SIGNATURE* PEFile::getRichHeaderSign()
221{
222 size_t dosStubOffset = this->core.dos->e_lfarlc;
223 size_t dosStubEnd = this->core.dos->e_lfanew; // PE header start
224 const size_t maxSize = dosStubEnd - dosStubOffset; // Rich Header is somewhere in the space between DOS and PE headers
225 BYTE *dosPtr = this->getContentAt(dosStubOffset, maxSize);
226 if (!dosPtr) {
227 return NULL;
228 }
229
230 pe::RICH_SIGNATURE* richSign = NULL;
231 size_t toSearchSize = maxSize;
232 const offset_t startOffset = dosStubOffset; //we are starting from the beginning of DOS stub
233 const size_t step = sizeof(DWORD); //RichHeader is padded by DWORDS
234
235 while (toSearchSize > 0) {
236 richSign = (pe::RICH_SIGNATURE*) this->getContentAt(startOffset + toSearchSize, sizeof(pe::RICH_SIGNATURE));
237 if (!richSign) break;
238 if (richSign->richId == pe::RICH_HDR_MAGIC) break; //got it!
239 // the search goes backward.
241 }
242 if (!richSign) return NULL;
243 if (richSign->richId != pe::RICH_HDR_MAGIC) {
244 return NULL; //invalid
245 }
246 return richSign;
247}
248
249
251{
252 if (!this->getSectionsCount()) {
253 return INVALID_ADDR;
254 }
255 SectionHdrWrapper* sec = this->getSecHdr(0);
256 if (!sec) {
257 return INVALID_ADDR;
258 }
259 return sec->getContentOffset(Executable::RVA);
260}
261
267
269{
270 if (this->wrappers[WR_DATADIR] == NULL) return NULL;
271 return static_cast<IMAGE_DATA_DIRECTORY*>(this->wrappers[WR_DATADIR]->getPtr());
272}
273
275{
276 if (aType == Executable::NOT_ADDR) return 0;
277
278 if (aType == Executable::RAW) {
279 return this->getContentSize();
280 }
281 const size_t PAGE_SIZE = 0x1000;
282 bufsize_t vSize = 0;
285 }
286 if (vSize < PAGE_SIZE) {
287 return PAGE_SIZE;
288 }
289 return vSize;
290}
291
293{
294 if (optHdr == NULL) return INVALID_ADDR;
295
296 bool isOk = false;
298 if (isOk == false) return INVALID_ADDR;
299
301 if (addrType != epType) {
302 entryPoint = this->convertAddr(entryPoint, epType, addrType);
303 }
304 return entryPoint;
305}
306
308{
309 if (optHdr == NULL) return false;
310
313 return isOk;
314}
315
317{
318 bool isOk = false;
320 if (isOk == false) return 0;
321
322 return static_cast<size_t> (secNum);
323}
324
326{
327 uint64_t count = newNum;
329 if (canSet == false) {
330 Logger::append(Logger::D_ERROR,"Can not change FileHdr!");
331 return false;
332 }
333 return true;
334}
335
337{
338 uint64_t size = newSize;
340 if (canSet == false) {
341 Logger::append(Logger::D_ERROR, "Can not change OptHdr!");
342 return false;
343 }
344 return true;
345}
346
348{
349 if (useMapped == false) {
350 return hdrSectionsNum();
351 }
352 return (this->sects) ? this->sects->getEntriesCount() : 0;
353}
354
356{
357 if (raw >= this->getMappedSize(Executable::RAW)) return INVALID_ADDR;
358
360 if (sec) {
361 offset_t bgnVA = sec->getContentOffset(Executable::VA);
362 offset_t bgnRaw = sec->getContentOffset(Executable::RAW);
364
365 bufsize_t curr = (raw - bgnRaw);
366
367 bufsize_t vSize = sec->getContentSize(Executable::VA, true);
368 if (curr >= vSize) {
369 //address out of section
370 return INVALID_ADDR;
371 }
372 return bgnVA + curr;
373 }
374 //TODO: make more tests
375 if (this->getSectionsCount() == 0) return raw;
376 if (raw < this->hdrsSize()) {
377 return raw;
378 } //else: content that is between the end of sections headers and the first virtual section is not mapped
379 return INVALID_ADDR;
380}
381
383{
384 if (rva >= this->getMappedSize(Executable::RVA)) return INVALID_ADDR;
385
387 if (sec) {
388 offset_t bgnRVA = sec->getContentOffset(Executable::RVA);
389 offset_t bgnRaw = sec->getContentOffset(Executable::RAW);
391
392 bufsize_t curr = (rva - bgnRVA);
393 bufsize_t rawSize = sec->getContentSize(Executable::RAW, true);
394 if (curr >= rawSize) {
395 // the address might be in a virtual cave that is not related to any raw address
396 return INVALID_ADDR;
397 }
398 return bgnRaw + curr;
399 }
400 if (rva >= this->getMappedSize(Executable::RAW)) {
401 return INVALID_ADDR;
402 }
403 if (this->getSectionsCount()) { // do this check only if sections count is non-zero
404 if (rva >= this->hdrsSize()) {
405 // the address is in the cave between the headers and the first section: cannot be mapped
406 return INVALID_ADDR;
407 }
408 }
409 // at this point we are sure that the address is within the raw size:
410 return rva;
411}
412
414{
415 if (eType >= pe::DIR_ENTRIES_COUNT) return NULL;
416 return dataDirEntries[eType];
417}
418
420{
421 SectionHdrWrapper *sec = this->getSecHdr(secId);
422 if (sec == NULL) {
423 Logger::append(Logger::D_WARNING, "No such section");
424 return NULL;
425 }
426 return _createSectionView(sec);
427}
428
430{
431 bool allowExceptions = true; //TODO: configure exception mode outside...
432
434 if (entry == NULL) {
435 if (allowExceptions) throw ExeException("No such Data Directory");
436 return false;
437 }
440 if (ddirWrapper == NULL || ddir == NULL) {
441 if (allowExceptions) throw ExeException("Cannot fetch DataDirTable");
442 return false;
443 }
446 if (dataDirAddr == INVALID_ADDR) {
447 if (allowExceptions) throw ExeException("Invalid new offset");
448 return false;
449 }
450 offset_t targetRaw = this->toRaw(newOffset, addrType);
451 if (entry->canCopyToOffset(targetRaw) == false) {
452 if (allowExceptions) throw ExeException("Cannot copy: no space at such offset");
453 return false;
454 }
455 if (entry->copyToOffset(targetRaw) == false) {
456 if (allowExceptions) throw ExeException("Cannot copy: error occured");
457 return false;
458 }
459 entry->fillContent(0);
460 ddir[id].VirtualAddress = static_cast<DWORD> (dataDirAddr);
461 return true;
462}
463
465{
467 if (sec == NULL || sec->canAddEntry() == false) {
468 return false;
469 }
470 const size_t secCount = hdrSectionsNum();
471 if (secCount == SectHdrsWrapper::SECT_COUNT_MAX) return false; //limit exceeded
472
473 //TODO: some more checks? overlay?
474 return true;
475}
476
477
479{
480 if (canAddNewSection() == false) return NULL;
481
483 if (!v_size) v_size = size;
484
489
490 if (setVirtualSize(newVirtualSize) == false) {
491 Logger::append(Logger::D_ERROR, "Failed to change virtual size");
492 return NULL;
493 }
494
495 if (resize(newSize) == false) {
496 Logger::append(Logger::D_ERROR, "Failed to resize");
497 return NULL;
498 }
499 // fetch again after resize:
501 if (sec == NULL) {
502 return NULL;
503 }
504
507
508 //name copy:
509 const size_t nameLen = name.length();
510 const size_t bufSize = sizeof(secHdr.Name);
511 const size_t copySize = (nameLen < bufSize) ? nameLen : bufSize;
512 if (copySize) {
513 ::memcpy(secHdr.Name, name.toStdString().c_str(), copySize);
514 }
515
516 secHdr.PointerToRawData = static_cast<DWORD>(roundedRawEnd);
517 secHdr.VirtualAddress = static_cast<DWORD>(roundedVirtualEnd);
518 secHdr.SizeOfRawData = size;
519 secHdr.Misc.VirtualSize = v_size;
520
522 SectionHdrWrapper* secHdrWr = dynamic_cast<SectionHdrWrapper*>(sec->addEntry(&wr));
523 return secHdrWr;
524}
525
527{
528 size_t secCount = this->getSectionsCount(true);
529 if (secCount == 0) return NULL;
530 return this->getSecHdr(secCount - 1);
531}
532
534{
536
537 /* check sections bounds */
538 const size_t secCounter = this->getSectionsCount(true);
539 if (!secCounter) {
540 // if PE file has no sections, full file will be mapped
541 return getMappedSize(aType);
542 }
543 for (size_t i = 0; i < secCounter; i++) {
545 if (!sec) continue;
546
547 offset_t secLastMapped= sec->getContentOffset(aType, true);
548 if (secLastMapped == INVALID_ADDR) continue;
549
550 const size_t size = (aType == Executable::RAW) ? sec->getMappedRawSize() : sec->getMappedVirtualSize();
551 if (size == 0) continue; // exclude not mapped sections
552
553 secLastMapped += size;
556 }
557 }
558
559 /* check header bounds */
560 /* section headers: */
563 }
564 // PE hdrs ending:
565 const offset_t peHdrsEnd = this->core.peSignatureOffset() + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + this->core.peNtHeadersSize();
566 if (lastMapped < peHdrsEnd) {
568 }
569 // OptionalHdr -> SizeOfHeaders:
571 if (lastMapped < ntHeadersEndOffset) {
573 }
574 return lastMapped;
575}
576
578{
580 if (secHdr == NULL) return NULL;
581
582 //TODO: check overlay...
585
586 offset_t secROffset = secHdr->getContentOffset(Executable::RAW, false);
587 if (secROffset == INVALID_ADDR) {
588 return NULL;
589 }
590 const bufsize_t secNewRSize = newSize - secROffset; //include overlay in section
591
593
594 const offset_t secVOffset = secHdr->getContentOffset(Executable::RVA, false);
595 const bufsize_t secVSize = secHdr->getContentSize(Executable::RVA, false);
596
597 // if the previous virtual size is smaller than the new raw size, then update it:
598 if (secVSize < secNewRSize) {
600
601 // if the virtual size of section has changed,
602 // update the Size of Image (saved in the header):
604 this->setVirtualSize(newVSize);
605 }
606
607 //update raw size:
608 this->resize(newSize);
609 //finally, retrieve the resized section:
610 return getLastSection();
611}
612
614{
616 if (ddir[pe::DIR_BOUND_IMPORT].VirtualAddress == 0 && ddir[pe::DIR_BOUND_IMPORT].Size == 0) {
617 // No bound imports already, nothing to do here!
618 return true;
619 }
620 ddir[pe::DIR_BOUND_IMPORT].VirtualAddress = 0;
621 ddir[pe::DIR_BOUND_IMPORT].Size = 0;
622 DataDirEntryWrapper *bImp = this->getDataDirEntry(pe::DIR_BOUND_IMPORT);
623 if (bImp == NULL) {
624 //printf("No Bound imports wrapper!\n");
625 return false; // todo: throw error?
626 }
627 bool isOk = bImp->wrap();
628 //TODO: change timestamp for all library entries from (-1 : BOUND) to 0 : NOT BOUND
629 return isOk;
630}
631
633{
635 return false; //not my section
636 }
638 if (!secView) return false;
639
640 bufsize_t dumpedSize = FileBuffer::dump(fileName, *secView, false);
641 delete secView;
642
643 return dumpedSize ? true : false;
644}
645
646//protected:
647
649{
651 offset_t start = sec->getContentOffset(aType, true);
652 bufsize_t size = sec->getContentSize(aType, true);
653 if (start == INVALID_ADDR || size == 0) {
654 return NULL;
655 }
656 return new BufferView(this, start, size);
657}
658
660{
661 size_t initialSize = entrypoints.size();
662
663 ExportDirWrapper* exports = dynamic_cast<ExportDirWrapper*>(this->getWrapper(PEFile::WR_DIR_ENTRY + pe::DIR_EXPORT));
664 if (!exports) return 0;
665
666 const size_t entriesCnt = exports->getEntriesCount();
667 if (entriesCnt == 0) return 0;
668
669 for (int i = 0; i < entriesCnt; i++) {
670 ExportEntryWrapper* entry = dynamic_cast<ExportEntryWrapper*>(exports->getEntryAt(i));
671 if (!entry) continue;
672
674 if (forwarder.length()) {
675 continue;
676 }
677 offset_t rva = entry->getFuncRva();
678 offset_t offset = this->convertAddr(rva, Executable::RVA, aType);
679 if (offset == INVALID_ADDR) {
680 continue;
681 }
682 entrypoints.insert(offset, entry->getName());
683 }
684 return entrypoints.size() - initialSize;
685}
INT_TYPE _getNumValue(void *ptr)
uint32_t bufsize_t
const offset_t INVALID_ADDR
uint64_t offset_t
virtual BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
virtual offset_t getOffset(void *ptr, bool allowExceptions=false)
static bufsize_t dump(const QString &fileName, AbstractByteBuffer &buf, bool allowExceptions=false)
virtual bufsize_t getContentSize()
virtual bool setNumValue(size_t fieldId, size_t subField, uint64_t val)
virtual offset_t getFieldOffset(size_t fieldId, size_t subField=FIELD_NONE)
virtual uint64_t getNumValue(size_t fieldId, size_t subField, bool *isOk)
virtual size_t getEntriesCount()
std::map< size_t, ExeElementWrapper * > wrappers
Definition MappedExe.h:27
virtual ExeElementWrapper * getWrapper(size_t wrapperId)
Definition MappedExe.cpp:13
AbstractByteBuffer * buf
Definition Executable.h:125
virtual offset_t toRaw(offset_t offset, addr_type addrType, bool allowExceptions=false)
BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
Definition Executable.h:57
virtual offset_t convertAddr(offset_t inAddr, Executable::addr_type inType, Executable::addr_type outType)
virtual bufsize_t getContentSize()
Definition Executable.h:51
QString getForwarderStr()
virtual void * getPtr()
virtual bool resize(bufsize_t newSize)
Definition MappedExe.h:40
virtual void * getPtr()
bufsize_t hdrsSize() const
Definition PECore.cpp:129
bool wrap(AbstractByteBuffer *v_buf)
Definition PECore.cpp:13
virtual bufsize_t getImageSize()
Definition PECore.cpp:117
offset_t peSignatureOffset() const
Definition PECore.cpp:59
bufsize_t peNtHeadersSize() const
Definition PECore.cpp:83
IMAGE_DOS_HEADER * dos
Definition PECore.h:54
virtual Executable * build(AbstractByteBuffer *buf)
Definition PEFile.cpp:31
virtual bool signatureMatches(AbstractByteBuffer *buf)
Definition PEFile.cpp:4
DataDirEntryWrapper * dataDirEntries[pe::DIR_ENTRIES_COUNT]
Definition PEFile.h:272
size_t getSecIndex(SectionHdrWrapper *sec) const
Definition PEFile.h:119
virtual bufsize_t getMappedSize(Executable::addr_type aType)
Definition PEFile.cpp:274
BufferView * _createSectionView(SectionHdrWrapper *sec)
Definition PEFile.cpp:648
size_t getExportsMap(QMap< offset_t, QString > &entrypoints, Executable::addr_type aType=Executable::RVA)
Definition PEFile.cpp:659
SectHdrsWrapper * sects
Definition PEFile.h:269
SectionHdrWrapper * getSecHdr(size_t index) const
Definition PEFile.h:109
bool unbindImports()
Definition PEFile.cpp:613
offset_t peDataDirOffset()
Definition PEFile.cpp:262
virtual offset_t getEntryPoint(Executable::addr_type addrType=Executable::RVA)
Definition PEFile.cpp:292
offset_t getMinSecRVA()
Definition PEFile.cpp:250
friend class SectHdrsWrapper
Definition PEFile.h:274
offset_t getLastMapped(Executable::addr_type aType)
Definition PEFile.cpp:533
FileHdrWrapper * fHdr
Definition PEFile.h:267
ResourcesAlbum * album
Definition PEFile.h:271
bool setEntryPoint(offset_t entry, Executable::addr_type aType)
Definition PEFile.cpp:307
size_t getSectionsCount(bool useMapped=true) const
Definition PEFile.cpp:347
pe::RICH_DANS_HEADER * getRichHeaderBgn(pe::RICH_SIGNATURE *sign)
Definition PEFile.cpp:193
SectionHdrWrapper * extendLastSection(bufsize_t addedSize)
Definition PEFile.cpp:577
@ WR_DIR_ENTRY
Definition PEFile.h:51
@ WR_DATADIR
Definition PEFile.h:49
@ WR_OPTIONAL_HDR
Definition PEFile.h:48
@ WR_FILE_HDR
Definition PEFile.h:47
@ WR_DOS_HDR
Definition PEFile.h:45
@ WR_SECTIONS
Definition PEFile.h:50
@ WR_RICH_HDR
Definition PEFile.h:46
PECore core
Definition PEFile.h:259
void initDirEntries()
Definition PEFile.cpp:125
virtual void wrap()
Definition PEFile.cpp:132
SectionHdrWrapper * getLastSection()
Definition PEFile.cpp:526
OptHdrWrapper * optHdr
Definition PEFile.h:268
bool dumpSection(SectionHdrWrapper *sec, QString fileName)
Definition PEFile.cpp:632
virtual offset_t rvaToRaw(offset_t rva)
Definition PEFile.cpp:382
BufferView * createSectionView(size_t secNum)
Definition PEFile.cpp:419
bool setHdrSectionsNum(size_t newNum)
Definition PEFile.cpp:325
bool setVirtualSize(bufsize_t newSize)
Definition PEFile.cpp:336
DataDirEntryWrapper * getDataDirEntry(pe::dir_entry eType)
Definition PEFile.cpp:413
bool moveDataDirEntry(pe::dir_entry id, offset_t newOffset, Executable::addr_type addType=Executable::RAW)
Definition PEFile.cpp:429
virtual void clearWrappers()
Definition PEFile.cpp:114
IMAGE_DATA_DIRECTORY * getDataDirectory()
Definition PEFile.cpp:268
virtual offset_t rawToRva(offset_t raw)
Definition PEFile.cpp:355
bufsize_t hdrsSize()
Definition PEFile.h:93
offset_t secHdrsEndOffset() const
Definition PEFile.h:83
size_t hdrSectionsNum() const
Definition PEFile.cpp:316
PEFile(AbstractByteBuffer *v_buf)
Definition PEFile.cpp:105
virtual bufsize_t getAlignment(Executable::addr_type aType) const
Definition PEFile.h:70
pe::RICH_SIGNATURE * getRichHeaderSign()
Definition PEFile.cpp:220
bool canAddNewSection()
Definition PEFile.cpp:464
static long computeChecksum(BYTE *buffer, size_t bufferSize, offset_t checksumOffset)
Definition PEFile.cpp:45
DosHdrWrapper * dosHdrWrapper
Definition PEFile.h:265
SectionHdrWrapper * getSecHdrAtOffset(offset_t offset, Executable::addr_type aType, bool recalculate=false, bool verbose=false)
Definition PEFile.h:114
SectionHdrWrapper * addNewSection(QString name, bufsize_t size, bufsize_t v_size=0)
Definition PEFile.cpp:478
static size_t SECT_COUNT_MAX
static size_t SECT_INVALID_INDEX
bool append(dbg_level lvl, const char *format,...)
Definition Util.cpp:8
@ D_ERROR
Definition Util.h:26
@ D_WARNING
Definition Util.h:26
@ D_INFO
Definition Util.h:26
bufsize_t roundupToUnit(bufsize_t size, bufsize_t unit)