登录  | 立即注册

游客您好!登录后享受更多精彩

查看: 257|回复: 0

关于不用汇编获取IDT的方式

[复制链接]

171

主题

21

回帖

1106

积分

管理员

积分
1106
发表于 2024-12-24 19:56:59 | 显示全部楼层 |阅读模式
#include <WinDef.h>
#include<ntddk.h>

   typedef union _KIDTENTRY64 {
    struct {
     USHORT OffsetLow;
     USHORT Selector;
     USHORT IstIndex : 3;
     USHORT Reserved0 : 5;
     USHORT Type : 5;
     USHORT Dpl : 2;
     USHORT Present : 1;
     USHORT OffsetMiddle;
     ULONG OffsetHigh;
     ULONG Reserved1;
    };
    ULONG64 Alignment;
   } KIDTENTRY64, *PKIDTENTRY64;
   typedef struct _AMD64_DESCRIPTOR {
    USHORT  Pad[3];
    USHORT  Limit;
    ULONG64 Base;
   } AMD64_DESCRIPTOR, *PAMD64_DESCRIPTOR;
   typedef NTSTATUS(NTAPI *_KeSetAffinityThread)(
    IN PKTHREAD Thread,
    IN KAFFINITY Affinity);
   PKIDTENTRY64 *g_ppIdtEntry;


VOID GetIDT()
{
PKIDTENTRY64 Idt;
KAFFINITY Processor = KeQueryActiveProcessors();
UNICODE_STRING ustrKeSetAffinityThread;
_KeSetAffinityThread KeSetAffinityThread;
RtlInitUnicodeString(&ustrKeSetAffinityThread, L"KeSetAffinityThread");
KeSetAffinityThread = (_KeSetAffinityThread)MmGetSystemRoutineAddress(&ustrKeSetAffinityThread);
LONG Count = 0;
for (LONG i = 0; i < Processor; i++)
{
   LONG a = Processor & (1 << i);
   if (a != 0)
   {
    KeSetAffinityThread(KeGetCurrentThread(), (KAFFINITY)a);
    Idt = KeGetPcr()->IdtBase;//主要是巨硬封装好的函数
    g_ppIdtEntry[Count] = Idt;
    DbgPrint("%d  %p \r\n", Count, g_ppIdtEntry[Count]);
    Count++;
    continue;
   }
   break;
}
}
VOID IDTUnload(IN PDRIVER_OBJECT DriverObject)
{
DbgPrint("卸载成功");
ExFreePoolWithTag(g_ppIdtEntry, 'gidt');
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING  RegistryPath)
{
NTSTATUS Status = STATUS_SUCCESS;

g_ppIdtEntry = (PKIDTENTRY64 *)ExAllocatePoolWithTag(NonPagedPool, sizeof(PKIDTENTRY64) * KeNumberProcessors,'gidt');
if (!MmIsAddressValid(g_ppIdtEntry))
{
   DbgPrint("g_ppIdtEntry Error ");
   return Status;
}
GetIDT();
for (size_t i = 0; i < KeNumberProcessors; i++)
{
   DbgPrint("%0.8X %0.8X %0.8X %p\r\n",
    g_ppIdtEntry[0].OffsetHigh,
    g_ppIdtEntry[0].OffsetMiddle,
    g_ppIdtEntry[0].OffsetLow,
    (((ULONGLONG)g_ppIdtEntry[0].OffsetHigh << 32) |               //(直接+也可以)
    ((ULONGLONG)g_ppIdtEntry[0].OffsetMiddle << 16) |
    (ULONG)g_ppIdtEntry[0].OffsetLow));
}

DriverObject->DriverUnload = IDTUnload;
return Status;
}

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|断点社区 |网站地图

GMT+8, 2025-4-11 18:00 , Processed in 0.101989 second(s), 23 queries , Yac On.

Powered by XiunoBBS

Copyright © 2001-2025, 断点社区.

快速回复 返回顶部 返回列表