Skip to content

Commit 167b4f6

Browse files
DllUnInject read target list
1 parent 497df9d commit 167b4f6

File tree

5 files changed

+92
-6
lines changed

5 files changed

+92
-6
lines changed

APIHOOK/DllUnInject/DllUnInject.cpp

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,92 @@
77

88
int main()
99
{
10-
10+
WCHAR szCurrentDirectory[MAX_PATH];
11+
1112
//SetPrivilege
1213
if (!SetPrivilege(SE_DEBUG_NAME, TRUE))
1314
{
1415
OutputDebugString(L"SetPrivilege ERROR\n");
1516
return 0;
1617
}
1718

18-
DoSearchProcess(NULL);
19-
//DoReleaseSemaphoreStatus();
19+
GetModuleDirectory(szCurrentDirectory);
20+
21+
ReadTargetListAndDo(szCurrentDirectory);
22+
23+
DoReleaseSemaphoreStatus();
2024

2125
return 0;
2226
}
2327

2428

29+
void GetModuleDirectory(PWCHAR szCurrentDirectory)
30+
{
31+
DWORD dwCurDirPathLen;
32+
dwCurDirPathLen = GetModuleFileName(NULL, szCurrentDirectory, MAX_PATH);
33+
if (!dwCurDirPathLen)
34+
{
35+
printf("GetModuleFileName ERROR\n");
36+
return;
37+
}
38+
SIZE_T i = 0;
39+
StringCbLengthW(szCurrentDirectory, MAX_PATH, &i);
40+
if (0 == i)
41+
{
42+
return;
43+
}
44+
for (; i > 0 && L'\\' != szCurrentDirectory[i - 1]; i--) {}
45+
szCurrentDirectory[i] = L'\0';
46+
OutputDebugString(szCurrentDirectory);
47+
OutputDebugString(L"\n");
48+
49+
}
50+
51+
void ReadTargetListAndDo(LPCWCHAR szCurrentDirectory) {
52+
WCHAR szListDirectory[MAX_PATH];
53+
WCHAR szProcName[MAX_PATH];
54+
WCHAR szBuf[2];
55+
DWORD dwNumRead;
56+
HANDLE hFile = NULL;
57+
58+
StringCbCopy(szListDirectory, MAX_PATH, szCurrentDirectory);
59+
StringCbCat(szListDirectory, MAX_PATH, L"TargetList.txt");
60+
OutputDebugString(szListDirectory);
61+
OutputDebugString(L"\n");
62+
hFile = CreateFile(szListDirectory, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
63+
if (INVALID_HANDLE_VALUE == hFile)
64+
{
65+
OutputDebugString(L"TargetList.txt NOT FOUND\n");
66+
return;
67+
}
68+
StringCbCopy(szProcName, MAX_PATH, L"");
69+
while (TRUE)
70+
{
71+
ReadFile(hFile, szBuf, 2, &dwNumRead, NULL);
72+
szBuf[1] = L'\0';
73+
if (0 == dwNumRead)
74+
{
75+
CloseHandle(hFile);
76+
break;
77+
}
78+
if (L'\r' == *szBuf)
79+
{
80+
OutputDebugString(szProcName);
81+
OutputDebugString(L" in TargetList\n");
82+
DoSearchProcess(szProcName);
83+
StringCbCopy(szProcName, MAX_PATH, L"");
84+
continue;
85+
86+
}
87+
if (L'\n' == *szBuf)
88+
{
89+
continue;
90+
}
91+
StringCbCat(szProcName, MAX_PATH, szBuf);
92+
}
93+
}
94+
95+
2596
void DoSearchProcess(LPCWCHAR szProcessName)
2697
{
2798
DWORD dwPId = 0;

APIHOOK/DllUnInject/DllUnInject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#define MAX_TARGET_NUM 10
4-
3+
void GetModuleDirectory(PWCHAR szCurrentDirectory);
4+
void ReadTargetListAndDo(LPCWCHAR szCurrentDirectory);
55
void DoSearchProcess(LPCWCHAR dwProcesName);
66
void DoSearchModule(DWORD dwProcessId);
77
void DoDllUnInject(DWORD dwProcessId, HMODULE hModule);

APIHOOK/DllUnInject/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <tchar.h>
1212
#include <windows.h>
1313
#include <TlHelp32.h>
14+
#include <strsafe.h>
1415

1516

1617

APIHOOK/Monitor/Monitor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ int wmain(int argc, wchar_t *argv[], wchar_t *envp[])
99

1010
if (2 != argc) {
1111
ShowHelp();
12+
int i;
13+
scanf_s("%d", &i);
14+
switch(i)
15+
{
16+
case 1:
17+
StartMonitor();
18+
break;
19+
case 2:
20+
StopMonitor();
21+
break;
22+
case 3:
23+
RestartMonitor();
24+
break;
25+
}
1226
}
1327
else if (CSTR_EQUAL == CompareString(LOCALE_SYSTEM_DEFAULT, LINGUISTIC_IGNORECASE, argv[1], -1, L"start", -1))
1428
{

APIHOOK/TESTAPI/TESTAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
int main()
55
{
6-
for (;;);
6+
Sleep(INFINITE);
77
return 0;
88
}

0 commit comments

Comments
 (0)