Link to home
Start Free TrialLog in
Avatar of yuhoo
yuhoo

asked on

self-modifying code API

I am trying to make "self-modifying" code, like the following example:

procedure TForm1.Button1Click(Sender: TObject);
var
P: ^Byte;
begin
     P := Addr(TForm1.Button1Click);
     ShowMessage('The address is: ' + IntToHex(Integer(P), 8));
     P^ := 0;    //   <---- Access Violation occurs here
     ShowMessage('Done!');
end;


but the system reports:

Access violation at address 0042BBCA in module 'Project1.exe'
Write of address 0042BB6c

which is understandable, since this is not .DATA segment, but .CODE

What is API(s)  for "unlocking" the CODE segment?
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial