8 std::map<ULONGLONG, std::set<peconv::ExportedFunc>>::iterator itr;
9 for (itr = addrToFunc.begin(); itr != addrToFunc.end(); ++itr) {
10 std::set<peconv::ExportedFunc> &expSet = itr->second;
11 const peconv::ExportedFunc& exp = *(expSet.begin());
12 if (exp.isByOrdinal) {
15 if (exp.funcName.length() > max_len) {
16 max_len = exp.funcName.length();
28 cov =
new peconv::ImportedDllCoverage(funcAddresses, *exportsMap);
29 if (!cov->findCoveringDll()) {
33 size_t covered_count = cov->mapAddressesToFunctions(cov->dllName);
34 this->dllFullName = exportsMap->get_dll_fullname(cov->dllName);
35 this->covered = (covered_count == this->funcAddresses.size());
41 if (!buf_start || !this->cov)
return false;
43 if (!this->cov->isMappingComplete()) {
48 const size_t field_size = is64b ?
sizeof(ULONGLONG) :
sizeof(DWORD);
50 const size_t thunks_count = this->
funcCount();
51 const size_t thunks_area_size = (thunks_count * field_size) + field_size;
53 size_t names_rva = bufRVA + thunks_area_size;
56 BYTE *buf =
const_cast<BYTE*
>(buf_start);
57 const BYTE *buf_end = buf_start + buf_size;
58 for (
size_t i = 0; i < thunks_count; i++) {
61 std::cerr <<
"ERR: run out of buffer for names! Failed to make space for the name\n";
66 ULONGLONG *val = (ULONGLONG*)buf;
70 DWORD *val = (DWORD*)buf;
75 names_rva +=
sizeof(IMAGE_IMPORT_BY_NAME) + longest_name;
84 size_t space_size = 0;
85 if (!this->cov->isMappingComplete()) {
89 const size_t field_size = is64b ?
sizeof(ULONGLONG) :
sizeof(DWORD);
90 const size_t entriesCount = this->
funcCount();
91 for (
size_t i = 0; i < entriesCount; i++) {
92 space_size += field_size;
93 space_size +=
sizeof(IMAGE_IMPORT_BY_NAME) + longest_name;
96 space_size +=
sizeof(field_size);
103 return this->dllFullName;
110 if (!exportsMap)
return false;
112 IATThunksSeriesSet::iterator itr;
113 std::set<IATThunksSeries*>to_split;
119 to_split.insert(series);
123 std::set<IATThunksSeries*>::iterator sItr;
124 for (sItr = to_split.begin(); sItr != to_split.end(); ++sItr) {
127 if (!splitted.size()) {
131 std::cout <<
"Uncovered series: " << std::hex << series->
startOffset <<
" splitted into: " << std::dec << splitted.size() <<
" series\n";
135 this->
thunkSeries.insert(splitted.begin(), splitted.end());
140 size_t covered_count = 0;
151 total += (*it1)->funcCount();
153 std::cout <<
"[#] IAT block: " << std::hex << this->
iatOffset <<
" Total: " << std::dec << total <<
" Missed: " << (this->
countThunks() - total) << std::endl;
162 if (!series)
return splitted;
164 std::map<DWORD, ULONGLONG> addresses = series->getRvaToFuncMap();
167 std::map<DWORD, ULONGLONG>::iterator itr;
168 std::string last_dll =
"";
170 for (itr = addresses.begin(); itr != addresses.end(); ++itr) {
171 ULONGLONG func_addr = itr->second;
172 DWORD offset = itr->first;
173 const peconv::ExportedFunc *func = exportsMap.find_export_by_va(func_addr);
174 if (new_series && (!func || func->libName != last_dll)) {
176 splitted.insert(new_series);
177 new_series =
nullptr;
184 last_dll = func->libName;
186 std::cout << std::hex <<
"addr: " << offset <<
" set DLL: " << last_dll <<
"\n";
189 new_series->
insert(offset, func_addr);
192 splitted.insert(new_series);
200 IATThunksSeriesSet::iterator itr;
203 size_t curr_size = series->
getDllName().length() + 1;
204 if (curr_size > max_size) max_size = curr_size;
217 std::stringstream stream;
218 stream <<
"---\nIAT at: " << std::hex <<
iatOffset <<
", size: " <<
iatSize <<
", thunks: "
225 std::map<ULONGLONG, const peconv::ExportedFunc*>::const_iterator itr;
227 ULONGLONG offset = itr->first;
228 const peconv::ExportedFunc* exp = itr->second;
230 stream << std::hex << offset <<
"," <<
addrToFunctionVA[offset] <<
"," << exp->toString() <<
"\n";
std::map< ULONGLONG, const peconv::ExportedFunc * > functions
size_t countThunks() const
bool makeCoverage(IN const peconv::ExportsMapper *exportsMap)
IATThunksSeriesSet thunkSeries
std::map< ULONGLONG, ULONGLONG > addrToFunctionVA
IATThunksSeriesSet splitSeries(IN IATThunksSeries *notCoveredSeries, IN const peconv::ExportsMapper &exportsMap)
bool makeCoverage(IN const peconv::ExportsMapper *exportsMap)
bool insert(DWORD rva, ULONGLONG funcAddr)
size_t sizeOfNamesSpace(bool is64b)
bool fillNamesSpace(const BYTE *buf_start, size_t buf_size, DWORD bufRVA, bool is64b)
#define MASK_TO_DWORD(val)
size_t get_longest_func_name(std::map< ULONGLONG, std::set< peconv::ExportedFunc > > &addrToFunc)
std::set< IATThunksSeries *, IATThunksSeriesPtrCompare > IATThunksSeriesSet