make attribute name an argument

master
Сергей Маринкевич 3 years ago
parent 323db2eaae
commit 339addff30

@ -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;
}

Loading…
Cancel
Save