37
49
#include <glib/gstdio.h>
40
* Foreach file identified by their sha1sum, we store the offset where
41
* the firmware begin in the file.
43
* If a file does not work, you may need to add an entry here. To find
44
* the offset in the driver file, use a hexadecimal editor (e.g. ghex)
45
* and search for "USBSend". You will find data like this :
47
* "start USBSend #4 returned 0x%x.....X.....4.~.........%\"
50
* Each period means 0x00. The firmware start at the ^ sign
51
* position. Read the offset and store in in this array. The tool must
52
* output the sha1sum of the file, use this to fill the .sha1sum
59
unsigned char sha1sum[20];
63
static const struct offset offsets[] = {
64
{ "Mac OS X.6 MacBook 1,1",
65
.sha1sum = { 0x32, 0xcc, 0xa3, 0x17, 0xae, 0x54, 0xb5, 0x1c,
66
0x4c, 0xfa, 0x66, 0x4d, 0x0d, 0xa0, 0x47, 0xe9,
67
0x11, 0x01, 0xf9, 0x1e },
70
{ "Mac OS X.6 MacBook 5,2",
71
.sha1sum = { 0x06, 0x2d, 0x20, 0xde, 0x72, 0xb9, 0x6a, 0x24,
72
0xb7, 0x41, 0xc9, 0x51, 0xda, 0x04, 0x5d, 0xd7,
73
0x81, 0x9c, 0x7b, 0xc8 },
76
{ "Mac OS X.6 MacBook Unibody",
77
.sha1sum = { 0xcd, 0x38, 0xe9, 0x08, 0x06, 0xae, 0x06, 0xec,
78
0xe0, 0x5b, 0x47, 0x26, 0x04, 0x3b, 0xef, 0xec,
79
0x40, 0x15, 0x73, 0x4d },
83
.sha1sum = { 0x95, 0x6b, 0xf7, 0x0d, 0xa9, 0x03, 0xa0, 0xb4,
84
0x8b, 0x41, 0x44, 0x87, 0x61, 0xa0, 0xff, 0xd2,
85
0xd6, 0x93, 0xa2, 0x90 },
89
.sha1sum = { 0xa1, 0x7c, 0xfe, 0xe1, 0xaa, 0x48, 0x83, 0xf6,
90
0x63, 0xb9, 0xf8, 0x95, 0x2d, 0x15, 0x6a, 0xe2,
91
0x8f, 0x90, 0xd9, 0x11 },
95
.sha1sum = { 0x62, 0xe8, 0xed, 0xa7, 0x67, 0xa8, 0x37, 0x4f,
96
0x1b, 0x13, 0xc4, 0x61, 0xdd, 0x60, 0x8c, 0x84,
97
0xf3, 0xc8, 0xc0, 0x24 },
100
{ "Mac OS X.5.x (Macbook Air)",
101
.sha1sum = { 0xbd, 0x5d, 0xc3, 0xff, 0xf3, 0xa6, 0x5f, 0x35,
102
0xa6, 0xb8, 0xa1, 0x81, 0x40, 0x29, 0x8c, 0x06,
103
0x94, 0xb3, 0xed, 0xc6 },
107
.sha1sum = { 0xf9, 0x91, 0xab, 0x81, 0xf8, 0x98, 0x8f, 0x41,
108
0x6f, 0x2d, 0xf0, 0x79, 0x2d, 0xf7, 0x60, 0x2c,
109
0x82, 0x01, 0x2b, 0xeb },
113
.sha1sum = { 0x89, 0x84, 0x60, 0x94, 0x2e, 0x12, 0x65, 0xa3,
114
0x57, 0xb5, 0xac, 0x86, 0x82, 0x4a, 0xf2, 0xd4,
115
0xa4, 0xf7, 0x3b, 0x98 },
118
{ "Mac OS X.5.1 late 2007",
119
.sha1sum = { 0x1c, 0x60, 0xef, 0x27, 0xd5, 0x72, 0x21, 0xcf,
120
0x3d, 0x76, 0x68, 0x7a, 0x49, 0x73, 0xec, 0x72,
121
0xff, 0x6f, 0xa1, 0x03 },
124
{ "Mac OS X.5.1 driver 1.0.9",
125
.sha1sum = { 0xa1, 0x7b, 0x71, 0xc0, 0xe6, 0x3b, 0xd3, 0x87,
126
0x82, 0x10, 0x88, 0xdb, 0x3a, 0x66, 0x5b, 0xb8,
127
0x7a, 0xdc, 0xa2, 0x08 },
131
.sha1sum = { 0xb6, 0x9f, 0x49, 0xd3, 0xfa, 0x68, 0x58, 0x41,
132
0x63, 0x24, 0xc3, 0x90, 0xef, 0xfe, 0x14, 0x33,
133
0x6a, 0x1d, 0xdb, 0x0b },
136
{ "Mac OS X.4 intel",
137
.sha1sum = { 0x01, 0xe2, 0x91, 0xd5, 0x29, 0xe7, 0xc1, 0x8d,
138
0xee, 0xa2, 0xeb, 0xa2, 0x52, 0xd1, 0x81, 0x14,
139
0xe0, 0x96, 0x27, 0x6e },
142
{ "Mac OS X unknown version",
143
.sha1sum = { 0xc6, 0xc9, 0x4d, 0xd7, 0x7b, 0x86, 0x4f, 0x8b,
144
0x2d, 0x31, 0xab, 0xf3, 0xcb, 0x2d, 0xe4, 0xc9,
145
0xd1, 0x39, 0xe1, 0xbf },
148
{ "Mac OS X unknown version",
149
.sha1sum = { 0xa1, 0x4c, 0x15, 0x9b, 0x17, 0x6d, 0x27, 0xa6,
150
0xe9, 0x8d, 0xcb, 0x5d, 0xea, 0x5d, 0x78, 0xb8,
151
0x1e, 0x15, 0xad, 0x41 },
154
{ "Mac OS X unknown version",
155
.sha1sum = { 0x86, 0x43, 0x0c, 0x04, 0xf9, 0xb6, 0x7c, 0x5c,
156
0x3d, 0x84, 0x40, 0x91, 0x38, 0xa7, 0x67, 0x98,
157
0x27, 0x02, 0x5e, 0xc2 },
160
{ "Mac OS X.4.10 PPC64",
161
.sha1sum = { 0xde, 0xf7, 0xf4, 0xf0, 0x08, 0xd7, 0x8f, 0x39,
162
0x3f, 0x95, 0x94, 0x6f, 0xbf, 0x85, 0xd7, 0xb1,
163
0xbd, 0xdc, 0x41, 0x11 },
169
52
* The vanilla firmware have bugs in USB Interface descriptor
170
53
* values. We override buggy value with correct one. Those value are
171
54
* triplet, we replace 0xFF 0xFF 0xFF by specific value.
238
138
/* IMPLEMENTATION */
240
static unsigned char*
241
get_sha1sum(char*filename)
243
unsigned char *digest;
247
digest = g_malloc0 (gcry_md_get_algo_dlen (GCRY_MD_SHA1));
248
if (!(file = g_mapped_file_new (filename, FALSE, &gerr))) {
249
g_error(_("Unable to open driver: %s"),
250
gerr ? gerr->message : "?");
253
gcry_md_hash_buffer (GCRY_MD_SHA1, digest,
254
g_mapped_file_get_contents (file),
255
g_mapped_file_get_length (file));
256
g_mapped_file_free (file);
262
sha1sum_string(unsigned char*digest)
267
for (i = 0; i < 20; i++) {
268
sha1sum = g_strdup_printf("%s %02x", sha1sum, digest[i]);
273
static const struct offset*
274
find_offset(unsigned char*digest)
278
for (n = 0; n < G_N_ELEMENTS (offsets); n++)
279
if (!memcmp (offsets[n].sha1sum, digest, 20))
282
if (n == G_N_ELEMENTS (offsets)) {
283
g_warning(_("Unknown driver. Please report it to %s with "
284
"machine description and Mac OS X version."),
288
/* translators : %s is the known origin of the driver */
289
g_message(_("Found %s driver"),
141
* To find the offset in the driver file, use a hexadecimal editor
142
* (e.g. ghex) and search for "USBSend". You will find data like
145
* "start USBSend #4 returned 0x%x.....X.....4.~.........%\"
148
* Each period means 0x00. The firmware start at the ^ sign
149
* position. Read the offset and store in in this array. The tool must
150
* output the sha1sum of the file, use this to fill the .sha1sum
154
seek_offset(const gchar* filename)
158
/* This is the preambule of the firmware in the driver file */
159
const guchar needle[8] = {0xC2, 0x34, 0x06, 0x7E,
160
0x05, 0x00, 0x00, 0x00};
161
guint read_len, chunk_len = 8;
163
guchar* chunk = g_new0(guchar, chunk_len);
165
if ((fd = g_open (filename, O_RDONLY)) == -1) {
166
g_error(_("Unable to open %s."), filename);
171
for (pos = 0x1000; pos < 0xD000; pos++) {
172
if (lseek(fd, pos, SEEK_SET) != pos) {
173
g_error(_("Failed to seek %s at position %x."),
174
filename, (guint) pos);
178
if ((read_len = read(fd, chunk, chunk_len)) != chunk_len) {
179
g_error(_("Failed to read %s at position %x."),
180
filename, (guint) pos);
184
if (memcmp(needle, chunk, chunk_len) == 0) {
186
g_message(_("Found firmware signature at offset 0x%X."),
295
202
/* extract firmware from filename at offset to output, checking the