• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 461
  • Last Modified:

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?

0
grg99
Asked:
grg99
1 Solution
 
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
 
Computer101Commented:
PAQed with points refunded (125)

Computer101
EE Admin
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now