home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.msdos.programmer
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!menudo.uh.edu!cosc16to
- From: cosc16to@menudo.uh.edu (Andy Hakim)
- Subject: Re: changes to exe (binary) file
- Message-ID: <1992Jul30.152020.8261@menudo.uh.edu>
- Organization: University of Houston
- References: <1992Jul29.125540.7401@hou.amoco.com>
- Date: Thu, 30 Jul 1992 15:20:20 GMT
- Lines: 65
-
- In article <1992Jul29.125540.7401@hou.amoco.com> jim@n5ial.chi.il.us writes:
- >
- >I've seen lots of programs (usually shareware types) that allow you to
- >make configuration changes, insert registration info, etc., directly into
- >the compiled exe file. that is, instead of having a config file hanging
- >around, the exe itself is modified to include the new config info.
- >how would one go about doing this? btw, the program in question is in
- >C, and uses Turbo C++ version 1.0.
- I had written a shareware program that writes changes directly to the
- program file. Here's how: create a data structure holding all
- information you wish to change ( D in example), this allows all pertinent
- data to be stored in one place, and it can easily be read/written to disk.
-
- To figure out the offset: (DEFAULT_OFFSET in example) compile the
- program, then use a program such as LIST to scan for a sequence of
- matching bytes ( 100 118 138 ) The HEX DUMP mode of LIST is handy.
- Next, go back to your source file, and update the correct offset.
- An alternative way to figure out the offset is to use info from .map files.
-
- It's very important to keep the variable D initialized in the program
- because most compilers by default do not store un-initialized data as part
- of the exe (to reduce size).
-
- Here are relevant pieces of code from my program:
- //------------------------------------------------------------------------
- #define DEFAULT_OFFSET 0xAA8A
- typedef struct
- {
- char nr_factor;
- unsigned minimum;
- unsigned maximum;
- unsigned duration;
- long length;
- char fancy;
- char process;
- char playfile;
- char overwrite;
- unsigned sbport;
- char endpause;
- } DEFAULTS;
- //.........................................................................
- DEFAULTS D = {100, 118, 138, 3600, 200, YES, YES, 3, NO, 0x220, YES};
- DEFAULTS FACTORY = {100, 118, 138, 3600, 200, YES, YES, 3, NO, 0x220, YES};
- //.........................................................................
- void fsavedefaults(char *program_name)
- {
- FILE *fptr;
- if ((fptr = fopen (program_name, "rb+")) != NULL)
- {
- printf ("Saving new defaults to %s\n", program_name);
- fseek (fptr, DEFAULT_OFFSET, SEEK_SET);
- fwrite (&D, sizeof(D), 1, fptr);
- }
- else show_error (9, program_name);
- fclose (fptr);
- }
- //------------------------------------------------------------------------
- The program can be obtained from most ftp sites as nohiss10.zip. I'd be
- happy to provide the full source code via email. BTW, the complete
- path\program_name is stored in argv[0] (i believe you only get the path
- from dos 3.0 or higher but that's good enough)
-
- -Andy Hakim
- <cosc16to@menudo.uh.edu>
-
-