aswcy483875672 发表于 2021-11-12 21:25

XP驱动加载器

本帖最后由 aswcy483875672 于 2021-11-13 19:54 编辑

windows xp运行没啥问题,64位暂时还没有研究
使用说明:拖拽文件到界面,即可进行安装与卸载成品下载地址:
https://www.lanzoui.com/iaTFhvwp7rc?w
核心源码:
#include<windows.h>
#include<winioctl.h>
#include<stdio.h>
#include <winsvc.h>
#include <conio.h>
#pragma comment(lib, "Advapi32.lib")
TCHAR szPath = { 0 };
TCHAR szFileName = { 0 };

void GetFileName() {
      int i = strlen(szPath);
      int index = 0;
      while (szPath != '\\') {
                i--;
      }

      while (i < strlen(szPath)) {
                szFileName = szPath[++i];
      }
}

void CMFCApplication1Dlg::OnDropFiles(HDROP hDropInfo)
{
      UINT nCount = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
      for (UINT i = 0; i < nCount; ++i)
      {
                DragQueryFile(hDropInfo, i, szPath, MAX_PATH);
                //MessageBox(szPath);
      }
      DragFinish(hDropInfo);

      SetWindowText(szPath);
      UpdateData(FALSE);

      GetFileName();
}

void CMFCApplication1Dlg::LoadDriver(){
      BOOL bRet = FALSE;
      SC_HANDLE hServiceMgr = NULL;//SCM绠$悊鍣ㄧ殑鍙ユ焺
      SC_HANDLE hServiceDDK = NULL;//NT椹卞姩绋嬪簭鐨勬湇鍔″彞鏌?
      //鎵撳紑鏈嶅姟鎺у埗绠$悊鍣?
      hServiceMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
      if (hServiceMgr == NULL)
      {
                //OpenSCManager澶辫触
                SetWindowText("OpenSCManager() Faild");
                bRet = FALSE;
                goto BeforeLeave;
      }
      else
      {
                ////OpenSCManager鎴愬姛
                printf("OpenSCManager() ok ! /n");
      }
      //鍒涘缓椹卞姩鎵?瀵瑰簲鐨勬湇鍔?
      hServiceDDK = CreateService(hServiceMgr,
                szFileName, //椹卞姩绋嬪簭鐨勫湪娉ㄥ唽琛ㄤ腑鐨勫悕瀛?   
                szFileName, // 娉ㄥ唽琛ㄩ┍鍔ㄧ▼搴忕殑 DisplayName 鍊?   
                SERVICE_ALL_ACCESS, // 鍔犺浇椹卞姩绋嬪簭鐨勮?闂?潈闄?   
                SERVICE_KERNEL_DRIVER,// 琛ㄧず鍔犺浇鐨勬湇鍔℃槸椹卞姩绋嬪簭   
                SERVICE_DEMAND_START, // 娉ㄥ唽琛ㄩ┍鍔ㄧ▼搴忕殑 Start 鍊?   
                SERVICE_ERROR_IGNORE, // 娉ㄥ唽琛ㄩ┍鍔ㄧ▼搴忕殑 ErrorControl 鍊?   
                szPath,//娉ㄥ唽琛ㄩ┍鍔ㄧ▼搴忕殑 ImagePath 鍊?   
                NULL,
                NULL,
                NULL,
                NULL,
                NULL);
      DWORD dwRtn;
      //鍒ゆ柇鏈嶅姟鏄?惁澶辫触
      if (hServiceDDK == NULL)
      {
                dwRtn = GetLastError();
                if (dwRtn != ERROR_IO_PENDING && dwRtn != ERROR_SERVICE_EXISTS)
                {
                        //鐢变簬鍏朵粬鍘熷洜鍒涘缓鏈嶅姟澶辫触
                        SetWindowText("CrateService() Faild");
                        bRet = FALSE;
                        goto BeforeLeave;
                }
                else
                {
                        //鏈嶅姟鍒涘缓澶辫触锛屾槸鐢变簬鏈嶅姟宸茬粡鍒涚珛杩?
                        SetWindowText("CrateService() Faild Service is ERROR_IO_PENDING or ERROR_SERVICE_EXISTS!");
                }
                // 椹卞姩绋嬪簭宸茬粡鍔犺浇锛屽彧闇?瑕佹墦寮?   
                hServiceDDK = OpenService(hServiceMgr, szFileName, SERVICE_ALL_ACCESS);
                if (hServiceDDK == NULL)
                {
                        //濡傛灉鎵撳紑鏈嶅姟涔熷け璐ワ紝鍒欐剰鍛抽敊璇?
                        dwRtn = GetLastError();
                        SetWindowText("OpenService() Faild");
                        bRet = FALSE;
                        goto BeforeLeave;
                }
                else
                {
                        SetWindowText("OpenService() ok");
                }
      }
      else
      {
                SetWindowText("CrateService() ok");
      }
      //寮?鍚??椤规湇鍔?
      bRet = StartService(hServiceDDK, NULL, NULL);
      if (!bRet)
      {
                DWORD dwRtn = GetLastError();
                if (dwRtn != ERROR_IO_PENDING && dwRtn != ERROR_SERVICE_ALREADY_RUNNING)
                {
                        SetWindowText("StartService() Faild");
                        bRet = FALSE;
                        goto BeforeLeave;
                }
                else
                {
                        if (dwRtn == ERROR_IO_PENDING)
                        {
                              //璁惧?琚?寕浣?
                              SetWindowText("StartService() Faild");
                              bRet = FALSE;
                              goto BeforeLeave;
                        }
                        else
                        {
                              //鏈嶅姟宸茬粡寮?鍚?
                              SetWindowText("StartService() Faild");
                              bRet = TRUE;
                              goto BeforeLeave;
                        }
                }
      }
      bRet = TRUE;
      //绂诲紑鍓嶅叧闂?彞鏌?
BeforeLeave:
      if (hServiceDDK)
      {
                CloseServiceHandle(hServiceDDK);
      }
      if (hServiceMgr)
      {
                CloseServiceHandle(hServiceMgr);
      }
}

