Solved

Self modifying executable

Posted on 2002-07-10
9
413 Views
Last Modified: 2008-02-01
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
Comment
Question by:bmatumbura
9 Comments
 
LVL 4

Expert Comment

by:gencross
Comment Utility
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
 
LVL 3

Expert Comment

by:Elmo_
Comment Utility
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
 
LVL 2

Expert Comment

by:nahumd
Comment Utility
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
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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
 
LVL 4

Accepted Solution

by:
AlonHirsch earned 50 total points
Comment Utility
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
 
LVL 11

Author Comment

by:bmatumbura
Comment Utility
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
 

Expert Comment

by:apakian
Comment Utility


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
 
LVL 4

Expert Comment

by:AlonHirsch
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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