PE-sieve
Scans all running processes. Recognizes and dumps a variety of potentially malicious implants (replaced/implanted PEs, shellcodes, hooks, in-memory patches).
Loading...
Searching...
No Matches
iat_block.h
Go to the documentation of this file.
1#pragma once
2
3#include <peconv.h>
4
5#include <sstream>
6#include <map>
7#include <set>
8
9namespace pesieve {
10
12 {
13 public:
14 IATThunksSeries(DWORD start_offset)
15 : startOffset(start_offset), cov(nullptr), covered(false)
16 {
17 }
18
20 {
21 delete cov;
22 }
23
24 bool operator<(const IATThunksSeries &other) const
25 {
26 return startOffset < other.startOffset;
27 }
28
29 bool insert(DWORD rva, ULONGLONG funcAddr)
30 {
31 rvaToFuncVA[rva] = funcAddr;
32 funcAddresses.insert(funcAddr);
33 return true;
34 }
35
36 bool makeCoverage(IN const peconv::ExportsMapper* exportsMap);
37
38 bool isCovered()
39 {
40 return covered;
41 }
42
43 std::string getDllName();
44
45 //calculate the number of bytes required for filling imports names
46 size_t sizeOfNamesSpace(bool is64b);
47
48 // fill the buffer with imports thunks and names
49 bool fillNamesSpace(const BYTE* buf_start, size_t buf_size, DWORD bufRVA, bool is64b);
50
51 std::map<DWORD, ULONGLONG> getRvaToFuncMap()
52 {
53 return rvaToFuncVA;
54 }
55
57
58 private:
59 bool covered;
60 std::string dllFullName;
61 std::set<ULONGLONG> funcAddresses;
62 std::map<DWORD, ULONGLONG> rvaToFuncVA;
63
64 peconv::ImportedDllCoverage *cov;
65 };
66
68 {
69 bool operator()(const IATThunksSeries* lhs, const IATThunksSeries* rhs) const
70 {
71 if (!lhs || !rhs) return false;
72 return *lhs < *rhs;
73 }
74 };
75
76 typedef std::set<IATThunksSeries*, IATThunksSeriesPtrCompare> IATThunksSeriesSet;
77
79 {
80 public:
81 IATBlock(bool _is64bit, DWORD _iat_offset)
82 : is64bit(_is64bit),
83 iatOffset(_iat_offset), iatSize(0),
84 isInMain(false), isTerminated(false), isCoverageComplete(false),
86 {
87 }
88
90 {
92 }
93
94 bool operator<(const IATBlock &other) const
95 {
96 return iatOffset < other.iatOffset;
97 }
98
100 {
101 thunkSeries.insert(series);
102 }
103
104 bool append(ULONGLONG offset, ULONGLONG functionVA, const peconv::ExportedFunc *exp)
105 {
106 if (!exp) return false;
107
108 functions[offset] = exp;
109 addrToFunctionVA[offset] = functionVA;
110 return true;
111 }
112
113 bool isCovered() const
114 {
115 return isCoverageComplete;
116 }
117
118 bool isValid() const
119 {
120 //allow for every block with complete coverage
121 return isCovered();
122 }
123
124 //how many functions the IAT has
125 size_t countThunks() const
126 {
127 return functions.size();
128 }
129
130 std::string toString();
131
133 {
134 IATThunksSeriesSet::iterator itr;
135 for (itr = this->thunkSeries.begin(); itr != thunkSeries.end(); ++itr) {
136 delete *itr;
137 }
138 thunkSeries.clear();
139 }
140
141 bool makeCoverage(IN const peconv::ExportsMapper* exportsMap);
142
143 size_t maxDllLen();
144 size_t sizeOfDllsSpace();
145
146 bool isTerminated; // is the IAT finished by 0
147 bool isInMain; // is the IAT included in the one set in the Data Directory
148
150 size_t iatSize;
151
153
154 protected:
155 IATThunksSeriesSet splitSeries(IN IATThunksSeries* notCoveredSeries, IN const peconv::ExportsMapper& exportsMap);
156
158
161
162 std::map<ULONGLONG, const peconv::ExportedFunc*> functions;
163 std::map<ULONGLONG, ULONGLONG> addrToFunctionVA;
164
165 friend class ImpReconstructor;
166 };
167
168};
IATBlock(bool _is64bit, DWORD _iat_offset)
Definition iat_block.h:81
std::map< ULONGLONG, const peconv::ExportedFunc * > functions
Definition iat_block.h:162
size_t countThunks() const
Definition iat_block.h:125
bool operator<(const IATBlock &other) const
Definition iat_block.h:94
bool isValid() const
Definition iat_block.h:118
bool isCovered() const
Definition iat_block.h:113
DWORD importTableOffset
Definition iat_block.h:152
bool append(ULONGLONG offset, ULONGLONG functionVA, const peconv::ExportedFunc *exp)
Definition iat_block.h:104
void deleteThunkSeries()
Definition iat_block.h:132
std::string toString()
void appendSeries(IATThunksSeries *series)
Definition iat_block.h:99
size_t sizeOfDllsSpace()
bool makeCoverage(IN const peconv::ExportsMapper *exportsMap)
IATThunksSeriesSet thunkSeries
Definition iat_block.h:157
std::map< ULONGLONG, ULONGLONG > addrToFunctionVA
Definition iat_block.h:163
IATThunksSeriesSet splitSeries(IN IATThunksSeries *notCoveredSeries, IN const peconv::ExportsMapper &exportsMap)
bool makeCoverage(IN const peconv::ExportsMapper *exportsMap)
Definition iat_block.cpp:25
IATThunksSeries(DWORD start_offset)
Definition iat_block.h:14
bool insert(DWORD rva, ULONGLONG funcAddr)
Definition iat_block.h:29
bool operator<(const IATThunksSeries &other) const
Definition iat_block.h:24
size_t sizeOfNamesSpace(bool is64b)
Definition iat_block.cpp:78
bool fillNamesSpace(const BYTE *buf_start, size_t buf_size, DWORD bufRVA, bool is64b)
Definition iat_block.cpp:39
std::map< DWORD, ULONGLONG > getRvaToFuncMap()
Definition iat_block.h:51
std::set< IATThunksSeries *, IATThunksSeriesPtrCompare > IATThunksSeriesSet
Definition iat_block.h:76
bool operator()(const IATThunksSeries *lhs, const IATThunksSeries *rhs) const
Definition iat_block.h:69