Solved

How to poke into code segment?

Posted on 2006-11-15
5
451 Views
Last Modified: 2010-04-04
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
Comment
Question by:grg99
5 Comments
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 17953257
i thought you set break points from the IDE not the code?
0
 
LVL 22

Author Comment

by:grg99
ID: 17954932
Hi, I figure out how to do it.  You call VirtualProtect with READ_WRITE.

0
 
LVL 9

Expert Comment

by:alkisg
ID: 17957953
For a complete working example, look at the fastcode.sourceforge.net library.
It uses code patching to substitute delphi functions with faster ones.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 21133154
PAQed with points refunded (125)

Computer101
EE Admin
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

17 Experts available now in Live!

Get 1:1 Help Now