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->cov->addrToFunc.size();
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 std::map<ULONGLONG, std::set<peconv::ExportedFunc>>::iterator itr;
59 for (itr = this->cov->addrToFunc.begin(); itr != cov->addrToFunc.end() && buf < buf_end; ++itr) {
61 std::set<peconv::ExportedFunc> &expSet = itr->second;
62 const peconv::ExportedFunc& exp = *(expSet.begin());
64 ULONGLONG *val = (ULONGLONG*)buf;
68 DWORD *val = (DWORD*)buf;
73 names_rva +=
sizeof(IMAGE_IMPORT_BY_NAME) + longest_name;
82 size_t space_size = 0;
83 if (!this->cov->isMappingComplete()) {
87 const size_t field_size = is64b ?
sizeof(ULONGLONG) :
sizeof(DWORD);
88 std::map<ULONGLONG, std::set<peconv::ExportedFunc>>::iterator itr;
89 for (itr = this->cov->addrToFunc.begin(); itr != cov->addrToFunc.end(); ++itr) {
90 std::set<peconv::ExportedFunc> &expSet = itr->second;
91 const peconv::ExportedFunc& exp = *(expSet.begin());
92 space_size += field_size;
93 space_size +=
sizeof(IMAGE_IMPORT_BY_NAME) + longest_name;
96 space_size +=
sizeof(field_size);
110 if (!exportsMap)
return false;
112 IATThunksSeriesSet::iterator itr;
113 std::set<IATThunksSeries*>to_split;
115 for (itr = this->thunkSeries.begin(); itr != thunkSeries.end(); ++itr) {
118 to_split.insert(series);
122 std::set<IATThunksSeries*>::iterator sItr;
123 for (sItr = to_split.begin(); sItr != to_split.end(); ++sItr) {
126 if (!splitted.size()) {
130 std::cout <<
"Uncovered series splitted into: " << splitted.size() <<
" series\n";
132 this->thunkSeries.erase(series);
133 this->thunkSeries.insert(splitted.begin(), splitted.end());
138 size_t covered_count = 0;
139 for (itr = this->thunkSeries.begin(); itr != thunkSeries.end(); ++itr) {
147 isCoverageComplete = (covered_count == this->thunkSeries.size());
148 return isCoverageComplete;
154 if (!series)
return splitted;
156 std::map<DWORD, ULONGLONG> addresses = series->getRvaToFuncMap();
159 std::map<DWORD, ULONGLONG>::iterator itr;
160 std::string last_dll =
"";
162 for (itr = addresses.begin(); itr != addresses.end(); ++itr) {
163 ULONGLONG func_addr = itr->second;
164 DWORD offset = itr->first;
165 const peconv::ExportedFunc *func = exportsMap.find_export_by_va(func_addr);
166 if (new_series && (!func || func->libName != last_dll)) {
168 splitted.insert(new_series);
169 new_series =
nullptr;
176 last_dll = func->libName;
178 std::cout << std::hex <<
"addr: " << offset <<
" set DLL: " << last_dll <<
"\n";
181 new_series->
insert(offset, func_addr);
184 splitted.insert(new_series);
209 std::stringstream stream;
210 stream <<
"---\nIAT at: " << std::hex << iatOffset <<
", size: " << iatSize <<
", thunks: "
211 << countThunks() <<
", is_terminated: " << isTerminated <<
", in_main: " << isInMain <<
"\n";
213 if (this->importTableOffset) {
214 stream <<
"ImportTable: " << std::hex << importTableOffset <<
"\n";
217 std::map<ULONGLONG, const peconv::ExportedFunc*>::const_iterator itr;
218 for (itr = functions.begin(); itr != functions.end(); ++itr) {
219 ULONGLONG offset = itr->first;
220 const peconv::ExportedFunc* exp = itr->second;
222 stream << std::hex << offset <<
"," << addrToFunctionVA[offset] <<
"," << exp->toString() <<
"\n";