📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  Brainstorms - General  >>  MOV EDI, EDI Function Prolog

Topic created on: May 8, 2007 13:20 CDT by JLeCours .

I was wondering why certain function prologs begin with MOV EDI, EDI or similar NOP-equivalent instructions.  Is this done by certain compilers? or is it standard?  I can think of some functionality it might provide, but for the most part... it seems like it's just a waste of an instruction / padding.  Any ideas? :)

  ero     May 8, 2007 14:13.08 CDT
The purpose of the, otherwise, useless "MOV EDI, EDI" is to provide with a total of 5 known bytes at the start of a function.
Five because that's the length of a "JMP XXXXXXXX", so those functions can be hotpatched without need to disassemble their prolog to figure out how many bytes need to be saved.

Anything wanting to hotpatch a function with such prolog can just override those first 5 known bytes "MOV EDI, EDI" and "PUSH EBP", jump elsewhere and jump back to the instruction starting in the 6th byte after issuing a "PUSH EBP"

And very silly, but just in case you wonder why the "MOV EDI, EDI" that and not a NOP NOP sequence... it's simple, it's just one instruction as oposed to 2.

Maybe someone can expand if I forgot any details...

  JLeCours   May 8, 2007 14:32.32 CDT
:) I was thinking it was to make hot patching more convenient.  

Thanks for the extra info at the end.  The thought had run through my mind. ;)

  bugcheck     May 8, 2007 21:31.06 CDT
its actually intended to be for a short jmp -5. using this method is the only way to be sure there isnt a race condition on replacing the instructions.

http://rootkit.com/blog.php?newsid=451&user=bugcheck

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit