diff --git a/bin2fex.c b/bin2fex.c
index 2e11acb..5e0bed0 100644
--- a/bin2fex.c
+++ b/bin2fex.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
#include "sunxi-tools.h"
+#include "bin2fex.h"
#include
#include
@@ -27,12 +28,45 @@
#define errf(...) fprintf(stderr, __VA_ARGS__)
+static int decompile(void *bin, size_t bin_size, int out, const char *out_name);
+static int decompile_section(void *bin, size_t bin_size,
+ struct script_section *section,
+ int out, const char* out_named);
/**
*/
-static int decompile(const char *bin, size_t bin_size, int out, const char *out_name)
+static int decompile(void *bin, size_t bin_size, int out, const char *out_name)
{
- errf("bin size: %zu\n", bin_size);
- return 0;
+ int i;
+ struct {
+ struct script_head head;
+ struct script_section sections[];
+ } *script = bin;
+
+ errf("bin format: %d.%d.%d\n", script->head.version[0],
+ script->head.version[1], script->head.version[2]);
+ errf("bin size: %zu (%d sections)\n", bin_size,
+ script->head.sections);
+
+ /* TODO: SANITY: compare head.sections with bin_size */
+ for (i=0; i < script->head.sections; i++) {
+ struct script_section *section = &script->sections[i];
+
+ errf("%s: (section:%d, length:%d, offset:%d)\n",
+ section->name, i+1, section->length, section->offset);
+
+ if (!decompile_section(bin, bin_size, section, out, out_name))
+ return 1; /* failure */
+ }
+ return 0; /* success */
+}
+
+/**
+ */
+static int decompile_section(void *bin, size_t bin_size,
+ struct script_section *section,
+ int out, const char* out_named)
+{
+ return 1; /* success */
}
/**
diff --git a/bin2fex.h b/bin2fex.h
new file mode 100644
index 0000000..53d9452
--- /dev/null
+++ b/bin2fex.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 Alejandro Mery
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#ifndef _SUNXI_TOOLS_BIN2FEX_H
+#define _SUNXI_TOOLS_BIN2FEX_H
+
+#include
+
+struct script_head {
+ int32_t sections;
+ int32_t version[3];
+};
+
+struct script_section {
+ char name[32];
+ int32_t length;
+ int32_t offset;
+};
+
+struct script_section_entry {
+ char name[32];
+ int32_t offset;
+ int32_t pattern;
+};
+
+#endif