Skip to content

Commit 42d63f3

Browse files
committed
bianma
1 parent 9b84ca2 commit 42d63f3

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

examples/notify_example/notify_example/notify_example.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ BOOLEAN monitor_svc_delete(WCHAR *user_name, WCHAR *process, WCHAR *file_path)
5656

5757
BOOLEAN monitorprocess_kill(WCHAR *user_name, WCHAR *process, WCHAR *file_path)
5858
{
59-
wprintf(_T("monitor_svc_delete\n User=%s, Process=%s, file=%s\n"), user_name, process, file_path);
60-
return TRUE;
59+
wprintf(_T("monitorprocess_kill\n User=%s, Process=%s, file=%s\n"), user_name, process, file_path);
60+
return FALSE;
6161
}
6262

6363
BOOLEAN monitor_svc_create(WCHAR *user_name, WCHAR *process, WCHAR *file_path, WCHAR *bin)

src/monitor/monitor/monitor.cpp

+22-12
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ SC_HANDLE WINAPI fake_CreateServiceW(
8787
HIPS_RULE_NODE hrn;
8888

8989
RtlZeroMemory(&hrn,sizeof(hrn));
90-
9190
hrn.major_type = SERVICE_OP;
9291
if (dwServiceType == SERVICE_FILE_SYSTEM_DRIVER || dwServiceType == SERVICE_KERNEL_DRIVER)
9392
{
@@ -125,22 +124,34 @@ SC_HANDLE WINAPI fake_CreateServiceW(
125124
);
126125
}
127126

128-
PWSTR Ansi2Unicode(PCSTR pszLibFile) {
129-
130-
if (!pszLibFile)
127+
PWSTR Ansi2Unicode(PCSTR str)
128+
{
129+
int len = 0;
130+
if (!str)
131131
{
132132
return NULL;
133133
}
134-
SIZE_T cchSize = lstrlenA(pszLibFile) + 1;
135-
PWSTR pszLibFileW = (PWSTR)malloc(cchSize * sizeof(wchar_t));
136-
137-
if (!pszLibFileW)
134+
len = strlen(str);
135+
int unicodeLen = ::MultiByteToWideChar(CP_ACP,
136+
0,
137+
str,
138+
-1,
139+
NULL,
140+
0);
141+
wchar_t * pUnicode;
142+
pUnicode = (wchar_t*)malloc((unicodeLen + 1)*sizeof(WCHAR));
143+
if (!pUnicode)
138144
{
139145
return NULL;
140146
}
141-
StringCchPrintfW(pszLibFileW, cchSize, L"%S", pszLibFile);
142-
143-
return pszLibFileW;
147+
memset(pUnicode, 0, (unicodeLen + 1)*sizeof(WCHAR));
148+
::MultiByteToWideChar(CP_ACP,
149+
0,
150+
str,
151+
-1,
152+
(LPWSTR)pUnicode,
153+
unicodeLen);
154+
return pUnicode;
144155
}
145156

146157
SC_HANDLE WINAPI fake_CreateServiceA(
@@ -168,7 +179,6 @@ SC_HANDLE WINAPI fake_CreateServiceA(
168179
LPCWSTR lpServiceStartNameW = Ansi2Unicode(lpServiceStartName);
169180
LPCWSTR lpPasswordW = Ansi2Unicode(lpPassword);
170181

171-
172182
handle = fake_CreateServiceW
173183
(
174184
hSCManager,

0 commit comments

Comments
 (0)