forked from hasherezade/pin_n_sieve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScanProcess.cpp
81 lines (71 loc) · 1.68 KB
/
ScanProcess.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "ScanProcess.h"
#include "my_paths.h"
#include <pe_sieve_api.h>
#include <pe_sieve_return_codes.h>
#include <sstream>
#ifdef _WIN64
#define PE_SIEVE "pe-sieve64.exe"
#else
#define PE_SIEVE "pe-sieve32.exe"
#endif
int getPidByThreadHndl(void* hndl)
{
HANDLE phndl = (HANDLE)hndl;
DWORD pid = GetProcessIdOfThread(phndl);
return pid;
}
int getPidByProcessHndl(void *hndl)
{
HANDLE phndl = (HANDLE)hndl;
DWORD pid = GetProcessId(phndl);
return pid;
}
bool create_new_process(PROCESS_INFORMATION &pi, const LPSTR cmdLine, LPCSTR startDir = NULL)
{
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
if (!CreateProcessA(
NULL,
cmdLine,
NULL, //lpProcessAttributes
NULL, //lpThreadAttributes
FALSE, //bInheritHandles
CREATE_NO_WINDOW, //dwCreationFlags
NULL, //lpEnvironment
startDir, //lpCurrentDirectory
&si, //lpStartupInfo
&pi //lpProcessInformation
))
{
return false;
}
return true;
}
scan_res ScanProcess(const char pesieve_dir[], int pid, const char out_dir[])
{
std::stringstream ss;
ss << pesieve_dir;
ss << "\\";
ss << PE_SIEVE;
ss << " /pid " << std::dec << pid;
ss << " /dir " << out_dir;
ss << " /mignore ntdll.dll"; // NTDLL is patched by the Pin
ss << " /quiet";
std::string cmdline = ss.str();
PROCESS_INFORMATION pi = { 0 };
if (!create_new_process(pi, (LPSTR)cmdline.c_str())) {
return SCAN_ERROR_0;
}
DWORD code = 0;
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &code);
if (code == PESIEVE_NOT_DETECTED) {
return SCAN_NOT_SUSPICIOUS;
}
if (code == PESIEVE_DETECTED) {
return SCAN_SUSPICIOUS;
}
return SCAN_ERROR_1;
}