BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
ImportDirWrapper.h
Go to the documentation of this file.
1#pragma once
2
4#include "pe_formats.h"
5
6/*
7typedef struct _IMAGE_THUNK_DATA32 {
8 union {
9 DWORD ForwarderString; // PBYTE
10 DWORD Function; // PDWORD
11 DWORD Ordinal;
12 DWORD AddressOfData; // PIMAGE_IMPORT_BY_NAME
13 } u1;
14} IMAGE_THUNK_DATA32;
15
16typedef struct _IMAGE_THUNK_DATA64 {
17 union {
18 ULONGLONG ForwarderString; // PBYTE
19 ULONGLONG Function; // PDWORD
20 ULONGLONG Ordinal;
21 ULONGLONG AddressOfData; //PIMAGE_IMPORT_BY_NAME
22 } u1;
23} IMAGE_THUNK_DATA64;
24*/
25
29
31{
32public:
34 : ImportBaseDirWrapper(pe, pe::DIR_IMPORT) { wrap(); }
35
36 virtual void* getPtr() { return firstDescriptor(); }
37 virtual bufsize_t getSize();
38 virtual QString getName() { return "Imports"; }
39
40protected:
41 virtual bool loadNextEntry(size_t cntr);
42
43 IMAGE_DATA_DIRECTORY* getDataDirectory();
44 IMAGE_IMPORT_DESCRIPTOR *firstDescriptor();
45
46friend class ImportEntryWrapper;
47};
48
49
51{
52public:
53 /* fields :*/
63
64 ImportEntryWrapper(PEFile *pe, ImportDirWrapper *importsDir, size_t entryNumber)
65 : ImportBaseEntryWrapper(pe, importsDir, entryNumber) { wrap(); }
66
67 //virtual bool wrap();
68 //bool isValid();
69
70 /* full structure boundaries */
71 virtual void* getPtr();
72
73 virtual bufsize_t getSize();
74 bool isBound();
75 virtual QString getName();
76 virtual size_t getFieldsCount() { return FIELD_COUNTER; }
77
78 /* specific field boundaries */
79 virtual void* getFieldPtr(size_t fieldId, size_t subField = FIELD_NONE);
80 virtual QString getFieldName(size_t fieldId);
81 virtual Executable::addr_type containsAddrType(size_t fieldId, size_t subField = FIELD_NONE);
82
84 {
85 if (m_Exe == NULL) return 0;
87 }
88
90 {
91 offset_t nextOffset = INVALID_ADDR;
92 //get after existing entries:
93 if (this->getEntriesCount() > 0) {
95 }
96 //get by thunk:
97 IMAGE_IMPORT_DESCRIPTOR* desc = (IMAGE_IMPORT_DESCRIPTOR*) this->getPtr();
98 if (!desc) return INVALID_ADDR;
99
100 offset_t firstThunk = desc->FirstThunk;
101 if (firstThunk == 0) {
102 firstThunk = desc->OriginalFirstThunk;
103 }
104 nextOffset = m_Exe->convertAddr(desc->FirstThunk, Executable::RVA, Executable::RAW);
105 return nextOffset;
106 }
107
108 char* getLibraryName();
109
110protected:
111 bool loadNextEntry(size_t entryNum);
112
113friend class ImportDirWrapper;
114};
115
117{
118public:
119 /* fields :*/
128
129 ImportedFuncWrapper(PEFile *pe, ImportEntryWrapper* parentLib, size_t entryNumber)
130 : ImportBaseFuncWrapper(pe, parentLib, entryNumber) {}// this->parentLib = parentLib; }
131
132 /* full structure boundaries */
133 virtual void* getPtr();
134 virtual IMAGE_IMPORT_BY_NAME* getImportByNamePtr();
135
136 virtual bufsize_t getSize();
137 //virtual QString getName();
138 virtual size_t getFieldsCount() { return FIELD_COUNTER; }
139 virtual size_t getSubFieldsCount() { return 1; }
140
141 /* specific field boundaries */
142 virtual void* getFieldPtr(size_t fieldId, size_t subField = FIELD_NONE);
143 virtual bufsize_t getFieldSize(size_t fieldId, size_t subField = FIELD_NONE);
144 virtual QString getFieldName(size_t fieldId);
145 virtual Executable::addr_type containsAddrType(size_t fieldId, size_t subField = FIELD_NONE);
146
147 uint64_t getThunkValue();
148
151
153 bool isByOrdinal();
154 virtual uint64_t getOrdinal() { return getThunkValue(); }
155 char* getFunctionName();
156
157friend class ImportDirWrapper;
158};
159
uint32_t bufsize_t
const offset_t INVALID_ADDR
uint64_t offset_t
#define FIELD_NONE
virtual offset_t getNextEntryOffset()
virtual size_t getEntriesCount()
virtual exe_bits getBitMode()
Definition Executable.h:56
virtual offset_t convertAddr(offset_t inAddr, Executable::addr_type inType, Executable::addr_type outType)
static bufsize_t thunkSize(Executable::exe_bits bits)
bool wrap()
ImportDirWrapper(PEFile *pe)
IMAGE_DATA_DIRECTORY * getDataDirectory()
virtual void * getPtr()
virtual QString getName()
virtual bufsize_t getSize()
virtual bool loadNextEntry(size_t cntr)
IMAGE_IMPORT_DESCRIPTOR * firstDescriptor()
bool isBound()
FieldID
@ FIRST_THUNK
@ FORWARDER
@ ORIG_FIRST_THUNK
@ NONE
@ NAME
@ TIMESTAMP
@ FIELD_COUNTER
virtual QString getName()
bufsize_t geEntrySize()
char * getLibraryName()
virtual QString getFieldName(size_t fieldId)
ImportEntryWrapper(PEFile *pe, ImportDirWrapper *importsDir, size_t entryNumber)
bool loadNextEntry(size_t entryNum)
virtual size_t getFieldsCount()
virtual void * getPtr()
virtual Executable::addr_type containsAddrType(size_t fieldId, size_t subField=FIELD_NONE)
virtual void * getFieldPtr(size_t fieldId, size_t subField=FIELD_NONE)
virtual offset_t getNextEntryOffset()
virtual bufsize_t getSize()
virtual uint64_t getOrdinal()
virtual void * getFieldPtr(size_t fieldId, size_t subField=FIELD_NONE)
ImportedFuncWrapper(PEFile *pe, ImportEntryWrapper *parentLib, size_t entryNumber)
virtual void * getPtr()
virtual bufsize_t getSize()
virtual Executable::addr_type containsAddrType(size_t fieldId, size_t subField=FIELD_NONE)
virtual size_t getFieldsCount()
virtual QString getFieldName(size_t fieldId)
void * getValuePtr(ImportEntryWrapper::FieldID fId)
offset_t getFieldRVA(ImportEntryWrapper::FieldID fId)
virtual offset_t callVia()
virtual IMAGE_IMPORT_BY_NAME * getImportByNamePtr()
virtual size_t getSubFieldsCount()
virtual bufsize_t getFieldSize(size_t fieldId, size_t subField=FIELD_NONE)