-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathucode_write_byte.pl
More file actions
executable file
·58 lines (50 loc) · 1.52 KB
/
ucode_write_byte.pl
File metadata and controls
executable file
·58 lines (50 loc) · 1.52 KB
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
#!/usr/bin/env perl
use strict;
use warnings;
=pod
This script can be used to rearrange the ucode found in the bcm43438 to enable disassembling
The '-r' parameter can be used to reverse this process
=cut
my $buffer;
my @bytes = ();
my $cnt = 0;
my $reverse = 0;
my $infile;
my $outfile;
my $num_args = $#ARGV + 1;
if ($num_args < 2) {
print "Usage: [-r] in_file out_file\n";
exit;
}
if($ARGV[0] =~ '-r') {
$reverse = 1;
$infile = $ARGV[1];
$outfile = $ARGV[2];
} else {
$infile = $ARGV[0];
$outfile = $ARGV[1];
}
print("Using infile: '$infile', outfile: '$outfile'\n");
# File size of $infile
my $ucode_len = -s $infile;
open(FH, '<:raw', $infile);
read(FH, $buffer, $ucode_len);
@bytes = unpack('C*',$buffer); # 'C*' multiple unsigned character
close(FH);
open(FHW, '>:raw', $outfile);
if(not $reverse) {
while($cnt < $ucode_len) {
$cnt += 7;
my $byte1 = ($bytes[$cnt-3] << 16) | ($bytes[$cnt-4] << 24) | ($bytes[$cnt-1]) | ($bytes[$cnt-2] << 8);
print FHW pack('I', $byte1); # 'I' 32 bit unsigned int
my $byte2 = ($bytes[$cnt-6] << 8) | ($bytes[$cnt-7] << 16) | ($bytes[$cnt-5]);
print FHW pack('I', $byte2);
}
} else {
while($cnt < $ucode_len) {
$cnt += 8;
my $byte1 = sprintf("%014x", ($bytes[$cnt-2] << 48) | ($bytes[$cnt-3] << 40) | ($bytes[$cnt-4] << 32) | ($bytes[$cnt-5] << 24) | ($bytes[$cnt-6] << 16) | ($bytes[$cnt-7] << 8) | ($bytes[$cnt-8]));
print FHW pack('H*', $byte1); # 'H*' hex string (high nybble first)
}
}
close(FHW);