.386
.model flat,stdcall
option casemap:none
include D:\RadASM\masm32\include\w2k\ntstatus.inc
include D:\RadASM\masm32\include\w2k\ntddk.inc
include D:\RadASM\masm32\include\w2k\ntoskrnl.inc
includelib D:\RadASM\masm32\lib\w2k\ntoskrnl.lib
include D:\RadASM\masm32\Macros\Strings.mac
_NTOPENPROCESS typedef proto :DWORD,:DWORD,:DWORD,:DWORD
NTOPENPROCESS typedef ptr _NTOPENPROCESS
.data
OldNtOpenProcess NTOPENPROCESS ?
dwNtOpenProcess_Addr dd ?
dwImageFileNameOffset dd ?
.code
GetImageFileNameOffset proc uses esi ebx
invoke IoGetCurrentProcess
mov esi, eax
xor ebx, ebx
.while ebx < 1000h
lea eax, [esi+ebx]
invoke _strnicmp, eax, $CTA0("system"), 6
.break .if eax == 0
inc ebx
.endw
.if eax == 0
mov eax, ebx
.else
xor eax, eax
.endif
ret
GetImageFileNameOffset endp
MyNtOpenProcess proc hProcess,DesiredAccess,pObjectAttributes,pClientId
local lpEPROCESS:PVOID
mov ecx,pClientId
assume ecx:ptr CLIENT_ID
invoke PsLookupProcessByProcessId,[ecx].UniqueProcess,addr lpEPROCESS
assume ecx:nothing
.if eax == STATUS_SUCCESS
mov esi,lpEPROCESS
add esi,dwImageFileNameOffset
invoke _strnicmp, esi, $CTA0("notepad.exe"),7
.if eax==0
mov eax,STATUS_ACCESS_DENIED
ret
.endif
.endif
invoke OldNtOpenProcess,hProcess,DesiredAccess,pObjectAttributes,pClientId
ret
MyNtOpenProcess endp
DriverUnload proc pDriverObject:PDRIVER_OBJECT
pushad
invoke DbgPrint,$CTA0("卸载成功\n")
cli
mov eax,cr0
xor eax,10000h
mov cr0,eax
mov esi,dwNtOpenProcess_Addr
mov eax,OldNtOpenProcess
mov dword ptr[esi],eax
mov eax, cr0
xor eax,10000h
mov cr0, eax
sti
popad
ret
DriverUnload endp
DriverEntry proc pDriverObject:PDRIVER_OBJECT,pRegistryPath:PUNICODE_STRING
pushad
invoke DbgPrint,$CTA0("安装成功\n")
invoke GetImageFileNameOffset
mov dwImageFileNameOffset,eax
mov eax,KeServiceDescriptorTable
mov esi,[eax]
mov esi,[esi]
invoke MmGetSystemRoutineAddress,$CCOUNTED_UNICODE_STRING("ZwOpenProcess")
inc eax
movzx ecx,byte ptr[eax]
sal ecx,2
add esi,ecx
mov dwNtOpenProcess_Addr,esi
mov edi,dword ptr[esi]
mov OldNtOpenProcess,edi
invoke DbgPrint,$CTA0("OldNtOpenProcess: %X \n"),OldNtOpenProcess
mov edi,offset MyNtOpenProcess
cli
mov eax,cr0
xor eax,10000h
mov cr0,eax
mov dword ptr[esi],edi
mov eax, cr0
xor eax,10000h
mov cr0, eax
sti
invoke DbgPrint,$CTA0("MyNtOpenProcess: %X \n"),offset MyNtOpenProcess
mov esi,pDriverObject
mov [esi+34h],offset DriverUnload
popad
mov eax,STATUS_SUCCESS
ret
DriverEntry endp
end DriverEntry