1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/perl
use strict;
@ARGV || die "Usage: $0 <file1> <file2> ... <fileN>\n";
my @index;
my $offset = 0;
foreach my $file ( @ARGV )
{
if( -f $file && open F, "< $file" )
{
warn sprintf "Member at 0x%08X\n", $offset;
push @index, [ ];
my $size = length $file;
print $file;
print "\0" x ( $size % 4 );
$index[-1][0] = $offset;
$index[-1][1] = $size;
$index[-1][2] = $offset + $size + ( $size % 4 );
$size = 0;
while( read F, my $buffer, 4096 ) {
$size += length $buffer;
print $buffer;
}
print "\0" x ( $size % 4 );
$index[-1][3] = $size;
$offset = $index[-1][2] + $size + ( $size % 4 );
close F;
}
}
foreach my $file ( @index )
{
warn sprintf "Index: 0x%08X 0x%08X 0x%08X 0x%08X\n", $file->[0], $file->[1], $file->[2], $file->[3];
print pack "NNNNnn", $file->[0], $file->[1], $file->[2], $file->[3], 0x0000, 0x0000;
}
warn sprintf "Index at 0x%08X, length 0x%08X\n", $offset, @index * 20;
print pack "N", $offset;
|