Implement xml export / import #3

Merged
mhu merged 20 commits from xml-export into master 2023-01-06 18:50:08 +01:00
2 changed files with 51 additions and 5 deletions
Showing only changes of commit aa15e1a541 - Show all commits

View File

@ -7,7 +7,9 @@
#include <patchelfcrc/elfpatch.h> #include <patchelfcrc/elfpatch.h>
struct xml_crc_entry { struct xml_crc_entry {
char *name;
uint64_t vma; uint64_t vma;
uint64_t lma;
uint64_t size; uint64_t size;
uint32_t crc; uint32_t crc;
}; };

View File

@ -296,7 +296,7 @@ int get_uint64_from_node_attribute(xmlNodePtr node, const char *attr, uint64_t *
return ret; return ret;
} }
int get_uint32_from_node_attribute(xmlNodePtr node, const char *attr, uint32_t *output) static int get_uint32_from_node_attribute(xmlNodePtr node, const char *attr, uint32_t *output)
{ {
int ret; int ret;
uint64_t tmp = 0; uint64_t tmp = 0;
@ -304,7 +304,7 @@ int get_uint32_from_node_attribute(xmlNodePtr node, const char *attr, uint32_t *
ret = get_uint64_from_node_attribute(node, attr, &tmp); ret = get_uint64_from_node_attribute(node, attr, &tmp);
if (tmp > UINT32_MAX || ret) { if (tmp > UINT32_MAX || ret) {
print_err("Cannot conver attribute %s to number\n", attr); print_err("Cannot convert attribute %s to 32 bit number\n", attr);
ret = -1; ret = -1;
} else { } else {
*output = (uint32_t)tmp; *output = (uint32_t)tmp;
@ -313,6 +313,39 @@ int get_uint32_from_node_attribute(xmlNodePtr node, const char *attr, uint32_t *
return ret; return ret;
} }
static int get_uint64_from_node_content(xmlNodePtr node, uint64_t *output)
{
xmlChar *data;
int ret = -1;
data = xmlNodeGetContent(node);
if (data) {
ret = convert_number_string_to_uint((const char *)data, output);
xmlFree(data);
}
return ret;
}
static int get_uint32_from_node_content(xmlNodePtr node, uint32_t *output)
{
int ret;
uint64_t tmp = 0;
ret = get_uint64_from_node_content(node, &tmp);
if (tmp > UINT32_MAX || ret) {
print_err("Cannot convert content to 32 bit number\n");
ret = -1;
} else {
*output = (uint32_t)tmp;
}
return ret;
}
struct xml_crc_import *xml_import_from_file(const char *path) struct xml_crc_import *xml_import_from_file(const char *path)
{ {
struct xml_crc_import *ret = NULL; struct xml_crc_import *ret = NULL;
@ -405,12 +438,17 @@ struct xml_crc_import *xml_import_from_file(const char *path)
ret->xml_crc_entries = sl_list_append(ret->xml_crc_entries, crc); ret->xml_crc_entries = sl_list_append(ret->xml_crc_entries, crc);
get_uint64_from_node_attribute(current_node, "vma", &tmp_num64); get_uint64_from_node_attribute(current_node, "vma", &tmp_num64);
crc->vma = tmp_num64;
get_uint64_from_node_attribute(current_node, "size", &tmp_num64); get_uint64_from_node_attribute(current_node, "size", &tmp_num64);
crc->size = tmp_num64;
get_uint64_from_node_attribute(current_node, "lma", &tmp_num64); get_uint64_from_node_attribute(current_node, "lma", &tmp_num64);
crc->lma = tmp_num64;
get_uint32_from_node_content(current_node, &tmp_num32);
crc->crc = tmp_num32;
crc->name = (char *)xmlGetProp(current_node, "name");
} }
ret_close_doc: ret_close_doc:
if (xpath_obj) if (xpath_obj)
@ -429,10 +467,16 @@ ret_none:
} }
static void free_xml_crc_entry(void *entry) { static void free_xml_crc_entry(void *entry)
if (entry) {
struct xml_crc_entry *e = (struct xml_crc_entry *)entry;
if (entry) {
if (e->name)
xmlFree(e->name);
free(entry); free(entry);
} }
}
void xml_crc_import_free(struct xml_crc_import *data) void xml_crc_import_free(struct xml_crc_import *data)
{ {