Solved

Changing the EXE file.

Posted on 1998-08-22
12
144 Views
Last Modified: 2010-04-04
Hi,
I´m making a program in delphi 3 where i at on point in the program need to make changes in the programs EXE file. It´s an array in the program that needs to be changed each time the program is launched. But when i try to Open the file "Paramstr(0)" with the "reset" procedure, an error message pops up on the screen. (I/O Error 32).

The code i use is below.
var F : file of byte;
begin
  assign(F,paramstr(0));
  Reset(F);            {This is where the program Halts }

If you know how to change the Application´s EXE file Please answer thes question.
0
Comment
Question by:Hypo
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Must be possible somehow, but I don't know how. Opening your running application's file produces an error, because it is already "in use". Perhaps you could do something with the "HInstance" var, because some Win32-API's (e.g. LoadBitmap) use this var to load resources from the file. But I don't know how.  :-(

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:erajoj
Comment Utility
Hi,
I don't recommend you to use self-modifying code (SMC), ever!
You should always try to use the registry or data-files.
Windows95/98 and NT locks the executable files for writing when running for safety reasons.
Check this page for an example of how to use VirtualProtect:
http://zeus.fh-brandenburg.de/~puchert/selfmod.html

/// John
0
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
Why did you try to change exe file and how did you know the location of array in the exe file. Opening exe file is very danger. More over if you attempt to write at runable exe file access denied error will be raised
If you need to manuplate such data you must use external data files this is a very easy task.

You can read only from exe file will it run. So that before reset you must set file mode to read only e.g :

Assign(f,paramstr(0));
FileMode:=0;     (*** Read only ***)
Reset(f);

Reset dose not mean read in data files or non-text files. It mean open for read and write.

Motaz, from Sudan
0
 
LVL 4

Expert Comment

by:erajoj
Comment Utility
Yes, that answer was SO MUCH better than my mere comment that it REALLY deserved to be posted as an answer... >;->

/// John
0
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
Thanks John
0
 
LVL 4

Expert Comment

by:erajoj
Comment Utility
Hi Motaz,
Didn't mean to offend you. Just was in an ironic mood that day.
Just trying so hard to offer really good input, in order to help fellow Delphians...

/// John
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Expert Comment

by:Motaz
Comment Utility
What did you mean ?
0
 
LVL 12

Author Comment

by:Hypo
Comment Utility
The reason why i want to make changes in an exe file is because I need to know how  many times the program has been launched by a specified user. I don´t want to use an  external file to do this because then it would be much easier to erase the changes that´ll  be made each time the program has been launched.
 To find the location in of the array the EXE file is easy. The array is a constant of bytes  wich will be in the data area of the exe file. All i have to do is to
 Compile the program
 Copy the filename.exe to filename2.exe
 Change the first byte in the constant array
 Then compile it again
 And compare the two Exe files.
 If the one of the results from the compare(tion???) is equal to the changes i made, I know  that on that position in the file the Array is located.

 Thanks alot for the answers, but I don´t need to know how to read from the EXE file, I only  need to know how to write to the one that´s operating. If it´s possible.
 
 Thanks again.
 
 


0
 
LVL 4

Expert Comment

by:erajoj
Comment Utility
Have you checked my comment at all?

/// John
0
 
LVL 7

Accepted Solution

by:
Motaz earned 100 total points
Comment Utility
You can use external file and hide it in another directory, for example in windows directory or temporary directory and change it's date-time to earler one, no one will ever know where is that file exist.
I think this is an easy way to know who many times your programe launched.

Motaz, from Sudan.
motaz1@yahoo.com
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Motaz,

that's right and that's not right. Because there are little utilities that monitor all changes made during installation (e.g. Uninstall utilities like CleanSweep). So your little file would be revealed.
But what is with erajoj's comment!? Looks quite nice to me...

Regards, Madshi.
0
 
LVL 12

Author Comment

by:Hypo
Comment Utility
I´m satisfied with this information,
Thanks everyone!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

6 Experts available now in Live!

Get 1:1 Help Now