Finish import/export functionality

This commit is contained in:
2023-01-06 18:43:47 +01:00
parent aa15e1a541
commit c41214fc75
6 changed files with 165 additions and 157 deletions

View File

@@ -0,0 +1,20 @@
#ifndef _ELFPATCHCRC_DATATYPES_H_
#define _ELFPATCHCRC_DATATYPES_H_
#include <stdint.h>
struct crc_entry {
char *name;
uint64_t vma;
uint64_t lma;
uint64_t size;
uint32_t crc;
};
struct crc_import_data {
int elf_bits;
struct crc_settings crc_config;
SlList *crc_entries; /**< @brief linked list of @ref crc_entry structs */
};
#endif /* _ELFPATCHCRC_DATATYPES_H_ */

View File

@@ -27,6 +27,7 @@
#include <patchelfcrc/crc.h>
#include <stdbool.h>
#include <linklist-lib/singly-linked-list.h>
#include <patchelfcrc/crc-datatypes.h>
typedef struct elfpatch elfpatch_handle_t;
@@ -87,17 +88,9 @@ int elf_patch_compute_crc_over_section(elfpatch_handle_t *ep, const char *sectio
void elf_patch_close_and_free(elfpatch_handle_t *ep);
/**
* @brief Write CRCs to output section. This will have no effect, if file is opened read onyl
* @param ep Elf patch object
* @param[in] section Section name to place CRCs in
* @param[in] section_name_list The list of sections the data belongs to
* @param[in] crcs CRCs. Must be of the same lenght as the \p section_name_list
* @return 0 Success
* @return -1000 Parameter error
* @return -1 internal error
*/
int elf_patch_write_crcs_to_section(elfpatch_handle_t *ep, const char *section, const SlList *section_name_list,
const uint32_t *crcs, uint8_t crc_size_bits, uint32_t start_magic, uint32_t end_magic,
bool check_start_magic, bool check_end_magic, enum crc_format format, bool little_endian);
int elf_patch_write_crcs_to_section(elfpatch_handle_t *ep, const char *output_sec_name,
const struct crc_import_data *crc_data, bool use_vma,
uint32_t start_magic, uint32_t end_magic,
bool check_start_magic, bool check_end_magic,
enum crc_format format, bool little_endian);
#endif /* _ELFPATCH_H_ */

View File

@@ -1,29 +1,13 @@
#ifndef _ELFPATCHCRC_XML_H_
#define _ELFPATCHCRC_XML_H_
#include <stdint.h>
#include <linklist-lib/singly-linked-list.h>
#include <patchelfcrc/crc.h>
#include <patchelfcrc/elfpatch.h>
struct xml_crc_entry {
char *name;
uint64_t vma;
uint64_t lma;
uint64_t size;
uint32_t crc;
};
struct xml_crc_import {
int elf_bits;
struct crc_settings crc_config;
SlList *xml_crc_entries; /**< @brief linked list of @ref xml_crc_entry structs */
};
#include <patchelfcrc/crc-datatypes.h>
void xml_init(void);
int xml_write_crcs_to_file(const char *path, const uint32_t *crcs, SlList *section_names,
const struct crc_settings *crc_params, elfpatch_handle_t *ep);
int xml_write_crcs_to_file(const char *path, const struct crc_import_data *crc_data);
/**
* @brief xml_import_from_file Import from file
@@ -31,17 +15,19 @@ int xml_write_crcs_to_file(const char *path, const uint32_t *crcs, SlList *secti
* @return Returns a newly allocated struct. Must be freed with @ref xml_crc_import_free
* @return NULL in case of error
*/
struct xml_crc_import *xml_import_from_file(const char *path);
struct crc_import_data *xml_import_from_file(const char *path);
/**
* @brief Fully free supplied import data
* @param data Data to free
*/
void xml_crc_import_free(struct xml_crc_import *data);
void xml_crc_import_free(struct crc_import_data *data);
/**
* @brief Print XML XSD file to stdout
*/
void xml_print_xsd(void);
struct crc_import_data *xml_crc_import_alloc(void);
#endif /* _ELFPATCHCRC_XML_H_ */