21 if (
m_PE == NULL)
return NULL;
24 return (
void*) this->header;
30 offset_t secOffset = firstSecOffset + (this->
sectNum *
sizeof(IMAGE_SECTION_HEADER));
33 this->header = (IMAGE_SECTION_HEADER*)
m_PE->
getContentAt(secOffset,
sizeof(IMAGE_SECTION_HEADER));
34 return (
void*) this->header;
39 IMAGE_SECTION_HEADER* header = (IMAGE_SECTION_HEADER*)
getPtr();
40 if (!header)
return false;
49 char *buf =
new char[BUF_LEN];
50 memset(buf, 0, BUF_LEN);
51 snprintf(buf, BUF_LEN,
"%.8s", (
char*) header->Name);
62 if (
m_PE == NULL)
return 0;
63 return sizeof(IMAGE_SECTION_HEADER);
69 if (!this->
name)
return "";
75 IMAGE_SECTION_HEADER* sec = (IMAGE_SECTION_HEADER*)
getPtr();
76 if (!sec)
return NULL;
77 if (!this->
name)
return NULL;
80 case NAME:
return (
void*) &sec->Name;
81 case VSIZE:
return (
void*) &sec->Misc.VirtualSize;
82 case VPTR:
return (
void*) &sec->VirtualAddress;
83 case RSIZE:
return (
void*) &sec->SizeOfRawData;
84 case RPTR:
return(
void*) &sec->PointerToRawData;
86 case RELOC_PTR:
return (
void*) &sec->PointerToRelocations;
87 case RELOC_NUM:
return (
void*) &sec->NumberOfRelocations;
88 case LINENUM_PTR:
return (
void*) &sec->PointerToLinenumbers;
89 case LINENUM_NUM:
return (
void*) &sec->NumberOfLinenumbers;
91 case CHARACT:
return (
void*) &sec->Characteristics;
100 case NAME:
return "Name";
101 case VSIZE:
return "Virtual Size";
102 case VPTR:
return "Virtual Addr.";
103 case RSIZE:
return "Raw size";
104 case RPTR:
return "Raw Addr.";
105 case CHARACT:
return "Characteristics";
127 if (fieldId ==
NAME) {
141 offset =
static_cast<offset_t>(this->header->PointerToRawData);
143 offset =
static_cast<offset_t>(this->header->VirtualAddress);
157 if (offset < minAlign || offset > peSize) {
166 const bool useMapped =
true;
177 if (this->header == NULL)
return 0;
181 size =
static_cast<bufsize_t>(this->header->SizeOfRawData);
183 size =
static_cast<bufsize_t>(this->header->Misc.VirtualSize);
203 if (secOffset > peSize) {
211 const bufsize_t secEnd = secOffset + roundedUpSize;
214 if (secEnd > peSize) {
216 const bufsize_t trimmedSize = peSize - secOffset;
219 if (trimmedSize > virtualSize) {
224 return roundedUpSize;
239 bufsize_t mVirtualSize = (dVirtualSize > mRawSize) ? dVirtualSize : mRawSize;
251 if (this->header == NULL)
return 0;
252 if (
m_PE == NULL)
return 0;
278 if (sEntry == NULL) {
288 if (entrySize == 0)
return false;
297 if (
m_PE == NULL)
return NULL;
304 size_t count = secCount + 1;
321 if (sec == NULL)
return false;
322 if (sec->
getPtr() == NULL) {
335 if (sec == NULL)
return;
349 if (
rSec.find(endRaw) !=
rSec.end()) {
351 if (prevSec == NULL)
return;
367 for (
size_t i = 0; i < count; i++) {
369 if (sec == NULL)
continue;
377 if (this->
m_PE == NULL)
return false;
381 for (
size_t i = 0; i < count; i++) {
394 if (
entries.size() == 0)
return NULL;
400 if (this->
m_PE == NULL)
return 0;
406 offset_t endOffset = hdrOffset + (secCount *
sizeof(IMAGE_SECTION_HEADER));
408 if (endOffset > fileSize) {
411 return bufsize_t (endOffset - hdrOffset);
422 if (fieldId >=
entries.size())
return NULL;
423 return entries[fieldId]->getName();
428 size_t size = this->
entries.size();
429 std::map<offset_t, SectionHdrWrapper*> *secMap = NULL;
432 secMap = &this->
rSec;
434 secMap = &this->
vSec;
436 if (secMap == NULL)
return NULL;
438 std::map<offset_t, SectionHdrWrapper*>::iterator found = secMap->lower_bound(offset);
439 std::map<offset_t, SectionHdrWrapper*>::iterator itr;
440 for (itr = found; itr != secMap->end(); itr++) {
442 if (sec == NULL)
continue;
444 printf(
"found [%llX] key: %llX sec: %llX %llX\n",
445 static_cast<unsigned long long>(offset),
446 static_cast<unsigned long long>(itr->first),
457 if (offset >= startOffset && offset < endOffset) {
460 if (offset < startOffset)
break;
467 std::map<offset_t, SectionHdrWrapper*> *secMap = NULL;
470 secMap = &this->
rSec;
472 secMap = &this->
vSec;
474 if (secMap == NULL)
return;
476 std::map<offset_t, SectionHdrWrapper*>::iterator itr;
477 for (itr = secMap->begin(); itr != secMap->end(); itr++) {
481 printf(
"[%llX] %s %llX %llX\n",
482 static_cast<unsigned long long>(secEnd),
483 sec->
getName().toStdString().c_str(),
const offset_t INVALID_ADDR
bool isAreaEmpty(offset_t rawOffset, bufsize_t size)
virtual bufsize_t getContentSize()
ExeNodeWrapper * getLastEntry()
virtual ExeNodeWrapper * getEntryAt(size_t fieldId)
virtual bufsize_t geEntrySize()
std::vector< ExeNodeWrapper * > entries
virtual offset_t getNextEntryOffset()
virtual size_t getEntriesCount()
virtual ExeNodeWrapper * addEntry(ExeNodeWrapper *entry)
BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
virtual offset_t getRawSize() const
virtual bufsize_t getMappedSize(Executable::addr_type aType)
bool setHdrSectionsNum(size_t newNum)
virtual bufsize_t getAlignment(Executable::addr_type aType)
std::map< offset_t, SectionHdrWrapper * > rSec
void printSectionsMapping(Executable::addr_type aType)
ExeNodeWrapper * addEntry(ExeNodeWrapper *entry)
virtual bufsize_t getSize()
virtual bool loadNextEntry(size_t entryNum)
virtual QString getFieldName(size_t fieldId)
SectionHdrWrapper * getSecHdrAtOffset(offset_t offset, Executable::addr_type addrType, bool roundup, bool verbose=false)
bool isMyEntryType(ExeNodeWrapper *entry)
virtual void reloadMapping()
static size_t SECT_COUNT_MAX
std::map< offset_t, SectionHdrWrapper * > vSec
void addMapping(SectionHdrWrapper *sec)
virtual size_t getFieldsCount()
bufsize_t getMappedVirtualSize()
virtual QString getName()
virtual QString getFieldName(size_t fieldId)
bufsize_t getContentSize(Executable::addr_type aType, bool roundup)
offset_t getContentDeclaredOffset(Executable::addr_type aType)
virtual void * getFieldPtr(size_t fieldId, size_t subField=FIELD_NONE)
bufsize_t getContentDeclaredSize(Executable::addr_type aType)
virtual Executable::addr_type containsAddrType(size_t fieldId, size_t subField=FIELD_NONE)
offset_t getContentEndOffset(Executable::addr_type aType, bool roundup)
offset_t getContentOffset(Executable::addr_type aType, bool useMapped=true)
bufsize_t getMappedRawSize()
virtual WrappedValue::data_type containsDataType(size_t fieldId, size_t subField=FIELD_NONE)
virtual bufsize_t getSize()
bool append(dbg_level lvl, const char *format,...)
bufsize_t roundupToUnit(bufsize_t size, bufsize_t unit)
uint64_t roundup(uint64_t value, uint64_t unit)