There is a problem when listing this Atari BASIC program on the screen...
You have access to the listing of a commercially released program written in Atari BASIC.
However, there's a problem. This program looks strange when listed: the variable names having funny, unusual names.
The reason is simple: the program has been protected using an obfuscation method.
What is this obfuscation protection?
This technique was used to prevent modification or understanding of an Atari BASIC program by deliberately making the code difficult to read or modify. This method was often used by developers to protect commercial software from being easily altered or pirated.
For example, one of these obfuscation methods or a combination of both was often used:
- Several variables (or even all variables) have names that are normally forbidden by the Atari BASIC editor for a variable. For instance:
- A variable named with a digit, "2" for instance
- A variable named after an Atari BASIC command or function
- A variable name with a length that exceeds the normally authorised limit
- A variable named "CHR$(155)", that is the [RETURN] character
- Or even a variable named with a semi-graphic symbol, such as a club or a spade.
- Anything violating the Atari BASIC editor rules will do.
- Several variables (or even all variables) share the same name.
This is something that the Atari BASIC editor would normally prevent: if you use the variable name "LOOPCOUNT" twice for instance, the editor will assume it is the same variable. However, to protect a program, using a special trick, it is possible to rename ALL variables with the same name – say, "LOOPCOUNT", for example, for a numeric variable. When the program runs, it runs just fine. Atari BASIC recognises them as variables with token number 128, 129, 130... The running Atari BASIC code simply doesn’t care about the actual names of the variables, just their token number. But when listing the program on the screen for instance, you see LOOPCOUNT, LOOPCOUNT, LOOPCOUNT, even though they are actually different variables, albeit with the same name.
All these methods prevent you from modifying an Atari BASIC program protected in this way: Any program line containing only a single variable will be impossible for you to modify.
The example listed above is a commercial Atari BASIC program, APX 10001 PERITEL "Limonade", French version.
Pay close attention to the obfuscated variable names.
Line 230, among others.
How to fix this?
Fortunately, there is a fairly simple method to automatically rename all the variables with simple names compatible with the Atari BASIC editor, allowing you to modify the program again.
Software needed
My very favourite emulator. Simply the best: Altirra Atari 8-Bit Emulator
Step 1 — Move file to your main Windows computer
Transfer the program — let's call it BADPRG.BAS
for now — to your Windows computer running the Altirra emulator.
You have plenty of options: FujiNet, SIDE3, or any "SIO-to-Something" device.
Create a virtual .ATR disk, format it in DOS 2.5, make it bootable, and copy your obfuscated Atari BASIC program onto this virtual .ATR disk. Then, transfer the .ATR file to your computer running the Altirra emulator.
Step 2 — Load the program into memory
Start Altirra with "Atari BASIC enabled" and boot on your bootable .ATR disk — the one created during Step 1 with BADPRG.BAS
on it.
In Atari BASIC, type:
NEW
LOAD "D1:BADPRG.BAS"
Do not run the program.
Step 3 — In the debbuger
Launch the Altirra debugger by pressing the [F8] key
Type this command:
.basic_rebuildvnt
of course, press [RETURN] to execute the command.
Step 4 — Save the "clean" program
Exit the debugger by de-selecting the "Debug > Enable Debugger" option in Altirra.
Save the Atari BASIC program with a new name, for example:
SAVE "D1:GOODPRG.BAS"
There you go! All variables are now renamed with names compatible with the Atari BASIC editor. You can now edit and modify the program as you wish.
Check like 230 again.
A word of warning: this will rename all variables currently in RAM memory. If the program was designed to auto-edit itself, or if it loads other segments with ENTER
commands for instance, this will not rename the new variables used in these new program lines.
Bonus 1 — Give the variables new friendly names
Use the "APX 20177 Extended Atari BASIC" program to rename the variables with friendlier names, easy-to-understand-their-usage names.
The "APX 20177 Extended Atari BASIC" program allows you to easily rename the variables in your Atari BASIC program. It directly modifies the variable names in the table that stores all variable names (VNT – Variable Names Table). In practice, this renames your variables immediately and EVERYWHERE in the listing.
Obviously, save your program again afterwards.
Bonus 2 — Get help and inspiration for the new variables names
Submit the listing obtained in Step 4 to an AI engine and ask it to suggest clear and meaningful variable names.
For example, using a prompt like this:
"You are an expert in Atari BASIC programming, the BASIC language of Atari 8-bit computers such as the Atari 400/800/600XL/800XL/65XE/130XE.
Here is the listing of a program written in Atari BASIC.
I would like you to carefully examine all variables used throughout the program and determine their function.
After this analysis, I would like you to suggest new, explicit, and meaningful names for each variable in the program. Each new variable name you propose must follow the standard constraints of a valid Atari BASIC variable name: the name must start with a letter (A-Z).
Ensure that each new name is unique – Atari BASIC does not allow two variables to have the same name.
If a variable is used only once, please highlight this to me.
<your listing goes here>"
Knowledge base article: kb-software-0007-atari-basic-remove-obfuscation-protection
REV. 002.