首页
社区
课程
招聘
求助:除零异常与int 0的区别?
发表于: 2010-5-25 22:32 8409

求助:除零异常与int 0的区别?

2010-5-25 22:32
8409

除零会引发0号异常,使用try...except...能捕捉到EXCEPTION_INT_DIVIDE_BY_ZERO的异常。

但是使用int 0替换除零语句,却没有捕捉到EXCEPTION_INT_DIVIDE_BY_ZERO异常,相反引发了EXCEPTION_ACCESS_VIOLATION 异常。

使用反汇编跟踪,发现执行int 0后,后续指令错位:

(执行int 0之前)
__asm int 0;
004113FD  int         0    (<--光标)

(执行int 0之后)
004113FD  db          cdh  
004113FE  add         bh,al  (<--光标)
00411400  inc         ebp  
00411401  cld              
00411402  db          feh  
00411403  db          ffh  
00411404  db          ffh  
00411405  db          ffh  

怀疑CPU把int 0当做int 3(cc)看待了,回退到下一个字节的指令处重新执行,因此产生了EXCEPTION_ACCESS_VIOLATION 异常。

那么问题所在:
1、是否CPU把int x都当做int 3(cc)看待?
2、为什么没有引发除零异常?

请诸位帮助我分析一下除零和int 0的区别所在,以及以上的问题,多谢大家!

P.S. 最近在下在研究Windows异常,一直纠结于CPU产生异常和程序员主动调用int x的区别,不胜纠结啊,希望大家帮我梳理一下~

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 0
支持
分享
最新回复 (16)
雪    币: 622
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
同学 可以参考一下 idt 表
2010-5-25 22:36
0
雪    币: 1505
能力值: (RANK:210 )
在线值:
发帖
回帖
粉丝
3
研究不如直接看书
软件调试 那本很厚的书上有详细说明.建议楼主花钱买一本.
然后把k币给我.
2010-5-25 22:38
0
雪    币: 156
活跃值: (26)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
4
CPU遇到除零异常,不是也去idt表的0项找处理程序么?int 0,不就是主动调用IDT的0项的处理程序么?

我就是在这里没想明白区别
2010-5-25 22:38
0
雪    币: 156
活跃值: (26)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
5
软件调试早已经拜读过了……没找到这个问题的解,所以今晚才做的这个实验

可能是最近我大脑抽风了,怎么也想不明白这个问题,希望大家不吝赐教……
2010-5-25 22:39
0
雪    币: 622
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
从抛出的异常入手 应该也能找到答案  可以找个仿的代码看看
2010-5-25 22:58
0
雪    币: 2067
活跃值: (82)
能力值: ( LV9,RANK:180 )
在线值:
发帖
回帖
粉丝
7
你写 int 0 , 他产生的是 int 0D.
分给我吧  
2010-5-26 03:10
0
雪    币: 156
活跃值: (26)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
8
指令是cd 00啊,为什么会产生 int 0D?
2010-5-26 07:15
0
雪    币: 2067
活跃值: (82)
能力值: ( LV9,RANK:180 )
在线值:
发帖
回帖
粉丝
9
你可去看一下CPU的书

翻到以前写的, 你先凑合一下
http://bbs.pediy.com/showthread.php?t=86385
4楼
2010-5-26 07:56
0
雪    币: 331
活跃值: (57)
能力值: ( LV7,RANK:100 )
在线值:
发帖
回帖
粉丝
10
从栈结构上看Int指令不会有出错码,而异常可能有。另外任何的Int出来后都停留在下一条指令(其实那条指令已经执行了,好像有个反单步调试确实是跳过一个字节)
2010-5-26 10:35
0
雪    币: 156
活跃值: (26)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
11
1、除零异常没有出错码啊
2、不会吧,貌似就是int 3是这样吧,因为OS的ISR手动实现了ip的回退,使用int 0x2e进行系统调用的时候指令流也是正常的啊。
2010-5-26 11:40
0
雪    币: 156
活跃值: (26)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
12
[QUOTE=sessiondiy;813602]你可去看一下CPU的书

翻到以前写的, 你先凑合一下
http://bbs.pediy.com/showthread.php?t=86385
4楼[/QUOTE]

看了你的帖子,貌似明白了一些,等我再翻翻资料整理一下思路再来回复。

P.S. 我觉得看Intel的那三本手册才是王道,但是真的啃不动……
2010-5-26 11:46
0
雪    币: 246
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
13
应当是Ring级别访问控制问题,除零会引发0号异常,是具有最高权限ring0的系统核心做出,所以它正常执行int0代码,从而可以捕捉到EXCEPTION_INT_DIVIDE_BY_ZERO异常;

而你在ring3直接调用int0,则超出了ring3的权限,系统发现你越权后,并没有执行int0,而是执行int3产生EXCEPTION_ACCESS_VIOLATION,告诉你越权了。

