How to poke into code segment?

Hi, using Delphi 2006, I have a need to poke a few bytes into the code so I can set breakpoints, something like:

    var p: ^ byte;

    function Func( x: integer ): integer;
    begin
        Func := x * x ;
       end;


begin
    p := @Func;
    p^ := $CC;
end;


... but of course I'm not allowed to write to the code.  A good thing, except right now.

Any ideas?

LVL 22
grg99Asked:
Who is Participating?
 
Computer101Commented:
PAQed with points refunded (125)

Computer101
EE Admin
0
 
tobjectpascalCommented:
i thought you set break points from the IDE not the code?
0
 
grg99Author Commented:
Hi, I figure out how to do it.  You call VirtualProtect with READ_WRITE.

0
 
alkisgCommented:
For a complete working example, look at the fastcode.sourceforge.net library.
It uses code patching to substitute delphi functions with faster ones.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.