Solved

Self modifying executable

Posted on 2002-07-10
9
414 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
ID: 7143440
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_
ID: 7143676
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
ID: 7143835
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
ID: 7143987
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:rspahitz
ID: 7143997
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
ID: 7145301
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
ID: 7149551
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
ID: 12535915


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
ID: 12537873
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
z = x + y – 1 6 67
VBA error replacing data 6 36
Hide vba in gp 7 80
Prevent user closing word document opened with VB6 6 67
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

930 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

10 Experts available now in Live!

Get 1:1 Help Now