了解一下IRETD/ RET/ RETF

IRETD/ RET/ RETF 有什么区别,今天GOOGLE了一下:

RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

IRET returns from an interrupt (hardware or software) by means of popping IP (or EIP), CS and the flags off the stack and then continuing execution from the new CS:IP.

IRETW pops IP, CS and the flags as 2 bytes each, taking 6 bytes off the stack in total.

IRETD pops EIP as 4 bytes, pops a further 4 bytes of which the top two are discarded and the bottom two go into CS, and pops the flags as 4 bytes as well, taking 12 bytes off the stack.

IRET is a shorthand for either IRETW or IRETD, depending on the default BITS setting at the time.

知道原因后,就可以灵活运用了

 

*前面push个什么地址,后面就跳到什么地址去执行

阅读更多
换一批

不理解王爽汇编 10.1 retretf 求解答

10-19

就看下面这个例子吧 rnassume cs:code rnrnstack segment rn db 16 dup (0) rnstack ends rnrncode segment rnrn mov ax,4c00h rn int 21h rnrnstart: mov ax,stack rn mov ss,ax rn mov sp,16 rn mov ax,0 rn push cs rn push ax rn mov bx,0 rn retf rn rncode ends rnrnend start rnrndebug 的结果为: rnC:\masm5>debug 10b.exe rn-r rnAX=0000 BX=0000 CX=0026 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000 rnDS=0B5A ES=0B5A SS=0B6A CS=0B6B IP=0005 NV UP EI PL NZ NA PO NC rn0B6B:0005 B86A0B MOV AX,0B6A rn-u rn0B6B:0005 B86A0B MOV AX,0B6A rn0B6B:0008 8ED0 MOV SS,AX rn0B6B:000A BC1000 MOV SP,0010 rn0B6B:000D B80000 MOV AX,0000 rn0B6B:0010 0E PUSH CS rn0B6B:0011 50 PUSH AX rn0B6B:0012 BB0000 MOV BX,0000 rn0B6B:0015 CB RETF rn0B6B:0016 FF365607 PUSH [0756] rn0B6B:001A E821FC CALL FC3E rn0B6B:001D 83C402 ADD SP,+02 rn0B6B:0020 FF065607 INC WORD PTR [0756] rn0B6B:0024 5E POP SI rn-t rnrnAX=0B6A BX=0000 CX=0026 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000 rnDS=0B5A ES=0B5A SS=0B6A CS=0B6B IP=0008 NV UP EI PL NZ NA PO NC rn0B6B:0008 8ED0 MOV SS,AX rn-t rnrnAX=0B6A BX=0000 CX=0026 DX=0000 SP=0010 BP=0000 SI=0000 DI=0000 rnDS=0B5A ES=0B5A SS=0B6A CS=0B6B IP=000D NV UP EI PL NZ NA PO NC rn0B6B:000D B80000 MOV AX,0000 rn-t rnrnAX=0000 BX=0000 CX=0026 DX=0000 SP=0010 BP=0000 SI=0000 DI=0000 rnDS=0B5A ES=0B5A SS=0B6A CS=0B6B IP=0010 NV UP EI PL NZ NA PO NC rn0B6B:0010 0E PUSH CS rn-t rnrnAX=0000 BX=0000 CX=0026 DX=0000 SP=000E BP=0000 SI=0000 DI=0000 rnDS=0B5A ES=0B5A SS=0B6A CS=0B6B IP=0011 NV UP EI PL NZ NA PO NC rn0B6B:0011 50 PUSH AX rn-t rnrnAX=0000 BX=0000 CX=0026 DX=0000 SP=000C BP=0000 SI=0000 DI=0000 rnDS=0B5A ES=0B5A SS=0B6A CS=0B6B IP=0012 NV UP EI PL NZ NA PO NC rn0B6B:0012 BB0000 MOV BX,0000 rn-t rnrnAX=0000 BX=0000 CX=0026 DX=0000 SP=000C BP=0000 SI=0000 DI=0000 rnDS=0B5A ES=0B5A SS=0B6A CS=0B6B IP=0015 NV UP EI PL NZ NA PO NC rn0B6B:0015 CB RETF rn-t rnrnAX=0000 BX=0000 CX=0026 DX=0000 SP=0010 BP=0000 SI=0000 DI=0000 rnDS=0B5A ES=0B5A SS=0B6A CS=0B6B IP=0000 NV UP EI PL NZ NA PO NC rn0B6B:0000 B8004C MOV AX,4C00 rnrn根据 retf 的公式 计算 : rnip= 0B6A*16+000C=0B6AC rnSP = SP+2 = 000C+2=000E rnrnCS = 0B6A*16+000E = 0B6AE rnSP = SP +2 = 000E+2 =0010 rnCS:IP最后怎么会指向 0B6B:0 rnrn请问我这样理解哪里 错了?

没有更多推荐了,返回首页