Move source code to SRC folder and start doxygen

This commit is contained in:
Mario Hüttel 2022-10-24 20:47:38 +02:00
parent f3f7b1a7ad
commit 19a84ef4f2
13 changed files with 2844 additions and 35 deletions

View File

@ -2,17 +2,32 @@ cmake_minimum_required(VERSION 3.5)
project(patchelfcrc LANGUAGES C)
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(ELF REQUIRED libelf)
set (CFILES
main.c
version.c
named_crcs.c
crc.c
elfpatch.c
reporting.c
)
find_package(Doxygen)
aux_source_directory("src" CFILES)
set(GEN_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/include/generated")
@ -38,4 +53,26 @@ target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/
target_include_directories(${PROJECT_NAME} PRIVATE "include")
add_dependencies(${PROJECT_NAME} version-header)
if (DOXYGEN_FOUND)
set(DOXYFILE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/doxygen/Doxyfile.in")
set(DOXYFILE_DEST "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
configure_file(${DOXYFILE_SRC} ${DOXYFILE_DEST} @ONLY)
add_custom_target(doxygen
DEPENDS
doxygen-version-header
COMMAND
${DOXYGEN_EXECUTABLE} ${DOXYFILE_DEST}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(doxygen-version-header
COMMAND
bash ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/gen-version-string.sh "${CMAKE_CURRENT_BINARY_DIR}/doxyversion.in"
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
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)

2666
doxygen/Doxyfile.in Normal file

File diff suppressed because it is too large Load Diff

7
doxygen/gen-version-string.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if [[ -z $1 ]]; then
exit -1
fi
echo "PROJECT_NUMBER = `git describe --tags --always --dirty`" > $1

View File

@ -1,3 +1,20 @@
/*
* This file is part of patchelfcrc.
* Copyright (c) 2022 Mario Hüttel.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 only.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CRC_OUTPUT_STRUCT_H_
#define _CRC_OUTPUT_STRUCT_H_

View File

@ -1,3 +1,25 @@
/*
* This file is part of patchelfcrc.
* Copyright (c) 2022 Mario Hüttel.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 only.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file elfpatch.h
* @brief Header for ELF Patching Class
*/
#ifndef _ELFPATCH_H_
#define _ELFPATCH_H_
@ -28,6 +50,16 @@ elfpatch_handle_t *elf_patch_open(const char *path, bool readonly);
*/
int elf_patch_check_for_section(elfpatch_handle_t *ep, const char *section);
/**
* @brief Compute CRC over a section in an ELF file
* @param ep Elf patch object
* @param section Section name
* @param[out] crc CRC output
* @param granularity CRC calculation granularity
* @param little_endian memory layout is little endian
* @return 0 if successful
* @return negative if error
*/
int elf_patch_compute_crc_over_section(elfpatch_handle_t *ep, const char *section, struct crc_calc *crc,
enum granularity granularity, bool little_endian);

View File

@ -1,3 +1,21 @@
/*
* This file is part of patchelfcrc.
* Copyright (c) 2022 Mario Hüttel.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 only.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _REPORTING_H_
#define _REPORTING_H_

View File

@ -1,27 +0,0 @@
#include <patchelfcrc/reporting.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
static bool global_verbosity_state = false;
void print_debug(const char *fmt, ...)
{
va_list va;
if (global_verbosity_state) {
va_start(va, fmt);
(void)vprintf(fmt, va);
va_end(va);
}
}
void reporting_enable_verbose(void)
{
global_verbosity_state = true;
}
bool reporting_get_verbosity(void)
{
return global_verbosity_state;
}

View File

View File

@ -53,6 +53,14 @@ struct command_line_options {
const char *output_section;
};
/**
* @brief Parse command line options
* @param key Option key
* @param arg Argument passed
* @param state State of ARGP parser
* @return 0 No error
* @return ARGP_ERR_UNKNOWN in case of an unknown option
*/
static error_t parse_opt(int key, char *arg, struct argp_state *state)
{
struct command_line_options *args = (struct command_line_options *)state->input;
@ -324,6 +332,12 @@ static int compute_crcs(elfpatch_handle_t *ep, SlList *list, const struct comman
return ret;
}
/**
* @brief Debug-print the CRCs of sections in form of a table
* @param[in] list List of section names
* @param[in] crcs Array of CRCs.
* @note The array @p crcs must be at least as long as @p list
*/
static void print_crcs(SlList *list, const uint32_t *crcs)
{
SlList *iter;

45
src/reporting.c Normal file
View File

@ -0,0 +1,45 @@
/*
* This file is part of patchelfcrc.
* Copyright (c) 2022 Mario Hüttel.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 only.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <patchelfcrc/reporting.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
static bool global_verbosity_state = false;
void print_debug(const char *fmt, ...)
{
va_list va;
if (global_verbosity_state) {
va_start(va, fmt);
(void)vprintf(fmt, va);
va_end(va);
}
}
void reporting_enable_verbose(void)
{
global_verbosity_state = true;
}
bool reporting_get_verbosity(void)
{
return global_verbosity_state;
}