I come across some weird behavior with a built-in Delphi build, as shown in this very short and simple program:
program test; {$APPTYPE CONSOLE} uses SysUtils; type TAsdf = class public int: Integer; end; TBlah = class public asdf: TAsdf; constructor Create(a: TAsdf); procedure Test; end; constructor TBlah.Create(a: TAsdf); begin asdf := a; end; procedure TBlah.Test; begin asm mov eax, [asdf] end; end; var asdf: TAsdf; blah: TBlah; begin asdf := TAsdf.Create; blah := TBlah.Create(asdf); blah.Test; readln; end.
Itβs just for an example ( mov ing [asdf] in eax not much, but works for an example). If you look at the assembly for this program, you will see that
mov eax, [asdf]
turned into
mov eax, ds:[4]
(as presented by OllyDbg), which is obviously falling. However, if you do this:
var temp: TAsdf; begin temp := asdf; asm int 3; mov eax, [temp]; end;
It changes to mov eax, [ebp-4] which works. Why is this? I usually work with C ++, and I'm used to using such instance instances, it is possible that I am using instance variables incorrectly.
EDITOR: Yes, thatβs all. Changing mov eax, [asdf] to mov eax, [Self.asdf] fixes the problem. Sorry.
assembly delphi instance-variables basm
Okey
source share