Warning: This site is under construction, most links will be broken.

Open formats: ZPF: Patch file format

Last modified on Mon, 26th Feb 2007 at 22:31 GMT by zipplet

ZPF patch file format, 25th July 2004 (version 1.00)
----------------------------------------------------

Important definitions
---------------------

hexadecimal numbers:
prefixed with $

byte:
8-bit integer. Sign does not matter as we don't mind what the byte contains. (1 byte in size)

word:
16-bit unsigned integer, little endian byte order. (2 bytes in size)

dword:
32-bit unsigned integer, little endian byte order. (4 bytes in size)

array:
array length in bytes (stored as a word), followed by array data (unformatted). i.e. the following array ($00, $11, $22) would be stored in the file as follows:
$00 $03 (word = 3) $00 $11 $22 (data).
The reason for using a word to specify the length is it results in a smaller patch for the majority of patches.

file size:
This patch format is designed to be used on files of up to 2GB in size.

file offsets:
Offsets start with 0 being the first byte in the file.

string:
Just a string of ascii characters, no size is specified.

Patch format - basic layout
---------------------------

+-----------+---------+----------------------------------------------+
| Offset    | Type    | Description                                  |
+-----------+---------+----------------------------------------------+
| 0         | string  | The string "ZPF100". 100 is the version and  |
|           |         | the patch utility should NOT attempt to      |
|           |         | continue if the version is more recent than  |
|           |         | the version the patch utility was designed   |
|           |         | for. To determine this, convert the last 3   |
|           |         | characters into an integer, and just compare |
|           |         | using the ">" operator.                      |
+-----------+---------+----------------------------------------------+
| 6         | dword   | The length of the file this patch is for, in |
|           |         | bytes.                                       |
+-----------+---------+----------------------------------------------+
| 10 - EOF  |         | Patch data, described below.                 |
+-----------+---------+----------------------------------------------+

Patch data format
-----------------

The patch data is a stream composed of commands and parameters. A command is a single byte identifying an action, which may or may not be followed by parameters. Any parameters are listed after the command, and follow it immediately. Here is an example of a command, and how it would look in a hex editor (if you opened the file):

command: replace byte at $12345678 with $FF
patch data: $01 $78 $65 $34 $12 $FF

0: End of stream
1: Replace byte
2: Replace range of bytes with array
3: Replace range of bytes with a single character

0 - End of stream
-----------------

No parameters.

Upon encountering this command the patch is complete.

1 - Replace byte
----------------

dword: offset
byte: value

Replace the contents of <offset> with <value>.

2 - Replace range of bytes with array
-------------------------------------

dword: offset
array: data

Replace a range of bytes starting at <offset> with <array>. Note that the range is limited to 64KB, use multiple commands to replace a larger range.

3 - Replace range of bytes with a single character
--------------------------------------------------

dword: offset
word: length
byte: value

Replace a range of bytes starting at <offset> with <value>. The number of bytes to replace is <length>.

eof