2834|3

71

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

idt hook在有其它线程运行的时候,出现蓝屏,为什么? [复制链接]




#include "MyKeyHook.h"

///////////////////////////////////////////////////
// IDT structures
///////////////////////////////////////////////////
#pragma pack(1)

// entry in the IDT, this is sometimes called
// an "interrupt gate"
typedef struct
{
        unsigned short LowOffset;
        unsigned short selector;
        unsigned char unused_lo;
        unsigned char segment_type:4;        //0x0E is an interrupt gate
        unsigned char system_segment_flag:1;
        unsigned char DPL:2;        // descriptor privilege level
        unsigned char P:1; /* present */
        unsigned short HiOffset;
} IDTENTRY;

/* sidt returns idt in this format */
typedef struct
{
        unsigned short IDTLimit;
        unsigned short LowIDTbase;
        unsigned short HiIDTbase;
} IDTINFO;

#pragma pack()


unsigned long old_ISR_pointer;
unsigned char keystroke_buffer[MAX_CHARS];
int kb_array_ptr=0;

       
VOID OnUnload( IN PDRIVER_OBJECT DriverObject )
{
        IDTINFO                idt_info;
        IDTENTRY*        idt_entries;
//        char _t[255];

        // load idt_info
        __asm        sidt        idt_info       
        idt_entries = (IDTENTRY*) MAKELONG(idt_info.LowIDTbase,idt_info.HiIDTbase);

        DbgPrint("UnHooking Interrupt...");

        // restore the original interrupt handler
        __asm cli
        idt_entries[kb_int].LowOffset = (unsigned short) old_ISR_pointer;
        idt_entries[kb_int].HiOffset = (unsigned short)((unsigned long)old_ISR_pointer >> 16);
        __asm sti

        DbgPrint("UnHooking Interrupt complete.");
       
        DbgPrint("Keystroke Buffer is: ");
        DbgPrint("%s", keystroke_buffer);
}

#pragma data_seg()
LARGE_INTEGER gl_CurrentTime;
#pragma data_seg()
LARGE_INTEGER result;
KIRQL irql,irql2;
void __stdcall print_timecount()
{

        result=KeQueryPerformanceCounter(&gl_CurrentTime);

        DbgPrint("my___________________________________Hook%16u %16u\n",result.HighPart,result.LowPart);          //经测试,在有其它线程运行时,由于此处发生蓝屏,为什么?????????

                                                                                                                  //如果没有其它线程运行,则此IDT HOOK正常运行
}


__declspec(naked) my_interrupt_hook()
{
       
        __asm
        {
                cli
                pushad                                        // save all general purpose registers
                pushfd                                        // save the flags register

        }

       

        __asm call print_timecount
       
        __asm
        {
                       

                popfd                                        // restore the flags
                popad                                        // restore the general registers

                sti
                jmp                old_ISR_pointer        // goto the original ISR

        }
}




#pragma INITCODE
NTSTATUS DriverEntry( IN PDRIVER_OBJECT theDriverObject, IN PUNICODE_STRING theRegistryPath )
{
        IDTINFO                idt_info;
        IDTENTRY*        idt_entries;
//        char _t[255];
       
        theDriverObject->DriverUnload  = OnUnload;



        kb_int= 0x93;//为本机键盘中断号
        DbgPrint("kb_int = 0x%02X\n", kb_int);

        // load idt_info
        __asm        sidt        idt_info
       
        idt_entries = (IDTENTRY*) MAKELONG(idt_info.LowIDTbase,idt_info.HiIDTbase);

        DbgPrint("Hooking Interrupt...");
        old_ISR_pointer = MAKELONG(idt_entries[kb_int].LowOffset,idt_entries[kb_int].HiOffset);
       
        // remember we disable interrupts while we patch the table
        __asm cli
        idt_entries[kb_int].LowOffset = (unsigned short)my_interrupt_hook;
        idt_entries[kb_int].HiOffset = (unsigned short)((unsigned long)my_interrupt_hook >> 16);
        __asm sti

        DbgPrint("Hooking Interrupt complete: Old = 0x%08X, New = 0x%08X\n", old_ISR_pointer, my_interrupt_hook);

         _asm int 0x93;

        return STATUS_SUCCESS;
}





最新回复

