summaryrefslogtreecommitdiffstats
path: root/src/file_fh5.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-07-26 15:50:55 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-07-26 15:50:55 +0200
commit8fe1fd7abb0ffa11e9e8be75e66321bb0accaff6 (patch)
treebf079c49e62408a02c9ef60659cab26b888c41c7 /src/file_fh5.c
parenta67f0c1cedcaa4dd2929b6f16b46d8221ddb67d4 (diff)
PhotoRec: stricter check for .fh5 files
Diffstat (limited to 'src/file_fh5.c')
-rw-r--r--src/file_fh5.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/src/file_fh5.c b/src/file_fh5.c
index 385ecc2..866ce3d 100644
--- a/src/file_fh5.c
+++ b/src/file_fh5.c
@@ -40,8 +40,6 @@ struct fh5_header_s
typedef struct fh5_header_s fh5_header_t;
static void register_header_check_fh5(file_stat_t *file_stat);
-static int header_check_fh5(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
-static void file_check_fh5(file_recovery_t *file_recovery);
const file_hint_t file_hint_fh5= {
.extension="fh5",
@@ -53,33 +51,30 @@ const file_hint_t file_hint_fh5= {
.register_header_check=&register_header_check_fh5
};
-static const unsigned char fh5_header[8] = { 0x41, 0x47, 0x44, 0x31, 0xbe, 0xb8, 0xbb, 0xce };
-
-static void register_header_check_fh5(file_stat_t *file_stat)
+static void file_check_fh5(file_recovery_t *file_recovery)
{
- register_header_check(0, fh5_header,sizeof(fh5_header), &header_check_fh5, file_stat);
+ if(file_recovery->file_size < file_recovery->calculated_file_size)
+ file_recovery->file_size=0;
+ else if(file_recovery->file_size> file_recovery->calculated_file_size+4096)
+ file_recovery->file_size=file_recovery->calculated_file_size+4096;
}
static int header_check_fh5(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
const fh5_header_t *fh5_buffer=(const fh5_header_t *) buffer;
- if(memcmp(fh5_buffer->id,fh5_header,sizeof(fh5_header))==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->min_filesize=4096,
- file_recovery_new->calculated_file_size=be32(fh5_buffer->datalen);
- file_recovery_new->extension=file_hint_fh5.extension;
- file_recovery_new->file_check=file_check_fh5;
-// log_debug("header_check_fh5: Guessed length : %u\n", fh5_file_size);
- return 1;
- }
- return 0;
+ if(be32(fh5_buffer->datalen) < sizeof(struct fh5_header_s))
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->min_filesize=4096;
+ file_recovery_new->calculated_file_size=be32(fh5_buffer->datalen);
+ file_recovery_new->extension=file_hint_fh5.extension;
+ file_recovery_new->file_check=file_check_fh5;
+ // log_debug("header_check_fh5: Guessed length : %u\n", fh5_file_size);
+ return 1;
}
-static void file_check_fh5(file_recovery_t *file_recovery)
+static void register_header_check_fh5(file_stat_t *file_stat)
{
- if(file_recovery->file_size < file_recovery->calculated_file_size)
- file_recovery->file_size=0;
- else if(file_recovery->file_size> file_recovery->calculated_file_size+4096)
- file_recovery->file_size=file_recovery->calculated_file_size+4096;
+ static const unsigned char fh5_header[8] = { 0x41, 0x47, 0x44, 0x31, 0xbe, 0xb8, 0xbb, 0xce };
+ register_header_check(0, fh5_header,sizeof(fh5_header), &header_check_fh5, file_stat);
}