forked from kbdfck/cnu-fpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsign.pl
executable file
·62 lines (49 loc) · 1.34 KB
/
unsign.pl
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
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
#Cisco firmware/package signature remover
#Written by kbdfck, 2007
#http://virtualab.ru
use strict;
use warnings;
sub usage {
print STDERR "Usage:\n";
print STDERR "$0 <input file> <file type> <output file>\n";
print STDERR "File type can be 'gz' for main firmware archive or 'cnu' for firmware files\n";
exit();
}
sub check_sign {
my $buffer = $_[0];
my $sign = $_[1];
return index( $buffer, $sign );
}
##################################################################
my $sign;
my $input_file = $ARGV[0] || usage();
my $type = $ARGV[1] || usage();
my $output_file = $ARGV[2] || usage();
if ( $type eq 'gz' ) {
$sign = "\x1f\x8b\x08"; #tar.gz firmware package
}
if ( $type eq 'cnu' ) {
$sign = "CNU_"; #CNU firmware file
}
die "Unknown file type $type" unless $sign;
my $buf;
open( F, "<",$input_file ) or die "Can't open input file $input_file: $!";
binmode(F);
read( F, $buf, 500 );
my $offset = check_sign( $buf, $sign );
if ( $offset >= 0 ) {
printf "Found signature offset: %s\n", $offset;
}
else {
print "Signature not found\n";
exit;
}
die "Can't seek to $offset" unless seek( F, $offset, 0 );
open( OF, ">", $output_file ) || die "Can't open output file $output_file: $!";
binmode(OF);
while ( read( F, $buf, 2048 ) ) {
print OF $buf;
}
close(F);
close(OF);