Solved

Changing the EXE file.

Posted on 1998-08-22
12
147 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 119
Delphi Form ownership 4 70
Delphi IDE crash without error message ... 7 75
Delphi and Access based Enumeration 9 44
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

14 Experts available now in Live!

Get 1:1 Help Now