Search code examples
assemblyx86ida

How to use JMP in IDA?


.text:004430FE                 jz      short loc_44311B
.text:00443100                 push    30h             ; uType
.text:00443102                 push    offset Athingy; "Hello"
.text:00443107                 push    offset AnotherThingy; "Works"
.text:0044310C                 call    sub_438090
.text:00443111                 add     esp, 0Ch
.text:00443114                 push    0
.text:00443116                 call    sub_44C424
.text:0044311B
.text:0044311B loc_44311B:                             ; CODE XREF: sub_442C70+48Ej
.text:0044311B                 mov     ecx, 0FAh
.text:00443120                 mov     esi, offset buf
.text:00443125                 lea     edi, [ebp+var_3FC]
.text:0044312B                 rep movsd
.text:0044312D                 push    offset aTest; "test"
.text:00443132                 lea     eax, [ebp+var_3FC]
.text:00443138                 push    eax
.text:00443139                 call    sub_465450
.text:0044313E                 add     esp, 8

If I wanted to change jz (at the top) to jmp and set it go to add esp, 8. How would I be able to do so?

I know how to patch the program and go to assemble, but what would I type about jmp?


Solution

  • You can look up the opcode for a short jmp in Intel's manuals. I don't have it handy, but if memory serves it's 0xEB.

    The formula to use for calculating the jmp offset is (target address - address of jmp instruction - 2). (the 2 is because that's the length of the short jump instruction, including its argument - the CPU adds the offset to what the instruction pointer value is following the jump instruction).