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
module_scan_report.h
Go to the documentation of this file.
1#pragma once
2
3#include <windows.h>
4
5#include <iostream>
6#include <sstream>
7#include <string>
8#include <vector>
9
10#include <peconv.h>
11#include "pe_sieve_types.h"
12
13#include "../utils/path_util.h"
15
16namespace pesieve {
17
23
26 {
27 public:
28 static const size_t JSON_LEVEL = 1;
29
31 {
32 if (report == nullptr) {
33 return SCAN_ERROR;
34 }
35 return report->status;
36 }
37
39 {
40 this->module = _module;
41 this->moduleSize = _moduleSize;
42 this->status = _status;
43 this->isDotNetModule = false;
44 }
45
47 {
48 this->module = _module;
49 this->moduleSize = _moduleSize;
50 this->isDotNetModule = false;
52 }
53
54 virtual ~ModuleScanReport() {}
55
57 {
58 return (ULONGLONG)this->module;
59 }
60
61 const virtual bool toJSON(std::stringstream &outs, size_t level = JSON_LEVEL, const pesieve::t_json_level &jdetails = JSON_BASIC) = 0;
62
63 HMODULE module;
64 size_t moduleSize;
66 std::string moduleFile;
68
69 protected:
70 const virtual bool _toJSON(std::stringstream& outs, size_t level = JSON_LEVEL, const pesieve::t_json_level& jdetails = JSON_BASIC)
71 {
72 OUT_PADDED(outs, level, "\"module\" : ");
73 outs << "\"" << std::hex << (ULONGLONG)module << "\"" << ",\n";
74 if (moduleSize){
75 OUT_PADDED(outs, level, "\"module_size\" : ");
76 outs << "\"" << std::hex << (ULONGLONG)moduleSize << "\"" << ",\n";
77 }
78 if (moduleFile.length()) {
79 OUT_PADDED(outs, level, "\"module_file\" : ");
80 outs << "\"" << pesieve::util::escape_path_separators(moduleFile) << "\"" << ",\n";
81 }
82 OUT_PADDED(outs, level, "\"status\" : ");
83 outs << std::dec << status;
84 if (isDotNetModule) {
85 outs << ",\n";
86 OUT_PADDED(outs, level, "\"is_dot_net\" : \"");
87 outs << isDotNetModule << "\"";
88 }
89 return true;
90 }
91
92 };
93
95 {
96 public:
102
103 const virtual bool toJSON(std::stringstream &outs, size_t level = JSON_LEVEL, const pesieve::t_json_level &jdetails = JSON_BASIC)
104 {
105 OUT_PADDED(outs, level, "\"unreachable_scan\" : ");
106 outs << "{\n";
108 outs << "\n";
109 OUT_PADDED(outs, level, "}");
110 return true;
111 }
112 };
113
115 {
116 public:
122
123 const virtual bool toJSON(std::stringstream &outs, size_t level = JSON_LEVEL, const pesieve::t_json_level &jdetails = JSON_BASIC)
124 {
125 OUT_PADDED(outs, level, "\"skipped_scan\" : ");
126 outs << "{\n";
128 outs << "\n";
129 OUT_PADDED(outs, level, "}");
130 return true;
131 }
132 };
133
135 {
136 public:
142
143 const virtual bool toJSON(std::stringstream &outs, size_t level = JSON_LEVEL, const pesieve::t_json_level &jdetails = JSON_BASIC)
144 {
145 OUT_PADDED(outs, level, "\"malformed_header\" : ");
146 outs << "{\n";
148 outs << "\n";
149 OUT_PADDED(outs, level, "}");
150 return true;
151 }
152 };
153
154}; //namespace pesieve
virtual const bool toJSON(std::stringstream &outs, size_t level=JSON_LEVEL, const pesieve::t_json_level &jdetails=JSON_BASIC)
MalformedHeaderReport(HMODULE _module, size_t _moduleSize, std::string _moduleFile)
A base class of all the reports detailing on the output of the performed module's scan.
virtual const bool _toJSON(std::stringstream &outs, size_t level=JSON_LEVEL, const pesieve::t_json_level &jdetails=JSON_BASIC)
virtual ULONGLONG getRelocBase()
virtual const bool toJSON(std::stringstream &outs, size_t level=JSON_LEVEL, const pesieve::t_json_level &jdetails=JSON_BASIC)=0
static const size_t JSON_LEVEL
static t_scan_status get_scan_status(const ModuleScanReport *report)
ModuleScanReport(HMODULE _module, size_t _moduleSize, t_scan_status _status)
ModuleScanReport(HMODULE _module, size_t _moduleSize)
SkippedModuleReport(HMODULE _module, size_t _moduleSize, std::string _moduleFile)
virtual const bool toJSON(std::stringstream &outs, size_t level=JSON_LEVEL, const pesieve::t_json_level &jdetails=JSON_BASIC)
virtual const bool toJSON(std::stringstream &outs, size_t level=JSON_LEVEL, const pesieve::t_json_level &jdetails=JSON_BASIC)
UnreachableModuleReport(HMODULE _module, size_t _moduleSize, std::string _moduleFile)
#define OUT_PADDED(stream, field_size, str)
Definition format_util.h:12
std::string escape_path_separators(std::string path)
Definition path_util.cpp:27
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
enum pesieve::module_scan_status t_scan_status
The types used by PE-sieve API.
@ JSON_BASIC
basic
Final summary about the scanned process.