33#include " DBKControl.h"
44#include " MemLoadDriver.h"
55
6+ static LoadType g_LoadType;
7+ static WCHAR g_DriverFilePath[MAX_PATH] = { 0 };
8+ static WCHAR g_DriverName[100 ] = L" \\ FileSystem\\ " ;
9+
10+ bool ParseCommandLine ()
11+ {
12+ int nArgs = 0 ;
13+ LPWSTR* argList = CommandLineToArgvW (GetCommandLineW (), &nArgs);
14+ if (nArgs < 3 )
15+ {
16+ LOG (" Number of command args is too few: %d" , nArgs);
17+ return false ;
18+ }
19+
20+ // 判断驱动文件是否存在
21+ if (!std::filesystem::exists (argList[2 ]))
22+ {
23+ LOG (" Parameter error, path not exist: %ws" , argList[2 ]);
24+ return false ;
25+ }
26+ LOG (" Find driver file path: %ws" , g_DriverFilePath);
27+
28+ // 获取驱动文件绝对路径
29+ std::filesystem::path driverFilePath = std::filesystem::absolute (argList[2 ]);
30+ wcscpy (g_DriverFilePath, driverFilePath.c_str ());
31+
32+ // 获取驱动文件名
33+ std::wstring driverName = driverFilePath.stem ();
34+ if (driverName.length () > 90 )
35+ {
36+ LOG (" Parameter error, file name is too long: %ws" , driverName.c_str ());
37+ return false ;
38+ }
39+ wcscat (g_DriverName, driverName.c_str ());
40+
41+ // 获取加载类型
42+ if (0 == _wcsicmp (argList[1 ], L" -load_by_shellcode" ))
43+ {
44+ g_LoadType = LoadByShellcode;
45+ LOG (" Parameter error, load type: load by shellcode" );
46+ }
47+ else if (0 == _wcsicmp (argList[1 ], L" -load_by_driver" ))
48+ {
49+ g_LoadType = LoadByIoCreateDriver;
50+ LOG (" load type: load by driver, driver name: %ws" , g_DriverName);
51+ }
52+ else
53+ {
54+ LOG (" Unknown load type: %ws" , argList[1 ]);
55+ return false ;
56+ }
57+
58+ return true ;
59+ }
60+
661void Worker ()
762{
863 // 提权
@@ -41,7 +96,7 @@ void Worker()
4196 LOG (" init DBKDriver success" );
4297
4398 // 加载自定义驱动
44- if (!DBK_LoadMyDriver (DRIVER_TO_LOAD, DRIVER_NAME ))
99+ if (!DBK_LoadMyDriver (g_LoadType, g_DriverFilePath, g_DriverName ))
45100 {
46101 LOG (" load my driver failed" );
47102 return ;
@@ -59,6 +114,12 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
59114
60115 __try
61116 {
117+ if (!ParseCommandLine ())
118+ {
119+ LOG (" ParseCommandLine failed" );
120+ __leave;
121+ }
122+
62123 Worker ();
63124 }
64125 __finally
0 commit comments