Solved

Self modifying executable

Posted on 2002-07-10
9
417 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 75
Adding to a VBA? 6 76
Crystal reports - Formula Field code need assistance with code 17 81
VBA: Insert New column with specific format type 12 38
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

789 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