Hypo
asked on
Changing the EXE file.
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.
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.
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
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
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
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
Yes, that answer was SO MUCH better than my mere comment that it REALLY deserved to be posted as an answer... >;->
/// John
/// John
Thanks John
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
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
What did you mean ?
ASKER
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.
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.
Have you checked my comment at all?
/// John
/// John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
I´m satisfied with this information,
Thanks everyone!
Thanks everyone!
Regards, Madshi.