summaryrefslogtreecommitdiffstats
path: root/src/file_1cd.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-07-24 23:23:45 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-07-24 23:23:45 +0200
commit3cb1f0247ec4021ff4919fb83143beba3563d370 (patch)
tree2d7e4a4d496aeb86d6322f2ea9755bc3ed1c9d28 /src/file_1cd.c
parent1a13c103323594cc0e25c9c53c551a082a7b9270 (diff)
PhotoRec: stricter check for .1cd file
Diffstat (limited to 'src/file_1cd.c')
-rw-r--r--src/file_1cd.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/file_1cd.c b/src/file_1cd.c
index 0da48a9..d9fa298 100644
--- a/src/file_1cd.c
+++ b/src/file_1cd.c
@@ -29,9 +29,9 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
+#include "common.h"
static void register_header_check_1cd(file_stat_t *file_stat);
-static int header_check_1cd(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 file_hint_t file_hint_1cd= {
.extension="1cd",
@@ -43,26 +43,28 @@ const file_hint_t file_hint_1cd= {
.register_header_check=&register_header_check_1cd
};
-static const unsigned char header_1cd[9]= {
- '1', 'C', 'D', 'B', 'M', 'S', 'V', '8', 0x08
-};
+struct header_1cd
+{
+ char magic[8];
+ uint32_t version;
+ uint32_t size;
+} __attribute__ ((__packed__));
-static void register_header_check_1cd(file_stat_t *file_stat)
+static int header_check_1cd(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)
{
- register_header_check(0, header_1cd, sizeof(header_1cd), &header_check_1cd, file_stat);
+ const struct header_1cd *hdr=(const struct header_1cd *)buffer;
+ if(le32(hdr->size)==0)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_1cd.extension;
+ file_recovery_new->calculated_file_size=le32(hdr->size)<<12;
+ file_recovery_new->data_check=&data_check_size;
+ file_recovery_new->file_check=&file_check_size;
+ return 1;
}
-static int header_check_1cd(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 register_header_check_1cd(file_stat_t *file_stat)
{
- if(memcmp(buffer, header_1cd, sizeof(header_1cd))==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_1cd.extension;
- file_recovery_new->calculated_file_size=((uint64_t)buffer[0xC]<<12) + (((uint64_t)buffer[0xD])<<20) +
- (((uint64_t)buffer[0xE])<<28) + (((uint64_t)buffer[0xF])<<36);
- file_recovery_new->data_check=&data_check_size;
- file_recovery_new->file_check=&file_check_size;
- return 1;
- }
- return 0;
+ static const unsigned char header_1cd[9]= { '1', 'C', 'D', 'B', 'M', 'S', 'V', '8', 0x08 };
+ register_header_check(0, header_1cd, sizeof(header_1cd), &header_check_1cd, file_stat);
}