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 bool anyModified = false;
196 // rewrap directories
197 for (size_t i = 0 ; i < pe::DIR_ENTRIES_COUNT; i++) {
198 if (dataDirEntries[i]) {
199 if (dataDirEntries[i]->wrap()) {
200 anyModified = true;
201 }
202 }
203 }
204 // rewrap resources
205 if (this->album) {
206 this->album->wrapLeafsContent();
207 }
208 return anyModified;
209}
210
212{
213 wrapCore();
214 wrapDataDirs();
215}
216
217pe::RICH_DANS_HEADER* PEFile::getRichHeaderBgn(pe::RICH_SIGNATURE* richSign)
218{
219 if (!richSign) return NULL;
220
221 DWORD xorkey = richSign->checksum;
222 const offset_t richOffset = this->getOffset(richSign);
223
224 pe::RICH_DANS_HEADER* dansHdr = NULL;
225
226 offset_t offset = richOffset - sizeof(pe::RICH_DANS_HEADER);
227 while (offset > 0) {
228 dansHdr = (pe::RICH_DANS_HEADER*) this->getContentAt(offset, sizeof(pe::RICH_DANS_HEADER));
229 if (!dansHdr) {
230 break;
231 }
232 if (dansHdr->dansId == (pe::DANS_HDR_MAGIC ^ xorkey)) {
233 break; //got it!
234 }
235 //walking back
236 offset -= sizeof(DWORD);
237 }
238 if (!dansHdr || dansHdr->dansId != (pe::DANS_HDR_MAGIC ^ xorkey)) {
239 return NULL; //not found
240 }
241 return dansHdr;
242}
243
244pe::RICH_SIGNATURE* PEFile::getRichHeaderSign()
245{
246 size_t dosStubOffset = this->core.dos->e_lfarlc;
247 size_t dosStubEnd = this->core.dos->e_lfanew; // PE header start
248 const size_t maxSize = dosStubEnd - dosStubOffset; // Rich Header is somewhere in the space between DOS and PE headers
249 BYTE *dosPtr = this->getContentAt(dosStubOffset, maxSize);
250 if (!dosPtr) {
251 return NULL;
252 }
253
254 pe::RICH_SIGNATURE* richSign = NULL;
255 size_t toSearchSize = maxSize;
256 const offset_t startOffset = dosStubOffset; //we are starting from the beginning of DOS stub
257 const size_t step = sizeof(DWORD); //RichHeader is padded by DWORDS
258
259 while (toSearchSize > 0) {
260 richSign = (pe::RICH_SIGNATURE*) this->getContentAt(startOffset + toSearchSize, sizeof(pe::RICH_SIGNATURE));
261 if (!richSign) break;
262 if (richSign->richId == pe::RICH_HDR_MAGIC) break; //got it!
263 // the search goes backward.
265 }
266 if (!richSign) return NULL;
267 if (richSign->richId != pe::RICH_HDR_MAGIC) {
268 return NULL; //invalid
269 }
270 return richSign;
271}
272
274{
276 if (!this->_getSectionsCount()) {
277 return INVALID_ADDR;
278 }
279 SectionHdrWrapper* sec = this->_getSecHdr(0);
280 if (!sec) {
281 return INVALID_ADDR;
282 }
283 return sec->getContentOffset(Executable::RVA);
284}
285
291
293{
294 if (this->wrappers[WR_DATADIR] == NULL) return NULL;
295 return static_cast<IMAGE_DATA_DIRECTORY*>(this->wrappers[WR_DATADIR]->getPtr());
296}
297
299{
300 if (aType == Executable::NOT_ADDR) return 0;
301
302 if (aType == Executable::RAW) {
303 return this->getContentSize();
304 }
305 const size_t unit_size = 0x1000;
306 bufsize_t vSize = 0;
309 }
310 if (vSize < unit_size) {
311 return unit_size;
312 }
313 return vSize;
314}
315
317{
318 if (optHdr == NULL) return INVALID_ADDR;
319
320 bool isOk = false;
322 if (isOk == false) return INVALID_ADDR;
323
325 if (addrType != epType) {
326 entryPoint = this->convertAddr(entryPoint, epType, addrType);
327 }
328 return entryPoint;
329}
330
332{
333 if (optHdr == NULL) return false;
334
337 return isOk;
338}
339
341{
342 bool isOk = false;
344 if (isOk == false) return 0;
345
346 return static_cast<size_t> (secNum);
347}
348
350{
351 uint64_t count = newNum;
353 if (canSet == false) {
354 Logger::append(Logger::D_ERROR,"Can not change FileHdr!");
355 return false;
356 }
357 return true;
358}
359
361{
362 uint64_t size = newSize;
364 if (canSet == false) {
365 Logger::append(Logger::D_ERROR, "Can not change OptHdr!");
366 return false;
367 }
368 return true;
369}
370
372{
373 if (useMapped == false) {
374 return hdrSectionsNum();
375 }
376 return (this->sects) ? this->sects->getEntriesCount() : 0;
377}
378
380{
382 if (raw >= this->getMappedSize(Executable::RAW)) return INVALID_ADDR;
383
385 if (sec) {
386 offset_t bgnVA = sec->getContentOffset(Executable::VA);
387 offset_t bgnRaw = sec->getContentOffset(Executable::RAW);
389
390 bufsize_t curr = (raw - bgnRaw);
391
392 bufsize_t vSize = sec->getContentSize(Executable::VA, true);
393 if (curr >= vSize) {
394 //address out of section
395 return INVALID_ADDR;
396 }
397 return bgnVA + curr;
398 }
399 //TODO: make more tests
400 if (this->_getSectionsCount() == 0) return raw;
401 if (raw < this->hdrsSize()) {
402 return raw;
403 } //else: content that is between the end of sections headers and the first virtual section is not mapped
404 return INVALID_ADDR;
405}
406
408{
410 if (rva >= this->getMappedSize(Executable::RVA)) {
411 return INVALID_ADDR;
412 }
414 if (sec) {
415 offset_t bgnRVA = sec->getContentOffset(Executable::RVA);
416 offset_t bgnRaw = sec->getContentOffset(Executable::RAW);
417 if (bgnRVA == INVALID_ADDR || bgnRaw == INVALID_ADDR) {
418 return INVALID_ADDR;
419 }
420 bufsize_t curr = (rva - bgnRVA);
421 bufsize_t rawSize = sec->getContentSize(Executable::RAW, true);
422 if (curr >= rawSize) {
423 // the address might be in a virtual cave that is not related to any raw address
424 return INVALID_ADDR;
425 }
426 return bgnRaw + curr;
427 }
428 if (rva >= this->getMappedSize(Executable::RAW)) {
429 return INVALID_ADDR;
430 }
431 if (this->_getSectionsCount()) { // do this check only if sections count is non-zero
432 if (rva >= this->hdrsSize()) {
433 // the address is in the cave between the headers and the first section: cannot be mapped
434 return INVALID_ADDR;
435 }
436 }
437 // at this point we are sure that the address is within the raw size:
438 return rva;
439}
440
442{
443 if (eType >= pe::DIR_ENTRIES_COUNT) return NULL;
444 return dataDirEntries[eType];
445}
446
448{
450 SectionHdrWrapper *sec = this->_getSecHdr(secId);
451 if (!sec) {
452 Logger::append(Logger::D_WARNING, "No such section");
453 return NULL;
454 }
455 return _createSectionView(sec);
456}
457
459{
460 bool allowExceptions = true; //TODO: configure exception mode outside...
461
463 if (entry == NULL) {
464 if (allowExceptions) throw ExeException("No such Data Directory");
465 return false;
466 }
469 if (ddirWrapper == NULL || ddir == NULL) {
470 if (allowExceptions) throw ExeException("Cannot fetch DataDirTable");
471 return false;
472 }
475 if (dataDirAddr == INVALID_ADDR) {
476 if (allowExceptions) throw ExeException("Invalid new offset");
477 return false;
478 }
479 offset_t targetRaw = this->toRaw(newOffset, addrType);
480 if (entry->canCopyToOffset(targetRaw) == false) {
481 if (allowExceptions) throw ExeException("Cannot copy: no space at such offset");
482 return false;
483 }
484 if (entry->copyToOffset(targetRaw) == false) {
485 if (allowExceptions) throw ExeException("Cannot copy: error occured");
486 return false;
487 }
488 entry->fillContent(0);
489 ddir[id].VirtualAddress = static_cast<DWORD> (dataDirAddr);
490 return true;
491}
492
494{
496 if (sec == NULL || sec->canAddEntry() == false) {
497 return false;
498 }
499 const size_t secCount = hdrSectionsNum();
501 return false; //limit exceeded
502 }
503 //TODO: some more checks? overlay?
504 return true;
505}
506
508{
509 if (!r_size && !v_size) return nullptr; //nothing to add
510
511 bufsize_t newSize = 0;
514 SectionHdrWrapper* secHdrWr = nullptr;
515 { //scope0
517 if (!_canAddNewSection()) {
518 return nullptr;
519 }
521 if (!v_size) {
522 v_size = r_size;
523 }
528 if (setVirtualSize(newVirtualSize) == false) {
529 Logger::append(Logger::D_ERROR, "Failed to change virtual size to: %X", newVirtualSize);
530 return nullptr;
531 }
532 } //scope0
533
534 // the PE file is resized and rewrapped:
535 if (resize(newSize) == false) {
536 Logger::append(Logger::D_ERROR, "Failed to resize");
537 return nullptr;
538 }
539
540 { //scope1
542 // fetch again after resize:
544 if (!sec) {
545 return nullptr;
546 }
547
550
551 //name copy:
552 const size_t nameLen = name.length();
553 const size_t bufSize = sizeof(secHdr.Name);
554 const size_t copySize = (nameLen < bufSize) ? nameLen : bufSize;
555 if (copySize) {
556 ::memcpy(secHdr.Name, name.toStdString().c_str(), copySize);
557 }
558 secHdr.PointerToRawData = static_cast<DWORD>(roundedRawEnd);
559 secHdr.VirtualAddress = static_cast<DWORD>(roundedVirtualEnd);
560 secHdr.SizeOfRawData = r_size;
561 secHdr.Misc.VirtualSize = v_size;
562
564 secHdrWr = dynamic_cast<SectionHdrWrapper*>(sec->addEntry(&wr));
565 }
566 return secHdrWr;
567}
568
570{
571 size_t secCount = this->_getSectionsCount(true);
572 return (secCount > 0) ? this->_getSecHdr(secCount - 1) : nullptr;
573}
574
576{
578
579 /* check sections bounds */
580 const size_t secCounter = this->_getSectionsCount(true);
581 if (!secCounter) {
582 // if PE file has no sections, full file will be mapped
583 return getMappedSize(aType);
584 }
585 for (size_t i = 0; i < secCounter; i++) {
587 if (!sec) continue;
588
589 offset_t secLastMapped= sec->getContentOffset(aType, true);
590 if (secLastMapped == INVALID_ADDR) continue;
591
592 const size_t size = (aType == Executable::RAW) ? sec->getMappedRawSize() : sec->getMappedVirtualSize();
593 if (size == 0) continue; // exclude not mapped sections
594
595 secLastMapped += size;
598 }
599 }
600
601 /* check header bounds */
602 /* section headers: */
605 }
606 // PE hdrs ending:
607 const offset_t peHdrsEnd = this->core.peSignatureOffset() + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + this->core.peNtHeadersSize();
608 if (lastMapped < peHdrsEnd) {
610 }
611 // OptionalHdr -> SizeOfHeaders:
613 if (lastMapped < ntHeadersEndOffset) {
615 }
616 return lastMapped;
617}
618
620{
621 bufsize_t newSize = 0;
622
623 { //scope0
626 if (!secHdr) return nullptr;
627
628 //TODO: check overlay...
631
632 const offset_t secROffset = secHdr->getContentOffset(Executable::RAW, false);
633 if (secROffset == INVALID_ADDR) {
634 return NULL;
635 }
636 const bufsize_t secNewRSize = newSize - secROffset; //include overlay in section
638
639 const offset_t secVOffset = secHdr->getContentOffset(Executable::RVA, false);
640 const bufsize_t secVSize = secHdr->getContentSize(Executable::RVA, false);
641
642 // if the previous virtual size is smaller than the new raw size, then update it:
643 if (secVSize < secNewRSize) {
645
646 // if the virtual size of section has changed,
647 // update the Size of Image (saved in the header):
649 this->setVirtualSize(newVSize);
650 }
651
652 }
653
654 //update raw size:
655 this->resize(newSize);
656 //finally, retrieve the resized section:
657 return getLastSection();
658}
659
661{
664 return false; //not my section
665 }
667 if (!secView) return false;
668
669 bufsize_t dumpedSize = FileBuffer::dump(fileName, *secView, false);
670 delete secView;
671
672 return dumpedSize ? true : false;
673}
674
676{
678 if (ddir[pe::DIR_BOUND_IMPORT].VirtualAddress == 0 && ddir[pe::DIR_BOUND_IMPORT].Size == 0) {
679 // No bound imports already, nothing to do here!
680 return true;
681 }
682 ddir[pe::DIR_BOUND_IMPORT].VirtualAddress = 0;
683 ddir[pe::DIR_BOUND_IMPORT].Size = 0;
684 DataDirEntryWrapper *bImp = this->getDataDirEntry(pe::DIR_BOUND_IMPORT);
685 if (bImp == NULL) {
686 //printf("No Bound imports wrapper!\n");
687 return false; // todo: throw error?
688 }
689 bool isOk = bImp->wrap();
690 //TODO: change timestamp for all library entries from (-1 : BOUND) to 0 : NOT BOUND
691 return isOk;
692}
693
694//protected:
695
697{
699 offset_t start = sec->getContentOffset(aType, true);
700 bufsize_t size = sec->getContentSize(aType, true);
701 if (start == INVALID_ADDR || size == 0) {
702 return NULL;
703 }
704 return new BufferView(this, start, size);
705}
706
708{
709 size_t initialSize = entrypoints.size();
710
711 ExportDirWrapper* exports = dynamic_cast<ExportDirWrapper*>(this->getWrapper(PEFile::WR_DIR_ENTRY + pe::DIR_EXPORT));
712 if (!exports) return 0;
713
714 const size_t entriesCnt = exports->getEntriesCount();
715 if (entriesCnt == 0) return 0;
716
717 for (int i = 0; i < entriesCnt; i++) {
718 ExportEntryWrapper* entry = dynamic_cast<ExportEntryWrapper*>(exports->getEntryAt(i));
719 if (!entry) continue;
720
722 if (forwarder.length()) {
723 continue;
724 }
725 offset_t rva = entry->getFuncRva();
726 offset_t offset = this->convertAddr(rva, Executable::RVA, aType);
727 if (offset == INVALID_ADDR) {
728 continue;
729 }
730 entrypoints.insert(offset, entry->getName());
731 }
732 return entrypoints.size() - initialSize;
733}
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 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:400
QMutex m_peMutex
Definition PEFile.h:401
virtual bufsize_t getMappedSize(Executable::addr_type aType)
Definition PEFile.cpp:298
BufferView * _createSectionView(SectionHdrWrapper *sec)
Definition PEFile.cpp:696
size_t getExportsMap(QMap< offset_t, QString > &entrypoints, Executable::addr_type aType=Executable::RVA)
Definition PEFile.cpp:707
SectHdrsWrapper * sects
Definition PEFile.h:397
SectionHdrWrapper * _getSecHdr(size_t index) const
Definition PEFile.h:368
bool unbindImports()
Definition PEFile.cpp:675
offset_t peDataDirOffset()
Definition PEFile.cpp:286
virtual offset_t getEntryPoint(Executable::addr_type addrType=Executable::RVA)
Definition PEFile.cpp:316
void _init(AbstractByteBuffer *v_buf)
Definition PEFile.cpp:116
offset_t getMinSecRVA()
Definition PEFile.cpp:273
friend class SectHdrsWrapper
Definition PEFile.h:403
FileHdrWrapper * fHdr
Definition PEFile.h:395
bool wrapDataDirs()
Definition PEFile.cpp:193
size_t _getSecIndex(SectionHdrWrapper *sec) const
Definition PEFile.h:363
ResourcesAlbum * album
Definition PEFile.h:399
bool setEntryPoint(offset_t entry, Executable::addr_type aType)
Definition PEFile.cpp:331
pe::RICH_DANS_HEADER * getRichHeaderBgn(pe::RICH_SIGNATURE *sign)
Definition PEFile.cpp:217
SectionHdrWrapper * extendLastSection(bufsize_t addedSize)
Definition PEFile.cpp:619
@ 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:392
void initDirEntries()
Definition PEFile.cpp:173
virtual void wrap()
Definition PEFile.cpp:211
SectionHdrWrapper * getLastSection()
Definition PEFile.h:188
OptHdrWrapper * optHdr
Definition PEFile.h:396
bool dumpSection(SectionHdrWrapper *sec, QString fileName)
Definition PEFile.cpp:660
offset_t _getLastMapped(Executable::addr_type aType)
Definition PEFile.cpp:575
virtual offset_t rvaToRaw(offset_t rva)
Definition PEFile.cpp:407
BufferView * createSectionView(size_t secNum)
Definition PEFile.cpp:447
bool setHdrSectionsNum(size_t newNum)
Definition PEFile.cpp:349
bool setVirtualSize(bufsize_t newSize)
Definition PEFile.cpp:360
bool _canAddNewSection()
Definition PEFile.cpp:493
void wrapCore()
Definition PEFile.cpp:180
DataDirEntryWrapper * getDataDirEntry(pe::dir_entry eType)
Definition PEFile.cpp:441
SectionHdrWrapper * _getSecHdrAtOffset(offset_t offset, Executable::addr_type aType, bool recalculate=false, bool verbose=false)
Definition PEFile.h:373
bool moveDataDirEntry(pe::dir_entry id, offset_t newOffset, Executable::addr_type addType=Executable::RAW)
Definition PEFile.cpp:458
SectionHdrWrapper * _getLastSection()
Definition PEFile.cpp:569
virtual void clearWrappers()
Definition PEFile.cpp:162
offset_t _secHdrsEndOffset()
Definition PEFile.h:349
IMAGE_DATA_DIRECTORY * getDataDirectory()
Definition PEFile.cpp:292
virtual offset_t rawToRva(offset_t raw)
Definition PEFile.cpp:379
bufsize_t hdrsSize()
Definition PEFile.h:82
size_t hdrSectionsNum() const
Definition PEFile.cpp:340
PEFile(AbstractByteBuffer *v_buf)
Definition PEFile.cpp:105
virtual bufsize_t getAlignment(Executable::addr_type aType) const
Definition PEFile.h:69
pe::RICH_SIGNATURE * getRichHeaderSign()
Definition PEFile.cpp:244
static long computeChecksum(BYTE *buffer, size_t bufferSize, offset_t checksumOffset)
Definition PEFile.cpp:45
DosHdrWrapper * dosHdrWrapper
Definition PEFile.h:393
size_t _getSectionsCount(bool useMapped=true) const
Definition PEFile.cpp:371
SectionHdrWrapper * addNewSection(QString name, bufsize_t size, bufsize_t v_size=0)
Definition PEFile.cpp:507
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)