FastCode: studying its code
I'm studying the code of FastMM that change the address of the methods and function in run time. But I didn't understand some things.
http://koders.com/delphi/fid356C72C9C454FA74A916971690F624B0FF9111E5.aspx?s=pos
My doubt is on line 47: "if PBYTE(AStub)^ = $E8 then" Why this comparison? Ok, to check if it's assigned or not. Am I wrong ? But why $E8(232) ? If it's always the same value, wont it be always the same result ?
The rest开发者_运维问答 of the code it's "ok" in my mind. But if some one could explain all of it I thank.
tks in advice.
That code returns the target address of a CALL instruction. The test is just to check that it really is a CALL instruction that has been passed to the routine. It's not fool proof because you could be passing the address of the middle of an instruction, or even something that isn't code.
So yes, the test should always succeed, if the function is called correctly.
These two routines are presumably used in tandem. First of all you get the address of the CALL instruction, and then the code at that site is replaced with a JMP ($E9).
精彩评论