BearParser
Portable Executable parsing library (from PE-bear)
ExceptionDirWrapper.cpp
Go to the documentation of this file.
2#include "pe/PEFile.h"
3
4uint64_t ExceptionDirWrapper::EntriesLimit = 10000;
5
6/*
7typedef struct _IMAGE_IA64_RUNTIME_FUNCTION_ENTRY {
8 DWORD BeginAddress;
9 DWORD EndAddress;
10 DWORD UnwindInfoAddress;
11} IMAGE_IA64_RUNTIME_FUNCTION_ENTRY, *PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY;
12*/
13
15{
16 clear();
17 parsedSize = 0;
18 bufsize_t maxSize = getDirEntrySize();
19 if (maxSize == 0) return false; // nothing to parse
20
21 if (!exceptFunc64()) return false;
22
23 //printf("maxSize = %x\n", maxSize);
24 const size_t ENTRY_SIZE = sizeof(IMAGE_IA64_RUNTIME_FUNCTION_ENTRY);
25
26 for (int i = 0; i < ExceptionDirWrapper::EntriesLimit && parsedSize < maxSize; i++) {
27 ExceptionEntryWrapper* entry = new ExceptionEntryWrapper(this->m_Exe, this, i);
28
29 if (entry->getPtr() == NULL) {
30 delete entry;
31 break;
32 }
33 this->parsedSize += ENTRY_SIZE;
34 this->entries.push_back(entry);
35
36 /*printf("pageVA = %llx size = %llx\n",
37 entry->getNumValue(ExceptionEntryWrapper::PAGE_VA, &isOk),
38 entry->getNumValue(ExceptionEntryWrapper::BLOCK_SIZE, &isOk)
39 );*/
40 }
42 "Entries num = %lu, parsedSize = %lX",
43 static_cast<unsigned long>(entries.size()),
44 static_cast<unsigned long>(parsedSize)
45 );
46 return true;
47}
48
49IMAGE_IA64_RUNTIME_FUNCTION_ENTRY* ExceptionDirWrapper::exceptFunc64()
50{
52 BYTE *ptr = m_Exe->getContentAt(rva, Executable::RVA, sizeof(IMAGE_IA64_RUNTIME_FUNCTION_ENTRY));
53 if (ptr == NULL) return NULL;
54
55 IMAGE_IA64_RUNTIME_FUNCTION_ENTRY* exc = (IMAGE_IA64_RUNTIME_FUNCTION_ENTRY*) ptr;
56 return exc;
57}
58
59//----------------
60
62{
63 if (this->parentDir == NULL) return NULL;
64 IMAGE_IA64_RUNTIME_FUNCTION_ENTRY* first = this->parentDir->exceptFunc64();
65 if (!first) return NULL;
66
67 const size_t ENTRY_SIZE = sizeof(IMAGE_IA64_RUNTIME_FUNCTION_ENTRY);
68
69 uint64_t firstOffset = this->getOffset(first);
70 uint64_t myOffset = firstOffset + this->entryNum * ENTRY_SIZE;
71
72 BYTE *ptr = m_Exe->getContentAt(myOffset, Executable::RAW, ENTRY_SIZE);
73 return ptr;
74}
75
77{
78 if (this->parentDir == NULL) return 0;
79 if (this->getPtr() == NULL) return 0;
80
81 return sizeof(IMAGE_IA64_RUNTIME_FUNCTION_ENTRY);
82}
83
84void* ExceptionEntryWrapper::getFieldPtr(size_t fieldId, size_t subField)
85{
86 IMAGE_IA64_RUNTIME_FUNCTION_ENTRY* exc = (IMAGE_IA64_RUNTIME_FUNCTION_ENTRY*) this->getPtr();
87 if (!exc) return NULL;
88
89 switch (fieldId) {
90 case BEGIN_ADDR : return &exc->BeginAddress;
91 case END_ADDR : return &exc->EndAddress;
92 case UNWIND_INFO_ADDR : return &exc->UnwindInfoAddress;
93 }
94 return getPtr();
95}
96
98{
99 switch (fieldId) {
100 case BEGIN_ADDR : return "BeginAddress";
101 case END_ADDR : return "EndAddress";
102 case UNWIND_INFO_ADDR : return "UnwindInfoAddress";
103 }
104 return getName();
105}
106
108{
109 switch (fieldId) {
110 case BEGIN_ADDR :
111 case END_ADDR :
112 case UNWIND_INFO_ADDR :
113 return Executable::RVA;
114 }
116}
117
uint32_t bufsize_t
uint64_t offset_t
bufsize_t getDirEntrySize()
offset_t getDirEntryAddress()
friend class ExceptionEntryWrapper
IMAGE_IA64_RUNTIME_FUNCTION_ENTRY * exceptFunc64()
virtual void * getPtr()
virtual QString getName()
virtual void * getFieldPtr(size_t fieldId, size_t subField=FIELD_NONE)
@ BEGIN_ADDR
@ UNWIND_INFO_ADDR
@ END_ADDR
virtual Executable::addr_type containsAddrType(size_t fieldId, size_t subField)
virtual QString getFieldName(size_t fieldId)
virtual bufsize_t getSize()
std::vector< ExeNodeWrapper * > entries
virtual void clear()
BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
Definition: Executable.h:57
bool append(dbg_level lvl, const char *format,...)
Definition: Util.cpp:8
@ D_INFO
Definition: Util.h:26