BBS: Inland Empire Archive
Date: 06-28-92 (14:34) Number: 1656
From: RICK PEDLEY Refer#: NONE
To: AL LAWRENCE Recvd: NO
Subj: Self modifying code Conf: (2) Quik_Bas
On 06-26-92 Al Lawrence wrote to All...
AL> Does anyone have any code that would allow a program to
AL> modify a numeric or string variable each time the program
AL> is run, and maintain the modified variable from run to
AL> Thanks in advance...
In your program, define a string something like this:
Count$ = ">>>#$#$#$"
The alternating #$ characters ensure that when you compile, the compiler
won't pack the string -- you want it to remain exactly as it is in the
source. Also the >>> is easy to spot/find with a hex editor.
Marker$ = ">>>"
Num& = -1
B$ = SPACE$(3)
OPEN PROG.EXE FOR BINARY AS #1
FileLen& = LOF(1)
FOR x& = 1 TO FileLen& - 9
SEEK #1, x&
IF B$ = Marker$ THEN
Num$ = SPACE$(6)
NumStart& = x& + 3
SEEK #1, NumStart&
Num& = VAL(Num$)
IF Num& = -1 THEN
PRINT "Couldn't find ";Marker$
Num& = Num& + 1
IF Num& > 25 THEN
PRINT "NEENER NEENER DEADBEAT, TRIAL PERIOD HAS EXPIRED!"
*.*" if you prefer.
Num$ = LEFT$("000000", 6 - LEN(STR$(Num&))) + STR$(Num&)
SEEK #1, NumStart&
There are faster ways to find Marker$, like GET a 32K string and use
INSTR to find the ">>>", but the fastest way is once you have the
program finished, hardcode NumStart& as NumStart$ in your program
(i.e. use a hex editor to find exactly where Num$ begins and add 1
to it, as all hex editors count from zero), then SEEK that position
directly; SEEKing through the file byte by byte is slow. Also, the
user could easily install a fresh copy of the program or set the
read only attribute to defeat this method.
Caveat: I typed this in an editor without testing so be careful and
please excuse minor errors.
... OFFLINE 1.37
--- Maximus 2.01wb
* Origin: The BULLpen BBS * Intel 14.4EX (613)549-5168 (1:249/140)