This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathintel-blob2dat.php
110 lines (79 loc) · 2.04 KB
/
intel-blob2dat.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
Author: NewEraCracker
License: Public Domain
*/
function blob2dat($fn_read, $fn_write)
{
if(!file_exists($fn_read) || file_exists($fn_write) || !is_readable($fn_read))
return 0;
$count = 0;
$mtime = filemtime($fn_read);
$fp_write = fopen($fn_write /*'uc_intel.dat'*/, 'wb');
if(!$fp_write) {
return 0;
}
$fp_read = fopen($fn_read /*'uc_intel.bin'*/, 'rb');
do {
$bytes = fread($fp_read, 4);
if(!strlen($bytes))
break;
$text = '0x' . bin2hex($bytes[3] . $bytes[2]) . bin2hex($bytes[1] . $bytes[0]) . ',';
$count++;
if($count % 4) {
$text .= ' ';
} else {
$text .= "\n";
}
fwrite($fp_write, $text);
fflush($fp_write);
}
while (!feof($fp_read));
fclose($fp_read);
fclose($fp_write);
touch($fn_write, $mtime, $mtime);
return $count;
}
function dat2blob($fn_read, $fn_write)
{
if(!file_exists($fn_read) || file_exists($fn_write) || !is_readable($fn_read))
return 0;
$count = 0;
$mtime = filemtime($fn_read);
$fp_write = fopen($fn_write /*'uc_intel.bin'*/, 'wb');
if(!$fp_write) {
return 0;
}
$fl_read = @file($fn_read /*'uc_intel.dat'*/, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($fl_read as $l)
{
if($l[0] == '/')
continue;
$wrt = '';
$hex = array_map('trim', explode(',', $l));
foreach($hex as $h) {
$bytes = str_split($h, 2);
$hex0x = array_shift($bytes);
if($hex0x == '0x') {
for($i = count($bytes) - 1; $i >= 0; $i--) {
$wrt .= pack('H*' , $bytes[$i]);
}
$count++;
}
}
fwrite($fp_write, $wrt);
fflush($fp_write);
}
fclose($fp_write);
touch($fn_write, $mtime, $mtime);
return $count;
}
($_SERVER['argc'] == 3) || die('Usage: ' . $_SERVER['argv'][0] . ' microcode.dat microcode.bin' . PHP_EOL);
$fn_read = $_SERVER['argv'][1];
$fn_write = $_SERVER['argv'][2];
$ex_read = pathinfo($fn_read, PATHINFO_EXTENSION);
$ex_write = pathinfo($fn_write, PATHINFO_EXTENSION);
if($ex_read == 'dat' && $ex_write == 'bin')
dat2blob($fn_read, $fn_write);
if($ex_read == 'bin' && $ex_write == 'dat')
blob2dat($fn_read, $fn_write);