以上观点是个人认识,请认真求证,以确保正确。
2010-5-26 13:21
0
雪    币: 331
活跃值: (57)
能力值: ( LV7,RANK:100 )
在线值:
发帖
回帖
粉丝
14
Interrupt Descriptor Table
Base: 8003F400   Limit: 000007FF

Selector        - Segment Selector for destination code segment
Offset                - Offset to procedure entry point
DPL                ?Descriptor privilege level
P                ?Segment present
D                - Size of gate: 1 = 32 bits; 0 = 16 bits D

--------------------------------------------------------------------------------------------------------------
Int.  Sel.:Offset    DPL  P   D        Descriptor Type   Description
--------------------------------------------------------------------------------------------------------------
0000  0008:80542420   0   P   32 bits  Interrupt Gate   Fault       Divide Error
0001  0008:8054259C   0   P   32 bits  Interrupt Gate   Fault/Trap  Debug
0002  0058:0000112E   0   P            Task Gate        Interrupt   NMI Interrupt
0003  0008:805429B0   3   P   32 bits  Interrupt Gate   Trap        Breakpoint
0004  0008:80542B30   3   P   32 bits  Interrupt Gate   Trap        Overflow
0005  0008:80542C90   0   P   32 bits  Interrupt Gate   Fault       BOUND Range Exceeded
0006  0008:80542E04   0   P   32 bits  Interrupt Gate   Fault       Invalid Opcode (Undefined Opcode). Was introduced in the Pentium Pro processor
0007  0008:8054347C   0   P   32 bits  Interrupt Gate   Fault       Device Not Available (No Math Coprocessor)
0008  0050:00001188   0   P            Task Gate        Abort       Double Fault
0009  0008:80543880   0   P   32 bits  Interrupt Gate   Fault       Coprocessor Segment Overrun (reserved). IA-32 processors after the Intel386 processor do not generate this exception.
000A  0008:805439A0   0   P   32 bits  Interrupt Gate   Fault       Invalid TSS
000B  0008:80543AE0   0   P   32 bits  Interrupt Gate   Fault       Segment Not Present
000C  0008:80543D40   0   P   32 bits  Interrupt Gate   Fault       Stack-Segment Fault
000D  0008:8054402C   0   P   32 bits  Interrupt Gate   Fault       General Protection
000E  0008:80544740   0   P   32 bits  Interrupt Gate   Fault       Page Fault
000F  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
0010  0008:80544B98   0   P   32 bits  Interrupt Gate   Fault       x87 FPU Floating-Point Error (Math Fault)
0011  0008:80544CD4   0   P   32 bits  Interrupt Gate   Fault       Alignment Check. Was introduced in the Intel486 processor.
0012  00A0:80544A78   0   P            Task Gate        Abort       Machine Check. Was introduced in the Pentium processor and enhanced in the P6 family processors.
0013  0008:80544E3C   0   P   32 bits  Interrupt Gate   Fault       SIMD Floating-Point Exception. Was introduced in the Pentium III processor.
0014  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
0015  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
0016  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
0017  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
0018  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
0019  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
001A  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
001B  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
001C  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
001D  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
001E  0008:80544A78   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
001F  0008:806E510C   0   P   32 bits  Interrupt Gate               Intel reserved. Do not use
0020  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0021  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0022  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0023  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0024  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0025  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0026  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0027  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0028  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
0029  0008:00000000   0   NP  16 bits                               User Defined (Non-reserved) Interrupts
002A  0008:80541C4E   3   P   32 bits  Interrupt Gate               User Defined (Non-reserved) Interrupts
002B  0008:80541D50   3   P   32 bits  Interrupt Gate               User Defined (Non-reserved) Interrupts
002C  0008:80541F00   3   P   32 bits  Interrupt Gate               User Defined (Non-reserved) Interrupts
002D  0008:8054288C   3   P   32 bits  Interrupt Gate               User Defined (Non-reserved) Interrupts
002E  0008:805416D1   3   P   32 bits  Interrupt Gate               User Defined (Non-reserved) Interrupts
恩楼上正解……
2010-5-26 18:36
0
雪    币: 156
活跃值: (26)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
15
看到sessiondiy 的帖子让我顿悟了,原来我忘记了还有一个叫做dpl的东东……

那么答案应该是int指令会进行权限检查,而CPU自己产生的exception不会。

感谢诸位的帮助,分数主要就给最先提供答案的sessiondiy兄了。
2010-5-27 06:59
0
雪    币: 40
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
16
14楼的同学 的信息是用什么工具看的啊
2010-7-22 11:19
0
雪    币: 459
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
17
之前我也没想明白
2010-7-22 11:34
0
游客
登录 | 注册 方可回帖
返回
//