flat assembler
Message board for the users of flat assembler.

Index > Windows > is it possible to write to an *.exe file

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
moriman



Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman
Hi,

Just wondering, when an app is started, is it possible for it to open and write to it's own *.exe file? I was thinking this would be a way to 'permanently' update user options without using an *.ini or similar extraneous file.

Many thanks for any input

mori
Post 04 Apr 2006, 10:33
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
discussed already
look for self-overwriting exe or so
maybe it could go to interesting threads
Post 04 Apr 2006, 11:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Kermil



Joined: 26 Oct 2005
Posts: 35
Location: Russia
Kermil
Quote:

I was thinking this would be a way to 'permanently' update user options without using an *.ini or similar extraneous file.

It is wrong way, because some antiviruses will be locking your program, when you will try to write in a exe-file.
Post 04 Apr 2006, 11:15
View user's profile Send private message ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
moriman wrote:
Hi,

Just wondering, when an app is started, is it possible for it to open and write to it's own *.exe file? I was thinking this would be a way to 'permanently' update user options without using an *.ini or similar extraneous file.

Many thanks for any input

mori


just use the registry in this case

_________________
redghost.ca
Post 04 Apr 2006, 12:59
View user's profile Send private message AIM Address MSN Messenger Reply with quote
moriman



Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman
OK, thx all for the replies Wink

mori
Post 04 Apr 2006, 13:13
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
There was a self-deleting file example somewhere around these forums - if you find it - you may aswell find a way to change it.

The problem (or the difference from deleting) is that when you change that file, you need to mess with the PE headers again meaning you should have the source and FASM packed with your executable so you can reassemble it. Changing one byte might not harm a PE file, like changing the first instructino to INT3 to debug it Very Happy, but by settings you mean at least 10 bytes... I think you need to change the dates and checksums and other stuff lying around the PE header.
Post 04 Apr 2006, 13:23
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
You can change bytes inside the exe but don't add or remove them. Also you can add as much as you want to the end.
Post 04 Apr 2006, 19:02
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
id go for having separate section for doing it and then CreateRemoteThread to modify those settings which does wait until app is closed and then change them to your exe... look for comrade's selfsave example(masm)...

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 04 Apr 2006, 20:38
View user's profile Send private message MSN Messenger Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Madis731: In fact it isn't such difficult. You don;t have to have a copy of FASM and your sources to reassemble everything. It can all be calculated. Like every PE packer/protector do. They get all values to be written in PE header during runtime.
Post 28 May 2006, 14:44
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Plue: and how do you do this in a way that works from win95 to XP SP2? Smile
Post 28 May 2006, 17:52
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
IMHO people seem to over complicate the task of self modifying an exe file at runtime. Especially if the information you wish to store is of a static size or a size that is no greater than a set limit.

I'll elaborate further,
While an EXE file is running you still have...
- Readonly access to the EXE file
- Ability to rename the file

So all your exe file has to do to edit itself is...
1- Rename itself to (ie: deleteme.exe)
2- Make a copy of itself with the correct EXE name
3- Edit the copy using the file io APIs
4- Run the copy and shutdown the old instance
5- The copy should have a short procedure at the beginning to deletefile "deleteme.exe".

People talking about adding sections and using PE analyses seems excessive
Code:
.data
...
;;A short unique string of bytes to make editing easier
PointerToStart dq 0ABCDEF99ABCDEF99, 11111111AAAAAAAAh
SavedRecordSpace dq 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;;or use DUP
    


Now in step three you only need a simple loop going through the mapped view of the file searching for your unique string and changing the bytes after it to your new saved record data.
Post 29 May 2006, 05:48
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Quote:

- Ability to rename the file

Not on win9x...

Besides, the rename-modify-relaunch will make your application "flicker in and out of existance" if you have any open windows (obviously), this looks pretty ugly.
Post 29 May 2006, 13:14
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Or you could just use environment variables to change default behavior. Much cleaner than worrying about rewriting .EXEs, IMO.
Post 29 May 2006, 20:36
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
rugxulo, using the registry is obviously the correct solution, but it's out of the scope of this particular thread.

f0dder, you could have the new instance close the old one, so the it would be more of an overlap then a flicker.
But for serious use the only case where my method would be aesthetically viable would be if the data only needed to be saved at the shutdown of the program. (Because then no restart/flicker would be necessary)

AND how much longer do we have to make our code coddle win9x. It's newest iteration is 8yrs old. Not that it's a bad OS or anything, it's just antique Razz
Post 29 May 2006, 22:06
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
r22 wrote:
AND how much longer do we have to make our code coddle win9x. It's newest iteration is 8yrs old. Not that it's a bad OS or anything, it's just antique Razz
Do you mean time reduces the quality of software? I think that, for example, a game that we play today will be the same after 8 years (if it isn't lost in that period, of course Wink). It will still be the same. Just think a bit.

Okay, I'm no Microsoft old-product-lover, and I certainly don't say Win9x has higher quality than Win2K, but it was only an example. Take your time and analyze those things, and then say what most people say, that products are being poorer (sorry, can't find better word) by age. This is nonsense. Those who say that are usually spoilt people... Razz

Personally, if I was in charge of the world, I would let people appreciate all things, and only give them the "cooler toys" after they appreciated the "old toys". This way will they understand everything and not be blinded by "toys will suck in time, cooler is magic, etc.." and then they'll see the truth about it.


About your method: I see it as kinda brute-force one.. I simply don't like it (of course no offense)...

And Registry sucks!! Imagine what kind of trash is in there!! If all programs had only .ini we wouldn't even need to install them -- we could just copy them (if we had information, of course). The only thing that has to be modified this way will be the application path, but that's not a big deal, since it can be obtained with APIs, so why write it in Registry.

From my point of view, Registry was one of the bad designs of Windows -- it grew so popularily that we simply have to live with it Razz
Post 30 May 2006, 18:06
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Quote:

And Registry sucks!! Imagine what kind of trash is in there!! If all programs had only .ini we wouldn't even need to install them -- we could just copy them (if we had information, of course). The only thing that has to be modified this way will be the application path, but that's not a big deal, since it can be obtained with APIs, so why write it in Registry.

The registry has pretty fast data access, though - you don't need to parse text files, and it has binary search to look up keys. The downside is that many people forget to defrag their drives... Smile
Post 30 May 2006, 18:13
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Why not make .ini binary then, and a .ini editor like regedit?
Post 30 May 2006, 18:14
View user's profile Send private message Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7
you can make small registry for each program Smile
Post 30 May 2006, 18:38
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Yes I know, but it still adds up in the Registry after you "apply it". That's why you need Registry cleaners and no Ini cleaners.
Post 30 May 2006, 18:40
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
The only real advantage of registry cleaners is to clean up COM components and filetype associations, stuff like that. They don't speed up your system because entries are removed, really, but because of the type of entries they clean up...
Post 30 May 2006, 18:43
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.