• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

Self modifying executable

How do I create and maintain a Self modifying executable?

Assume I have an executable file "noname.exe". This file has a configuarations panel when I can set various settings of the application. I want to be able to save these settings in the noname.exe file. How can I achieve this. I know Winword.exe from MS Office 97 can do this for the user's licence information.
0
bmatumbura
Asked:
bmatumbura
1 Solution
 
gencrossCommented:
I don't think this is going to be possible.  You can save the application settings to the registry or an INI file.

I do not believe the settings are actually set in the EXE file itself.
0
 
Elmo_Commented:
I agree with gencross here.  You can only have the default values for your application hard coded in but If you want it to save settings and then run based on these you will need to set up registry entries/Local Db or INI files.

As far as I can remember the Licence information for MS word is stored in the Registry.

Cheers,

Ed.
0
 
nahumdCommented:
Anyway its not a very good idea to do it.
Suppose you want to change a configuration, then you have to rewrite your exe file, and in the middle of the writing the computer crash, or the power is turned off. In that case your application is lost.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PaulHewsCommented:
Adding to what has been said (and agreeing it's not a good way to do it): when the executable is running, the file system will mark it as being in use and you will not be able to modify the exe.  Use savesetting/getsetting functions to save and retrieve settings from the registry.

You could modify the main exe from another exe if the main exe is not running.  If you decide to do this, append the data to the main exe.  This will not affect the executable's function, but it may set off your virus scanner.

0
 
rspahitzCommented:
What you refer to in the Office applications is called metadata.  You'll notice that when you change the metadata, the executable does not change, so it is being stored elsewhere or MS is bypassing its own Widonws I/O routines.  Either way, as indicated above, this is risky.

However, if you must...We have an application that version-stamps various executables created by another department that doesn't seem to believe in versions.  We simply attach it to the end of the executable, which is an area ignored by the app.  Of course, we don't do this while the executable is running, so maybe it's okay that way.

Anyway, as indicated, the preferred way is to write entries to the registry, usually using SaveSettings and GetSettings.
0
 
Alon HirschSoftware Development ManagerCommented:
Hi,

Generally, this is not a good idea and no longer is done by Microsoft.
In the 'old' days, this was the way companies would store the registration information.

It is relatively easy to implement if you want to go ahead :
In your project (VB source code), declare STRING variables for each of the values you want to modify.
Somewhere in code set the string to a DEFAULT (unregistered) value of XXXXXXXXXXXXXXXXXXXX or something else that is known to you as the developer.
Make sure that each variable is set to a different value.
When you make an EXE - string literals are saved as is - so that if you were to open the EXE in notepad and search for XXXXXXXXXXXXXXXXXXXX, you will see it there.
All your VB program has to do now, is open the EXE file for binary READ/WRITE with SHARED access, and you can read the file searching for XXXXXXXXXXXXXXXXXXXX. When you find it, you can replace it with whatever you want.
MAKE SURE THAT THE VALUE YOU REPLACE IT WITH IS EXACTLY THE SAME LENGTH.

It's as simple as that.

HTH,
Alon
0
 
bmatumburaAuthor Commented:
Hie experts:

I know it's possible to create a self-modifying executable for windows. I have seen an article somewhere that had sample code on how to achieve this but in Delphi (I have forgotten the actual URL but should be at www.delphi3000.com)

I'll try out AlonHirsh idea.

Thanks for the comments.
0
 
apakianCommented:


hi,

to:":  AlonHirsch


if you change the data at runtime, wouldn't this cause the digest of the program to change..
I assumed windows stored the files digest or crc in it's PE header,, or am i mistaken ?

ashod

0
 
Alon HirschSoftware Development ManagerCommented:
Hi,

I'm not actually sure - personally I ahvem't done this myself.
I have seen it don, and in the old days MS used to do it when registered their software during an installation.
The program would prompt you for your user name and company and write the information back into the installation program (SETUP.EXE or whatever).
The sample above is based on some code I found way back when on the Microsoft MSDN.

Alon
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now