From b74225d7480d4ab938baf814cdbafac9d50bd8ea Mon Sep 17 00:00:00 2001 From: piotrkochan Date: Sat, 27 Sep 2025 15:16:59 +0200 Subject: [PATCH 1/3] add /sigfile parameter --- src/file_sig.c | 25 +++++++++++++++++++++++++ src/filegen.h | 2 ++ src/phmain.c | 8 +++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/file_sig.c b/src/file_sig.c index 1376c60d..0b808d4a 100644 --- a/src/file_sig.c +++ b/src/file_sig.c @@ -149,6 +149,17 @@ static signature_t signatures={ .list = TD_LIST_HEAD_INIT(signatures.list) }; +static char *custom_sig_file = NULL; + +void set_custom_signature_file(const char *path) +{ + if(custom_sig_file != NULL) + { + free(custom_sig_file); + } + custom_sig_file = (path != NULL) ? strdup(path) : NULL; +} + /*@ @ assigns \nothing; @*/ @@ -261,6 +272,20 @@ static int header_check_sig(const unsigned char *buffer, const unsigned int buff static FILE *open_signature_file(void) { + if(custom_sig_file != NULL) + { + FILE *handle = fopen(custom_sig_file, "rb"); + if(handle != NULL) + { +#ifndef DISABLED_FOR_FRAMAC + log_info("Open signature file %s\n", custom_sig_file); +#endif + return handle; + } +#ifndef DISABLED_FOR_FRAMAC + log_error("Failed to open signature file %s\n", custom_sig_file); +#endif + } #if defined(__CYGWIN__) || defined(__MINGW32__) { char *path; diff --git a/src/filegen.h b/src/filegen.h index c713eafb..55a01441 100644 --- a/src/filegen.h +++ b/src/filegen.h @@ -476,6 +476,8 @@ time_t get_time_from_YYYYMMDD_HHMMSS(const char *date_asc); @*/ void get_prev_location_smart(const alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset, const uint64_t prev_location); +void set_custom_signature_file(const char *path); + #ifdef __cplusplus } /* closing brace for extern "C" */ #endif diff --git a/src/phmain.c b/src/phmain.c index f336286a..54831771 100644 --- a/src/phmain.c +++ b/src/phmain.c @@ -123,11 +123,12 @@ static void sighup_hdlr(int sig) static void display_help(void) { - printf("\nUsage: photorec [/log] [/debug] [/d recup_dir] [file.dd|file.e01|device]\n"\ + printf("\nUsage: photorec [/log] [/debug] [/d recup_dir] [/sigfile photorec.sig] [file.dd|file.e01|device]\n"\ " photorec /version\n" \ "\n" \ "/log : create a photorec.log file\n" \ "/debug : add debug information\n" \ + "/sigfile path : specify custom path to signature file\n" \ "\n" \ "PhotoRec searches for various file formats (JPEG, Office...). It stores files\n" \ "in the recup_dir directory.\n"); @@ -277,6 +278,11 @@ int main( int argc, char **argv ) } i++; } + else if(i+1 Date: Sat, 27 Sep 2025 16:44:09 +0200 Subject: [PATCH 2/3] move /sigfile before /d in help cmd --- src/phmain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/phmain.c b/src/phmain.c index 54831771..b6ea025e 100644 --- a/src/phmain.c +++ b/src/phmain.c @@ -123,7 +123,7 @@ static void sighup_hdlr(int sig) static void display_help(void) { - printf("\nUsage: photorec [/log] [/debug] [/d recup_dir] [/sigfile photorec.sig] [file.dd|file.e01|device]\n"\ + printf("\nUsage: photorec [/log] [/debug] [/sigfile photorec.sig] [/d recup_dir] [file.dd|file.e01|device]\n"\ " photorec /version\n" \ "\n" \ "/log : create a photorec.log file\n" \ From c17d1a49b45df2cbaf4338d0be50ce28a24b4595 Mon Sep 17 00:00:00 2001 From: piotrkochan Date: Mon, 29 Sep 2025 22:07:40 +0200 Subject: [PATCH 3/3] move set_custom_signature_file to file_sig.h --- src/file_sig.c | 1 + src/file_sig.h | 34 ++++++++++++++++++++++++++++++++++ src/filegen.h | 2 -- src/phmain.c | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/file_sig.h diff --git a/src/file_sig.c b/src/file_sig.c index 0b808d4a..32f8aec9 100644 --- a/src/file_sig.c +++ b/src/file_sig.c @@ -42,6 +42,7 @@ #endif #include "types.h" #include "filegen.h" +#include "file_sig.h" #include "common.h" #include "log.h" diff --git a/src/file_sig.h b/src/file_sig.h new file mode 100644 index 00000000..c210c02b --- /dev/null +++ b/src/file_sig.h @@ -0,0 +1,34 @@ +/* + + File: file_sig.h + + Copyright (C) 2010 Christophe GRENIER + + This software 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; either version 2 of the License, or + (at your option) any later version. + + 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, write the Free Software Foundation, Inc., 51 + Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + */ +#ifndef _FILE_SIG_H +#define _FILE_SIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +void set_custom_signature_file(const char *path); + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/src/filegen.h b/src/filegen.h index 55a01441..c713eafb 100644 --- a/src/filegen.h +++ b/src/filegen.h @@ -476,8 +476,6 @@ time_t get_time_from_YYYYMMDD_HHMMSS(const char *date_asc); @*/ void get_prev_location_smart(const alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset, const uint64_t prev_location); -void set_custom_signature_file(const char *path); - #ifdef __cplusplus } /* closing brace for extern "C" */ #endif diff --git a/src/phmain.c b/src/phmain.c index b6ea025e..d27e0f35 100644 --- a/src/phmain.c +++ b/src/phmain.c @@ -86,6 +86,7 @@ #include "ext2_dir.h" #include "file_jpg.h" #include "file_gz.h" +#include "file_sig.h" #include "ntfs_dir.h" #include "pdiskseln.h" #include "dfxml.h"