|
发表于 2016-7-22 17:10:37
|
显示全部楼层
"第一步是说 在ds:[0eh] 处存储了call 的以一条指令的地址"
怎么理解,你那里不明白吗?
一开始 ds:[0eh] 的确是0
执行完 call word ptr ds:[0EH] 后改变成了call word ptr ds:[0EH]下一条指令的偏移地址 (是执行完以后改变的)
我亲自调试过,上面的分析是正确的
这是我的调试过程,可能会帮到你
- (0) context not implemented because BX_HAVE_HASH_MAP=0
- [0x000ffff0] f000:fff0 (unk. ctxt): jmp f000:e05b ; ea5be000f0
- <bochs:1> b 0x 7c00
- ..\bochsdbg.exe:1: syntax error at 'x'
- <bochs:2> b 0x7c00
- <bochs:3> c
- (0) Breakpoint 1, 0x7c00 in ?? ()
- Next at t=2393208
- (0) [0x00007c00] 0000:7c00 (unk. ctxt): mov ax, 0x7c0 ; b8c007
- <bochs:4> set $ip=0
- Error: set: unrecognized symbol.
- <bochs:5> info reg
- eax 0xaa55 43605
- ecx 0x100001 1048577
- edx 0x80 128
- ebx 0x80 128
- esp 0xfffe 0xfffe
- ebp 0x0 0x0
- esi 0x0 0
- edi 0xffe4 65508
- eip 0x7c00 0x7c00
- eflags 0x282 642
- cs 0x0 0
- ss 0x0 0
- ds 0x0 0
- es 0x0 0
- fs 0x0 0
- gs 0x0 0
- <bochs:6> set $eip=0
- <bochs:7> set $cs=0x7c0
- <bochs:8> s
- Next at t=2393209
- (0) [0x00007c03] 07c0:0003 (unk. ctxt): mov ss, ax ; 8ed0
- <bochs:9>
- Next at t=2393210
- (0) [0x00007c05] 07c0:0005 (unk. ctxt): mov sp, 0x25 ; bc2500
- <bochs:10>
- Next at t=2393211
- (0) [0x00007c08] 07c0:0008 (unk. ctxt): mov ds, ax ; 8ed8
- <bochs:11>
- Next at t=2393212
- (0) [0x00007c0a] 07c0:000a (unk. ctxt): mov ax, 0x0 ; b80000
- <bochs:12>
- Next at t=2393213
- [color=Red](0) [0x00007c0d] 07c0:000d (unk. ctxt): ds call word ptr [ds:0x23] ; 3eff162300[/color] // 第一次执行
- <bochs:13>
- Next at t=2393214
- [color=Red](0) [0x00007c00] 07c0:0000 (unk. ctxt): mov ax, 0x7c0 ; b8c007[/color] // 这里执行回到一开始的 mov ax, 0x7c0 ; b8c007
- <bochs:14>
- Next at t=2393215
- (0) [0x00007c03] 07c0:0003 (unk. ctxt): mov ss, ax ; 8ed0
- <bochs:15>
- Next at t=2393216
- (0) [0x00007c05] 07c0:0005 (unk. ctxt): mov sp, 0x25 ; bc2500
- <bochs:16>
- Next at t=2393217
- (0) [0x00007c08] 07c0:0008 (unk. ctxt): mov ds, ax ; 8ed8
- <bochs:17>
- Next at t=2393218
- (0) [0x00007c0a] 07c0:000a (unk. ctxt): mov ax, 0x0 ; b80000
- <bochs:18>
- Next at t=2393219
- [color=Red](0) [0x00007c0d] 07c0:000d (unk. ctxt): ds call word ptr [ds:0x23] ; 3eff162300[/color] //第二次执行
- <bochs:19>
- Next at t=2393220
- [color=Red](0) [0x00007c12] 07c0:0012 (unk. ctxt): inc ax ; 40[/color] //因为第一次执行 call word ptr [ds:0x23] 时,堆栈段偏移 0x23 的值已经是这条指令的地址
- <bochs:20>
- Next at t=2393221
- (0) [0x00007c13] 07c0:0013 (unk. ctxt): inc ax ; 40
- <bochs:21>
- Next at t=2393222
- (0) [0x00007c14] 07c0:0014 (unk. ctxt): inc ax ; 40
- <bochs:22>
- Next at t=2393223
- (0) [0x00007c15] 07c0:0015 (unk. ctxt): add byte ptr ds:[bx+si], al ; 0000
- <bochs:23>
复制代码
这是我用bochs调试的
这是程序源码
- mov ax,0x07c0
- mov ss,ax
- mov sp,stack + 16
- mov ds,ax
- mov ax,0
- call word [ds:23H]
- inc ax
- inc ax
- inc ax
- stack:
- resb 16
- times 510-($-$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为
- dw 0xaa55 ; 结束标志
复制代码
你如果要自己调试,请修改cs,eip的值(没错,是eip,bochs没有ip寄存器)
cs修改为 0x7c0
eip修改为 0
具体方法看我调试过程
|
|