Debian Codegraph @

test/cabs/large-cab.pl

raw
1 #!/usr/bin/perl -w
2 use strict;
3
4 my ($blocks1, $blocks2) = map {int} @ARGV;
5 die <<EOF unless $blocks1 && $blocks2 && $blocks1 < 65536 && $blocks2 < 65536;
6 Usage: $0 <blocks1> <blocks2>
7 This generates a CAB file with two files in it, where the first file
8 is 32768*blocks1 bytes long and the second file is 32768*blocks2 bytes
9 long. Neither file can be more than 65535*32768 bytes long.
10 EOF
11
12 my $header = pack('A4V5C2v5', 'MSCF', 0, 0, 0, 0, 0, 3, 1, 2, 2, 0, 0, 0);
13 my $folders = pack('Vvv', 0, $blocks1, 0)
14 . pack('Vvv', 0, $blocks2, 0);
15 my $files = pack('V2v4Z*', $blocks1*32768, 0, 0, 0x226C, 0x59BA, 0x20, 'test1.bin')
16 . pack('V2v4Z*', $blocks2*32768, 0, 1, 0x226C, 0x59BA, 0x20, 'test2.bin');
17 my $block = pack('VvvC*', 0, 32768, 32768, ((0..255) x 128));
18
19
20 # fixup offsets
21 my $files_offset = length($header) + length($folders);
22 my $blocks_offset = $files_offset + length($files);
23 my $cab_length = $blocks_offset + length($block) * ($blocks1 + $blocks2);
24 substr($header, 0x08, 4, pack 'V', $cab_length);
25 substr($header, 0x10, 4, pack 'V', $files_offset);
26 substr($folders, 0x00, 4, pack 'V', $blocks_offset);
27 substr($folders, 0x08, 4, pack 'V', $blocks_offset + length($block) * $blocks1);
28
29 die "Overall cabinet is too large ($cab_length > 4294967295)\n"
30 if $cab_length > 4294967295;
31
32 # print cab file to stdout
33 print $header . $folders . $files;
34 map {print $block} 1 .. ($blocks1 + $blocks2);