From 339addff309e4e98a34730f9776a428d36b2e278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9C=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=BA=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 26 Dec 2022 19:30:46 +0700 Subject: [PATCH] make attribute name an argument --- main.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index 7191cfa..ba83ed4 100644 --- a/main.c +++ b/main.c @@ -13,8 +13,6 @@ #define debug(...) #endif -#define SEARCH_NAME "data" - static int reads_counter = 0; static int fit_offset = 0; @@ -208,11 +206,13 @@ static int fdt_node_get_prop(char * filename, char * fdt, char * strings, int of return -1; } -static int fdt_dump_node_data(char * fdt, char * strings, const char *outname, const char *filename, int offset) +static int fdt_dump_node_attribute(char * fdt, char * strings, const char *attribute_name, + const char *outname, const char *filename, int offset) { int data_offset = 0; int data_len = 0; - if (fdt_node_get_prop(filename, fdt, strings, offset, SEARCH_NAME, &data_offset, &data_len)) + if (fdt_node_get_prop(filename, fdt, strings, offset, attribute_name, + &data_offset, &data_len)) return -1; char * data = malloc(data_len); @@ -238,7 +238,7 @@ static int fdt_dump_node_data(char * fdt, char * strings, const char *outname, c int ret = 0; char out_filename[128] = ""; - snprintf(out_filename, 128, "/tmp/%s", outname); + snprintf(out_filename, 128, "./%s", outname); *strchr(out_filename, '@') = '_'; debug("Open file '%s'\n", out_filename); fd = open(out_filename, O_WRONLY | O_CREAT, 0666); @@ -302,8 +302,22 @@ int b(int argc, const char * argv[]) printf("Gimme path to FIT!\n"); return -1; } - const char * filename = argv[1]; - argc--; + + if (argc < 3) + { + printf("Gimme name of attribute to dump from FIT!\n"); + return -1; + } + + if (argc < 4) + { + printf("Gimme FIT node name to dump it's attribute!\n"); + return -1; + } + + int argi = 1; + const char * filename = argv[argi++]; + const char * attribute_name = argv[argi++]; int fdt_start = 0; char * milf = malloc(WINDOW_SIZE); @@ -364,16 +378,16 @@ skip_milf: if (readed <= 0) return -1; - printf("B:\n"); int offset = 0; struct { const char * name; int offset; } node_offsets[10] = { 0 }; int node_idx = 0; - while (--argc) + while (argi < argc) { - node_offsets[node_idx].name = argv[2 + node_idx]; + node_offsets[node_idx].name = argv[argi]; node_offsets[node_idx].offset = -1; - debug("Remember argv[%d]: '%s'\n", 2 + node_idx, argv[2 + node_idx]); + debug("Remember argv[%d]: '%s'\n", 2 + node_idx, argv[argi]); + argi++; node_idx++; } debug("Search these nodes:\n"); @@ -433,8 +447,9 @@ skip_milf: { if (node_offsets[i].offset < 0) continue; - printf("%s offset: %x\n", node_offsets[i].name, node_offsets[i].offset); - int writed = fdt_dump_node_data(fdt, strings, node_offsets[i].name, filename, node_offsets[i].offset); + printf("%s offset: 0x%x\n", node_offsets[i].name, node_offsets[i].offset); + int writed = fdt_dump_node_attribute(fdt, strings, attribute_name, node_offsets[i].name, + filename, node_offsets[i].offset); if (writed) printf("Written %d bytes\n", writed); } @@ -446,6 +461,6 @@ skip_milf: int main(int argc, char *argv[]) { b(argc, argv); - printf("Counter: %d\n", reads_counter); + debug("Counter: %d\n", reads_counter); return 0; }