/
/
By: LyShark 内核开发系列教程
/
/
https:
/
/
www.cnblogs.com
/
LyShark
/
articles
/
16784393.html
typedef struct _IO_TIMER
{
INT16
Type
;
INT16 TimerFlag;
LONG32 Unknown;
LIST_ENTRY TimerList;
PVOID TimerRoutine;
PVOID Context;
PVOID DeviceObject;
}IO_TIMER,
*
PIO_TIMER;
/
/
得到IoInitializeTimer基址
PVOID GetIoInitializeTimerAddress()
{
PVOID VariableAddress
=
0
;
UNICODE_STRING uioiTime
=
{
0
};
RtlInitUnicodeString(&uioiTime, L
"IoInitializeTimer"
);
VariableAddress
=
(PVOID)MmGetSystemRoutineAddress(&uioiTime);
if
(VariableAddress !
=
0
)
{
return
VariableAddress;
}
return
0
;
}
VOID UnDriver(PDRIVER_OBJECT driver)
{
DbgPrint(
"卸载完成... \n"
);
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT Driver, PUNICODE_STRING RegistryPath)
{
DbgPrint((
"hello lyshark.com \n"
));
/
/
得到基址
PUCHAR IoInitializeTimer
=
GetIoInitializeTimerAddress();
DbgPrint(
"IoInitializeTimer Address = %p \n"
, IoInitializeTimer);
/
/
搜索IoTimerQueueHead地址
/
*
nt!IoInitializeTimer
+
0x5d
:
fffff806`
349963cd
488d5008
lea rdx,[rax
+
8
]
fffff806`
349963d1
48897018
mov qword ptr [rax
+
18h
],rsi
fffff806`
349963d5
4c8d05648de0ff
lea r8,[nt!IopTimerLock (fffff806`
3479f140
)]
fffff806`
349963dc
48897820
mov qword ptr [rax
+
20h
],rdi
fffff806`
349963e0
488d0d99f6cdff
lea rcx,[nt!IopTimerQueueHead (fffff806`
34675a80
)]
fffff806`
349963e7
e8c43598ff call nt!ExInterlockedInsertTailList (fffff806`
343199b0
)
fffff806`
349963ec
33c0
xor eax,eax
*
/
INT32 iOffset
=
0
;
PLIST_ENTRY IoTimerQueueHead
=
NULL;
PUCHAR StartSearchAddress
=
IoInitializeTimer;
PUCHAR EndSearchAddress
=
IoInitializeTimer
+
0xFF
;
UCHAR v1
=
0
, v2
=
0
, v3
=
0
;
for
(PUCHAR i
=
StartSearchAddress; i < EndSearchAddress; i
+
+
)
{
if
(MmIsAddressValid(i) && MmIsAddressValid(i
+
1
) && MmIsAddressValid(i
+
2
))
{
v1
=
*
i;
v2
=
*
(i
+
1
);
v3
=
*
(i
+
2
);
/
/
fffff806`
349963e0
48
8d
0d
99
f6 cd ff lea rcx,[nt!IopTimerQueueHead (fffff806`
34675a80
)]
if
(v1
=
=
0x48
&& v2
=
=
0x8d
&& v3
=
=
0x0d
)
{
memcpy(&iOffset, i
+
3
,
4
);
IoTimerQueueHead
=
(PLIST_ENTRY)(iOffset
+
(ULONG64)i
+
7
);
DbgPrint(
"IoTimerQueueHead = %p \n"
, IoTimerQueueHead);
break
;
}
}
}
/
/
枚举列表
KIRQL OldIrql;
/
/
获得特权级
OldIrql
=
KeRaiseIrqlToDpcLevel();
if
(IoTimerQueueHead && MmIsAddressValid((PVOID)IoTimerQueueHead))
{
PLIST_ENTRY NextEntry
=
IoTimerQueueHead
-
>Flink;
while
(MmIsAddressValid(NextEntry) && NextEntry !
=
(PLIST_ENTRY)IoTimerQueueHead)
{
PIO_TIMER Timer
=
CONTAINING_RECORD(NextEntry, IO_TIMER, TimerList);
if
(Timer && MmIsAddressValid(Timer))
{
DbgPrint(
"IO对象地址: %p \n"
, Timer);
}
NextEntry
=
NextEntry
-
>Flink;
}
}
/
/
恢复特权级
KeLowerIrql(OldIrql);
Driver
-
>DriverUnload
=
UnDriver;
return
STATUS_SUCCESS;
}