Compare commits
9 Commits
26eb480343
...
dev
Author | SHA1 | Date | |
---|---|---|---|
b49ae6e46c | |||
29fdc841b7 | |||
dc30188593 | |||
2bea5d288c | |||
8a0226a5ea | |||
ed6373473c | |||
80b5f5b1b3 | |||
4fab6ffd3a | |||
0ee19eaea4 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,3 +4,6 @@
|
||||
[submodule "linklist-lib"]
|
||||
path = linklist-lib
|
||||
url = https://git.shimatta.de/mhu/linklist-lib.git
|
||||
[submodule "test/catch2"]
|
||||
path = test/catch2
|
||||
url = https://git.shimatta.de/3rd-party/catch2.git
|
||||
|
2
3rdparty/libfort
vendored
2
3rdparty/libfort
vendored
Submodule 3rdparty/libfort updated: 41237162a9...5a8f9312bd
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.5...3.18)
|
||||
|
||||
project(patchelfcrc LANGUAGES C)
|
||||
|
||||
@@ -91,3 +91,5 @@ else (DOXYGEN_FOUND)
|
||||
message("${BoldMagenta}Doxygen needs to be installed to generate the doxygen documentation${ColorReset}")
|
||||
message("${BoldMagenta}doxygen target will not be available${ColorReset}")
|
||||
endif (DOXYGEN_FOUND)
|
||||
|
||||
add_subdirectory(test)
|
||||
|
9
bash-completion/patchelfcrc
Normal file
9
bash-completion/patchelfcrc
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
function _patchelfcrc() {
|
||||
echo "Cursor index: $COMP_CWORD"
|
||||
echo "line as array: $COMP_WORDS"
|
||||
echo "line as string: $COMP_LINE"
|
||||
}
|
||||
|
||||
complete -F _patchelfcrc patchelfcrc
|
Submodule linklist-lib updated: c20b5c2528...fdd99bad48
@@ -61,7 +61,7 @@
|
||||
: Export the calculated files to an XML file *XMLFILE*.
|
||||
|
||||
**--import**=*XMLFILE*
|
||||
: Import the CRCs from an XML file *XMLFILE* and do not caclulate anything in the given *ELF*
|
||||
: Import the CRCs from an XML file *XMLFILE* and do not calculate anything in the given *ELF*
|
||||
|
||||
**--help**, **-h**, **-?**
|
||||
: Print help.
|
||||
@@ -134,8 +134,8 @@
|
||||
|
||||
**patchelfcrc** -l -g word --start-magic=0x12345678 --end-magic=0x8754321 -p crc-32-mpeg -f bare -O .outputsection -S .text executable.elf
|
||||
: Calculate the CRC over *.text* section and place the result in the *.outputsection* section.
|
||||
The output sections start and end are checked for the given magic numbers in order to assure correct memory layout.
|
||||
*CRC-32-MPEG* is used as CRC algorothm.
|
||||
The output sections start and end are checked for the given magic numbers in order to ensure correct memory layout.
|
||||
*CRC-32-MPEG* is used as CRC algorithm.
|
||||
The memory is interpreted as *little endian* and the CRC calculation granularity is a 32 bit *word*.
|
||||
|
||||
# BUGS
|
||||
|
@@ -561,25 +561,24 @@ int elf_patch_compute_crc_over_section(elfpatch_handle_t *ep, const char *sectio
|
||||
/* Find section */
|
||||
sec = find_section_in_list(ep->sections, section);
|
||||
if (!sec) {
|
||||
print_err("Cannot find section %s\n", section);
|
||||
print_err("Cannot find section '%s'\n", section);
|
||||
return -1;
|
||||
}
|
||||
|
||||
data = elf_getdata(sec->scn, NULL);
|
||||
if (!data) {
|
||||
print_err("Error reading section data from %s: %s\n", section, elf_errmsg(-1));
|
||||
print_err("Error reading section data from '%s': %s\n", section, elf_errmsg(-1));
|
||||
return -1;
|
||||
}
|
||||
|
||||
print_debug("Section data length: %lu\n", data->d_size);
|
||||
if (!data->d_size) {
|
||||
print_err("Section %s contains no data.\n", section);
|
||||
print_err("Section '%s' contains no data.\n", section);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* NOBIT sections have a length but no data in the file. Abort in this case */
|
||||
if (!data->d_buf) {
|
||||
print_err("Section %s does not contain loadable data.\n", section);
|
||||
print_err("Section '%s' does not contain loadable data.\n", section);
|
||||
return -2;
|
||||
}
|
||||
|
||||
@@ -593,7 +592,7 @@ int elf_patch_compute_crc_over_section(elfpatch_handle_t *ep, const char *sectio
|
||||
/* Check granularity vs size of section */
|
||||
padding_count = (gran_in_bytes - data->d_size % gran_in_bytes) % gran_in_bytes;
|
||||
if (padding_count) {
|
||||
print_err("Section '%s' is not a multiple size of the given granularity. %u zero padding bytes will be added.\n",
|
||||
print_warn("Section '%s' is not a multiple size of the given granularity. %u zero padding bytes will be added.\n",
|
||||
section, padding_count);
|
||||
}
|
||||
|
||||
@@ -633,7 +632,7 @@ static size_t calculate_needed_space_for_crcs(enum crc_format format,
|
||||
break;
|
||||
default:
|
||||
needed_space = 0;
|
||||
print_err("Unsupported CRC output format\n");
|
||||
print_err("Unsupported CRC output format.\n");
|
||||
}
|
||||
/* Add existing magic numbers to required space */
|
||||
if (check_start_magic) {
|
||||
|
12
src/main.c
12
src/main.c
@@ -239,12 +239,11 @@ static void prepare_default_opts(struct command_line_options *opts)
|
||||
opts->output_section = NULL;
|
||||
opts->export_xml = NULL;
|
||||
opts->import_xml = NULL;
|
||||
opts->force_nocolor = false;
|
||||
}
|
||||
|
||||
static void print_verbose_start_info(const struct command_line_options *cmd_opts)
|
||||
{
|
||||
int i;
|
||||
SlList *list_iter;
|
||||
const struct named_crc *predef_crc;
|
||||
|
||||
print_debug("Start CRC patching\n");
|
||||
@@ -278,11 +277,6 @@ static void print_verbose_start_info(const struct command_line_options *cmd_opts
|
||||
|
||||
if (cmd_opts->import_xml)
|
||||
print_debug("Import CRCs from '%s'\n", cmd_opts->import_xml);
|
||||
|
||||
if (cmd_opts->section_list) {
|
||||
for (list_iter = cmd_opts->section_list, i = 1; list_iter; list_iter = sl_list_next(list_iter), i++)
|
||||
print_debug("Input section [%d]: \"%s\"\n", i, (const char *)list_iter->data);
|
||||
}
|
||||
}
|
||||
|
||||
static void free_cmd_args(struct command_line_options *opts)
|
||||
@@ -459,7 +453,7 @@ int main(int argc, char **argv)
|
||||
print_warn("--use-vma option only has an effect when exporting as struct output.\n");
|
||||
|
||||
if (!cmd_opts.output_section && cmd_opts.export_xml == NULL)
|
||||
print_warn("No output section / XML export specified. Will continue but not create any output\n");
|
||||
print_warn("No output section or XML export specified. Will continue but not create any output.\n");
|
||||
|
||||
/* Prepare libelf for use with the latest ELF version */
|
||||
elf_version(EV_CURRENT);
|
||||
@@ -501,7 +495,7 @@ int main(int argc, char **argv)
|
||||
|
||||
if (cmd_opts.export_xml) {
|
||||
if (xml_write_crcs_to_file(cmd_opts.export_xml, crc_data)) {
|
||||
print_err("Error during XML generation\n");
|
||||
print_err("Error during XML generation.\n");
|
||||
ret = -3;
|
||||
}
|
||||
}
|
||||
|
11
test/CMakeLists.txt
Normal file
11
test/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(patchelfcrc-test LANGUAGES CXX C)
|
||||
add_subdirectory(catch2 EXCLUDE_FROM_ALL)
|
||||
|
||||
add_custom_target(test "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" "-r compact" "-s" DEPENDS ${PROJECT_NAME})
|
||||
aux_source_directory("src" TEST_SOURCES)
|
||||
set(DUT_SOURCES ${CMAKE_CURRENT_LIST_DIR}/../src/crc.c)
|
||||
|
||||
add_executable(${PROJECT_NAME} EXCLUDE_FROM_ALL ${TEST_SOURCES} ${DUT_SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2WithMain)
|
1
test/catch2
Submodule
1
test/catch2
Submodule
Submodule test/catch2 added at 0631b607ee
Reference in New Issue
Block a user