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
scanned_modules.cpp
Go to the documentation of this file.
1#include "scanned_modules.h"
2
3#include <string>
4#include <iostream>
5#include <windows.h>
6#include <psapi.h>
7
8using namespace pesieve;
9
11{
12 if (lModule == nullptr) {
13 return false;
14 }
15 ULONGLONG start_addr = lModule->start;
16 if (this->modulesMap.find(start_addr) != this->modulesMap.end()) {
17 //already exist
18 return false;
19 }
20 modulesMap[start_addr] = lModule;
21 return true;
22}
23
25{
26 if (!report || report->moduleSize == 0) {
27 return false; //skip
28 }
30 ScannedModule* mod = this->getModuleAt(module_start);
31 if (mod == nullptr) {
32 //create new only if it was not found
33 mod = new ScannedModule(module_start, report->moduleSize);
34 if (!this->appendModule(mod)) {
35 delete mod; //delete the module as it was not appended
36 return false;
37 }
38 }
39 if (mod->moduleName == "") {
40 mod->moduleName = peconv::get_file_name(report->moduleFile);
41 }
42 size_t old_size = mod->getSize();
43 if (old_size < report->moduleSize) {
44 mod->resize(report->moduleSize);
45 }
46 if (!mod->isSuspicious()) {
47 //update the status
48 mod->setSuspicious(report->status == SCAN_SUSPICIOUS);
49 }
50 return true;
51}
52
54{
55 const ULONGLONG field_end = address + size;
56
57 // the first element that is greater than the start address
58 std::map<ULONGLONG, ScannedModule*>::const_iterator firstGreater = modulesMap.upper_bound(address);
59
60 std::map<ULONGLONG, ScannedModule*>::const_iterator itr;
61 for (itr = modulesMap.begin(); itr != firstGreater; ++itr) {
62 ScannedModule *module = itr->second;
63 if (!module) continue; //this should never happen
64
65 if (address >= module->getStart() && field_end <= module->getEnd()) {
66 // Address found in module:
67 return module;
68 }
69 }
70 return nullptr;
71}
72
74{
75 std::map<ULONGLONG, ScannedModule*>::iterator itr = modulesMap.begin();
76 for (; itr != modulesMap.end(); ++itr ) {
77 const ScannedModule *module = itr->second;
78 delete module;
79 }
80 this->modulesMap.clear();
81}
82
84{
85 std::map<ULONGLONG, ScannedModule*>::const_iterator start_itr = modulesMap.begin();
86 std::map<ULONGLONG, ScannedModule*>::const_iterator stop_itr = modulesMap.upper_bound(address);
87 std::map<ULONGLONG, ScannedModule*>::const_iterator itr = start_itr;
88
89 size_t max_size = 0;
90
91 for (; itr != stop_itr; ++itr) {
92 ScannedModule *module = itr->second;
93 if (address >= module->start && address < module->getEnd()) {
94 ULONGLONG diff = module->getEnd() - address;
95 if (diff > max_size) {
96 max_size = diff;
97 }
98 }
99 }
100 return max_size;
101}
102
104{
105 std::map<ULONGLONG, ScannedModule*>::const_iterator itr = modulesMap.find(address);
106 if (itr != modulesMap.end()) {
107 return itr->second;
108 }
109 return nullptr;
110}
111
A base class of all the reports detailing on the output of the performed module's scan.
ScannedModule * findModuleContaining(ULONGLONG address, size_t size=0) const
size_t getScannedSize(ULONGLONG start_address) const
bool appendToModulesList(ModuleScanReport *report)
bool appendModule(ScannedModule *module)
ScannedModule * getModuleAt(ULONGLONG address) const
Represents a basic info about the scanned module, such as its base offset, size, and the status.
size_t fill_iat(BYTE *vBuf, size_t vBufSize, IN const peconv::ExportsMapper *exportsMap, IN OUT IATBlock &iat, IN ThunkFoundCallback *callback)
Definition iat_finder.h:31
Final summary about the scanned process.