Delphi: How to get the address of an event variable?

How to get the address of a variable containing an event handler?

eg.

TExample = class(TObject)
private
    FOnChange: TNotifyEvent;
end;

I need a private member addressFOnChange , an event handler, a variable.


Why?

I am trying to figure out who overwrites my handler variable FOnChangewith garbage.

I go through the code:

if Assigned(FOnChange) then
    FOnChange(Self);

No event handler is assigned, and for a time is a variable FOnChange nilin the viewport:

@FOnChange: nil
Addr(FOnChange): nil

But later the variable FOnChangeturns into garbage:

@FOnChange: $2C
Addr(FOnChange): $2C

So, I want to look at a variable FOnChangein the data area of โ€‹โ€‹the CPU window so that I can look at it with:

00410018 00000000

to

00410018 0000002C

Also, I do not know the address FOnChange; I just made up $410018.

?


,

OnChange: nil
@OnChange: nil
@@OnChange: Variable required
@FOnChange: nil
Assigned(OnChange): False
Assigned(FOnChange): False
@@FOnChange: $253B588
addr(addr(FOnChange)): $253B588

Alt + F5

  • OnChange: OnChange: TNotifyEvent $253B588
  • FOnChange: "FOnChange":
  • Self.FOnChange: "Self.FOnChange": .
  • @OnChange: @OnChange: Pointer $253B588
  • @@OnChange: "@@OnChange":
  • @FOnChange: @FOnChange: Pointer $253B588
  • @@FOnChange: @@FOnChange: ^Untyped (no address) : @@FOnChange $253B588`

, -, 0x253B588.

, :

MyControl1.OnChange := TheOnChangeHandler;

:

mov edx,[ebp+$08]         ;move stack variable $08 into edx
mov [eax+$00000208],edx   ;and then into offset $208 of my control

mov edx,[ebp+$0c]         ;move stack variable $0c into edx
mov [eax+$0000020c],edx   ;and then into offset $20c of my control

, FOnChange, !

+3
5

Debug Inspector. , - , , , . Debug Inspector. , IDE, D2010 Run- > Inspect... Evaluate/Modify ALT-F5 . ( , ALT-F4!)

Debug . Debug Inspector. . , , , .

+6

Delphi 5, ( ) AExample.FOnChange.
.

+4

, , ! , , brakepoint, :

var X:TExample;
X.OnChange := nil;

brakepoint X.OnChange: = nil; , , - :

; assembler blah blah to get the address of X
xor EDX ; or whatever the compiler finds appropriate this time of day
mov [eax + $00000288], edx
mov [eax + $0000028c], edx

, , $288, , MOV. OFFSET "X" FOnChange. . -, - brakepoint, Alt + F5, Debug Inspector ( Ctrl + N, ) "Integer (Integer) MyExampleVariable)"; , , , FOnChange, MyExampleVariable, brakepoint.

+3

, Delphi 5, TMethod MethodAddress .

+1

?

, FOnChange .

- ! , ? ? . Delphi -, , , ...

, , . , , , , ( ) :)

0

Source: https://habr.com/ru/post/1751052/


All Articles