zwSetSystemInformation加载驱动

转自http://blog.csdn.net/xiaocaiju/article/details/7583234

 

zwSetSystemInformation函数是个未公开的函数,调用38号会加载驱动,对应的第二个参数为SYSTEM_LOAD_AND_CALL_IMAGE结构体,第三个参数为SYSTEM_LOAD_AND_CALL_IMAGE结构体的长度..


  1. #include <Windows.h>   
  2. #include <stdio.h>   
  3.   
  4. #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)   
  5.   
  6. #define SystemLoadAndCallImage  38   
  7.   
  8. typedef struct _UNICODE_STRING {  
  9.     USHORT Length;  
  10.     USHORT MaximumLength;  
  11.     PVOID  Buffer;  
  12. }UNICODE_STRING, *PUNICODE_STRING;  
  13.   
  14. //typedef unsigned long NTSTATUS;   
  15.   
  16. typedef struct _SYSTEM_LOAD_AND_CALL_IMAGE{  
  17.     UNICODE_STRING ModuleName;  
  18. } SYSTEM_LOAD_AND_CALL_IMAGE,*PSYSTEM_LOAD_AND_CALL_IMAGE;  
  19.   
  20. //声明三个函数的原型   
  21. typedef DWORD (CALLBACK* ZWSETSYSTEMINFORMATION)(DWORDPVOIDLONG );  
  22. ZWSETSYSTEMINFORMATION ZwSetSystemInformation;  
  23. //typedef DWORD (CALLBACK* RTLINITUNICODESTRING)(PUNICODE_STRING, PCWSTR);   
  24. //RTLINITUNICODESTRING RtlInitUnicodeString;   
  25. typedef DWORD (CALLBACK* RTLANSISTRINGTOUNICODESTRING)(PVOIDPVOIDDWORD);  
  26. RTLANSISTRINGTOUNICODESTRING RtlAnsiStringToUnicodeString;  
  27.   
  28.   
  29. int main(int argc, char* argv)  
  30. {  
  31.     SYSTEM_LOAD_AND_CALL_IMAGE gregsImage;  
  32.     UNICODE_STRING TmpBuff;  
  33.   
  34.     char szDrvFullPath[256];  
  35.     int iBufflen;  
  36.   
  37.     //手工加载这三个函数   
  38.     //if (!(RtlInitUnicodeString = (RTLINITUNICODESTRING)GetProcAddress(GetModuleHandle("ntdll.dll"),"RtlInitUnicodeString")))   
  39.     //{   
  40.     //  printf("GetProcAddrss error:%d\n", GetLastError());   
  41.     //  exit(-1);   
  42.     //}   
  43.     if (!(RtlAnsiStringToUnicodeString = (RTLANSISTRINGTOUNICODESTRING)GetProcAddress(GetModuleHandle("ntdll.dll"),"RtlAnsiStringToUnicodeString")))  
  44.     {  
  45.         printf("GetProcAddrss error:%d\n", GetLastError());  
  46.         exit(-1);  
  47.     }  
  48.     if (!(ZwSetSystemInformation = (ZWSETSYSTEMINFORMATION)GetProcAddress(GetModuleHandle("ntdll.dll"),"ZwSetSystemInformation")))  
  49.     {  
  50.         printf("GetProcAddrss error:%d\n", GetLastError());  
  51.         exit(-1);  
  52.     }  
  53.   
  54.     //ring 0 访问磁盘时要用\\??\\%s 的方式, 以前出错时少了一个?   
  55.     iBufflen = sprintf(szDrvFullPath, "\\??\\%s""c:\\aaa.sys");  
  56.     szDrvFullPath[iBufflen] = 0;  
  57.   
  58.     TmpBuff.Buffer = (PVOID)szDrvFullPath;  
  59.     TmpBuff.Length = iBufflen;  
  60.   
  61.     RtlAnsiStringToUnicodeString(&(gregsImage.ModuleName), &TmpBuff, 1);  
  62.     if (NT_SUCCESS(ZwSetSystemInformation(SystemLoadAndCallImage, &gregsImage, sizeof(SYSTEM_LOAD_AND_CALL_IMAGE))))  
  63.     {  
  64.         printf("drive %s was loaded....", szDrvFullPath);  
  65.     }  
  66.     else  
  67.     {  
  68.         printf("dirve load error...");  
  69.     }  
  70.     getchar();  
  71.     return 1;  
  72.   
  73.       
  74. }  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值