INT指令的确切行为是什么?
What is the exact behaviour of INT instruction?
如x86指令:push
可以精确描述为:
push:
sub esp, data_size
mov [esp], data
而call
可以描述为:
call:
push (eip+2)
jmp addr
了解了这些,我们就会完全清楚这些指令是如何影响堆栈、寄存器和标志的,我认为这是至关重要的。
然而,经过"Intel® 64 and IA-32 Architectures Software Developer’s Manual"之后。并且 "i386 programmers' manual" 我没有发现任何关于 INT 指令的确切行为。
现在,我想在 INT 调用后修改堆栈,使我的程序 return 到另一个地方。
那么,INT被调用后到底做了什么?
(通过程序员或硬件。我听说他们的行为不同)
提前致谢!!
ps:
As far as I know, INT pushes eip, 4 general registers, eflags and
some weird things in some order.
I observed that it consumed 6 bytes on stack when called by me,
and it consumed 18 bytes when triggered by hardware.(like clock)
supplement: my code
hook ivt 0x1ch(System Timer Tick) to my function [foo]
sti
jmp $
foo: print 'A'
I check the stack at jmp $
and just before entering foo
I observed that it consumed 6 bytes on stack when called by me
从这一行和标签 "operating-system" 中我得出结论,您已经使用了实地址模式中的 int
指令。在这种情况下,堆栈将在中断处理程序的开头保存 3 个字。
压入的第一个字(内存中最高的)是FLAGS
寄存器,压入的第二个字是CS
寄存器,压入的第三个字(内存中最低的)是IP
注册.
Now, I want to modify the stack after INT call, to make my program return to another place.
你可以自由地用这三个词中的任何一个或所有词来写任何合适的东西。
到return到不同的地址但仍然在同一个代码段,你会写:
mov word ptr [esp], OtherLabel
iret
到设置了 CarryFlag 的 return,你写:
or word ptr [esp+4], 1
iret
如x86指令:push
可以精确描述为:
push:
sub esp, data_size
mov [esp], data
而call
可以描述为:
call:
push (eip+2)
jmp addr
了解了这些,我们就会完全清楚这些指令是如何影响堆栈、寄存器和标志的,我认为这是至关重要的。
然而,经过"Intel® 64 and IA-32 Architectures Software Developer’s Manual"之后。并且 "i386 programmers' manual" 我没有发现任何关于 INT 指令的确切行为。
现在,我想在 INT 调用后修改堆栈,使我的程序 return 到另一个地方。
那么,INT被调用后到底做了什么?
(通过程序员或硬件。我听说他们的行为不同)
提前致谢!!
ps:
As far as I know, INT pushes eip, 4 general registers, eflags and some weird things in some order.
I observed that it consumed 6 bytes on stack when called by me,
and it consumed 18 bytes when triggered by hardware.(like clock)
supplement: my code
hook ivt 0x1ch(System Timer Tick) to my function [foo]
sti
jmp $
foo: print 'A'
I check the stack at
jmp $
and just before enteringfoo
I observed that it consumed 6 bytes on stack when called by me
从这一行和标签 "operating-system" 中我得出结论,您已经使用了实地址模式中的 int
指令。在这种情况下,堆栈将在中断处理程序的开头保存 3 个字。
压入的第一个字(内存中最高的)是FLAGS
寄存器,压入的第二个字是CS
寄存器,压入的第三个字(内存中最低的)是IP
注册.
Now, I want to modify the stack after INT call, to make my program return to another place.
你可以自由地用这三个词中的任何一个或所有词来写任何合适的东西。
到return到不同的地址但仍然在同一个代码段,你会写:
mov word ptr [esp], OtherLabel iret
到设置了 CarryFlag 的 return,你写:
or word ptr [esp+4], 1 iret