GaRY's Blog

Beginning is always beautiful

使用ZwSetSystemInformation加载驱动

 

#include <windows.h> 
#
include <stdio.h> 
#
define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0) 
#
define SystemLoadAndCallImage 38 

typedef struct _UNICODE_STRING { 
    USHORT Length; 
    USHORT MaximumLength; 
    PVOID Buffer;
} UNICODE_STRING
, *PUNICODE_STRING; 

typedef unsigned long NTSTATUS; 

typedef struct _SYSTEM_LOAD_AND_CALL_IMAGE 

    UNICODE_STRING ModuleName; 
} SYSTEM_LOAD_AND_CALL_IMAGE
, *PSYSTEM_LOAD_AND_CALL_IMAGE; 

typedef DWORD (
CALLBACK* ZWSETSYSTEMINFORMATION)(DWORD, PVOID, ULONG);
ZWSETSYSTEMINFORMATION ZwSetSystemInformation;
typedef DWORD (
CALLBACK* RTLINITUNICODESTRING)(PUNICODE_STRING,PCWSTR );
RTLINITUNICODESTRING RtlInitUnicodeString;
typedef DWORD (
CALLBACK* RTLANSISTRINGTOUNICODESTRING)(PVOID, PVOID,DWORD);
RTLANSISTRINGTOUNICODESTRING RtlAnsiStringToUnicodeString;

int main(int argc
, char *argv[])

    SYSTEM_LOAD_AND_CALL_IMAGE GregsImage; 
    UNICODE_STRING TmpBuff;
    char    szDrvFullPath[
256],szTmp[256];
    int iBuffLen;
    
    
printf("Load driver with ZwSetSystemInformation( )\r\n");
    
printf("Date: 8th May 2007\r\n");
    
printf("Modifed by: GaRY <wofeiwo_at_gmail_dot_com>\r\n\r\n");
    
if(argc != 2 || stricmp(argv[1], "-h"==0 || stricmp(argv[1], "-?"==0 || stricmp(argv[1], "/?"==0)
    {
        
printf("Usage: %s <DriverPath>\r\n", argv[0]);
        
exit(-1);
    }

    
// 从ntll.dll获取函数
    if!(RtlInitUnicodeString = (RTLINITUNICODESTRING) GetProcAddress( GetModuleHandle("ntdll.dll"),  "RtlInitUnicodeString" )) )  
    {
        
printf"GetProcAddress(\"RtlInitUnicodeString\") Error:%d\n", GetLastError() );
        
exit(1); 
    }
    
if!(ZwSetSystemInformation = (ZWSETSYSTEMINFORMATION) GetProcAddress( GetModuleHandle("ntdll.dll"), "ZwSetSystemInformation" )) )
    {
        
printf"GetProcAddress(\"ZwSetSystemInformation\") Error:%d\n", GetLastError() );
        
exit(1); 
    }
    
if!(RtlAnsiStringToUnicodeString = (RTLANSISTRINGTOUNICODESTRING) GetProcAddress( GetModuleHandle("ntdll.dll"), "RtlAnsiStringToUnicodeString" )) ) 
    {
        
printf"GetProcAddress(\"ZwSetSystemInformation\") Error:%d\n", GetLastError() );
        
exit(1); 
    }

    GetFullPathName(argv[
1], 256, szTmp, NULL);   
    
printf("Loading driver: %s\r\n", szTmp);
    iBuffLen 
= sprintf(szDrvFullPath, "\\??\\%s", szTmp);
    szDrvFullPath[iBuffLen]
=0;
    TmpBuff
.Buffer = (PVOID)szDrvFullPath;
    TmpBuff
.Length = iBuffLen;
    RtlAnsiStringToUnicodeString(
&(GregsImage.ModuleName),&TmpBuff,1);

    
if( NT_SUCCESS( ZwSetSystemInformation( SystemLoadAndCallImage, &GregsImage, sizeof(SYSTEM_LOAD_AND_CALL_IMAGE)) ))     //加载进内核空间
    { 
        
printf("Driver: %s loaded.\r\n", szDrvFullPath); 
    } 
    
else 
    { 
        
printf("Driver: %s not loaded.\r\n", szDrvFullPath); 
    } 
    
return true;

posted on 2007-05-08 20:54 wofeiwo 阅读(1967) 评论(1)  编辑 收藏 引用 网摘 所属分类: TipsOthers

评论

# re: 使用ZwSetSystemInformation加载驱动 2007-06-14 20:16 wofeiwo

driverdevelop的bbs上看来的,说是此方法加载驱动不能创建device,记录一笔  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航:

导航

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

统计

留言簿(10)

随笔分类(90)

随笔档案(61)

搜索

最新随笔

最新评论