PE-sieve
Scans all running processes. Recognizes and dumps a variety of potentially malicious implants (replaced/implanted PEs, shellcodes, hooks, in-memory patches).
Toggle main menu visibility
Loading...
Searching...
No Matches
scanners
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
8
using namespace
pesieve
;
9
10
bool
pesieve::ModulesInfo::appendModule
(
ScannedModule
* lModule)
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
24
bool
pesieve::ModulesInfo::appendToModulesList
(
ModuleScanReport
*
report
)
25
{
26
if
(!
report
||
report
->moduleSize == 0) {
27
return
false
;
//skip
28
}
29
ULONGLONG module_start = (ULONGLONG)
report
->module;
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
53
ScannedModule
*
pesieve::ModulesInfo::findModuleContaining
(ULONGLONG address,
size_t
size)
const
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
73
void
pesieve::ModulesInfo::deleteAll
()
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
83
size_t
pesieve::ModulesInfo::getScannedSize
(ULONGLONG address)
const
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
103
ScannedModule
*
pesieve::ModulesInfo::getModuleAt
(ULONGLONG address)
const
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
pesieve::ModuleScanReport
A base class of all the reports detailing on the output of the performed module's scan.
Definition
module_scan_report.h:56
pesieve::ModulesInfo::findModuleContaining
ScannedModule * findModuleContaining(ULONGLONG address, size_t size=0) const
Definition
scanned_modules.cpp:53
pesieve::ModulesInfo::getScannedSize
size_t getScannedSize(ULONGLONG start_address) const
Definition
scanned_modules.cpp:83
pesieve::ModulesInfo::deleteAll
void deleteAll()
Definition
scanned_modules.cpp:73
pesieve::ModulesInfo::appendToModulesList
bool appendToModulesList(ModuleScanReport *report)
Definition
scanned_modules.cpp:24
pesieve::ModulesInfo::appendModule
bool appendModule(ScannedModule *module)
Definition
scanned_modules.cpp:10
pesieve::ModulesInfo::getModuleAt
ScannedModule * getModuleAt(ULONGLONG address) const
Definition
scanned_modules.cpp:103
pesieve::ScannedModule
Represents a basic info about the scanned module, such as its base offset, size, and the status.
Definition
scanned_modules.h:14
pesieve::ScannedModule::isSuspicious
bool isSuspicious() const
Definition
scanned_modules.h:33
pesieve::ScannedModule::start
const ULONGLONG start
Definition
scanned_modules.h:73
pesieve::ScannedModule::getStart
ULONGLONG getStart() const
Definition
scanned_modules.h:18
pesieve::ScannedModule::setSuspicious
void setSuspicious(bool _is_suspicious)
Definition
scanned_modules.h:59
pesieve::ScannedModule::getSize
size_t getSize()
Definition
scanned_modules.h:28
pesieve::ScannedModule::resize
bool resize(size_t newSize)
Definition
scanned_modules.h:63
pesieve
Definition
pesieve.py:1
pesieve::SCAN_SUSPICIOUS
@ SCAN_SUSPICIOUS
Definition
module_scan_report.h:21
scanned_modules.h
report
Final summary about the scanned process.
Definition
pe_sieve_types.h:151
Generated by
1.17.0