6 # This is a quick hack to apply IPS patches. It is distributed under
7 # the terms of the GNU General Public License.
16 There are no options. Your original datafile is modified.
21 open PAT
, "$ARGV[1]" or die "Can't open $ARGV[1]";
22 open DAT
, "+<$ARGV[0]" or die "Can't open $ARGV[0]";
25 die "Bad magic bytes in $ARGV[1]" if $data ne "PATCH";
28 read PAT
, $data, 3 or die "Read error";
31 print STDERR
"Done!n";
34 # This is ugly, but unpack doesn't have anything that's
35 # very helpful for THREE-byte numbers.
36 $address = ord(substr($data,0,1))*256*256 +
37 ord(substr($data,1,1))*256 +
38 ord(substr($data,2,1));
39 print STDERR
"At address $address, ";
40 seek DAT
, $address, SEEK_SET
or die "Failed seek";
42 read PAT
, $data, 2 or die "Read error";
43 $length = ord(substr($data,0,1))*256 + ord(substr($data,1,1));
46 print STDERR
"Writing $length bytes, ";
47 read(PAT
, $data, $length) == $length or die "Read error";
52 read PAT
, $data, 2 or die "Read error";
53 $length = ord(substr($data,0,1))*256 + ord(substr($data,1,1));
54 print STDERR
"Writing $length bytes of RLE, ";
55 read PAT
, $byte, 1 or die "Read error";
56 print DAT
($byte)x
$length;