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
pe_sieve_api.cpp
Go to the documentation of this file.
1#include <windows.h>
2#include <string>
3#include <iostream>
4
5#include "pe_sieve.h"
6
7#define PESIEVE_EXPORTS
8#include <pe_sieve_api.h>
9
10#define LIB_NAME "PE-sieve"
11
12using namespace pesieve;
13
14size_t print_report(const pesieve::ReportEx& report, const pesieve::t_params args, const t_report_type rtype, char* json_buf, size_t json_buf_size)
15{
16 if (!report.scan_report || rtype == REPORT_NONE) return 0;
17
18 size_t level = 1;
19 std::string report_str = report_to_json(report, rtype, ProcessScanReport::REPORT_SUSPICIOUS_AND_ERRORS, args.json_lvl, level);
20 const size_t report_len = report_str.length();
21
22 if (json_buf && json_buf_size) {
23 ::memset(json_buf, 0, json_buf_size);
24 size_t max_len = report_len <= (json_buf_size - 1) ? report_len : (json_buf_size - 1);
25 ::memcpy(json_buf, report_str.c_str(), max_len);
26 }
27 return report_len;
28}
29
30PEsieve_report PESIEVE_API_FUNC PESieve_scan_ex(IN const PEsieve_params &args, IN const PEsieve_rtype rtype, OUT char* json_buf, IN size_t json_buf_size, OUT size_t* needed_size)
31{
32 if (IsBadReadPtr((LPVOID)&args, sizeof(PEsieve_params)) ) {
33 pesieve::t_report empty = { 0 };
34 empty.errors = 1;
35 return empty;
36 }
38 if (report == nullptr) {
39 pesieve::t_report nullrep = { 0 };
40 nullrep.pid = args.pid;
41 nullrep.errors = pesieve::ERROR_SCAN_FAILURE;
42 return nullrep;
43 }
44 pesieve::t_report summary = report->scan_report->generateSummary();
45 //check the pointers:
46 if (json_buf) {
47 if (!json_buf_size || IsBadWritePtr(json_buf, json_buf_size)) {
48 json_buf = nullptr;
49 json_buf_size = 0;
50 }
51 }
52 if (needed_size && IsBadWritePtr(needed_size, sizeof(size_t))) {
53 needed_size = nullptr;
54 }
55
56 //print the report (only if any valid output buffer was passed)
57 if (json_buf || needed_size) {
58 const size_t report_size = print_report(*report, args, rtype, json_buf, json_buf_size);
59 if (needed_size) {
60 *needed_size = report_size;
61 }
62 }
63 delete report;
64 return summary;
65}
66
68{
69 return PESieve_scan_ex(args, REPORT_NONE, nullptr, 0, nullptr);
70}
71
73{
74 std::string my_info = pesieve::info();
75
76 std::cout << my_info;
77 MessageBox(NULL, my_info.c_str(), LIB_NAME, MB_ICONINFORMATION);
78}
79
The final report about the actions performed on the process: scanning and dumping.
DWORD(__stdcall *_PssCaptureSnapshot)(HANDLE ProcessHandle
PESieve_help()
Definition pesieve.py:168
int ERROR_SCAN_FAILURE
Definition pesieve.py:9
PESieve_version
Definition pesieve.py:145
(t_report, str, int) PESieve_scan_ex(t_params params, t_report_type rtype, int buf_size)
Definition pesieve.py:186
std::string info()
The string with the basic information about the scanner.
Definition pe_sieve.cpp:268
std::string report_to_json(const pesieve::ReportEx &report, const t_report_type rtype, ProcessScanReport::t_report_filter filter, const pesieve::t_json_level &jdetails, size_t start_level=0)
ReportEx * scan_and_dump(IN const pesieve::t_params args)
The main action performed by PE-sieve: scanning the process and dumping the detected material.
Definition pe_sieve.cpp:193
t_report PESieve_scan(t_params params)
Definition pesieve.py:173
The root of the PE-sieve scanner.
size_t print_report(const pesieve::ReportEx &report, const pesieve::t_params args, const t_report_type rtype, char *json_buf, size_t json_buf_size)
#define LIB_NAME
The API: definitions of the exported elements that are accessible from PE-sieve DLL.
#define PESIEVE_API
#define PESIEVE_API_FUNC
@ REPORT_NONE
do not output a report
#define PESIEVE_PATCH_VERSION
#define PESIEVE_MINOR_VERSION
#define PESIEVE_MAJOR_VERSION
#define PESIEVE_MICRO_VERSION
Input parameters for PE-sieve, defining the configuration.
Final summary about the scanned process.