Solved

self-modifying code API

Posted on 1998-11-30
1
238 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
ID: 1348706
Look at VirtualProtect(Ex)...

Regards, Madshi.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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