void CMFCApplication1Dlg::UnLoadDriver(){
      BOOL bRet = FALSE;
      SC_HANDLE hServiceMgr = NULL;//SCM绠$悊鍣ㄧ殑鍙ユ焺
      SC_HANDLE hServiceDDK = NULL;//NT椹卞姩绋嬪簭鐨勬湇鍔″彞鏌?
      SERVICE_STATUS SvrSta;
      //鎵撳紑SCM绠$悊鍣?
      hServiceMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
      if (hServiceMgr == NULL)
      {
                //甯﹀紑SCM绠$悊鍣ㄥけ璐?
                SetWindowText("OpenSCManager() Faild");
                bRet = FALSE;
                goto BeforeLeave;
      }
      else
      {
                //甯﹀紑SCM绠$悊鍣ㄥけ璐ユ垚鍔?
                SetWindowText("OpenSCManager() ok !");
      }
      //鎵撳紑椹卞姩鎵?瀵瑰簲鐨勬湇鍔?
      hServiceDDK = OpenService(hServiceMgr, szFileName, SERVICE_ALL_ACCESS);
      if (hServiceDDK == NULL)
      {
                //鎵撳紑椹卞姩鎵?瀵瑰簲鐨勬湇鍔″け璐?
                SetWindowText("OpenService() Faild");
                bRet = FALSE;
                goto BeforeLeave;
      }
      else
      {
                SetWindowText("OpenService() ok !");
      }
      //鍋滄?椹卞姩绋嬪簭锛屽?鏋滃仠姝㈠け璐ワ紝鍙?湁閲嶆柊鍚?姩鎵嶈兘锛屽啀鍔ㄦ?佸姞杞姐??   
      if (!ControlService(hServiceDDK, SERVICE_CONTROL_STOP, &SvrSta))
      {
                SetWindowText("ControlService() Faild");
      }
      else
      {
                SetWindowText("ControlService() ok !");
                //鎵撳紑椹卞姩鎵?瀵瑰簲鐨勫け璐?
      }
      //鍔ㄦ?佸嵏杞介┍鍔ㄧ▼搴忋??   
      if (!DeleteService(hServiceDDK))
      {
                //鍗歌浇澶辫触
                SetWindowText("DeleteSrevice() Faild");
      }
      else
      {
                //鍗歌浇鎴愬姛
                SetWindowText("DelServer:eleteSrevice() ok !");
      }
      bRet = TRUE;
BeforeLeave:
      //绂诲紑鍓嶅叧闂?墦寮?鐨勫彞鏌?
      if (hServiceDDK)
      {
                CloseServiceHandle(hServiceDDK);
      }
      if (hServiceMgr)
      {
                CloseServiceHandle(hServiceMgr);
      }

}
此处有版主编辑,查毒分析地址为:https://sandbox.ti.qianxin.com/s ... e4d0700d87be8cc2ae1




superfasst 发表于 2021-11-13 07:30

多谢分享。

gzhi521 发表于 2021-11-13 08:54

学习学习!!!!!!

dzxushuai 发表于 2021-11-13 22:29

xp的流畅时代很怀念

LuckyClover 发表于 2021-11-14 08:34

消逝的过去 发表于 2021-11-16 09:12

支持一下,感谢分享

fatiao 发表于 2021-11-16 22:31

谢谢分享!!!

491140000 发表于 2021-11-16 22:47

豆0o0豆 发表于 2021-11-16 23:51

感谢分享{:7_231:}

wangyou2022 发表于 2021-11-17 13:08

下载后怎么用呢..
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: XP驱动加载器