diff --git a/man/photorec.8.in b/man/photorec.8.in index 50e00242..1def5f4e 100644 --- a/man/photorec.8.in +++ b/man/photorec.8.in @@ -3,7 +3,7 @@ .SH NAME photorec \- Recover lost files from harddisk, digital camera and cdrom .SH SYNOPSIS -.BI "photorec [/log] [/debug] [/d recup_dir] [device|image.dd|image.e01] +.BI "photorec [/log] [/debug] [/sigfile signature_file] [/d recup_dir] [device|image.dd|image.e01] .sp .BI "photorec /version .SH DESCRIPTION @@ -16,6 +16,9 @@ create a photorec.log file .TP .B /debug add debug information +.TP +.BI /sigfile " signature_file" +specify a custom signature file; if it cannot be opened, PhotoRec falls back to the default signature file locations .SH SEE ALSO .BR testdisk (8), .BR fdisk (8). diff --git a/src/Makefile.am b/src/Makefile.am index c059fdee..30be1ca0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -402,7 +402,7 @@ file_C = filegen.c \ file_zpr.c \ utfsize.c -file_H = ext2.h hfsp_struct.h filegen.h file_doc.h file_jpg.h file_gz.h file_riff.h file_sp3.h file_tar.h file_tiff.h luks_struct.h ntfs_struct.h ole.h pe.h suspend.h utfsize.h xfs_struct.h +file_H = ext2.h hfsp_struct.h filegen.h file_doc.h file_jpg.h file_gz.h file_riff.h file_sig.h file_sp3.h file_tar.h file_tiff.h luks_struct.h ntfs_struct.h ole.h pe.h suspend.h utfsize.h xfs_struct.h photorec_C = photorec.c phcfg.c addpart.c chgarch.c chgtype.c dir.c exfatp.c ext2grp.c ext2_dir.c ext2p.c fat_dir.c fatp.c file_found.c geometry.c ntfs_dir.c ntfsp.c pdisksel.c poptions.c sessionp.c dfxml.c partgptro.c json_log.c diff --git a/src/file_sig.c b/src/file_sig.c index 1376c60d..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" @@ -149,6 +150,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 +273,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/file_sig.h b/src/file_sig.h new file mode 100644 index 00000000..052b377f --- /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 diff --git a/src/phmain.c b/src/phmain.c index 056ae398..3cbf7d2c 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" @@ -124,12 +125,13 @@ static void sighup_hdlr(int sig) static void display_help(void) { - printf("\nUsage: photorec [/log] [/logjson log.jsonl] [/debug] [/d recup_dir] [file.dd|file.e01|device]\n"\ + printf("\nUsage: photorec [/log] [/logjson log.jsonl] [/debug] [/sigfile photorec.sig] [/d recup_dir] [file.dd|file.e01|device]\n"\ " photorec /version\n" \ "\n" \ "/log : create a photorec.log file\n" \ "/logjson : create a log in JSON format\n" \ "/debug : add debug information\n" \ + "/sigfile : specify a custom signature file\n" \ "\n" \ "PhotoRec searches for various file formats (JPEG, Office...). It stores files\n" \ "in the recup_dir directory.\n"); @@ -286,6 +288,11 @@ int main( int argc, char **argv ) } i++; } + else if(i+1