Originally published on: Sat, 25 Apr 2009 22:39:18 +0000
My goals and requirements for WSH2EXE were simple:
The data held in WSH2EXE would be a set of flags and variables containing the settings from the above and two stub EXE's; I would need a console-mode EXE to launch a console version of a script and a windowed-mode EXE to launch a windowed version of a script.
Keep in mind that I want the end-result EXE to contain the scripts and all of the above configuration data. My choices in storing this data in an already-compiled EXE include the option to overwrite some known portion of the EXE file itself, append the data to the EXE, or I could find a way to embed all of the data that I want as a Windows Resource data block into the EXE.
I chose to explore the second option; I would build a utility to stamp a block of data into a compiled EXE.
Please consider the source code for embedded.c below:
The output from this compiled code is:
someNumber is 1532713819
someString is [[[[
I have set a pointer to a struct of type internalData to refer to a char block that I have initialized with eight left-bracket characters. When the someNumber element is displayed, it has treated each of the first four '[' characters as data and displays the number 1532713819.
The element someString occupies the remainder of the block of data. When we display it, we only see the first four characters ( which are the last four '[' characters of the eight that I had specified ) and then nothing else once the zero byte is encountered.
I created the string of eight '[' bytes to act as a sentinel value so that I could create a separate utility to find and overwrite that block of the EXE.
Please consider the following program stamp.c:
The above program will open embedded.exe, which should be the output of the compiled embedded.c program, and will overwrite the internalData struct so that someString is "Don't look up!" and someNumber is 42.
Stamp.exe will then write the new EXE to a file named embedded2.exe.
The output of embedded2.exe is:
someNumber is 42
someString is Don't look up!
The data-stamping technique looked to be a plausible option. However, I didn't feel like defining a static buffer in WSH2EXE big enough to hold all of the data that would be needed by the two stub EXE's. I chose to use the stamping technique to embed the flags and variables.
My next proof-of-concept was to build a mechanism to append the stub EXE's to WSH2EXE.
To be continued...
Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless
Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
Click **here**
A JavaScript REPL for Android Devices
A Review of Kevin Mitnick's Book Ghost in the Wires
Play MP3 Files with Python on Windows
Understanding TRS-80 CMD Files
Mad Schemes : Learning Lisp via SICP
Tracing XSLT with a Tiny Java Web Server
Preventing Windows Screen-Saver Activation
BPL: Batch Programming Language Interpreter
Stacking Images with PerlMagick
Compiling Rhino JavaScript to Java
Command-Line Image Format Conversion
Why Some Web Sites will go Dark on Jan 18th
Book Review : Paull Allen - Idea Man
A 90's Experiment in Online Systems - The U.S. West CommunityLink Service