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
4{
5 if (buf == NULL) return false;
6
7 offset_t dosOffset = 0;
8 WORD *magic = (WORD*) buf->getContentAt(dosOffset, sizeof(WORD));
9 if (magic == NULL) return false;
10
11 if ((*magic) != pe::S_DOS) {
12 return false;
13 }
14 offset_t newOffset = dosOffset + (sizeof(IMAGE_DOS_HEADER) - sizeof(LONG));
15 LONG* lfnew = (LONG*) buf->getContentAt(newOffset, sizeof(LONG));
16 if (lfnew == NULL) {
17 return false;
18 }
19 offset_t peOffset = static_cast<offset_t>(*lfnew);
20 DWORD *peMagic = (DWORD*) buf->getContentAt(peOffset, sizeof(DWORD));
21 if (peMagic == NULL) {
22 return false;
23 }
24 if (*peMagic == pe::S_NT) {
25 return true;
26 }
27 return false;
28}
29
31{
32 Executable *exe = NULL;
33 if (signatureMatches(buf) == false) return NULL;
34
35 try {
36 exe = new PEFile(buf);
37 } catch (ExeException &e) {
38 //
39 }
40 return exe;
41}
42
43//-------------------------------------------------------------
44long PEFile::computeChecksum(BYTE *buffer, size_t bufferSize, size_t checksumOffset)
45{
46 WORD *wordBuff = (WORD*)buffer;
47 size_t wordSize = bufferSize / sizeof(WORD);
48
49 size_t checksumBgn = checksumOffset;
50 size_t checksumEnd = checksumOffset + sizeof(DWORD);
51
52 const long long maxVal = ((long long)1) << 32;
53 long long checksum = 0;
54
55 for (int i = 0; i < wordSize; i++) {
56 WORD chunk = wordBuff[i];
57
58 size_t bI = i * sizeof(WORD);
59 if (bI >= checksumBgn && bI < checksumEnd) {
60 size_t mask = (checksumEnd - bI) % sizeof(WORD);
61 size_t shift = (sizeof(WORD) - mask) * 8;
62 chunk = (chunk >> shift) << shift;
63 }
64
65 checksum = (checksum & 0xffffffff) + chunk + (checksum >> 32);
66 if (checksum > maxVal) {
67 checksum = (checksum & 0xffffffff) + (checksum >> 32);
68 }
69 }
70 checksum = (checksum & 0xffff) + (checksum >> 16);
71 checksum = (checksum)+(checksum >> 16);
72 checksum = checksum & 0xffff;
73 checksum += bufferSize;
74 return checksum;
75}
76
78
80 : MappedExe(v_buf, Executable::BITS_32), dosHdrWrapper(NULL), fHdr(NULL), optHdr(NULL), sects(NULL),
81 album(NULL)
82{
83 album = new ResourcesAlbum(this);
84 wrap(v_buf);
86}
87
89{
92}
93
95{
96 for (size_t i = 0 ; i < pe::DIR_ENTRIES_COUNT; i++) {
97 dataDirEntries[i] = NULL;
98 }
99}
100
102{
104 PEFile::wrap(this->buf);
105}
106
108{
109 core.wrap(v_buf);
110 this->dosHdrWrapper = new DosHdrWrapper(this);
111 this->wrappers[WR_DOS_HDR] = this->dosHdrWrapper;
112
113 this->fHdr = new FileHdrWrapper(this);
114 if (fHdr->getPtr() == NULL) throw ExeException("Cannot parse FileHdr: It is not PE File!");
115 this->wrappers[WR_FILE_HDR] = fHdr;
116 this->wrappers[WR_RICH_HDR] = new RichHdrWrapper(this);
117
118 this->optHdr = new OptHdrWrapper(this);
119 if (optHdr->getPtr() == NULL) throw ExeException("Cannot parse OptionalHeader: It is not PE File!");
121
122 this->wrappers[WR_DATADIR] = new DataDirWrapper(this);
123
124 bool isOk = false;
125 size_t secNum = fHdr->getNumValue(FileHdrWrapper::SEC_NUM, &isOk);
126 if (isOk){
127 this->sects = new SectHdrsWrapper(this);
128 this->wrappers[WR_SECTIONS] = sects;
129 }
130 // map Data Dirs
132 dataDirEntries[pe::DIR_IMPORT] = new ImportDirWrapper(this);
133 dataDirEntries[pe::DIR_DELAY_IMPORT] = new DelayImpDirWrapper(this);
134 dataDirEntries[pe::DIR_BOUND_IMPORT] = new BoundImpDirWrapper(this);
135 dataDirEntries[pe::DIR_DEBUG] = new DebugDirWrapper(this);
136 dataDirEntries[pe::DIR_EXPORT] = new ExportDirWrapper(this);
137 dataDirEntries[pe::DIR_SECURITY] = new SecurityDirWrapper(this);
138 dataDirEntries[pe::DIR_TLS] = new TlsDirWrapper(this);
139 dataDirEntries[pe::DIR_LOAD_CONFIG] = new LdConfigDirWrapper(this);
140 dataDirEntries[pe::DIR_BASERELOC] = new RelocDirWrapper(this);
141 dataDirEntries[pe::DIR_EXCEPTION] = new ExceptionDirWrapper(this);
142 dataDirEntries[pe::DIR_RESOURCE] = new ResourceDirWrapper(this, album);
143 dataDirEntries[pe::DIR_COM_DESCRIPTOR] = new ClrDirWrapper(this);
144
145 for (int i = 0; i < pe::DIR_ENTRIES_COUNT; i++) {
146 this->wrappers[WR_DIR_ENTRY + i] = dataDirEntries[i];
147 }
148
149 if (this->album) {
150 this->album->wrapLeafsContent();
151 }
152}
153
154pe::RICH_DANS_HEADER* PEFile::getRichHeaderBgn(pe::RICH_SIGNATURE* richSign)
155{
156 if (!richSign) return NULL;
157
158 DWORD xorkey = richSign->checksum;
159 const offset_t richOffset = this->getOffset(richSign);
160
161 pe::RICH_DANS_HEADER* dansHdr = NULL;
162
163 offset_t offset = richOffset - sizeof(pe::RICH_DANS_HEADER);
164 while (offset > 0) {
165 dansHdr = (pe::RICH_DANS_HEADER*) this->getContentAt(offset, sizeof(pe::RICH_DANS_HEADER));
166 if (!dansHdr) {
167 break;
168 }
169 if (dansHdr->dansId == (pe::DANS_HDR_MAGIC ^ xorkey)) {
170 break; //got it!
171 }
172 //walking back
173 offset -= sizeof(DWORD);
174 }
175 if (!dansHdr || dansHdr->dansId != (pe::DANS_HDR_MAGIC ^ xorkey)) {
176 return NULL; //not found
177 }
178 return dansHdr;
179}
180
181pe::RICH_SIGNATURE* PEFile::getRichHeaderSign()
182{
183 size_t dosStubOffset = this->core.dos->e_lfarlc;
184 size_t dosStubEnd = this->core.dos->e_lfanew; // PE header start
185 const size_t maxSize = dosStubEnd - dosStubOffset; // Rich Header is somewhere in the space between DOS and PE headers
186 BYTE *dosPtr = this->getContentAt(dosStubOffset, maxSize);
187 if (!dosPtr) {
188 return NULL;
189 }
190
191 pe::RICH_SIGNATURE* richSign = NULL;
192 size_t toSearchSize = maxSize;
193 const offset_t startOffset = dosStubOffset; //we are starting from the beginning of DOS stub
194 const size_t step = sizeof(DWORD); //RichHeader is padded by DWORDS
195
196 while (toSearchSize > 0) {
197 richSign = (pe::RICH_SIGNATURE*) this->getContentAt(startOffset + toSearchSize, sizeof(pe::RICH_SIGNATURE));
198 if (!richSign) break;
199 if (richSign->richId == pe::RICH_HDR_MAGIC) break; //got it!
200 // the search goes backward.
201 toSearchSize -= step;
202 }
203 if (!richSign) return NULL;
204 if (richSign->richId != pe::RICH_HDR_MAGIC) {
205 return NULL; //invalid
206 }
207 return richSign;
208}
209
210
212{
213 if (this->getSectionsCount() < 1) {
214 return INVALID_ADDR;
215 }
216 SectionHdrWrapper* sec = this->getSecHdr(0);
217 if (!sec) {
218 return INVALID_ADDR;
219 }
221}
222
224{
225 if (this->optHdr == NULL) return INVALID_ADDR;
227}
228
229IMAGE_DATA_DIRECTORY* PEFile::getDataDirectory()
230{
231 if (this->wrappers[WR_DATADIR] == NULL) return NULL;
232 return static_cast<IMAGE_DATA_DIRECTORY*>(this->wrappers[WR_DATADIR]->getPtr());
233}
234
236{
237 if (aType == Executable::RAW) {
238 return this->getContentSize();
239 }
240 const size_t PAGE_SIZE = 0x1000;
241 bufsize_t vSize = 0;
242 if (aType == Executable::VA || aType == Executable::RVA) {
243 vSize = core.getImageSize();
244 }
245 if (vSize < PAGE_SIZE) {
246 return PAGE_SIZE;
247 }
248 return vSize;
249}
250
252{
253 if (optHdr == NULL) return INVALID_ADDR;
254
255 bool isOk = false;
256 offset_t entryPoint = static_cast<offset_t> (optHdr->getNumValue(OptHdrWrapper::EP, &isOk));
257 if (isOk == false) return INVALID_ADDR;
258
260 if (addrType != epType) {
261 entryPoint = this->convertAddr(entryPoint, epType, addrType);
262 }
263 return entryPoint;
264}
265
267{
268 if (optHdr == NULL) return false;
269
270 offset_t epRva = this->convertAddr(entry, aType, Executable::RVA);
271 bool isOk = optHdr->setNumValue(OptHdrWrapper::EP, epRva);
272 return isOk;
273}
274
276{
277 bool isOk = false;
278 uint64_t secNum = this->fHdr->getNumValue(FileHdrWrapper::SEC_NUM , &isOk);
279 if (isOk == false) return 0;
280
281 return static_cast<size_t> (secNum);
282}
283
284bool PEFile::setHdrSectionsNum(size_t newNum)
285{
286 uint64_t count = newNum;
287 bool canSet = fHdr->setNumValue(FileHdrWrapper::SEC_NUM , count);
288 if (canSet == false) {
289 Logger::append(Logger::D_ERROR,"Can not change FileHdr!");
290 return false;
291 }
292 return true;
293}
294
296{
297 uint64_t size = newSize;
298 bool canSet = optHdr->setNumValue(OptHdrWrapper::IMAGE_SIZE, 0, size);
299 if (canSet == false) {
300 Logger::append(Logger::D_ERROR, "Can not change OptHdr!");
301 return false;
302 }
303 return true;
304}
305
306size_t PEFile::getSectionsCount(bool useMapped) const
307{
308 if (useMapped == false) {
309 return hdrSectionsNum();
310 }
311 return this->sects->getEntriesCount();
312}
313
315{
316 if (raw >= this->getMappedSize(Executable::RAW)) return INVALID_ADDR;
317
318 SectionHdrWrapper* sec = this->getSecHdrAtOffset(raw, Executable::RAW, true);
319 if (sec) {
322 if (bgnVA == INVALID_ADDR || bgnRaw == INVALID_ADDR) return INVALID_ADDR;
323
324 bufsize_t curr = (raw - bgnRaw);
325
326 bufsize_t vSize = sec->getContentSize(Executable::VA, true);
327 if (curr >= vSize) {
328 //address out of section
329 return INVALID_ADDR;
330 }
331 return bgnVA + curr;
332 }
333 //TODO: make more tests
334 if (this->getSectionsCount() == 0) return raw;
335 if (raw < this->hdrsSize()) {
336 return raw;
337 } //else: content that is between the end of sections headers and the first virtual section is not mapped
338 return INVALID_ADDR;
339}
340
342{
343 if (rva >= this->getMappedSize(Executable::RVA)) return INVALID_ADDR;
344
345 SectionHdrWrapper* sec = this->getSecHdrAtOffset(rva, Executable::RVA, true);
346 if (sec) {
349 if (bgnRVA == INVALID_ADDR || bgnRaw == INVALID_ADDR) return INVALID_ADDR;
350
351 bufsize_t curr = (rva - bgnRVA);
352 bufsize_t rawSize = sec->getContentSize(Executable::RAW, true);
353 if (curr >= rawSize) {
354 // the address might be in a virtual cave that is not related to any raw address
355 return INVALID_ADDR;
356 }
357 return bgnRaw + curr;
358 }
359 if (rva >= this->getMappedSize(Executable::RAW)) {
360 return INVALID_ADDR;
361 }
362 if (rva >= this->hdrsSize()) {
363 // the address is in the cave between the headers and the first section: cannot be mapped
364 return INVALID_ADDR;
365 }
366 // at this point we are sure that the address is within the raw size:
367 return rva;
368}
369
371{
372 if (eType >= pe::DIR_ENTRIES_COUNT) return NULL;
373 return dataDirEntries[eType];
374}
375
377{
378 SectionHdrWrapper *sec = this->getSecHdr(secId);
379 if (sec == NULL) {
380 Logger::append(Logger::D_WARNING, "No such section");
381 return NULL;
382 }
384 offset_t start = sec->getContentOffset(aType, true);
385 bufsize_t size = sec->getContentSize(aType, true);
386 if (start == INVALID_ADDR || size == 0) return NULL;
387
388 BufferView *secView = new BufferView(this, start, size);
389 return secView;
390}
391
392bool PEFile::moveDataDirEntry(pe::dir_entry id, offset_t newOffset, Executable::addr_type addrType)
393{
394 bool allowExceptions = true; //TODO: configure exception mode outside...
395
397 if (entry == NULL) {
398 if (allowExceptions) throw ExeException("No such Data Directory");
399 return false;
400 }
401 DataDirWrapper* ddirWrapper = dynamic_cast<DataDirWrapper*> (this->wrappers[WR_DATADIR]);
402 IMAGE_DATA_DIRECTORY *ddir = this->getDataDirectory();
403 if (ddirWrapper == NULL || ddir == NULL) {
404 if (allowExceptions) throw ExeException("Cannot fetch DataDirTable");
405 return false;
406 }
407 Executable::addr_type dataDirAddrType = ddirWrapper->containsAddrType(id, DataDirWrapper::ADDRESS);
408 offset_t dataDirAddr = this-> convertAddr(newOffset, addrType, dataDirAddrType);
409 if (dataDirAddr == INVALID_ADDR) {
410 if (allowExceptions) throw ExeException("Invalid new offset");
411 return false;
412 }
413 offset_t targetRaw = this->toRaw(newOffset, addrType);
414 if (entry->canCopyToOffset(targetRaw) == false) {
415 if (allowExceptions) throw ExeException("Cannot copy: no space at such offset");
416 return false;
417 }
418 if (entry->copyToOffset(targetRaw) == false) {
419 if (allowExceptions) throw ExeException("Cannot copy: error occured");
420 return false;
421 }
422 entry->fillContent(0);
423 ddir[id].VirtualAddress = static_cast<DWORD> (dataDirAddr);
424 return true;
425}
426
428{
430 if (sec == NULL || sec->canAddEntry() == false) {
431 return false;
432 }
433 const size_t secCount = hdrSectionsNum();
434 if (secCount == SectHdrsWrapper::SECT_COUNT_MAX) return false; //limit exceeded
435
436 //TODO: some more checks? overlay?
437 return true;
438}
439
440
442{
443 if (canAddNewSection() == false) return NULL;
444
446
449 bufsize_t newSize = roundedRawEnd + size;
450 bufsize_t newVirtualSize = roundedVirtualEnd + size;
451
452 if (setVirtualSize(newVirtualSize) == false) {
453 Logger::append(Logger::D_ERROR, "Failed to change virtual size");
454 return NULL;
455 }
456
457 if (resize(newSize) == false) {
458 Logger::append(Logger::D_ERROR, "Failed to resize");
459 return NULL;
460 }
461 // fetch again after resize:
462 sec = dynamic_cast<ExeNodeWrapper*>(getWrapper(PEFile::WR_SECTIONS));
463 if (sec == NULL) {
464 return NULL;
465 }
466
467 IMAGE_SECTION_HEADER secHdr;
468 memset(&secHdr, 0, sizeof(IMAGE_SECTION_HEADER));
469
470 //name copy:
471 std::string nameStr = name.toStdString();
472 const char *nameChar = nameStr.c_str();
473 size_t copySize = sizeof(secHdr.Name);
474 size_t nameLen = strlen(nameChar);
475 if (nameLen < copySize) copySize = nameLen;
476 memcpy(secHdr.Name, nameChar, copySize);
477
478 secHdr.PointerToRawData = static_cast<DWORD>(roundedRawEnd);
479 secHdr.VirtualAddress = static_cast<DWORD>(roundedVirtualEnd);
480 secHdr.SizeOfRawData = size;
481 secHdr.Misc.VirtualSize = size;
482
483 SectionHdrWrapper wr(this, &secHdr);
484 SectionHdrWrapper* secHdrWr = dynamic_cast<SectionHdrWrapper*>(sec->addEntry(&wr));
485 return secHdrWr;
486}
487
489{
490 size_t secCount = this->getSectionsCount(true);
491 if (secCount == 0) return NULL;
492 return this->getSecHdr(secCount - 1);
493}
494
496{
497 offset_t lastRaw = 0;
498
499 /* check sections bounds */
500 const size_t counter = this->getSectionsCount(true);
501 for (size_t i = 0; i < counter; i++) {
502 SectionHdrWrapper *sec = this->getSecHdr(i);
503 if (!sec) continue;
504
505 offset_t secLastRaw = sec->getContentOffset(Executable::RAW, false) + sec->getMappedRawSize();
506 if (secLastRaw > lastRaw) lastRaw = secLastRaw;
507 }
508
509 /* check header bounds */
510 /* section headers: */
511 if (lastRaw < this->secHdrsEndOffset()) lastRaw = this->secHdrsEndOffset();
512
513 /* NT headers: */
514 int ntHeadersEndOffset = this->core.peSignatureOffset() + this->core.hdrsSize();
515 if (lastRaw < ntHeadersEndOffset) lastRaw = ntHeadersEndOffset;
516 return lastRaw;
517}
518
520{
522 if (secHdr == NULL) return NULL;
523
524 //TODO: check overlay...
525 bufsize_t fullSize = getContentSize();
526 bufsize_t newSize = fullSize + addedSize;
527
528 offset_t secROffset = secHdr->getContentOffset(Executable::RAW, false);
529 bufsize_t secRSize = secHdr->getContentSize(Executable::RAW, false);
530 bufsize_t secNewRSize = newSize - secROffset; //include overlay in section
531
532 secHdr->setNumValue(SectionHdrWrapper::RSIZE, uint64_t(secNewRSize));
533
534 offset_t secVOffset = secHdr->getContentOffset(Executable::RVA, false);
535 bufsize_t secVSize = secHdr->getContentSize(Executable::RVA, false);
536 bufsize_t secNewVSize = secVSize;
537 // if the previous virtual size is smaller than the new raw size, then update it:
538 if (secVSize < secNewRSize) {
539 secNewVSize = secNewRSize;
540 secHdr->setNumValue(SectionHdrWrapper::VSIZE, uint64_t(secNewRSize));
541
542 // if the virtual size of section has changed,
543 // update the Size of Image (saved in the header):
544 bufsize_t newVSize = secVOffset + secNewVSize;
545 this->setVirtualSize(newVSize);
546 }
547
548 //update raw size:
549 this->resize(newSize);
550 //finally, retrieve the resized section:
551 return getLastSection();
552}
553
555{
556 IMAGE_DATA_DIRECTORY* ddir = this->getDataDirectory();
557 if (ddir[pe::DIR_BOUND_IMPORT].VirtualAddress == 0 && ddir[pe::DIR_BOUND_IMPORT].Size == 0) {
558 // No bound imports already, nothing to do here!
559 return true;
560 }
561 ddir[pe::DIR_BOUND_IMPORT].VirtualAddress = 0;
562 ddir[pe::DIR_BOUND_IMPORT].Size = 0;
563 DataDirEntryWrapper *bImp = this->getDataDirEntry(pe::DIR_BOUND_IMPORT);
564 if (bImp == NULL) {
565 //printf("No Bound imports wrapper!\n");
566 return false; // todo: throw error?
567 }
568 bool isOk = bImp->wrap();
569 //TODO: change timestamp for all library entries from (-1 : BOUND) to 0 : NOT BOUND
570 return isOk;
571}
572
573//protected:
574size_t PEFile::getExportsMap(QMap<offset_t,QString> &entrypoints, Executable::addr_type aType)
575{
576 size_t initialSize = entrypoints.size();
577
578 ExportDirWrapper* exports = dynamic_cast<ExportDirWrapper*>(this->getWrapper(PEFile::WR_DIR_ENTRY + pe::DIR_EXPORT));
579 if (!exports) return 0;
580
581 const size_t entriesCnt = exports->getEntriesCount();
582 if (entriesCnt == 0) return 0;
583
584 for(int i = 0; i < entriesCnt; i++) {
585 ExportEntryWrapper* entry = dynamic_cast<ExportEntryWrapper*>(exports->getEntryAt(i));
586 if (!entry) continue;
587
588 QString forwarder = entry->getForwarderStr();
589 if (forwarder.length()) {
590 continue;
591 }
592 offset_t rva = entry->getFuncRva();
593 offset_t offset = this->convertAddr(rva, Executable::RVA, aType);
594 if (offset == INVALID_ADDR) {
595 continue;
596 }
597
598 entrypoints.insert(offset, entry->getName());
599 }
600 return entrypoints.size() - initialSize;
601}
602
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)
bool fillContent(BYTE filling)
virtual Executable::addr_type containsAddrType(size_t fieldId, size_t subField=FIELD_NONE)
virtual bool setNumValue(size_t fieldId, size_t subField, uint64_t val)
virtual bool canCopyToOffset(offset_t rawOffset)
virtual offset_t getFieldOffset(size_t fieldId, size_t subField=FIELD_NONE)
bool copyToOffset(offset_t rawOffset)
virtual uint64_t getNumValue(size_t fieldId, size_t subField, bool *isOk)
virtual bool wrap()
virtual ExeNodeWrapper * getEntryAt(size_t fieldId)
virtual bool canAddEntry()
virtual size_t getEntriesCount()
virtual ExeNodeWrapper * addEntry(ExeNodeWrapper *entry)
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:108
virtual offset_t toRaw(offset_t offset, addr_type addrType, bool allowExceptions=false)
Definition: Executable.cpp:85
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)
Definition: Executable.cpp:46
virtual bufsize_t getContentSize()
Definition: Executable.h:51
QString getForwarderStr()
offset_t getFuncRva()
virtual QString getName()
virtual void * getPtr()
virtual bool resize(bufsize_t newSize)
Definition: MappedExe.h:41
virtual void * getPtr()
bufsize_t hdrsSize() const
Definition: PECore.cpp:127
bool wrap(AbstractByteBuffer *v_buf)
Definition: PECore.cpp:13
virtual bufsize_t getImageSize()
Definition: PECore.cpp:115
offset_t peSignatureOffset() const
Definition: PECore.cpp:57
IMAGE_DOS_HEADER * dos
Definition: PECore.h:39
virtual Executable * build(AbstractByteBuffer *buf)
Definition: PEFile.cpp:30
virtual bool signatureMatches(AbstractByteBuffer *buf)
Definition: PEFile.cpp:3
Definition: PEFile.h:41
DataDirEntryWrapper * dataDirEntries[pe::DIR_ENTRIES_COUNT]
Definition: PEFile.h:199
virtual bufsize_t getMappedSize(Executable::addr_type aType)
Definition: PEFile.cpp:235
size_t getExportsMap(QMap< offset_t, QString > &entrypoints, Executable::addr_type aType=Executable::RVA)
Definition: PEFile.cpp:574
SectHdrsWrapper * sects
Definition: PEFile.h:196
SectionHdrWrapper * getSecHdr(size_t index) const
Definition: PEFile.h:109
SectionHdrWrapper * addNewSection(QString name, bufsize_t size)
Definition: PEFile.cpp:441
bool unbindImports()
Definition: PEFile.cpp:554
offset_t peDataDirOffset()
Definition: PEFile.cpp:223
virtual offset_t getEntryPoint(Executable::addr_type addrType=Executable::RVA)
Definition: PEFile.cpp:251
offset_t getMinSecRVA()
Definition: PEFile.cpp:211
friend class SectHdrsWrapper
Definition: PEFile.h:201
offset_t getLastMapped(Executable::addr_type aType)
Definition: PEFile.cpp:495
FileHdrWrapper * fHdr
Definition: PEFile.h:194
ResourcesAlbum * album
Definition: PEFile.h:198
bool setEntryPoint(offset_t entry, Executable::addr_type aType)
Definition: PEFile.cpp:266
size_t getSectionsCount(bool useMapped=true) const
Definition: PEFile.cpp:306
pe::RICH_DANS_HEADER * getRichHeaderBgn(pe::RICH_SIGNATURE *sign)
Definition: PEFile.cpp:154
SectionHdrWrapper * extendLastSection(bufsize_t addedSize)
Definition: PEFile.cpp:519
@ 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:186
void initDirEntries()
Definition: PEFile.cpp:94
virtual void wrap()
Definition: PEFile.cpp:101
SectionHdrWrapper * getLastSection()
Definition: PEFile.cpp:488
OptHdrWrapper * optHdr
Definition: PEFile.h:195
virtual offset_t rvaToRaw(offset_t rva)
Definition: PEFile.cpp:341
BufferView * createSectionView(size_t secNum)
Definition: PEFile.cpp:376
bool setHdrSectionsNum(size_t newNum)
Definition: PEFile.cpp:284
bool setVirtualSize(bufsize_t newSize)
Definition: PEFile.cpp:295
DataDirEntryWrapper * getDataDirEntry(pe::dir_entry eType)
Definition: PEFile.cpp:370
bool moveDataDirEntry(pe::dir_entry id, offset_t newOffset, Executable::addr_type addType=Executable::RAW)
Definition: PEFile.cpp:392
virtual void clearWrappers()
Definition: PEFile.cpp:88
IMAGE_DATA_DIRECTORY * getDataDirectory()
Definition: PEFile.cpp:229
virtual offset_t rawToRva(offset_t raw)
Definition: PEFile.cpp:314
bufsize_t hdrsSize()
Definition: PEFile.h:93
offset_t secHdrsEndOffset() const
Definition: PEFile.h:83
size_t hdrSectionsNum() const
Definition: PEFile.cpp:275
virtual bufsize_t getAlignment(Executable::addr_type aType)
Definition: PEFile.h:70
PEFile(AbstractByteBuffer *v_buf)
Definition: PEFile.cpp:79
SectionHdrWrapper * getSecHdrAtOffset(offset_t offset, Executable::addr_type aType, bool roundup, bool verbose=false)
Definition: PEFile.h:114
static long computeChecksum(BYTE *buffer, size_t bufferSize, size_t checksumOffset)
Definition: PEFile.cpp:44
pe::RICH_SIGNATURE * getRichHeaderSign()
Definition: PEFile.cpp:181
bool canAddNewSection()
Definition: PEFile.cpp:427
DosHdrWrapper * dosHdrWrapper
Definition: PEFile.h:192
static size_t SECT_COUNT_MAX
bufsize_t getContentSize(Executable::addr_type aType, bool roundup)
offset_t getContentOffset(Executable::addr_type aType, bool useMapped=true)
bufsize_t getMappedRawSize()
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)