Solved

self-modifying code API

Posted on 1998-11-30
1
233 Views
Last Modified: 2010-04-04
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?
0
Comment
Question by:yuhoo
1 Comment
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
Comment Utility
Look at VirtualProtect(Ex)...

Regards, Madshi.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now