Recovery
Volume Number: 2
Issue Number: 7
Column Tag: Special Projects
Recovering Protected Basic Programs 
By DB Cooper, Seattle, WA
True Recovery at Last!
How many times have you saved what you thought was a completed MS Basic
program to disk in protected mode, only to discover that was your only copy and now
you need to make some changes? Recovering from Basic's protected option has been a
hotly contested struggle between Basic programmers and the interpreter, which until
now, has yielded very little in the way of a practical solution. In past issues of
MacTutor, various attempts have been published, but each of these required that you do
something to your program before you protected it. What if you didn't remember to do
the special thing first? You were out of luck. Until now. After studying Mike Steiner's
"Rescuit Program" in the September 1985 issue of MacTutor, I have invented a way to
recover any protected Basic program after it is protected without any requirement on
the author before he saved it. In otherwords, you can now unprotect any protected
program without thinking about it ahead of time. Simply run this Basic program and
your back in business! I accomplished this by writing the program below named
'Rescure(b)', which overwrites the encrypted code for: {Merge "it":'} at the front of
the protected program. Then I set up a second program named 'It' which is merged to the
protected program and then copies the program from memory to a file. This second step
is based on Mike Steiner's article.
Version 2.1 Different
Unfortunately, this scheme didn't work with programs in the Microsoft Basic
2.1 Format, so I started to experiment. I determined that version 2.1 uses a seperate
location in memory to store the names of the variables. I couldn't figure out how to find
this table in memory directly, so instead I added a new variable "TenZZZZZZZZZZ" to
the end of the table by defining it in the program, and had the routine search for ten Z's
in a row. Then the program back tracks until it hits a binary zero, which defines the
beginning and end of the variables table. (This method has worked with all the programs