C++ Win32 API 将驱动程序加载到内核空间
C++ Win32 API Load a driver to the kernel space
是否有用于在内核空间中加载和执行内核模式程序的Win32/本机API函数?(.sys,.exe)
首先,
您可以使用OpenSCManager()获得服务管理器的句柄。
然后你使用 SERVICE_KERNEL_DRIVER 和 SERVICE_DEMAND_START 调用 CreateService(),这将加载驱动程序。
下面是一个函数的一个很好的例子,它通过错误检查为你做这一切:
BOOL LoadNTDriver(WCHAR* lpszDriverName, WCHAR* lpszDriverPath)
{
WCHAR szDriverImagePath[256];
GetFullPathName(lpszDriverPath, 256, szDriverImagePath, NULL);
BOOL bRet = FALSE;
SC_HANDLE hServiceMgr = NULL;
SC_HANDLE hServiceDDK = NULL;
hServiceMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hServiceMgr == NULL)
{
printf("OpenSCManager() Faild %d ! n", GetLastError());
bRet = FALSE;
goto BeforeExit;
}
else
{
printf("OpenSCManager() ok ! n");
}
hServiceDDK = CreateService(hServiceMgr,
lpszDriverName,
lpszDriverName,
SERVICE_ALL_ACCESS,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE,
szDriverImagePath,
NULL,
NULL,
NULL,
NULL,
NULL);
DWORD dwRtn;
if (hServiceDDK == NULL)
{
dwRtn = GetLastError();
if (dwRtn != ERROR_IO_PENDING && dwRtn != ERROR_SERVICE_EXISTS)
{
printf("CrateService() Faild %d ! n", dwRtn);
bRet = FALSE;
goto BeforeExit;
}
else
{
printf("CrateService() Faild Service is ERROR_IO_PENDING or ERROR_SERVICE_EXISTS! n");
}
hServiceDDK = OpenService(hServiceMgr, lpszDriverName, SERVICE_ALL_ACCESS);
if (hServiceDDK == NULL)
{
dwRtn = GetLastError();
printf("OpenService() Faild %d ! n", dwRtn);
bRet = FALSE;
goto BeforeExit;
}
else
{
printf("OpenService() ok ! n");
}
}
else
{
printf("CrateService() ok ! n");
}
bRet = StartService(hServiceDDK, NULL, NULL);
if (!bRet)
{
DWORD dwRtn = GetLastError();
if (dwRtn != ERROR_IO_PENDING && dwRtn != ERROR_SERVICE_ALREADY_RUNNING)
{
printf("StartService() Faild %d ! n", dwRtn);
bRet = FALSE;
goto BeforeExit;
}
else
{
if (dwRtn == ERROR_IO_PENDING)
{
printf("StartService() Faild ERROR_IO_PENDING ! n");
bRet = FALSE;
goto BeforeExit;
}
else
{
printf("StartService() Faild ERROR_SERVICE_ALREADY_RUNNING ! n");
bRet = TRUE;
goto BeforeExit;
}
}
}
bRet = TRUE;
BeforeExit:
if (hServiceDDK)
{
CloseServiceHandle(hServiceDDK);
}
if (hServiceMgr)
{
CloseServiceHandle(hServiceMgr);
}
return bRet;
}
来源:https://github.com/roycncn/PUBG-wall-hacking-user-mode/blob/master/MapESP/LoadDriver.hpp
据
我所知,没有。你不能那样做(这将是一个相当大的安全问题)。您必须正确注册驱动程序并让 Windows 加载它。
后者可以使用DIFxAPI来完成,您应该在MSDN上阅读,因为它太复杂了,无法将其放在简单的答案中。
您应该寻找的核心功能是 DriverPackageInstall
.
相关文章:
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 命名空间中具有.h和.cpp文件的类
- 从父命名空间重载类型
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 在命名空间中定义函数还是限定函数
- C++:对不存在的命名空间使用命名空间指令
- CUDA内核和数学函数的显式命名空间
- pthread_spinlock是否会导致从用户空间切换到内核空间
- 为什么共享内存(在IPC中)不需要上下文切换?这是内核空间的内存,可以映射到用户空间
- 内核模块或用户空间应用程序
- Ubuntu,如何找到内核工作繁重的程序热点?似乎kernel.kallsyms上的函数没有标记为用户空间函数的子级
- 是否访问用户或内核空间
- 用户空间和内核空间进程中的信号处理程序集
- 内核模块定期调用用户空间程序
- std::线程在用户或内核空间中进行管理
- 设备内存空间中的 CUDA 程序内核代码
- ToUnicode是否调用ToUnicodeEx?ToUnicodeEx在内核空间线程上更改了什么
- 内核vs用户空间音频设备驱动程序在macOS
- 在32位linux内核上使用c++在堆上分配超过2GB的空间
- C++ Win32 API 将驱动程序加载到内核空间