|
采用了点硬编码,只是实验性质的,目前正在弄,半成品
别的没什么,防止底层的,特定扇区的读写~
要防删除文件什么的,还要再把MFT保护起来- #include <wdm.h>
- #include <srb.h>
- #include <windef.h>
- NTSTATUS
- DriverEntry( PDRIVER_OBJECT DriverObject,
- PUNICODE_STRING RegisterPath);
-
- #pragma alloc_text(INIT, DriverEntry)
- ////////////////////////////////////////
- //global
- ///////////////////////////////////////
- char jmpcode[5] = { 0xE9, 0x00, 0x00 , 0x00, 0x00};
- char origcode[5] = { 0};
- ULONG g_orig_addr = 0xf97a197e;
- ///////////////////////////////////////
- //function
- ///////////////////////////////////////
- VOID WPON()
- {
- __asm{
- mov eax,cr0
- or eax,0x10000
- mov cr0,eax
- STI
- }
-
- }
- VOID WPOFF()
- {
- __asm{
- cli
- mov eax, cr0
- and eax,not 0x10000
- mov cr0,eax
- }
-
- }
- VOID
- DriverUnload( PDRIVER_OBJECT DriverObject )
- {
- KIRQL oldIrql;
-
- WPOFF();
- oldIrql = KeRaiseIrqlToDpcLevel();
- RtlCopyMemory( (BYTE*)g_orig_addr, origcode, 5 );
-
- KeLowerIrql(oldIrql);
- WPON();
- }
- __declspec(naked)
- NTSTATUS
- orig_AtapiStartIo( PVOID devext_addr_ach,
- struct _SCSI_REQUEST_BLOCK* srb
- )
- {
- __asm
- {
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- _emit 0x90
- }
- }
-
- BOOLEAN
- fake_AtapiStartIo( PVOID devext_add_ach,
- struct _SCSI_REQUEST_BLOCK* srb
- )
- {
- ULONG max,min;
-
- max = 4868496+57;
- min = 4868496;
-
- if( srb->QueueSortKey <= max &&
- srb->QueueSortKey >= min)
- {
- KdBreakPoint();
- }
-
- return orig_AtapiStartIo(devext_add_ach, srb);
- }
- VOID
- InlineHook( ULONG orig_addr,
- ULONG fake_addr)
- {
- ULONG distance;
- KIRQL oldIrql;
- char jmp_orig_code[7] = { 0xEA, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 };
-
- distance = fake_addr-orig_addr-5;
- RtlCopyMemory( origcode, (BYTE*)orig_addr, 5);
- RtlCopyMemory( jmpcode+1, (BYTE*)&distance, 4);
-
- WPOFF();
- oldIrql = KeRaiseIrqlToDpcLevel();
-
- RtlCopyMemory( (BYTE*)orig_AtapiStartIo, (BYTE*)origcode, 5);
- *( (ULONG*)(jmp_orig_code + 1) ) = (ULONG)((BYTE*)orig_addr + 5);
- RtlCopyMemory( (BYTE*)orig_AtapiStartIo+5, jmp_orig_code, 7);
- RtlCopyMemory( (BYTE*)orig_addr, jmpcode, 5);
-
- KeLowerIrql(oldIrql);
- WPON();
-
- KdPrint(("\nthe inline hook has done!\n"));
- KdBreakPoint();
-
- return;
- }
- NTSTATUS
- DriverEntry( PDRIVER_OBJECT DriverObject,
- PUNICODE_STRING RegisterPath)
- {
- NTSTATUS status;
-
- DriverObject->DriverUnload = DriverUnload;
-
- InlineHook( g_orig_addr, (ULONG)fake_AtapiStartIo);
-
- status = STATUS_SUCCESS;
- return status;
- }
复制代码 |
|