#!/usr/bin/perl -w
#======================================================================|
# Usage: perl remswap.pl < dvb2000.bin > new.bin
#
# Patch DVB2000 to swap three buttons of the "international" remote control:
#     TEXT  --> MENU
#     MENU  --> GUIDE
#     GUIDE --> TEXT
# One unfortunate side effect of this patch is that "A" should now be
# entered with the TEXT button instead of the MENU button.
#
# 1999-10-17, Dick Streefland <dicks@xs4all.nl>
# 2002-03-10: adapted to new 2.00.0 (beta) versions
#======================================================================|

binmode STDIN;		# for DOS
binmode STDOUT;		# for DOS
undef $/;
$bin = <>;
$count = 0;
$pos = 0;
while	( ($pos = index $bin, "\x33\xc0\x01\x00\x02\x10", $pos) > 0 )
{
	$off = length( $bin ) - ($pos + 2);
	die( "already patched" ) if $off < 100;
	substr( $bin, $pos, 6 ) = pack "nN", 0x61ff, $off;
	$count++;
}
die( "instruction not found" ) if $count == 0;
$bin .= unpack "u", q=JL'Q<@F8&,#Q<4F`6L'Q<4F8&,#Q<.V`*L'Q<.V8$,#Q<@C/``0`"$$YU=;
print $bin;
