-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLibMain.cpp
58 lines (42 loc) · 1.6 KB
/
LibMain.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
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h> // for wcstombs_s()
#include "ProcessHelper.h"
using namespace ProcessHelper;
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if (fdwReason == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(hInstDLL);
}
return TRUE;
}
int GetProcessParameterA(DWORD dwProcId, PCHAR buf, DWORD dwSizeBuf, ProcessParameter parameter) {
LPWSTR psz = nullptr;
const auto rc = GetProcessParameter(dwProcId, psz, parameter);
if ((0 == rc) && psz) {
size_t conv;
wcstombs_s(&conv, buf, dwSizeBuf, psz, dwSizeBuf);
}
if (psz) { delete[] psz; }
return rc;
}
static int GetProcessParameterW(DWORD dwProcId, PWCHAR buf, DWORD dwSizeBuf, ProcessParameter parameter) {
LPWSTR psz = nullptr;
const auto rc = GetProcessParameter(dwProcId, psz, parameter);
if ((0 == rc) && psz) {
wcscpy_s(buf, dwSizeBuf, psz);
}
if (psz) { delete[] psz; }
return rc;
}
int __stdcall GetProcCmdLineA(DWORD dwProcId, PCHAR buf, DWORD dwSizeBuf) {
return GetProcessParameterA(dwProcId, buf, dwSizeBuf, ProcessParameter::CommandLine);
}
int __stdcall GetProcCmdLineW(DWORD dwProcId, PWCHAR buf, DWORD dwSizeBuf) {
return GetProcessParameterW(dwProcId, buf, dwSizeBuf, ProcessParameter::CommandLine);
}
int __stdcall GetProcWorkingDirA(DWORD dwProcId, PCHAR buf, DWORD dwSizeBuf) {
return GetProcessParameterA(dwProcId, buf, dwSizeBuf, ProcessParameter::WorkingDirectory);
}
int __stdcall GetProcWorkingDirW(DWORD dwProcId, PWCHAR buf, DWORD dwSizeBuf) {
return GetProcessParameterW(dwProcId, buf, dwSizeBuf, ProcessParameter::WorkingDirectory);
}