summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-08-13 08:43:04 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-08-13 08:43:04 +0200
commit4c04512708ec2e18f51a779d53452fb3670a1d43 (patch)
treea54f81f3d2c68a0a2eba513f12d410d961f989f6
parent918dbd1be09261e94bdf623b5e631566a5dad87c (diff)
PhotoRec: stricter check for .rm
-rw-r--r--src/file_rm.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/file_rm.c b/src/file_rm.c
index eff184b..22ef77d 100644
--- a/src/file_rm.c
+++ b/src/file_rm.c
@@ -29,7 +29,7 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
-
+#include "common.h"
static void register_header_check_rm(file_stat_t *file_stat);
static int header_check_rm(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);
@@ -44,20 +44,27 @@ const file_hint_t file_hint_rm= {
.register_header_check=&register_header_check_rm
};
-static const unsigned char rm_header[9] = { '.', 'R', 'M', 'F', 0x00, 0x00, 0x00, 0x12, 0x00};
+struct rm_header
+{
+ uint32_t type;
+ uint32_t size;
+ uint16_t version;
+ uint32_t file_version;
+ uint32_t header_nbr;
+} __attribute__ ((__packed__));
-static void register_header_check_rm(file_stat_t *file_stat)
+static int header_check_rm(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, rm_header,sizeof(rm_header), &header_check_rm, file_stat);
+ const struct rm_header *hdr=(const struct rm_header *)buffer;
+ if(be32(hdr->header_nbr) < 3)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_rm.extension;
+ return 1;
}
-static int header_check_rm(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_rm(file_stat_t *file_stat)
{
- if(memcmp(buffer,rm_header,sizeof(rm_header))==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_rm.extension;
- return 1;
- }
- return 0;
+ static const unsigned char rm_header[9] = { '.', 'R', 'M', 'F', 0x00, 0x00, 0x00, 0x12, 0x00};
+ register_header_check(0, rm_header,sizeof(rm_header), &header_check_rm, file_stat);
}