ZPatch 1.00 beta 3 manual

Ivan Gorinov, 2003

Overview

ZPatch is a small utility for changing small number of bytes in binary files.

It reads and executes commands from .CRK text file. Such a file can be created using any text editor.

Features:

  • Search & replace;
  • Checking file size and CRC before patching;
  • MD5 checksum support;
  • Querying program directory from registry;
  • PE checksum generation (for paching system files);
  • Reverse patching.
  • USING THE PATCHER

    Browsing

    When ZPatch has no command line parameters, it creates a file selection dialog that lets the user to select CRK file. Browsing starts from current directory.

    Command line

    You can specify a CRK file name in the command line:

    zpw File.crk

    If no input file specified, ZPatch uses patch.crk in current directory.

    Self-extracting archives

    You can add this program and the patch script to self-extracting archive.
    This example for WinZip adds the program with patch script "xxx110.crk" to archive "mypatch1.zip" and creates setup file "mypatch1.exe":

    wzzip mypatch1 zpw.exe xxx110.crk
    winzipse mypatch1 -setup -auto -c zpw xxx110.crk

    When you run "mypatch1.exe", it extracts the files to temporary folder and runs the patcher.

    ZPATCH INPUT FILE FORMAT

    Input .CRK file must be like that:

    Program Description (Line 1)
    Program Description (Line 2)
    ...
    Program Description (Line N)

    Patch description
    Command 1
    Command 2
    ...
    Command N

    The package contains some examples.

    LIST OF COMMANDS

    File I/O functions


    #FILE

    path/filename

    #FILE "path/filename" Flags

    Open file for patching.
    The path is relative to current directory.
    This command can handle files with Read/Only attribute.
    Current directory can be set by commands: #SYSDIR, #REGPATHVAL.

    Example
    bin/program.exe


    #SIZE

    #SIZE Size0 [Size1]

    Check file size.

    Size0
    File size before patching (decimal)
    Size1
    File size after patching (decimal)
    The file must be opened by FILE command before.

    Example
    #SIZE 65536 65536


    #CRC, #CRC32

    #CRC CRC0 [CRC1]
    #CRC32 CRC0 [CRC1]

    Check file CRC-32 checksum.

    CRC0
    File CRC-32 before patching (hex)
    CRC1
    File CRC-32 after patching (hex)
    The file must be opened by FILE command before.

    Example
    #CRC 2D56FC58 A4F9041C

    See also: CRC16.


    #CRC16

    #CRC16 CRC0 [CRC1]

    Check file CRC-16 checksum.

    CRC0
    File CRC-16 before patching (hex)
    CRC1
    File CRC-16 after patching (hex)

    The file must be opened by FILE command before.

    Example
    #CRC16 56FC F904

    See also: CRC.


    #MD5

    #MD5 Sum0 [Sum1]

    Check file MD5 checksum.

    Sum0
    File MD5 sum before patching (hex)
    Sum1
    File MD5 sum after patching (hex)

    The file must be opened by FILE command before.

    Example
    #MD5 86b899b7f3f73a6b9f5a735f56ab4fdf 438922e0b7704a0bff98a85f16efc3d6

    See also: CRC.


    Write

    ZZZZZZZZ: yy,yy...yy

    Write byte string Y at offset Z. All values are hexadecimal. Reverse patching is impossible with this command.
    If the separator is space, the string must be quoted.
    The file must be opened by FILE command before.

    Example
    00001045: 90,90,90,90
    00001045: "90 90 90 90"

    See also: Replace.


    Replace

    ZZZZZZZZ: xx,xx,...,xx yy,yy,...,yy
    ZZZZZZZZ: "xx xx ... xx" "yy yy ... yy"

    Replace binary string X by Y at offset Z. If bytes at offset Z neither X nor Y, patching is aborted.
    The file must be opened by FILE command before.

    Example
    00001015: 74,05 EB,05
    00001015: "74 05" "EB 05"


    Search the binary file for byte string X and replace by Y

    #SEARCH xx,xx,...,xx yy,yy...,yy
    #SEARCH "xx xx ... xx" "yy yy ... yy"

    The file must be opened by FILE command before.
    Example
    #SEARCH 4D,5A 6D,7A
    #SEARCH "4D 5A" "6D 7A"


    #FILL

    Fills a block in the binary file with byte string Y

    #FILL offset length yy,yy...yy

    The file must be opened by FILE command before.

    Example
    #FILL 00001000 00000100 01,00,00,00
    #FILL 00001000 00000100 "01 00 00 00"


    #PECHKSUM

    Corrects PE (Win32 executable) file checksum.

    #PECHKSUM

    The file must be opened by FILE command before.


    Windows Registry functions


    #REGKEY

    Open registry key

    #REGKEY Root KeyName

    Root
    Registry root
    HKLMHKEY_LOCAL_MACHINE
    HKCUHKEY_CURRENT_USER
    HKCRHKEY_CLASSES_ROOT
    KeyName
    Name of the registry key If the name contains spaces, it must be quoted.

    Example
    #REGKEY HKLM "Software\Super Soft\Very Useful Program"

    #REGPATHVAL

    #REGPATHVAL ValueName

    Sets current directory to path from registry value. The registry key must be opened before by "#REGKEY" command.

    Example
    #REGKEY HKLM "Software\Super Soft\Very Useful Program"
    #REGPATHVAL "InstallPath"


    #REGCHECKVAL

    #REGCHECKVAL ValueName [String]

    Check whether registry string value equal to String.
    If no string specified - check if the value exists.
    The registry key must be opened before by "#REGKEY" command.

    Example
    #REGKEY HKLM "Software\Super Soft\Very Useful Program"
    #REGCHECKVAL "Version" "1.0"


    Directory functions


    #PATH

    #PATH [AbsolutePath]

    Browse for program directory, starting in AbsolutePath. If no path specified, start directory is Program Files.

    See also: #REGPATHVAL.


    #SYSDIR

    Set current directory to system directory
    Win9x X:\WINDOWS\System
    WinNT/2000 X:\WINNT\System32
    WinXP X:\WINDOWS\System32

    Example
    #SYSDIR
    drivers/dongle.sys
    ...