BearParser
Portable Executable parsing library (from PE-bear)
ResourceStringsWrapper.cpp
Go to the documentation of this file.
2 
4 {
5  return this->sizePtr;
6 }
7 
9  WORD* len = this->sizePtr;
10  if (len == NULL) return 0;
11  return (*len) * sizeof(WORD) + sizeof(WORD);
12 }
13 
15 {
16  return getQString();
17 }
18 
19 /* specific field boundatries */
20 void* ResString::getFieldPtr(size_t fId, size_t subField)
21 {
22  switch (fId) {
23  case STR_LEN: return this->sizePtr;
24  case WSTRING:
25  {
26  bufsize_t size = (sizePtr == NULL) ? 0 : static_cast<bufsize_t>(*sizePtr);
27  WORD *content = (WORD*) this->m_Exe->getContentAt(offset,Executable::RAW, size);
28  return content;
29  }
30  }
31  return this->getPtr();
32 }
33 
34 QString ResString::getFieldName(size_t fId)
35 {
36  switch (fId) {
37  case STR_LEN: return "Length";
38  case WSTRING: return "WString";
39  }
40  return "";
41 }
42 
43 bufsize_t ResString::getFieldSize(size_t fId, size_t subField)
44 {
45  switch (fId) {
46  case STR_LEN: return sizeof(WORD);
47  case WSTRING:
48  {
49  WORD* len = this->sizePtr;
50  if (len == NULL) return 0;
51  return (*len) * sizeof(WORD);
52  }
53  }
54  return 0;
55 }
56 //------------------------------------------------------
58 
60 {
61  clear();
62  this->parsedSize = 0;
63 
64  BYTE *c = static_cast<BYTE*>(this->getPtr());
65  if (!c) {
66  return false;
67  }
68  size_t maxSize = this->getSize();
69  //printf("maxSize = %x\n", maxSize);
70  offset_t startRaw = getContentRaw();
71  offset_t cRaw = startRaw;
72 
73  for (size_t i = 0; i < ResourceStringsWrapper::EntriesLimit && parsedSize < maxSize; i++) {
74 
75  WORD* stringSize = (WORD*) this->getContentAt(cRaw, Executable::RAW, sizeof(WORD));
76  if (stringSize == NULL){
77  printf("Cannot fetch the string size!\n");
78  break;
79  }
80  this->parsedSize += sizeof(WORD);
81  cRaw += sizeof(WORD);
82 
83  size_t wStrSize = (*stringSize);
84  if (wStrSize == 0) {
85  continue;
86  }
87  bufsize_t totalStrSize = wStrSize * sizeof(WORD);
88 
89  WORD* uStringPtr = (WORD*) this->getContentAt(cRaw, Executable::RAW, totalStrSize);
90  if (uStringPtr == NULL) break;
91 
92  Executable *exe = this->myLeaf->getExe();
93  ResString *rStr = new ResString(uStringPtr, stringSize, cRaw, exe);
94  this->entries.push_back(rStr);
95 
96  this->parsedSize += totalStrSize;
97  cRaw += totalStrSize;
98  }
99  return true;
100 }
101 
103 {
104  return "ResourceString";
105 }
106 
107 void* ResourceStringsWrapper::getFieldPtr(size_t fId, size_t subField)
108 {
109  if (fId >= this->entries.size()) return NULL;
110  return this->entries[fId]->getFieldPtr(subField);
111 }
112 
114 {
115  if (fId >= this->entries.size()) return 0;
116  return this->entries[fId]->getFieldSize(subField);
117 }
118 
uint32_t bufsize_t
uint64_t offset_t
std::vector< ExeNodeWrapper * > entries
virtual void clear()
BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
Definition: Executable.h:57
virtual QString getFieldName(size_t fieldId)
virtual void * getFieldPtr(size_t fieldId, size_t subField)
virtual bufsize_t getFieldSize(size_t fId, size_t subField)
virtual bufsize_t getSize()
virtual void * getPtr()
QString getQString()
virtual QString getName()
BYTE * getContentAt(offset_t dataAddr, Executable::addr_type aT, bufsize_t dataSize)
ResourceLeafWrapper * myLeaf
virtual bufsize_t getSize()
virtual void * getFieldPtr(size_t fieldId, size_t subField)
virtual bufsize_t getFieldSize(size_t fieldId, size_t subField=FIELD_NONE)
virtual QString getFieldName(size_t fieldId)