Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

App to blockread itself

Posted on 2001-08-30
7
Medium Priority
?
264 Views
Last Modified: 2010-04-06
I want to write an app that will blockread only a specific part of itself, and then blockwrite it into a new file.

how do i do this?
0
Comment
Question by:rogueripper
7 Comments
 
LVL 3

Expert Comment

by:VSF
ID: 6440176
You should take a look at this web site:

http://delphi.does.it/

The "Self Modifying" demo demonstrates a nice work around on how to read itself.
The demo uses stream access, but the idea can be easily converted to a blockread approuch!

Direct links
Self Modifying Exe Demo-NEW VERSION!!!
http://www.geocities.com/gacarpenter386/SelfMod.zip

Download the Source for Self Modifying Exe Demo!
http://www.geocities.com/gacarpenter386/SelfModsrc.zip

View ReadMe file for Self Modifying Exe :-)
http://www.geocities.com/gacarpenter386/readme.html

Hope this helps!

VSF
www.victory.hpg.com.br

0
 
LVL 5

Expert Comment

by:Gwena
ID: 6441768
Hi VSF :-)
  I had to move my site back to geocities after the server where it was stored got hacked :-(  the direct links don't work at geo... they have disabled that... but you should be able to right-click on the links and choose 'save target as' :-)

By the way I'm finishing up a unit that will greatly simplify using self-altering exe's

also... you can read a block of data that is in your exe right from the ram... you don't need to get the file from the disk... try this procedure


TForm1.Button1Click(Sender: TObject);
Var x: Byte;
begin
  Form1.Caption := '';
  For X := 80 to 115 do
  begin
    Form1.Caption := Form1.Caption +
    Char(pointer(Hinstance+X)^);
  end;
end;

clicking the button will cause the PE dos stub message to be displayed as the forms caption... you can read any block of data from the exe just by altering the line

For X := 80 to 115 do

for instance using For X := 0 to 2 do
will set the caption to 'MZP' the first 3 bytes of any delphi app ...it's simple to read the bytes into an array or whatever... just grab the block of data you need with this simple technique :-)

To put that block of data into another file on disk I recommend using streams ... it's easier than old style pascal file handling :-)

0
 
LVL 5

Expert Comment

by:Gwena
ID: 6441780
Oh! I forgot to mention that an exe in ram differs ever so slightly from it's image on the disk.... but nearly all of it is identical :-)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:Pedja
ID: 6442131
There is no problem to open exe of the current
application as any other file. There is no difference.

Pedja
0
 
LVL 5

Accepted Solution

by:
Gwena earned 400 total points
ID: 6442572
Hi Pedia :-)

Yes it's easy for an exe to read it's own exe file from disk into a stream while it runs... just do it like this.

var ExeStream: TFileStream;
begin
ExeStream:=TFileStream.Create(Application.ExeName,fmOpenRead or fmShareDenyNone);
  try
  //do whatever you want with the stream here
  finally
  ExeStream.Free;
  end;
end;

when this runs you will have the running exe in the stream
ExeStream
0
 

Author Comment

by:rogueripper
ID: 6443998
WoW! thanx for all the help!

:o)


0
 
LVL 5

Expert Comment

by:Gwena
ID: 6445710
Your welcome!

And thanks for the points :-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

782 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