Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Self modifying executable

Posted on 2002-07-10
9
Medium Priority
?
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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:
Alon Hirsch earned 200 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:Alon Hirsch
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

Technology Partners: 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!

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…
Suggested Courses

618 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