Commit 32a346a4 authored by Alejandro Mery's avatar Alejandro Mery
Browse files

bin2fex: split decompiler of single datums into a separated function

parent 151f7afe
...@@ -68,6 +68,26 @@ static inline int decompile_gpio(struct script_section *section, ...@@ -68,6 +68,26 @@ static inline int decompile_gpio(struct script_section *section,
return ok; return ok;
} }
/**
*/
static inline int decompile_single(struct script_section *section,
struct script_section_entry *entry,
int32_t *d,
int length, FILE *out)
{
int ok = 1;
if (length != 1) {
pr_err("%s.%s: invalid length %d (assuming %d)\n",
section->name, entry->name, length, 1);
ok = 0;
}
fprintf(out, "%s\t= %d\n", entry->name, *d);
return ok;
}
/** /**
*/ */
static int decompile_section(void *bin, size_t bin_size, static int decompile_section(void *bin, size_t bin_size,
...@@ -86,17 +106,10 @@ static int decompile_section(void *bin, size_t bin_size, ...@@ -86,17 +106,10 @@ static int decompile_section(void *bin, size_t bin_size,
length = (entry->pattern >> 0) & 0xffff; length = (entry->pattern >> 0) & 0xffff;
switch(type) { switch(type) {
case SCRIPT_VALUE_TYPE_SINGLE_WORD: { case SCRIPT_VALUE_TYPE_SINGLE_WORD:
int32_t *d = data; if (!decompile_single(section, entry, data, length, out))
if (length != 1) {
pr_err("%s.%s: invalid length %d (assuming %d)\n",
section->name, entry->name, length, 1);
ok = 0; ok = 0;
} break;
/* TODO: some are preferred in hexa */
fprintf(out, "%s\t= %d\n", entry->name, *d);
}; break;
case SCRIPT_VALUE_TYPE_STRING: { case SCRIPT_VALUE_TYPE_STRING: {
size_t bytes = length << 2; size_t bytes = length << 2;
const char *p, *pe, *s = data; const char *p, *pe, *s = data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment