在驱动内增加一个IDT项

VOID IdtAt23()
{
 KdPrint(("IN 0x23\n"));
}

//=========================================================================
//函数名:AddIdt
//功能 :在IDT表中增加一个新的IDT项
//  
//参数:
//  IN ulIdtIndex  新的IDT表项
//  IN ulNewIdtFunAddr 新的Idt处理函数
//返回值:
//  TRUE 成功
//  FALSE 失败
//=========================================================================
void AddIdt(IN const ULONG ulIdtIndex,IN ULONG ulNewIdtFunAddr)
{
 IDTR idtr;
 PIDTENTRY pstTempEntry = NULL,pstOriEntry = NULL;
 ULONG ulAddress = 0;

 DriverObject->DriverUnload = OnUnload;

 _asm{
  sidt idtr
 }

 pstOriEntry = (PIDTENTRY)MAKELONG(idtr.LowIDTbase,idtr.HiDIDTbase);
 
 TempEntry = OriEntry + ulIdtIndex;
 ulAddress = (ULONG)ulNewIdtFunAddr;
 pstTempEntry->LowOffset = (USHORT)ulAddress;
 pstTempEntry->HiOffset = (USHORT)(ulAddress >> 16);
 pstTempEntry->DPL = 0x3;
 pstTempEntry->P = 0x1;
 pstTempEntry->Segment_Type = 0xe;
 pstTempEntry->Selector = 0x8;

 return;
}

voidt TestAddIdt(void)
{
 AddIdt(0x23,(ULONG)IdtAt23);
}
 

你可能感兴趣的:(职场,休闲,IDT,AddIdt)