Implement first working draft of CRC patching

This commit is contained in:
2022-10-23 15:45:31 +02:00
parent c8da6e4f4c
commit 341e0cecf8
6 changed files with 205 additions and 10 deletions

View File

@@ -4,6 +4,7 @@
#include <stdint.h>
#include <patchelfcrc/crc.h>
#include <stdbool.h>
#include <linklist-lib/singly-linked-list.h>
typedef struct elfpatch elfpatch_handle_t;
@@ -13,6 +14,10 @@ enum granularity {
GRANULARITY_32BIT = 32,
};
enum crc_format {
FORMAT_BARE = 0,
FORMAT_STRUCT,
};
elfpatch_handle_t *elf_patch_open(const char *path, bool readonly);
@@ -28,4 +33,17 @@ 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);
#endif /* _ELFPATCH_H_ */

View File

@@ -3,7 +3,7 @@
#include <stdbool.h>
#define print_err(fmt, ...) fprintf(stderr, (fmt), ## __VA_ARGS__);
#define print_err(fmt, ...) fprintf(stderr, "[ERR] " fmt, ## __VA_ARGS__);
void print_debug(const char *fmt, ...);