/
/
struct Attribute
{
UINT64 offset1 :
16
;
UINT64 p :
1
;
UINT64 dpl :
2
;
UINT64 s :
1
;
UINT64
type
:
4
;
UINT64 unuse :
6
;
UINT64 ist :
2
;
UINT64 selector :
16
;
UINT64 offset2 :
16
;
};
typedef struct _IDT_ENTRY64 {
union hightStruct
{
UINT64 lower;
struct Attribute attribute;
};
UINT64 hight;
}IDT_ENTRY64,
*
PIDT_ENTRY64;
typedef struct _IDTR
{
UINT16 limit;
UINT64 base;
}IDTR,
*
PIDTR;
VOID Unload(PDRIVER_OBJECT pDriver) {
KdPrint((
"unload\r\n"
));
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver, PUNICODE_STRING pRegPath) {
NTSTATUS status
=
STATUS_SUCCESS;
pDriver
-
>DriverUnload
=
Unload;
KdPrint((
"start\r\n"
));
/
/
关闭smap和smep
UINT64 cr4
=
__readcr4();
cr4 &
=
0xffffffffffcfffff
;
__writecr4(cr4);
IDTR idtr
=
{
0
};
PIDT_ENTRY64 idtEntryArr
=
NULL;
__sidt(&idtr);
KdPrint((
"idt base:0x%llx, limit:0x%x\r\n"
,idtr.base ,idtr.limit));
if
(idtr.base
=
=
NULL && idtr.limit <
=
0
) {
return
STATUS_UNSUCCESSFUL;
}
idtEntryArr
=
(PIDT_ENTRY64)idtr.base;
DbgBreakPoint();
SIZE_T i
=
0
;
while
(i < (idtr.limit
/
16
))
{
UINT64 hight
=
idtEntryArr
-
>hight <<
32
;
UINT64 lower_1
=
(idtEntryArr
-
>lower &
0xffff000000000000
) >>
32
;
UINT64 lower_2
=
(idtEntryArr
-
>lower &
0x000000000000ffff
);
UINT64 offset
=
hight
+
lower_1
+
lower_2;
UINT16 selector
=
(idtEntryArr
-
>lower &
0x00000000ffff0000
) >>
16
;
KdPrint((
"中断门 index=%llu---offset=0x%llx---selector=0x%x---p=%d---dpl=%d---type=%d---ist=%d\r\n"
,
i, offset, (UINT32)selector, (UINT32)idtEntryArr
-
>attribute.p,
(UINT32)idtEntryArr
-
>attribute.dpl, (UINT32)idtEntryArr
-
>attribute.
type
,
(UINT32)idtEntryArr
-
>attribute.ist));
i
+
+
;
idtEntryArr
+
+
;
}
KdPrint((
"end\r\n"
));
return
status;
}