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) {
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();
493 return false; //limit exceeded
494 }
495 //TODO: some more checks? overlay?
496 return true;
497}
498
500{
501 if (!r_size && !v_size) return nullptr; //nothing to add
502
503 bufsize_t newSize = 0;
506 SectionHdrWrapper* secHdrWr = nullptr;
507 { //scope0
509 if (!_canAddNewSection()) {
510 return nullptr;
511 }
513 if (!v_size) {
514 v_size = r_size;
515 }
520 if (setVirtualSize(newVirtualSize) == false) {
521 Logger::append(Logger::D_ERROR, "Failed to change virtual size to: %X", newVirtualSize);
522 return nullptr;
523 }
524 } //scope0
525
526 // the PE file is resized and rewrapped:
527 if (resize(newSize) == false) {
528 Logger::append(Logger::D_ERROR, "Failed to resize");
529 return nullptr;
530 }
531
532 { //scope1
534 // fetch again after resize:
536 if (!sec) {
537 return nullptr;
538 }
539
542
543 //name copy:
544 const size_t nameLen = name.length();
545 const size_t bufSize = sizeof(secHdr.Name);
546 const size_t copySize = (nameLen < bufSize) ? nameLen : bufSize;
547 if (copySize) {
548 ::memcpy(secHdr.Name, name.toStdString().c_str(), copySize);
549 }
550 secHdr.PointerToRawData = static_cast<DWORD>(roundedRawEnd);
551 secHdr.VirtualAddress = static_cast<DWORD>(roundedVirtualEnd);
552 secHdr.SizeOfRawData = r_size;
553 secHdr.Misc.VirtualSize = v_size;
554
556 secHdrWr = dynamic_cast<SectionHdrWrapper*>(sec->addEntry(&wr));
557 }
558 return secHdrWr;
559}
560
562{
563 size_t secCount = this->_getSectionsCount(true);
564 return (secCount > 0) ? this->_getSecHdr(secCount - 1) : nullptr;
565}
566
568{
570
571 /* check sections bounds */
572 const size_t secCounter = this->_getSectionsCount(true);
573 if (!secCounter) {
574 // if PE file has no sections, full file will be mapped
575 return getMappedSize(aType);
576 }
577 for (size_t i = 0; i < secCounter; i++) {
579 if (!sec) continue;
580
581 offset_t secLastMapped= sec->getContentOffset(aType, true);
582 if (secLastMapped == INVALID_ADDR) continue;
583
584 const size_t size = (aType == Executable::RAW) ? sec->getMappedRawSize() : sec->getMappedVirtualSize();
585 if (size == 0) continue; // exclude not mapped sections
586
587 secLastMapped += size;
590 }
591 }
592
593 /* check header bounds */
594 /* section headers: */
597 }
598 // PE hdrs ending:
599 const offset_t peHdrsEnd = this->core.peSignatureOffset() + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + this->core.peNtHeadersSize();
600 if (lastMapped < peHdrsEnd) {
602 }
603 // OptionalHdr -> SizeOfHeaders:
605 if (lastMapped < ntHeadersEndOffset) {
607 }
608 return lastMapped;
609}
610
612{
613 bufsize_t newSize = 0;
614
615 { //scope0
618 if (!secHdr) return nullptr;
619
620 //TODO: check overlay...
623
624 const offset_t secROffset = secHdr->getContentOffset(Executable::RAW, false);
625 if (secROffset == INVALID_ADDR) {
626 return NULL;
627 }
628 const bufsize_t secNewRSize = newSize - secROffset; //include overlay in section
630
631 const offset_t secVOffset = secHdr->getContentOffset(Executable::RVA, false);
632 const bufsize_t secVSize = secHdr->getContentSize(Executable::RVA, false);
633
634 // if the previous virtual size is smaller than the new raw size, then update it:
635 if (secVSize < secNewRSize) {
637
638 // if the virtual size of section has changed,
639 // update the Size of Image (saved in the header):
641 this->setVirtualSize(newVSize);
642 }
643
644 }
645
646 //update raw size:
647 this->resize(newSize);
648 //finally, retrieve the resized section:
649 return getLastSection();
650}
651
653{
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
668{
670 if (ddir[pe::DIR_BOUND_IMPORT].VirtualAddress == 0 && ddir[pe::DIR_BOUND_IMPORT].Size == 0) {
671 // No bound imports already, nothing to do here!
672 return true;
673 }
674 ddir[pe::DIR_BOUND_IMPORT].VirtualAddress = 0;
675 ddir[pe::DIR_BOUND_IMPORT].Size = 0;
676 DataDirEntryWrapper *bImp = this->getDataDirEntry(pe::DIR_BOUND_IMPORT);
677 if (bImp == NULL) {
678 //printf("No Bound imports wrapper!\n");
679 return false; // todo: throw error?
680 }
681 bool isOk = bImp->wrap();
682 //TODO: change timestamp for all library entries from (-1 : BOUND) to 0 : NOT BOUND
683 return isOk;
684}
685
686//protected:
687
689{
691 offset_t start = sec->getContentOffset(aType, true);
692 bufsize_t size = sec->getContentSize(aType, true);
693 if (start == INVALID_ADDR || size == 0) {
694 return NULL;
695 }
696 return new BufferView(this, start, size);
697}
698
700{
701 size_t initialSize = entrypoints.size();
702
703 ExportDirWrapper* exports = dynamic_cast<ExportDirWrapper*>(this->getWrapper(PEFile::WR_DIR_ENTRY + pe::DIR_EXPORT));
704 if (!exports) return 0;
705
706 const size_t entriesCnt = exports->getEntriesCount();
707 if (entriesCnt == 0) return 0;
708
709 for (int i = 0; i < entriesCnt; i++) {
710 ExportEntryWrapper* entry = dynamic_cast<ExportEntryWrapper*>(exports->getEntryAt(i));
711 if (!entry) continue;
712
714 if (forwarder.length()) {
715 continue;
716 }
717 offset_t rva = entry->getFuncRva();
718 offset_t offset = this->convertAddr(rva, Executable::RVA, aType);
719 if (offset == INVALID_ADDR) {
720 continue;
721 }
722 entrypoints.insert(offset, entry->getName());
723 }
724 return entrypoints.size() - initialSize;
725}
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:354
QMutex m_peMutex
Definition PEFile.h:355
virtual bufsize_t getMappedSize(Executable::addr_type aType)
Definition PEFile.cpp:290
BufferView * _createSectionView(SectionHdrWrapper *sec)
Definition PEFile.cpp:688
size_t getExportsMap(QMap< offset_t, QString > &entrypoints, Executable::addr_type aType=Executable::RVA)
Definition PEFile.cpp:699
SectHdrsWrapper * sects
Definition PEFile.h:351
SectionHdrWrapper * _getSecHdr(size_t index) const
Definition PEFile.h:322
bool unbindImports()
Definition PEFile.cpp:667
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:357
FileHdrWrapper * fHdr
Definition PEFile.h:349
size_t _getSecIndex(SectionHdrWrapper *sec) const
Definition PEFile.h:317
ResourcesAlbum * album
Definition PEFile.h:353
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:611
@ 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:346
void initDirEntries()
Definition PEFile.cpp:173
virtual void wrap()
Definition PEFile.cpp:193
SectionHdrWrapper * getLastSection()
Definition PEFile.h:187
OptHdrWrapper * optHdr
Definition PEFile.h:350
bool dumpSection(SectionHdrWrapper *sec, QString fileName)
Definition PEFile.cpp:652
offset_t _getLastMapped(Executable::addr_type aType)
Definition PEFile.cpp:567
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
bool _canAddNewSection()
Definition PEFile.cpp:485
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:327
bool moveDataDirEntry(pe::dir_entry id, offset_t newOffset, Executable::addr_type addType=Executable::RAW)
Definition PEFile.cpp:450
SectionHdrWrapper * _getLastSection()
Definition PEFile.cpp:561
virtual void clearWrappers()
Definition PEFile.cpp:162
offset_t _secHdrsEndOffset()
Definition PEFile.h:303
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
static long computeChecksum(BYTE *buffer, size_t bufferSize, offset_t checksumOffset)
Definition PEFile.cpp:45
DosHdrWrapper * dosHdrWrapper
Definition PEFile.h:347
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)