11std::map<DWORD, QString> SectionHdrWrapper::s_secHdrCharact;
15 char rights[] =
"---";
17 if (characteristics & SCN_MEM_READ)
19 if (characteristics & SCN_MEM_WRITE)
21 if (characteristics & SCN_MEM_EXECUTE)
28 secHdrCharact[SCN_MEM_READ] =
"readable";
29 secHdrCharact[SCN_MEM_WRITE] =
"writeable";
30 secHdrCharact[SCN_MEM_EXECUTE] =
"executable";
32 secHdrCharact[SCN_LNK_NRELOC_OVFL] =
"contains extended relocations";
33 secHdrCharact[SCN_MEM_DISCARDABLE] =
"discardable";
34 secHdrCharact[SCN_MEM_NOT_CACHED] =
"not cachable";
35 secHdrCharact[SCN_MEM_NOT_PAGED] =
"non-pageable";
36 secHdrCharact[SCN_MEM_SHARED] =
"shareable";
37 secHdrCharact[SCN_CNT_CODE] =
"code";
38 secHdrCharact[SCN_CNT_INITIALIZED_DATA] =
"initialized data";
39 secHdrCharact[SCN_CNT_UNINITIALIZED_DATA] =
"uninitialized data";
44 if (s_secHdrCharact.size() == 0) {
47 std::vector<DWORD> chSet;
48 std::map<DWORD, QString>::iterator iter;
49 for (iter = s_secHdrCharact.begin(); iter != s_secHdrCharact.end(); ++iter) {
50 if (charact & iter->first) {
51 chSet.push_back(iter->first);
59 if (s_secHdrCharact.size() == 0) {
63 if (s_secHdrCharact.find(charact) == s_secHdrCharact.end())
return "";
64 return s_secHdrCharact[charact];
81 if (
m_PE == NULL)
return NULL;
84 return (
void*) this->header;
88 offset_t secOffset = firstSecOffset + (this->
sectNum *
sizeof(IMAGE_SECTION_HEADER));
91 this->header = (IMAGE_SECTION_HEADER*)
m_PE->
getContentAt(secOffset,
sizeof(IMAGE_SECTION_HEADER));
92 return (
void*) this->header;
97 IMAGE_SECTION_HEADER* header = (IMAGE_SECTION_HEADER*)
getPtr();
98 if (!header)
return false;
107 this->
name = (
char*)::calloc(BUF_LEN, 1);
109 ::memset(this->
name, 0, BUF_LEN);
120 if (
m_PE == NULL)
return 0;
121 return sizeof(IMAGE_SECTION_HEADER);
127 if (!this->
name)
return "";
133 IMAGE_SECTION_HEADER* sec = (IMAGE_SECTION_HEADER*)
getPtr();
134 if (!sec)
return NULL;
135 if (!this->
name)
return NULL;
138 case NAME:
return (
void*) &sec->Name;
139 case VSIZE:
return (
void*) &sec->Misc.VirtualSize;
140 case VPTR:
return (
void*) &sec->VirtualAddress;
141 case RSIZE:
return (
void*) &sec->SizeOfRawData;
142 case RPTR:
return(
void*) &sec->PointerToRawData;
144 case RELOC_PTR:
return (
void*) &sec->PointerToRelocations;
145 case RELOC_NUM:
return (
void*) &sec->NumberOfRelocations;
146 case LINENUM_PTR:
return (
void*) &sec->PointerToLinenumbers;
147 case LINENUM_NUM:
return (
void*) &sec->NumberOfLinenumbers;
149 case CHARACT:
return (
void*) &sec->Characteristics;
158 case NAME:
return "Name";
159 case VSIZE:
return "Virtual Size";
160 case VPTR:
return "Virtual Addr.";
161 case RSIZE:
return "Raw size";
162 case RPTR:
return "Raw Addr.";
163 case CHARACT:
return "Characteristics";
185 if (fieldId ==
NAME) {
199 offset =
static_cast<offset_t>(this->header->PointerToRawData);
201 offset =
static_cast<offset_t>(this->header->VirtualAddress);
215 const offset_t rounded = units * align;
220 if (offset > peSize) {
229 const bool useMapped =
true;
240 if (this->header == NULL)
return 0;
244 size =
static_cast<bufsize_t>(this->header->SizeOfRawData);
246 size =
static_cast<bufsize_t>(this->header->Misc.VirtualSize);
261 if (secOffset > peSize) {
269 if (virtualSize == 0) {
272 if (virtualSize < rawSize) {
274 rawSize = virtualSize;
281 const bufsize_t secEnd = secOffset + rawSize;
283 if (secEnd > peSize) {
284 const bufsize_t trimmedSize = peSize - secOffset;
291 if ((virtualSize != 0) && (trimmedSize > virtualSize)) {
312 if (dVirtualSize == 0) {
317 bufsize_t mVirtualSize = (dVirtualSize > mRawSize) ? dVirtualSize : mRawSize;
323 bufsize_t secEnd = startOffset + mVirtualSize;
325 if (imgSize < startOffset) {
331 for (
size_t i = 0; i < secCounter; i++) {
337 if (currOffset > startOffset && currOffset < secEnd) {
342 if (secEnd > imgSize) {
343 const bufsize_t trimmedSize = imgSize - startOffset;
346 return (secEnd - startOffset);
351 if (!this->header || !
m_PE)
return 0;
377 if (sEntry == NULL) {
387 if (entrySize == 0)
return false;
396 if (
m_PE == NULL)
return NULL;
403 size_t count = secCount + 1;
410void SectHdrsWrapper::clear()
417bool SectHdrsWrapper::loadNextEntry(
size_t entryNum)
420 if (sec == NULL)
return false;
421 if (sec->
getPtr() == NULL) {
434 if (sec == NULL)
return;
435 bool recalculate =
true;
442 if (rSec.find(endRaw) != rSec.end()) {
444 if (prevSec == NULL)
return;
450 if (vSec.find(endRVA) != vSec.end()) {
452 if (prevSec == NULL)
return;
470 for (
size_t i = 0; i < count; i++) {
472 if (sec == NULL)
continue;
482 if (this->
m_PE == NULL)
return false;
485 if (this->loadNextEntry(i) ==
false)
break;
500 if (
entries.size() == 0)
return NULL;
508 if (this->
m_PE == NULL)
return 0;
510 size_t secCount = this->
entries.size();
511 if (!secCount)
return 0;
515 offset_t endOffset = hdrOffset + (secCount *
sizeof(IMAGE_SECTION_HEADER));
517 if (endOffset > fileSize) {
520 return bufsize_t (endOffset - hdrOffset);
531 if (fieldId >=
entries.size())
return NULL;
532 return entries[fieldId]->getName();
537 std::map<offset_t, SectionHdrWrapper*> *secMap = NULL;
540 secMap = &this->rSec;
542 secMap = &this->vSec;
544 if (!secMap)
return NULL;
546 std::map<offset_t, SectionHdrWrapper*>::iterator found = secMap->lower_bound(offset);
547 std::map<offset_t, SectionHdrWrapper*>::iterator itr;
548 for (itr = found; itr != secMap->end(); ++itr) {
550 if (sec == NULL)
continue;
552 printf(
"found [%llX] key: %llX sec: %llX %llX\n",
553 static_cast<unsigned long long>(offset),
554 static_cast<unsigned long long>(itr->first),
565 if (offset >= startOffset && offset < endOffset) {
568 if (offset < startOffset)
break;
575 std::map<offset_t, SectionHdrWrapper*> *secMap = NULL;
578 secMap = &this->rSec;
580 secMap = &this->vSec;
582 if (secMap == NULL)
return;
584 std::map<offset_t, SectionHdrWrapper*>::iterator itr;
585 for (itr = secMap->begin(); itr != secMap->end(); ++itr) {
589 printf(
"[%llX] %s %llX %llX\n",
590 static_cast<unsigned long long>(secEnd),
591 sec->
getName().toStdString().c_str(),
const offset_t INVALID_ADDR
virtual bufsize_t getContentSize()=0
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 getImageSize()
virtual bufsize_t getMappedSize(Executable::addr_type aType)
SectionHdrWrapper * _getSecHdr(size_t index) const
offset_t secHdrsOffset() const
bool setHdrSectionsNum(size_t newNum)
size_t hdrSectionsNum() const
virtual bufsize_t getAlignment(Executable::addr_type aType) const
size_t _getSectionsCount(bool useMapped=true) const
void printSectionsMapping(Executable::addr_type aType)
ExeNodeWrapper * addEntry(ExeNodeWrapper *entry)
virtual bufsize_t getSize()
virtual QString getFieldName(size_t fieldId)
SectionHdrWrapper * getSecHdrAtOffset(offset_t offset, Executable::addr_type addrType, bool roundup, bool verbose=false)
virtual void reloadMapping()
static size_t SECT_COUNT_MAX
static size_t SECT_INVALID_INDEX
virtual size_t getFieldsCount()
static std::vector< DWORD > splitCharacteristics(DWORD characteristics)
bufsize_t getMappedVirtualSize()
virtual QString getName()
virtual QString getFieldName(size_t fieldId)
offset_t getContentDeclaredOffset(Executable::addr_type aType)
static void initSecCharacter(std::map< DWORD, QString > &secHdrCharact)
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)
static QString translateCharacteristics(DWORD charact)
bufsize_t getContentSize(Executable::addr_type aType, bool recalculate)
offset_t getContentEndOffset(Executable::addr_type aType, bool roundup)
offset_t getContentOffset(Executable::addr_type aType, bool useMapped=true)
static QString getSecHdrAccessRightsDesc(DWORD characteristics)
bufsize_t getMappedRawSize()
static const size_t SECNAME_LEN
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)
size_t unitsCount(uint64_t value, uint64_t unit, bool roundup=true)