Using gfadec
The same reference as README.txt in the zip. The commands are the same on Windows, macOS and Linux.
Decompiling
gfadec program.prg [out_name] [-verify] [-lib LIBRARY] [-names NAMES_FILE] [-comments FILE] [-nosearch] [-run] [-restore]
The files go beside the program, or to out_name (its extension is dropped):
| Program | Files written |
|---|---|
| GFA BASIC 3.x | NAME.LST, the listing as the editor's Save,A writes it; NAME.GFA, the tokenised file the editor loads and the compiler compiles; XMODULE.O for the linker when the program has $X procedures |
| GFA BASIC 1.x/2.x | NAME.LST and NAME.BAS, and gfadec prints the compiler options to use |
| Patched 1.x/2.x | NAME.PAT, the bytes no source gives; NAME_XXXX.BIN for each block of DATA the code takes, with a Devpac NAME_XXXX.S for each block of machine code |
| Packed programs | NAME.UNP, the program depacked |
gfadec says which compiler the program was made with, and prints the exact -compile
command that rebuilds it with the same compiler and options. Lines it can't follow are kept as
' ?? comments, so the listing always loads.
| Option | What it does |
|---|---|
-verify | Compile the source again with the program's own compiler, write it as NAME.RE and compare it with the original byte for byte |
-lib LIBRARY | 3.x: match the program with this library (a GFA3BLIB or a fingerprint file), for a program linked with a patched library |
-names FILE | 3.x: give variables, procedures and labels real names, one generated_name new_name pair a line |
-comments FILE | 3.x: add comments to the listing, anchored to the units and lines they go with |
-nosearch | Skip trying the forms the compiler decides. Quicker, but the source may compile a little differently |
-run | Depack a program packed with an unknown packer by running its own depacker in the built-in 68000 interpreter |
-restore | Put back the original instructions of the hand patches gfadec recognises, then decompile the restored program (saved as NAME.RES) |
A 3.x program linked with a library patched in a way gfadec knows is recognised, and -verify
links with the library patched the same way. One example is the Falcon fix that patches out the
Line-A mouse calls of HIDEM and SHOWM.
Verifying
-verify prints one verdict and sets the exit status:
verified: recompiles byte-identical
differs: first difference at $xxxx (sizes original/recompiled)
For 3.x, gfadec also prints how many units (procedures, functions and the main program) match, and which differ.
Some programs can't compile to the same bytes from any source, because the file isn't just what the compiler wrote. It may have been patched or cracked after compiling, padded or cut when it was copied, or damaged, or it may hold bytes left over from an earlier compile. The decompiled source of such a program is still right; only the file differs. gfadec counts these as the same:
- pad bytes the compiler left to chance
- a desk-accessory start-up added after compiling
- the file ending, and a symbol table the original holds
- a hand patch that gfadec can name and put back
Hand patches
Where the bytes show that a program was patched after compiling, the verdict names the patches, such
as "hand-patched: nop in place of bne.s at $3074". -restore puts the original instructions
back, saves the restored program as NAME.RES, decompiles that and, with -verify, compares
against it:
restored: addq.l #4,a3 at $3074 (was nop)
The patches go in NAME.PAT as the program has them, so the patched program can be rebuilt exactly:
gfadec -compile NAME.LST -patch NAME.PAT
The original file is never changed. Patches gfadec can't name stay as they are and are still reported.
Compiling
gfadec -compile NAME.GFA|NAME.BAS|NAME.LST [out.prg] [-compiler NAME] [-opts OPTIONS] [-lib LIBRARY] [-acc] [-patch NAME.PAT] [-pack PACKER]
The built-in GFA compilers as a command-line compiler. The program goes to out.prg, or to
NAME.PRG by default. A .LST is tokenised first, so keep the .GFA or .BAS that gfadec wrote beside it
and the variables stay where they were.
| Option | What it does |
|---|---|
-compiler NAME | The compiler to use, as gfadec -compiler list names them ("3.6 TT D", "3.02 E", "2.02 GB issued 1987-09-16" ...) |
-opts OPTIONS | 1.x/2.x compiler options: stop=ever|loop|never, errors=text|no, bombs=+|-, trapv=+|- |
-lib LIBRARY | 3.x: link with this library instead of the version's own |
-acc | 1.x/2.x: make the program into a desk accessory |
-patch NAME.PAT | Write the patch file decompiling wrote over the compiled program |
-pack PACKER | Pack the compiled program with one of the built-in packers |
-compiler list marks some 1.x/2.x compilers as synthetic. They aren't
releases GFA Systemtechnik made. Each one is a real compiler with another release's changes put in,
standing in for a release no copy has been found of, so that programs made with it can be verified.
Scanning
gfadec -scan PATH [-recurse] [-verbose] [-run] [-test [-cache] [-restore]] [-log FILE]
Lists the GFA BASIC programs in a file or folder, looking inside ZIP archives and .ST and .MSA disk images nested to any depth. Each program is printed with its path through the archives, its compiler and any packers:
GAMES.ZIP/DISK1.ST/AUTO/FOO.PRG: GFA BASIC Compiler 3.6 TT D, packed (Ice 2.40)
| Option | What it does |
|---|---|
-recurse | Scan the folders below PATH too |
-verbose | List each archive, image or file that couldn't be read, with the reason |
-run | Also find programs packed with an unknown packer, by running their own depacker (up to about a second a program) |
-test | Decompile and verify each program found, and print the result in colour |
-cache | With -test: test each program once; a copy of one tested before in the same scan takes its result |
-restore | With -test: put back the hand patches gfadec recognises before verifying each program, as -verify -restore does |
-log FILE | Write every line to FILE as well, without colours, as the scan goes |
GAMES.ZIP/DISK1.ST/AUTO/FOO.PRG: GFA BASIC Compiler 3.6 TT D: success - verified: recompiles byte-identical
tested 120: 95 success, 22 partial, 3 failed (41 copies of programs tested before, not tested again)
A scan writes no files. With -test, the files decompiling writes go to a temporary folder
that is removed after each program.
Unpacking and packing
Packed programs are depacked before decompiling. To unpack a program only, GFA BASIC or not:
gfadec -unpack FILE
GAME.PRG: unpacked (Ice 2.40), 81234 bytes to 196608 bytes, saved as GAME.UNP
Result: success - unpacked (Ice 2.40)
To pack a program with one of the built-in packers (gfadec -pack list names them):
gfadec -pack FILE PACKER [OUT]
The built-in packers are the packer programs themselves, run in the 68000 interpreter, so the packed file is the one the packer writes:
- Automation Packer 2.31, 2.41, 2.51 and 5.01
- LSD Packer 1.2, 1.5 and 2.2, and JEK Packer 1.2d
- Atomik Cruncher 3.3, 3.5 and 3.6
- Pompey Pirates Packer 1.5 and 1.9a
- JAM Packer 3.0 and 4.0 (each of their methods)
- Pack-Ice 1.13, 2.11, 2.12, 2.20, 2.31, 2.34 and 2.40
- PFX/AFX-Packer 2.1 (PFX 1.13P) by Thomas Quester and Markus Fritze
-verify of a program that holds one of their stubs packs the recompiled program the same
way and compares it with the packed original too:
repacked with JAM Packer 4.0 (LZH): the same as the packed original
A program packed with a packer gfadec doesn't know can still be depacked with
-run. gfadec then prints "depacked by running its own depacker (packer not recognised ...)".
Please report these programs on the support
forum, so the packer can get a routine of its own.
Names and comments
A decompiled listing has made-up names such as v02ce and proc_0023c, and no
comments. For 3.x programs, -names and -comments put real ones in while
decompiling, so the listing still recompiles byte for byte:
gfadec GAME.PRG -names GAME.names -comments GAME.comments -verify
A names file holds one pair a line, and # starts a comment:
v02ce counter
proc_0023c draw_board # redraws the whole board
The prompts/ folder in the zip has prompts for an AI assistant to work out the names and
comments, one prompt file at a time. prompts/README.txt explains how, and how to check
that nothing else changed.
Results and exit status
Every run ends with one result line, printed last, in green, yellow or red on a colour console:
Result: success - every line decompiled
Result: partial - 2 of 6768 lines not decompiled (kept as ' ?? comments)
Result: success - recompiles byte-identical
Result: success - recompiles byte-identical apart from a hand patch: nop in place of trap #1 at $f2
Result: success - recompiles byte-identical after restoring 1 hand patch
Result: partial - decompiled, but recompiles differently: 20 of 25 units match
Result: success - wrote NAME.PRG
Result: failed
| Exit status | Meaning |
|---|---|
0 | Done. With -verify, the program recompiles byte-identical (apart from its file ending or a symbol table it holds) |
1 | -verify: the program differs |
2 | The program couldn't be decompiled, or the source didn't compile |
Also: gfadec -h prints the usage text and gfadec -version prints the version
number only.