16 Commits

Author SHA1 Message Date
4eab5532d0 Fix PKGBUILD 2025-08-05 23:36:32 +02:00
e68db8a433 Add man page to AUR build 2025-08-05 23:34:07 +02:00
4b9e2aa96a Make man page optional 2025-08-05 23:32:35 +02:00
b726d5ba75 Fix version generation 2025-08-05 23:29:24 +02:00
bfb587360d Make version generation more sane for program 2025-08-05 23:22:45 +02:00
f964ef7b60 fix stuff 2025-07-31 20:50:39 +02:00
dd05449f36 Remove man page generation without version 2025-07-31 20:37:05 +02:00
3ff626134e Allow build without git 2025-07-31 20:28:18 +02:00
29fdc841b7 Update cmake version 2025-05-10 22:53:35 +02:00
dc30188593 Update libraries 2025-05-10 22:51:36 +02:00
2bea5d288c Update linklist for cmake version 2025-05-10 22:47:55 +02:00
8a0226a5ea Fix typos in man page 2023-05-29 23:27:24 +02:00
ed6373473c Fix use of unitialized variable for nocolor terminal output 2023-05-29 23:13:06 +02:00
80b5f5b1b3 Fix error and debug messages in main.c 2023-05-29 23:07:03 +02:00
4fab6ffd3a Unify error messages in elfpatch.c 2023-05-29 23:06:02 +02:00
0ee19eaea4 Fix typo in man page 2023-05-29 23:04:00 +02:00
13 changed files with 61 additions and 43 deletions

View File

@@ -16,7 +16,7 @@ sha1sums=('SKIP' 'SKIP' 'SKIP')
pkgver () {
_date=`date +"%Y%m%d"`
cd "${srcdir}/${pkgname}-git"
echo "$(echo "$(sh ./gen-version-string.sh)" | sed 's/-/_/g')"
echo "$(echo "$(git describe --always --dirty)" | sed 's/-/_/g')"
}
build () {
@@ -24,6 +24,7 @@ build () {
cd "$srcdir/$pkgname-git/build"
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j12
make man-page
}
prepare () {

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.5...3.18)
project(patchelfcrc LANGUAGES C)
@@ -28,8 +28,6 @@ pkg_check_modules(ELF REQUIRED libelf)
find_package(Doxygen)
find_package(LibXml2 REQUIRED)
add_subdirectory(man)
aux_source_directory("src" CFILES)
set(GEN_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/include/generated")
@@ -37,12 +35,17 @@ set(GEN_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/include/generated")
add_custom_target(
version-header
COMMAND
mkdir -p ${GEN_HEADER_PATH} && bash "${CMAKE_CURRENT_SOURCE_DIR}/gen_version_header.sh" "${GEN_HEADER_PATH}/version.h"
${CMAKE_COMMAND} -D SRC=${CMAKE_SOURCE_DIR}/version.h.template
-D DST=${GEN_HEADER_PATH}/version.h
-P ${CMAKE_SOURCE_DIR}/GenerateVersion.cmake
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating version header"
)
add_subdirectory(man)
add_custom_target(schema-header DEPENDS "${GEN_HEADER_PATH}/schema-blob.h")
add_custom_command(
OUTPUT "${GEN_HEADER_PATH}/schema-blob.h"
@@ -66,7 +69,8 @@ target_link_directories(${PROJECT_NAME} PRIVATE ${ELF_LIBRARY_DIRS} ${LIBXML2_LI
target_include_directories(${PROJECT_NAME} PRIVATE ${ELF_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include")
target_include_directories(${PROJECT_NAME} PRIVATE "include")
add_dependencies(${PROJECT_NAME} version-header schema-header)
add_dependencies(${PROJECT_NAME} schema-header)
add_dependencies(${PROJECT_NAME} version-header)
if (DOXYGEN_FOUND)
set(DOXYFILE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/doxygen/Doxyfile.in")
@@ -83,11 +87,13 @@ if (DOXYGEN_FOUND)
add_custom_target(doxygen-version-header
COMMAND
bash ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/gen-version-string.sh "${CMAKE_CURRENT_BINARY_DIR}/doxyversion.in"
${CMAKE_COMMAND} -D SRC="${CMAKE_SOURCE_DIR}/doxyversion.in.template"
-D DST="${CMAKE_CURRENT_BINARY_DIR}/doxyversion.in"
-P ${CMAKE_SOURCE_DIR}/GenerateVersion.cmake
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
else (DOXYGEN_FOUND)
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)
endif (DOXYGEN_FOUND)

26
GenerateVersion.cmake Normal file
View File

@@ -0,0 +1,26 @@
find_package(Git)
if(GIT_EXECUTABLE)
get_filename_component(WORKING_DIR ${SRC} DIRECTORY)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always --dirty
WORKING_DIRECTORY ${WORKING_DIR}
OUTPUT_VARIABLE PROGRAM_GIT_VERSION
RESULT_VARIABLE ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ERROR_CODE EQUAL "0")
set(PROGRAM_GIT_VERSION "")
endif()
endif()
if(PROGRAM_GIT_VERSION STREQUAL "")
set(PROGRAM_GIT_VERSION 0.0.0-unknown)
message(WARNING "Failed to determine version from Git tags. Using default version \"${PROGRAM_GIT_VERSION}\".")
else()
message("Git Version: \"${PROGRAM_GIT_VERSION}\".")
endif()
configure_file(${SRC} ${DST} @ONLY)

1
doxyversion.in.template Normal file
View File

@@ -0,0 +1 @@
@PROGRAM_GIT_VERSION@

View File

@@ -1 +0,0 @@
echo `git describe --tags --always --dirty`

View File

@@ -1,11 +0,0 @@
#!/bin/bash
if [[ -z $1 ]]; then
exit -1;
fi
ver=`git describe --tags --always --dirty`
echo "#ifndef _VERSION_GENERATED_H_" > $1
echo "#define _VERSION_GENERATED_H_" >> $1
echo "#define GIT_VERSION_STRING \"$ver\"" >> $1
echo "#endif /* _VERSION_GENERATED_H_ */" >> $1

View File

@@ -1,7 +1,6 @@
set (MAN_PAGE_NAME "patchelfcrc.1.gz")
add_custom_target(man-page
ALL
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${MAN_PAGE_NAME}
)

View File

@@ -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

View File

@@ -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) {

View File

@@ -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;
}
}

4
version.h.template Normal file
View File

@@ -0,0 +1,4 @@
#ifndef _GENRATED_VERSION_H_
#define _GENRATED_VERSION_H_
#define GIT_VERSION_STRING "@PROGRAM_GIT_VERSION@"
#endif /* _GENRATED_VERSION_H_ */