Patch Tools
Background
This page summarises the tools I have developed to modify executables, data files and disk images
for the PC and Atari ST Computers. These programs can be used in general however to help patch any file.
The tools are:
1. hexsearch
2. hexdump
3. patchbytes
4. patchbytesoffset
5. trackcalc
6. execboot
These are all Win32 executables.
TrackCalc and ExecBoot have been written in .NET 2.0 and require the .NET 2.0 runtime.
Download
A ZIP download is available in the download section containing all these tools.
Why
Various tools had to be written to make some disks copyable by standard copy
programs such as FastCopy 3 on the Atari ST.
Usage
Example 1: Examining and modifying data
C:\UTILS\patchtools>hexdump test1.dat 0 10
20202020202020202020
C:\UTILS\patchtools>patchbytesoffset 8 ffff test1.dat test1out.dat
C:\UTILS\patchtools>hexsearch ffff test1out.dat
Found at offset
8 (0x8)
C:\UTILS\patchtools>hexdump test2.dat 0 10
2020202020202020ffff
|
Example 2: Patching all instances of a string
C:\UTILS\patchtools>patchbytes b200 4e714e714e71 test2.dat test2out.dat overwrite
Found at offset
2 (0x2)
note: the mode parameter is not used at the moment
C:\UTILS\patchtools>fc /B test2.dat test2out.dat
Comparing files test2.dat and TEST2OUT.DAT
00000002: B2 4E
00000003: 00 71
00000004: 20 4E
00000005: 20 71
00000006: 20 4E
00000007: 20 71
|
Example 3: Patching bytes at a known offset
This example patches the total track counter in the bootsector of an Atari ST disk image.
If the bootsector is executable the checksum alignment word (offset: 511) has to be recalculated.
Use ExecBoot to generate the patchbytesoffset command to do this.
C:\UTILS\patchtools>patchbytesoffset 19 4006 out.st temp.st
|
Example 4: Removing a call with nop instructions
debug shows us the call instruction op-code
ff15 call [di]
we know that the opcode for nop in x86 is 0x90 and we have to overwrite 2 bytes.
C:\UTILS\patchtools>patchbytesoffset 1067 9090 smallest.exe small.exe
|
Example 5: Boot Sector Track\Sector\Side Patch Calculator (Atari ST)
The track calculator is used to be able to patch boot sectors with the
correct number of tracks, sectors and sides. Some copy protections on
the Atari ST set these to incorrect values to prevent copiers like FastCopy 3
working correctly.
Simply type in the values of the number of tracks, sectors and sides
and press Calculate and the patch script will be output in the window below.
Example 6: Boot Sector Executable Checksum Calculator (Atari ST)
When an Atari ST boot sector is changed, if the boot sector is executable, then
a new checksum alignment value in bytes 510-511 will have to be written.
This value is the sum of the first 255 words - 0x1234.
Simply press the Make Executable button, select the .ST disk image or boot sector track image,
and the patch script will be written to the window below to patch in the correct
checksum alignment value.
Notes
1. For hexsearch the entire input file is read into memory for speed. For the other tools
the file is read simply using fgetc().
Extremely large files should not be read using these programs.
2. For ExecBoot the first 512 bytes are read into memory.
3. Deciding which parts of an executable program need to be patched
can be found using a disassembler or runtime debugger.
Further reading
Useful nop opcodes
0x86 0x90
68000 0x4e71
Z80 0x0
Useful Traps
68000
trap #14; 0x4e4e
Useful conditional and branch to subroutine opcodes
0x86
ff15 call [di]
68000
cmp.b d0,d1 ; 0xb200
beq label ; xx nn nn (xx = conditional on branch instruction type, nn nn = 16 bit signed address offset)
Z80
0xcd call nnnn
Executable Headers
Atari ST
0x601a
Other tools
The following tools are recommended for coding work in general.
Disassemblers
x86
debug.exe
disasm-32.exe
68000
Easy Rider 4
Bugaboo
IDEs and runtime debuggers
x86
OllyDbg, Visual Studio (Microsoft), Turbo Debugger (Borland), Watcom Disassembler, DJGPP
68000
Atari ST: HiSoft Devpac 2 (especially MonST for debugging), Ultimate Ripper
Amiga: MonAm, Action Replay
Emulators: Steem, Steem Debug, WinUAE
ZX Spectrum
Spectrum: Multiface (Genie), HiSoft Devpac
Emulators: Spectaculator, X128
Back to index.