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),
107 dosHdrWrapper(NULL), fHdr(NULL), optHdr(NULL), sects(NULL),
108 album(NULL)
109{
111
112 _init(v_buf);
114}
115
117{
118 // wrap the core:
119 core.wrap(v_buf);
120
121 album = new ResourcesAlbum(this);
122
123 //generate wrappers:
124 this->dosHdrWrapper = new DosHdrWrapper(this);
125 this->wrappers[WR_DOS_HDR] = this->dosHdrWrapper;
126
127 this->fHdr = new FileHdrWrapper(this);
128 if (fHdr->getPtr() == NULL) throw ExeException("Cannot parse FileHdr: It is not PE File!");
129 this->wrappers[WR_FILE_HDR] = fHdr;
130 this->wrappers[WR_RICH_HDR] = new RichHdrWrapper(this);
131
132 this->optHdr = new OptHdrWrapper(this);
133 if (optHdr->getPtr() == NULL) throw ExeException("Cannot parse OptionalHeader: It is not PE File!");
135
136 this->sects = new SectHdrsWrapper(this);
137 this->wrappers[WR_SECTIONS] = sects;
138
139 this->wrappers[WR_DATADIR] = new DataDirWrapper(this);
140 dataDirEntries[pe::DIR_IMPORT] = new ImportDirWrapper(this);
141 dataDirEntries[pe::DIR_DELAY_IMPORT] = new DelayImpDirWrapper(this);
142 dataDirEntries[pe::DIR_BOUND_IMPORT] = new BoundImpDirWrapper(this);
143 dataDirEntries[pe::DIR_DEBUG] = new DebugDirWrapper(this);
144 dataDirEntries[pe::DIR_EXPORT] = new ExportDirWrapper(this);
145 dataDirEntries[pe::DIR_SECURITY] = new SecurityDirWrapper(this);
146 dataDirEntries[pe::DIR_TLS] = new TlsDirWrapper(this);
147 dataDirEntries[pe::DIR_LOAD_CONFIG] = new LdConfigDirWrapper(this);
148 dataDirEntries[pe::DIR_BASERELOC] = new RelocDirWrapper(this);
149 dataDirEntries[pe::DIR_EXCEPTION] = new ExceptionDirWrapper(this);
150 dataDirEntries[pe::DIR_RESOURCE] = new ResourceDirWrapper(this, album);
151 dataDirEntries[pe::DIR_COM_DESCRIPTOR] = new ClrDirWrapper(this);
152
153 for (int i = 0; i < pe::DIR_ENTRIES_COUNT; i++) {
155 }
156 if (this->album) {
157 this->album->wrapLeafsContent();
158 }
159}
160
161
163{
166
167 this->dosHdrWrapper = NULL;
168 this->fHdr = NULL;
169 this->optHdr = NULL;
170 this->sects = NULL;
171}
172
174{
175 for (size_t i = 0 ; i < pe::DIR_ENTRIES_COUNT; i++) {
177 }
178}
179
181{
183 // rewrap the core:
184 core.wrap(this->buf);
185 // rewrap the PE headers:
186 for (int i = 0; i < WR_DIR_ENTRY; i++) {
187 this->wrappers[i]->wrap();
188 }
189 // rewrap the sections:
190 this->sects->wrap();
191}
192
194{
195 wrapCore();
196
197 // rewrap directories
198 for (size_t i = 0 ; i < pe::DIR_ENTRIES_COUNT; i++) {
199 if (dataDirEntries[i]) {
201 }
202 }
203 // rewrap resources
204 if (this->album) {
205 this->album->wrapLeafsContent();
206 }
207}
208
209pe::RICH_DANS_HEADER* PEFile::getRichHeaderBgn(pe::RICH_SIGNATURE* richSign)
210{
211 if (!richSign) return NULL;
212
213 DWORD xorkey = richSign->checksum;
214 const offset_t richOffset = this->getOffset(richSign);
215
216 pe::RICH_DANS_HEADER* dansHdr = NULL;
217
218 offset_t offset = richOffset - sizeof(pe::RICH_DANS_HEADER);
219 while (offset > 0) {
220 dansHdr = (pe::RICH_DANS_HEADER*) this->getContentAt(offset, sizeof(pe::RICH_DANS_HEADER));
221 if (!dansHdr) {
222 break;
223 }
224 if (dansHdr->dansId == (pe::DANS_HDR_MAGIC ^ xorkey)) {
225 break; //got it!
226 }
227 //walking back
228 offset -= sizeof(DWORD);
229 }
230 if (!dansHdr || dansHdr->dansId != (pe::DANS_HDR_MAGIC ^ xorkey)) {
231 return NULL; //not found
232 }
233 return dansHdr;
234}
235
236pe::RICH_SIGNATURE* PEFile::getRichHeaderSign()
237{
238 size_t dosStubOffset = this->core.dos->e_lfarlc;
239 size_t dosStubEnd = this->core.dos->e_lfanew; // PE header start
240 const size_t maxSize = dosStubEnd - dosStubOffset; // Rich Header is somewhere in the space between DOS and PE headers
241 BYTE *dosPtr = this->getContentAt(dosStubOffset, maxSize);
242 if (!dosPtr) {
243 return NULL;
244 }
245
246 pe::RICH_SIGNATURE* richSign = NULL;
247 size_t toSearchSize = maxSize;
248 const offset_t startOffset = dosStubOffset; //we are starting from the beginning of DOS stub
249 const size_t step = sizeof(DWORD); //RichHeader is padded by DWORDS
250
251 while (toSearchSize > 0) {
252 richSign = (pe::RICH_SIGNATURE*) this->getContentAt(startOffset + toSearchSize, sizeof(pe::RICH_SIGNATURE));
253 if (!richSign) break;
254 if (richSign->richId == pe::RICH_HDR_MAGIC) break; //got it!
255 // the search goes backward.
257 }
258 if (!richSign) return NULL;
259 if (richSign->richId != pe::RICH_HDR_MAGIC) {
260 return NULL; //invalid
261 }
262 return richSign;
263}
264
266{
268 if (!this->_getSectionsCount()) {
269 return INVALID_ADDR;
270 }
271 SectionHdrWrapper* sec = this->_getSecHdr(0);
272 if (!sec) {
273 return INVALID_ADDR;
274 }
275 return sec->getContentOffset(Executable::RVA);
276}
277
283
285{
286 if (this->wrappers[WR_DATADIR] == NULL) return NULL;
287 return static_cast<IMAGE_DATA_DIRECTORY*>(this->wrappers[WR_DATADIR]->getPtr());
288}
289
291{
292 if (aType == Executable::NOT_ADDR) return 0;
293
294 if (aType == Executable::RAW) {
295 return this->getContentSize();
296 }
297 const size_t unit_size = 0x1000;
298 bufsize_t vSize = 0;
301 }
302 if (vSize < unit_size) {
303 return unit_size;
304 }
305 return vSize;
306}
307
309{
310 if (optHdr == NULL) return INVALID_ADDR;
311
312 bool isOk = false;
314 if (isOk == false) return INVALID_ADDR;
315
317 if (addrType != epType) {
318 entryPoint = this->convertAddr(entryPoint, epType, addrType);
319 }
320 return entryPoint;
321}
322
324{
325 if (optHdr == NULL) return false;
326
329 return isOk;
330}
331
333{
334 bool isOk = false;
336 if (isOk == false) return 0;
337
338 return static_cast<size_t> (secNum);
339}
340
342{
343 uint64_t count = newNum;
345 if (canSet == false) {
346 Logger::append(Logger::D_ERROR,"Can not change FileHdr!");
347 return false;
348 }
349 return true;
350}
351
353{
354 uint64_t size = newSize;
356 if (canSet == false) {
357 Logger::append(Logger::D_ERROR, "Can not change OptHdr!");
358 return false;
359 }
360 return true;
361}
362
364{
365 if (useMapped == false) {
366 return hdrSectionsNum();
367 }
368 return (this->sects) ? this->sects->getEntriesCount() : 0;
369}
370
372{
374 if (raw >= this->getMappedSize(Executable::RAW)) return INVALID_ADDR;
375
377 if (sec) {
378 offset_t bgnVA = sec->getContentOffset(Executable::VA);
379 offset_t bgnRaw = sec->getContentOffset(Executable::RAW);
381
382 bufsize_t curr = (raw - bgnRaw);
383
384 bufsize_t vSize = sec->getContentSize(Executable::VA, true);
385 if (curr >= vSize) {
386 //address out of section
387 return INVALID_ADDR;
388 }
389 return bgnVA + curr;
390 }
391 //TODO: make more tests
392 if (this->_getSectionsCount() == 0) return raw;
393 if (raw < this->hdrsSize()) {
394 return raw;
395 } //else: content that is between the end of sections headers and the first virtual section is not mapped
396 return INVALID_ADDR;
397}
398
400{
402 if (rva >= this->getMappedSize(Executable::RVA)) {
403 return INVALID_ADDR;
404 }
406 if (sec) {
407 offset_t bgnRVA = sec->getContentOffset(Executable::RVA);
408 offset_t bgnRaw = sec->getContentOffset(Executable::RAW);
409 if (bgnRVA == INVALID_ADDR || bgnRaw == INVALID_ADDR) {
410 return INVALID_ADDR;
411 }
412 bufsize_t curr = (rva - bgnRVA);
413 bufsize_t rawSize = sec->getContentSize(Executable::RAW, true);
414 if (curr >= rawSize) {
415 // the address might be in a virtual cave that is not related to any raw address
416 return INVALID_ADDR;
417 }
418 return bgnRaw + curr;
419 }
420 if (rva >= this->getMappedSize(Executable::RAW)) {
421 return INVALID_ADDR;
422 }
423 if (this->_getSectionsCount()) { // do this check only if sections count is non-zero
424 if (rva >= this->hdrsSize()) {
425 // the address is in the cave between the headers and the first section: cannot be mapped
426 return INVALID_ADDR;
427 }
428 }
429 // at this point we are sure that the address is within the raw size:
430 return rva;
431}
432
434{
435 if (eType >= pe::DIR_ENTRIES_COUNT) return NULL;
436 return dataDirEntries[eType];
437}
438
440{
442 SectionHdrWrapper *sec = this->_getSecHdr(secId);
443 if (sec == NULL) {
444 Logger::append(Logger::D_WARNING, "No such section");
445 return NULL;
446 }
447 return _createSectionView(sec);
448}
449
451{
452 bool allowExceptions = true; //TODO: configure exception mode outside...
453
455 if (entry == NULL) {
456 if (allowExceptions) throw ExeException("No such Data Directory");
457 return false;
458 }
461 if (ddirWrapper == NULL || ddir == NULL) {
462 if (allowExceptions) throw ExeException("Cannot fetch DataDirTable");
463 return false;
464 }
467 if (dataDirAddr == INVALID_ADDR) {
468 if (allowExceptions) throw ExeException("Invalid new offset");
469 return false;
470 }
471 offset_t targetRaw = this->toRaw(newOffset, addrType);
472 if (entry->canCopyToOffset(targetRaw) == false) {
473 if (allowExceptions) throw ExeException("Cannot copy: no space at such offset");
474 return false;
475 }
476 if (entry->copyToOffset(targetRaw) == false) {
477 if (allowExceptions) throw ExeException("Cannot copy: error occured");
478 return false;
479 }
480 entry->fillContent(0);
481 ddir[id].VirtualAddress = static_cast<DWORD> (dataDirAddr);
482 return true;
483}
484
486{
488 if (sec == NULL || sec->canAddEntry() == false) {
489 return false;
490 }
491 const size_t secCount = hdrSectionsNum();
492 if (secCount == SectHdrsWrapper::SECT_COUNT_MAX) return false; //limit exceeded
493
494 //TODO: some more checks? overlay?
495 return true;
496}
497
498
500{
501 if (canAddNewSection() == false) return NULL;
502
504 if (!v_size) v_size = size;
505
510
511 if (setVirtualSize(newVirtualSize) == false) {
512 Logger::append(Logger::D_ERROR, "Failed to change virtual size");
513 return NULL;
514 }
515
516 if (resize(newSize) == false) {
517 Logger::append(Logger::D_ERROR, "Failed to resize");
518 return NULL;
519 }
520 // fetch again after resize:
522 if (sec == NULL) {
523 return NULL;
524 }
525
528
529 //name copy:
530 const size_t nameLen = name.length();
531 const size_t bufSize = sizeof(secHdr.Name);
532 const size_t copySize = (nameLen < bufSize) ? nameLen : bufSize;
533 if (copySize) {
534 ::memcpy(secHdr.Name, name.toStdString().c_str(), copySize);
535 }
536
537 secHdr.PointerToRawData = static_cast<DWORD>(roundedRawEnd);
538 secHdr.VirtualAddress = static_cast<DWORD>(roundedVirtualEnd);
539 secHdr.SizeOfRawData = size;
540 secHdr.Misc.VirtualSize = v_size;
541
543 SectionHdrWrapper* secHdrWr = dynamic_cast<SectionHdrWrapper*>(sec->addEntry(&wr));
544 return secHdrWr;
545}
546
548{
549 size_t secCount = this->_getSectionsCount(true);
550 if (secCount == 0) return NULL;
551 return this->_getSecHdr(secCount - 1);
552}
553
555{
557
558 /* check sections bounds */
559 const size_t secCounter = this->_getSectionsCount(true);
560 if (!secCounter) {
561 // if PE file has no sections, full file will be mapped
562 return getMappedSize(aType);
563 }
564 for (size_t i = 0; i < secCounter; i++) {
566 if (!sec) continue;
567
568 offset_t secLastMapped= sec->getContentOffset(aType, true);
569 if (secLastMapped == INVALID_ADDR) continue;
570
571 const size_t size = (aType == Executable::RAW) ? sec->getMappedRawSize() : sec->getMappedVirtualSize();
572 if (size == 0) continue; // exclude not mapped sections
573
574 secLastMapped += size;
577 }
578 }
579
580 /* check header bounds */
581 /* section headers: */
584 }
585 // PE hdrs ending:
586 const offset_t peHdrsEnd = this->core.peSignatureOffset() + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + this->core.peNtHeadersSize();
587 if (lastMapped < peHdrsEnd) {
589 }
590 // OptionalHdr -> SizeOfHeaders:
592 if (lastMapped < ntHeadersEndOffset) {
594 }
595 return lastMapped;
596}
597
599{
601 if (secHdr == NULL) return NULL;
602
603 //TODO: check overlay...
606
607 offset_t secROffset = secHdr->getContentOffset(Executable::RAW, false);
608 if (secROffset == INVALID_ADDR) {
609 return NULL;
610 }
611 const bufsize_t secNewRSize = newSize - secROffset; //include overlay in section
612
614
615 const offset_t secVOffset = secHdr->getContentOffset(Executable::RVA, false);
616 const bufsize_t secVSize = secHdr->getContentSize(Executable::RVA, false);
617
618 // if the previous virtual size is smaller than the new raw size, then update it:
619 if (secVSize < secNewRSize) {
621
622 // if the virtual size of section has changed,
623 // update the Size of Image (saved in the header):
625 this->setVirtualSize(newVSize);
626 }
627
628 //update raw size:
629 this->resize(newSize);
630 //finally, retrieve the resized section:
631 return getLastSection();
632}
633
635{
637 if (ddir[pe::DIR_BOUND_IMPORT].VirtualAddress == 0 && ddir[pe::DIR_BOUND_IMPORT].Size == 0) {
638 // No bound imports already, nothing to do here!
639 return true;
640 }
641 ddir[pe::DIR_BOUND_IMPORT].VirtualAddress = 0;
642 ddir[pe::DIR_BOUND_IMPORT].Size = 0;
643 DataDirEntryWrapper *bImp = this->getDataDirEntry(pe::DIR_BOUND_IMPORT);
644 if (bImp == NULL) {
645 //printf("No Bound imports wrapper!\n");
646 return false; // todo: throw error?
647 }
648 bool isOk = bImp->wrap();
649 //TODO: change timestamp for all library entries from (-1 : BOUND) to 0 : NOT BOUND
650 return isOk;
651}
652
654{
656 return false; //not my section
657 }
659 if (!secView) return false;
660
661 bufsize_t dumpedSize = FileBuffer::dump(fileName, *secView, false);
662 delete secView;
663
664 return dumpedSize ? true : false;
665}
666
667//protected:
668
670{
672 offset_t start = sec->getContentOffset(aType, true);
673 bufsize_t size = sec->getContentSize(aType, true);
674 if (start == INVALID_ADDR || size == 0) {
675 return NULL;
676 }
677 return new BufferView(this, start, size);
678}
679
681{
682 size_t initialSize = entrypoints.size();
683
684 ExportDirWrapper* exports = dynamic_cast<ExportDirWrapper*>(this->getWrapper(PEFile::WR_DIR_ENTRY + pe::DIR_EXPORT));
685 if (!exports) return 0;
686
687 const size_t entriesCnt = exports->getEntriesCount();
688 if (entriesCnt == 0) return 0;
689
690 for (int i = 0; i < entriesCnt; i++) {
691 ExportEntryWrapper* entry = dynamic_cast<ExportEntryWrapper*>(exports->getEntryAt(i));
692 if (!entry) continue;
693
695 if (forwarder.length()) {
696 continue;
697 }
698 offset_t rva = entry->getFuncRva();
699 offset_t offset = this->convertAddr(rva, Executable::RVA, aType);
700 if (offset == INVALID_ADDR) {
701 continue;
702 }
703 entrypoints.insert(offset, entry->getName());
704 }
705 return entrypoints.size() - initialSize;
706}
INT_TYPE _getNumValue(void *ptr)
uint32_t bufsize_t
const offset_t INVALID_ADDR
uint64_t offset_t
#define PE_SHOW_LOCK
Definition PEFile.h:30
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 bool wrap()
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:38
virtual void * getPtr()
bufsize_t hdrsSize() const
Definition PECore.cpp:130
bool wrap(AbstractByteBuffer *v_buf)
Definition PECore.cpp:13
virtual bufsize_t getImageSize()
Definition PECore.cpp:118
offset_t peSignatureOffset() const
Definition PECore.cpp:59
bufsize_t peNtHeadersSize() const
Definition PECore.cpp:84
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:326
QMutex m_peMutex
Definition PEFile.h:327
virtual bufsize_t getMappedSize(Executable::addr_type aType)
Definition PEFile.cpp:290
BufferView * _createSectionView(SectionHdrWrapper *sec)
Definition PEFile.cpp:669
size_t getExportsMap(QMap< offset_t, QString > &entrypoints, Executable::addr_type aType=Executable::RVA)
Definition PEFile.cpp:680
SectHdrsWrapper * sects
Definition PEFile.h:323
SectionHdrWrapper * _getSecHdr(size_t index) const
Definition PEFile.h:296
bool unbindImports()
Definition PEFile.cpp:634
offset_t peDataDirOffset()
Definition PEFile.cpp:278
virtual offset_t getEntryPoint(Executable::addr_type addrType=Executable::RVA)
Definition PEFile.cpp:308
void _init(AbstractByteBuffer *v_buf)
Definition PEFile.cpp:116
offset_t getMinSecRVA()
Definition PEFile.cpp:265
friend class SectHdrsWrapper
Definition PEFile.h:329
FileHdrWrapper * fHdr
Definition PEFile.h:321
size_t _getSecIndex(SectionHdrWrapper *sec) const
Definition PEFile.h:291
ResourcesAlbum * album
Definition PEFile.h:325
bool setEntryPoint(offset_t entry, Executable::addr_type aType)
Definition PEFile.cpp:323
pe::RICH_DANS_HEADER * getRichHeaderBgn(pe::RICH_SIGNATURE *sign)
Definition PEFile.cpp:209
SectionHdrWrapper * extendLastSection(bufsize_t addedSize)
Definition PEFile.cpp:598
@ WR_DIR_ENTRY
Definition PEFile.h:55
@ WR_DATADIR
Definition PEFile.h:53
@ WR_OPTIONAL_HDR
Definition PEFile.h:52
@ WR_FILE_HDR
Definition PEFile.h:51
@ WR_DOS_HDR
Definition PEFile.h:49
@ WR_SECTIONS
Definition PEFile.h:54
@ WR_RICH_HDR
Definition PEFile.h:50
PECore core
Definition PEFile.h:313
void initDirEntries()
Definition PEFile.cpp:173
virtual void wrap()
Definition PEFile.cpp:193
SectionHdrWrapper * getLastSection()
Definition PEFile.cpp:547
OptHdrWrapper * optHdr
Definition PEFile.h:322
bool dumpSection(SectionHdrWrapper *sec, QString fileName)
Definition PEFile.cpp:653
offset_t _getLastMapped(Executable::addr_type aType)
Definition PEFile.cpp:554
virtual offset_t rvaToRaw(offset_t rva)
Definition PEFile.cpp:399
BufferView * createSectionView(size_t secNum)
Definition PEFile.cpp:439
bool setHdrSectionsNum(size_t newNum)
Definition PEFile.cpp:341
bool setVirtualSize(bufsize_t newSize)
Definition PEFile.cpp:352
void wrapCore()
Definition PEFile.cpp:180
DataDirEntryWrapper * getDataDirEntry(pe::dir_entry eType)
Definition PEFile.cpp:433
SectionHdrWrapper * _getSecHdrAtOffset(offset_t offset, Executable::addr_type aType, bool recalculate=false, bool verbose=false)
Definition PEFile.h:301
bool moveDataDirEntry(pe::dir_entry id, offset_t newOffset, Executable::addr_type addType=Executable::RAW)
Definition PEFile.cpp:450
virtual void clearWrappers()
Definition PEFile.cpp:162
offset_t _secHdrsEndOffset()
Definition PEFile.h:277
IMAGE_DATA_DIRECTORY * getDataDirectory()
Definition PEFile.cpp:284
virtual offset_t rawToRva(offset_t raw)
Definition PEFile.cpp:371
bufsize_t hdrsSize()
Definition PEFile.h:81
size_t hdrSectionsNum() const
Definition PEFile.cpp:332
PEFile(AbstractByteBuffer *v_buf)
Definition PEFile.cpp:105
virtual bufsize_t getAlignment(Executable::addr_type aType) const
Definition PEFile.h:68
pe::RICH_SIGNATURE * getRichHeaderSign()
Definition PEFile.cpp:236
bool canAddNewSection()
Definition PEFile.cpp:485
static long computeChecksum(BYTE *buffer, size_t bufferSize, offset_t checksumOffset)
Definition PEFile.cpp:45
DosHdrWrapper * dosHdrWrapper
Definition PEFile.h:319
size_t _getSectionsCount(bool useMapped=true) const
Definition PEFile.cpp:363
SectionHdrWrapper * addNewSection(QString name, bufsize_t size, bufsize_t v_size=0)
Definition PEFile.cpp:499
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)