Solved

Changing the EXE file.

Posted on 1998-08-22
12
150 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
ID: 1337449
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
ID: 1337450
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
ID: 1337451
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 4

Expert Comment

by:erajoj
ID: 1337452
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
ID: 1337453
Thanks John
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337454
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
 
LVL 7

Expert Comment

by:Motaz
ID: 1337455
What did you mean ?
0
 
LVL 12

Author Comment

by:Hypo
ID: 1337456
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
ID: 1337457
Have you checked my comment at all?

/// John
0
 
LVL 7

Accepted Solution

by:
Motaz earned 100 total points
ID: 1337458
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
ID: 1337459
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
ID: 1337460
I´m satisfied with this information,
Thanks everyone!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

786 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