中断门:
 
中断描述符在IDT表里面
kd> dq idtr
80b95400  83e48e00`0008bfc0 83e48e00`0008c150
80b95410  00008500`00580000 83e4ee00`0008c5c0
80b95420  83e4ee00`0008c748 83e48e00`0008c8a8
80b95430  83e48e00`0008ca1c 83e48e00`0008d018
80b95440  00008500`00500000 83e48e00`0008d478
80b95450  83e48e00`0008d59c 83e48e00`0008d6dc
80b95460  83e48e00`0008d93c 83e48e00`0008dc2c
80b95470  83e48e00`0008e2fc 83e48e00`0008e6b0
//每一个都是int开头的中断 
如果查看INT 3中断
kd> !idt 3
Dumping IDT: 80b95400
844bd02600000003:	83e4c5c0 nt!KiTrap03
//83e4c5c0 是函数的调用地址
//nt!KiTrap03是INT 3中断的回调函数 
构造一个中断门
1.在IDT表找未使用的位置

2.假设构造的中断回调函数的地址是:0x00401000h,P = 1、DPL = 3、cs = 0x8
3.开始构造 INT 0x20
0000 0000 0100 0000 1110 1110 0000 0000 = 0040EE00
0000 0000 0000 1000 0001 0000 0000 0000 = 00081000
eq 80b95500 0040ee0000081000
#include "stdafx.h"
_declspec(naked) void func(){
	__asm{
		int 3
		iretd;
	}
}
int main(int argc, char* argv[])
{
	__asm{
        push fs;
		int 0x20;
        pop fs;
	}
	return 0;
} 
可以看到 中断门 压入了5个参数,iretd会返回这5个参数。
  
陷阱门:
 
陷阱门和中断门几乎一模一样。
#include "stdafx.h"
_declspec(naked) void func(){
	__asm{
		int 3;
		iretd;
	}
}
int main(int argc, char* argv[])
{
	__asm{
		push fs;
		int 0x20;
		pop fs;
	}
	return 0;
} 
根据陷阱门描述符修改一下 INT 0x20的描述符
eq 80b95500 0040ef0000081000

陷阱门与中断门的唯一的区别:
中断门执行时,会将IF标志位清零,但陷阱门不会。
IF=0 时:程序不再接收可屏蔽中断(有些硬件中断不响应)。



















