Skip to content

Commit 2a4af4f

Browse files
committed
fexc: Convert version[0] header field to filesize
Vendor-provided .bin files have repeatedly demonstrated that our previous interpretation of this field as version[0] is likely wrong. Instead, it seems to represent the file size (in bytes) of the .bin file. This commit fixes both decompilation (and header checks) and generation of .bin files, where it will now store the size to this field. TODO: It's unclear whether the 'filesize' needs some specific alignment (and the .bin corresponding padding). A value of 34864 (0x8830) has already been observed, so any possible alignment is expected not to exceed 16 bytes (0x10). (Currently our .bin generator doesn't care about any specific alignment.) Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
1 parent bf735b2 commit 2a4af4f

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

script_bin.c

+12-13
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ size_t script_bin_size(struct script *script,
9797
return bin_size;
9898
}
9999

100-
int script_generate_bin(void *bin, size_t UNUSED(bin_size),
100+
int script_generate_bin(void *bin, size_t bin_size,
101101
struct script *script,
102102
size_t sections, size_t entries)
103103
{
@@ -122,9 +122,9 @@ int script_generate_bin(void *bin, size_t UNUSED(bin_size),
122122
(void*)data-bin);
123123

124124
head->sections = sections;
125-
head->version[0] = 0;
126-
head->version[1] = 1;
127-
head->version[2] = 2;
125+
head->filesize = bin_size;
126+
head->version[0] = 1;
127+
head->version[1] = 2;
128128

129129
for (ls = list_first(&script->sections); ls;
130130
ls = list_next(&script->sections, ls)) {
@@ -326,11 +326,10 @@ int script_decompile_bin(void *bin, size_t bin_size,
326326
unsigned int i;
327327
struct script_bin_head *head = bin;
328328

329-
if (((head->version[0] & 0x3FFF) > SCRIPT_BIN_VERSION_LIMIT) ||
330-
(head->version[1] > SCRIPT_BIN_VERSION_LIMIT) ||
331-
(head->version[2] > SCRIPT_BIN_VERSION_LIMIT)) {
332-
pr_err("Malformed data: version %u.%u.%u.\n",
333-
head->version[0], head->version[1], head->version[2]);
329+
if ((head->version[0] > SCRIPT_BIN_VERSION_LIMIT) ||
330+
(head->version[1] > SCRIPT_BIN_VERSION_LIMIT)) {
331+
pr_err("Malformed data: version %u.%u.\n",
332+
head->version[0], head->version[1]);
334333
return 0;
335334
}
336335

@@ -340,10 +339,10 @@ int script_decompile_bin(void *bin, size_t bin_size,
340339
return 0;
341340
}
342341

343-
pr_info("%s: version: %u.%u.%u\n", filename,
344-
head->version[0] & 0x3FFF, head->version[1], head->version[2]);
345-
pr_info("%s: size: %zu (%u sections)\n", filename,
346-
bin_size, head->sections);
342+
pr_info("%s: version: %u.%u\n", filename,
343+
head->version[0], head->version[1]);
344+
pr_info("%s: size: %zu (%u sections), header value: %u\n", filename,
345+
bin_size, head->sections, head->filesize);
347346

348347
/* TODO: SANITY: compare head.sections with bin_size */
349348
for (i=0; i < head->sections; i++) {

script_bin.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ struct script_bin_section {
2727
/** binary representation of the head of the script file */
2828
struct script_bin_head {
2929
uint32_t sections;
30-
uint32_t version[3];
30+
uint32_t filesize;
31+
uint32_t version[2];
3132
struct script_bin_section section[];
3233
};
3334

0 commit comments

Comments
 (0)