home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
-
-
-
- PATCH22
-
-
- version 1.2 (8 August 1991)
-
- Jurgen A. Doornik
-
-
-
-
-
-
-
-
-
- 1. Introduction.
- ___________________________________________________________________
-
- PATCH22 can be used to make patches to any file. The main
- advantage is that it gives a format to distribute patches. You
- can avoid detailed description of DEBUG commands. Instead you
- just supply PATCH22 with the patch in a *.P22 file.
- PATCH22 can also accept patches on the command line.
- Patches have a C-like character constant format, making
- it easy to enter hexadecimal values. PATCH22 will show the
- context of the patch, but can work silently as well.
- PATCH22 is written in C (source code provided), and faster than
- many other public domain patch programs.
- PATCH22 is written by Jurgen Doornik.
-
- The disk (or archive) should contain the following files:
-
- PATCH22.C - source code (MSC 6.0)
- PATCH22.DOC - this documentation
- PATCH22.EXE - executable file.
- *.P22 - patch files (if any).
-
- If you have any suggestions for improvement, or find any bugs,
- please report them to me, via email:
-
- BITNET/EARN: ECONZ@UK.AC.OX.VAX
-
- or by mail:
-
- Jurgen Doornik
- Institute of Economics and Statistics
- St Cross Building, Manor Road
- Oxford OX1 3UL
- United Kingdom
-
- Special thanks are due to Arjen Merckens, who spotted many bugs and
- gave useful suggestions. Needless to say that all remaining errors
- are mine.
- Arjen is author of BOOTCOMP.zip: a package which uses the original
- BIOS interrupts to detect ANY changes to the bootsector [possibly]
- made by a virus. He also wrote ACD (ChDir FAST; more features than
- LCD/NCD and free).
-
-
- 2. How to execute PATCH22.
- ___________________________________________________________________
-
- PATCH22 can accept patches on the command line or from a file.
-
-
- 2.1 Command line patch.
- _______________________
-
- form: PATCH22 fname patch
- fname - file to be patched
- patch - patch command: +##*##si?search_text?new_text?
-
- If the patch line on the command line contains spaces, it must be
- enclosed in double quotes.
-
- examples:
- PATCH22 test.exe ?abc?cde? replace (with confirmation)
- every occurrence of abc with cde.
- PATCH22 test.exe "?a c?c e?" replace (with confirmation)
- every occurrence of a c with c e.
-
- If in the last example the double quotes are omitted, PATCH22 will
- think that the patch is ?a, and tell you that it expects a ?.
-
- 2.2 Command file patch.
- _______________________
-
- form: PATCH22 @fname
- @fname - file with (multiple) PATCH22 commands, with format:
- fname +##*##si?Search_text?New_text?
-
- If the patch command is in a file, line breaks in the Search_text
- and New_text are ignored.
-
- example:
-
- PATCH22 @test.p22
-
- where test.p22 looks like:
- ; comment lines start with a semi colon.
- test.exe ?a c?c e?
- ; line breaks in the Search_text and New_text are ignored:
- test.exe ?a cdd?c edd?
- ; equals
- test.exe ?a cd
- d?c ed
- d?
- ; note that no double quotes are used here.
-
-
- 3. The patch command.
- ___________________________________________________________________
-
- form: +##*##si?Search_text?New_text?"
- syntax: patch = Conditions "?" Search_text "?" New_text "?".
-
- The syntax reads as follows:
- "a" indicates a literal text a.
- [b] indicates an optional item b.
- {c} indicates one or more occurences of c.
- d|e indicates either d or e.
-
- 3.1 The Conditions.
-
- syntax: Conditions = [Offset][Max_#_patches][Silent_mode].
- Offset = ["+"] long | "-" long.
- Max_#_patches= "*" int.
- long = ["0"] ["x" | "X"] digit {digit}.
- int = ["0"] ["x" | "X"] digit {digit}.
- Silent_mode = "s".
- Ignore_case = "i".
-
- The Offset is a signed long integer, while the maximum number of patches
- is a * followed by an unsigned integer. These integers can be decimal,
- hexadecimal (leading 0x or 0X) or octal (leading 0).
- An s indicates silent mode. Each number is read up to the first character
- which is not part of it.
- An i indicates case insensitive searching. The search string is converted
- to uppercase, so comparosion is mad in uppercase. The default is case
- sensitivity.
- The Conditions field can be empty, in which case the Offset is zero,
- every patch has to be confirmed, and there is no maximum number of
- patches.
-
- examples: 0x131d Offset is 131d (hexadecimal), no maximum
- number of patches.
- +0177*12 Offset is 177 (octal), not more than 12 patches.
- +177*12 Offset is 177 (decimal), not more than 12 patches.
- *1s Zero Offset, one patch, silent mode (no prompt for
- confirmation of patch).
- *09?n?n? The 0 in the Max_#_patches field indicates an octal
- number, but 9 is not octal, so scanning stops and
- a 0 is read. The 9 then is interpreted as the
- Offset. However a request of 0 patches generates
- an error message.
-
- 3.2 The Search_text and New_text.
- _________________________________
-
- syntax: Search_text = [ {chars | escape_code} ].
- escape_code = "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v"
- | "\\" | "\?" | "\'" | "\""
- | "\" octal [octal [octal]]
- | "\x" hex [hex]
- | "\w" hex [hex [hex [hex]]]
- | "\h" hex hex {hex hex}.
- New_text = Search_text.
-
- The text is a C-type character constant. It may contain the C
- escape codes
- \a (07h), \b (08h), \f (0Ch), \n (0Ah), \r (0Dh), \t (09h), \v (0Bh);
- or
- \### (octal byte, not more than 3 digits);
- \x## (hexadecimal byte, not more than 2 digits).
- \w#### (hexadecimal word, not more than 4 digits).
- The characters \ ? ' " must be written as: \" \\ \? \' \".
- An additional escape code is \h, which indicates that the rest of the
- text (up to the question mark which indicates the end) consists
- of two-digit hexadecimal numbers.
-
- examples: \h0d0a00 three hexadecimal numbers:
- carriage return, line feed, null character.
- \r\n\0 the same three characters, in escape codes,
- (note that \0 is an octal number).
- «gr_» literal text.
- \x1\xa\wb000 two bytes and one word: 01h 0Ah B000h
- (since on IBM PC's low order byte comes before
- hi order byte this is written as 01h 0Ah 00h B0h)
-
- 3.3 How the patch is executed.
- ______________________________
-
- Assume non-silent mode (default).
-
- First PATCH22 locates the search string. If the search string is
- empty, the first byte in the file matches. Then PATCH22 displays
- the search string.
-
- Next it moves the file pointer Offset bytes from the start of the
- found search string. (If the Offset is negative, PATCH22 will move
- backwards.)
- Then it will display the context with the bytes selected for modi-
- fication highlighted. PATCH22 will also display the new text, and
- prompt for confirmation of the patch.
-
- The file will be unchanged in size, unless the patch extends beyond
- the current end of the file. The time and date stamp of the file are
- updated.
-
- Example 1: replace a text with a new text
- *1?\he8d30e?\h909090? Only one patch is requested.
-
- Example 2: modify text at a certain offset from an identification text
- 168*1?<gr_>?\h010a00b0? Modify the 4 bytes at offset 168 (decimal)
- from the start of <gr_>. Don't make more
- than one patch.
-
- Example 3: search for a certain text.
- ?\h303132?? PATCH22 will look for 012 (which has
- hexadecimal ASCII code 30,31,32). PATCH22
- will display the context without any
- highlights, since the replace string is
- empty. If if the patch is confirmed,
- none will be made (although PATCH22 will
- report it as a patch).
-
- Example 4: modify a text at a certain location in the file.
- 0x131d??\h707070? There is no search string, so the first
- byte will match. Then at offset 131d
- from the start the text ppp will be
- written. Note that this will overwrite
- whatever is at offset 131d..131f.
- With an empty search string, there will
- be only one search, and hence not more
- than one possible patch.
-
- Example 5: case insensitive patching.
- i?\x73ymbol?symbol? The search string is converted to upper-
- case before the escape sequences are
- converted. So here the search string
- becomes sYMBOL. The first letter must match
- exactly, the rest is case insensitive.
- Examples of matching words are sYmBol and
- sYMBol, a non matching word is Symbol.
-
-
- 4. Some notes.
- ___________________________________________________________________
-
- I have used PATCH22 to write a configuration program for PC-GIVE
- (an econometric program). In the help code, for example, the
- configurable data is preceded by a signature. Using PATCH22, the
- data after the signature can be modified in the executable file.
- Of course the signature has to be unique if you want to do a silent
- patch.
-
- NOTE that LINK has the capability to remove sequences of
- repeated bytes (/Exepack). So make sure that you initialize the
- configurable data to have different bytes.
-
- PATCH22 has a very simple password protection scheme, which
- I shall use as an illustration.
- By default there is no password, but when a password has been
- installed, it has to be the first argument on the command line,
- for PATCH22 to execute.
-
- The declaration in PATCH22.c looks like:
-
- char sP22[] = { '«','p','2','2','_','»' }; /* signature */
- char sPassword[] = "\0 gf ggv aewf bvsbago";/* password: 21 chars+\0 */
- /* leading \0 indicates no password; rest avoids .exe compression */
-
- Of course, you must be certain that the two strings are stored
- consecutively in the executable (otherwise make it into one string).
- Do not write
- char sPassword[22] = "";
- This, in combination with /E, cannot be patched.
- In this example «p22_» is the signature, written like this to
- avoid the ending '\0'.
-
- To set the password to "user":
- PATCH22 patch22.exe 6?«p22_»?user\0?
- The 6 is the offset from the start of «p22_».
- Then, to change the password:
- PATCH22 user patch22.exe 6?«p22_»?anonymous\0?
-
-
- If you have any useful (and legal!) patches of interest, I look
- forward to receiving them. They can then be included with PATCH22.
-
-
- 5. License, warranty and disclaimer.
- ___________________________________________________________________
-
- PATCH22 is written by Jurgen A. Doornik for the IBM PC using
- DOS 2.0 or later. You may distribute PATCH22 given these
- restrictions:
-
- o the program shall be supplied in its original, unmodified
- form, which includes this documentation;
-
- o no fee is charged;
-
- o the program may be included, or bundled, with any other
- programs/products (including for-profit products) on the
- condition that I shall receive one copy of the program/
- product (as given/sold), and an update each time PATCH22
- is bundled with the update.
-
- o You may use and modify the source code for personal pur-
- poses only, and on the condition that I shall receive
- a copy of the modified version.
-
- For any other use contact me.
-
-
-
- Jurgen Doornik BITNET: ECONZ@UK.AC.OX.VAX
- Nuffield College
- Oxford OX1 1NF
- United Kingdom
-
-
- DISCLAIMER:
- I shall not be responsible for any damages or inconveniences
- incurred due to the usage of PATCH22, nor to the usage of
- files patched with PATCH22. I shall not be liable if PATCH22
- is used to patch files illegally. More formally:
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL JURGEN DOORNIK BE
- LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
- OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
- USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
- DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES)
- THESE PROGRAMS, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF
- SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
-
-
- 6. Revision history.
- ___________________________________________________________________
-
- 8-08-91: released version 1.2
- 22-07-91: - The date/time stamp of a file is reset if any patches
- are made.
- - Added (simple) password protection option, see ch 4.
- Maximum password length is 21 characters (excl. trailing \0).
- 7-07-91: - If user chooces Quit, now breaks out of while loop, instead
- of spooling to end of file.
- - Corrected bug pointed out by Ernst Raedecker of Amsterdam:
- find function did not allow for search string matching
- within itself. EG. file PIET containing "wwwp bevalt", then
- patch22 PIET ?wwp?ord?
- failed.
- This is fixed by doing a fseek backwards after a partially
- successful match. As Ernst pointed out, the search can be
- done more efficiently.
- Thanks a lot for your comments, Ernst!
- - Now the next search continues one byte after the start of
- the previous match.
- 12-05-91: released version 1.1
-
-