Solved

Changing the EXE file.

Posted on 1998-08-22
12
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

617 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