Read section name from XML
This commit is contained in:
parent
e93b42dd40
commit
aa15e1a541
@ -7,7 +7,9 @@
|
||||
#include <patchelfcrc/elfpatch.h>
|
||||
|
||||
struct xml_crc_entry {
|
||||
char *name;
|
||||
uint64_t vma;
|
||||
uint64_t lma;
|
||||
uint64_t size;
|
||||
uint32_t crc;
|
||||
};
|
||||
|
54
src/xml.c
54
src/xml.c
@ -296,7 +296,7 @@ int get_uint64_from_node_attribute(xmlNodePtr node, const char *attr, uint64_t *
|
||||
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;
|
||||
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);
|
||||
|
||||
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;
|
||||
} else {
|
||||
*output = (uint32_t)tmp;
|
||||
@ -313,6 +313,39 @@ int get_uint32_from_node_attribute(xmlNodePtr node, const char *attr, uint32_t *
|
||||
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 *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);
|
||||
|
||||
get_uint64_from_node_attribute(current_node, "vma", &tmp_num64);
|
||||
crc->vma = 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);
|
||||
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:
|
||||
|
||||
if (xpath_obj)
|
||||
@ -429,9 +467,15 @@ ret_none:
|
||||
|
||||
}
|
||||
|
||||
static void free_xml_crc_entry(void *entry) {
|
||||
if (entry)
|
||||
static void free_xml_crc_entry(void *entry)
|
||||
{
|
||||
struct xml_crc_entry *e = (struct xml_crc_entry *)entry;
|
||||
|
||||
if (entry) {
|
||||
if (e->name)
|
||||
xmlFree(e->name);
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void xml_crc_import_free(struct xml_crc_import *data)
|
||||
|
Loading…
Reference in New Issue
Block a user