没记错的话,IDT表是每个CPU都有一个,你有考虑么  详情 回复 发表于 2009-4-13 14:07
点赞 关注

回复
举报

85

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
--------------------------------------------------
我在任意的一下进程中,新建一个线程,如
WORD WINAPI ThreadProc1( LPVOID lpParam )
{
  while(1)
  {

  }

  return 1;
}



hThread[1] = CreateThread(
      NULL,              // default security attributes
      0,                 // use default stack size  
      ThreadProc1,        // thread function
      NULL,             // argument to thread function
      0,                 // use default creation flags
      &dwThreadId[1]);   // returns the thread identifier


这样再按键盘就会出现蓝屏,DUMP如下
kd> !analyze -v
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************

UNEXPECTED_KERNEL_MODE_TRAP (7f)
This means a trap occurred in kernel mode, and it's a trap of a kind
that the kernel isn't allowed to have/catch (bound trap) or that
is always instant death (double fault).  The first number in the
bugcheck params is the number of the trap (8 = double fault, etc)
Consult an Intel x86 family manual to learn more about what these
traps are. Here is a *portion* of those codes:
If kv shows a taskGate
        use .tss on the part before the colon, then kv.
Else if kv shows a trapframe
        use .trap on that value
Else
        .trap on the appropriate frame will show where the trap was taken
        (on x86, this will be the ebp that goes with the procedure KiTrap)
Endif
kb will then show the corrected stack.
Arguments:
Arg1: 0000000d, EXCEPTION_GP_FAULT
Arg2: 00000000
Arg3: 00000000
Arg4: 00000000

Debugging Details:
------------------

*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: kernel32!pNlsUserInfo                         ***
***                                                                   ***
*************************************************************************
*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: kernel32!pNlsUserInfo                         ***
***                                                                   ***
*************************************************************************

BUGCHECK_STR:  0x7f_d

DEFAULT_BUCKET_ID:  DRIVER_FAULT

PROCESS_NAME:  MultiThreadTest

LAST_CONTROL_TRANSFER:  from 804f8b9d to 80528bdc

STACK_TEXT:  
ef40b8a4 804f8b9d 00000003 ef40bc00 00000000 nt!RtlpBreakWithStatusInstruction
ef40b8f0 804f978a 00000003 80538f15 02480248 nt!KiBugCheckDebugBreak+0x19
ef40bcd0 80541dff 0000007f 0000000d 00000000 nt!KeBugCheck2+0x574
ef40bcd0 80538f15 0000007f 0000000d 00000000 nt!KiSystemFatalException+0xf
ef40bd8c f898d393 f898f1b4 00000000 1b70c81e nt!_SEH_prolog+0x5
WARNING: Stack unwind information not available. Following frames may be wrong.
ef40bda0 f898d3a0 00000002 0064ffb4 02480248 HelloDDK+0x1393
ef40bddc 80542dd2 efcd893d efcd7fc0 00000000 HelloDDK+0x13a0
ef40bde0 efcd893c efcd7fc0 00000000 0000027f nt!KiThreadStartup+0x16
ef40bdf0 02480000 00000000 00000000 00000000 rdbss!RxInitializeContext+0x132
ef40be04 00000000 02480248 02480248 02480248 0x2480000


STACK_COMMAND:  kb

FOLLOWUP_IP:
HelloDDK+1393
f898d393 83c40c          add     esp,0Ch

SYMBOL_STACK_INDEX:  5

SYMBOL_NAME:  HelloDDK+1393

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: HelloDDK

IMAGE_NAME:  HelloDDK.sys

DEBUG_FLR_IMAGE_TIMESTAMP:  49d1da6b

FAILURE_BUCKET_ID:  0x7f_d_HelloDDK+1393

BUCKET_ID:  0x7f_d_HelloDDK+1393

Followup: MachineOwner
---------



请问这是为什么呢?




 
 

回复

73

帖子

0

TA的资源

一粒金砂(中级)

板凳
 
请大家帮分析一下啊,我实在想不明白了
 
 
 

回复

72

帖子

0

TA的资源

一粒金砂(初级)

4
 
没记错的话,IDT表是每个CPU都有一个,你有考虑么
 
 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
【干货上新】电源解决方案和技术第二趴 | DigiKey 应用探索站
当月好物、电源技术资源、特色活动、DigiKey在线实用工具,干货多多~

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网 5

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表