summaryrefslogtreecommitdiffstats
path: root/src/file_hds.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-08-13 08:31:02 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-08-13 08:31:02 +0200
commitbf475c707d278d5d0f1d852b309b047ef1e1acb5 (patch)
tree781dcf5d53e1ef740e793c3d0acbe74f8b576abb /src/file_hds.c
parent8377b01f167373b04655824637b261a15fad9572 (diff)
PhotoRec: stricter check for .hds
Diffstat (limited to 'src/file_hds.c')
-rw-r--r--src/file_hds.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/file_hds.c b/src/file_hds.c
index b2d5d35..0bee2b6 100644
--- a/src/file_hds.c
+++ b/src/file_hds.c
@@ -28,10 +28,9 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
-
+#include "common.h"
static void register_header_check_hds(file_stat_t *file_stat);
-static int header_check_hds(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_hds= {
.extension="hds",
@@ -43,11 +42,6 @@ const file_hint_t file_hint_hds= {
.register_header_check=&register_header_check_hds
};
-static const unsigned char hds_header[20]= {
- 'W','i','t','h','o','u','t','F','r','e','e','S','p','a','c','e',
- 0x02, 0x00, 0x00, 0x00
-};
-
// always little-endian
struct parallels_header {
char magic[16]; // "WithoutFreeSpace"
@@ -60,18 +54,24 @@ struct parallels_header {
char padding[24];
} __attribute__((packed));
-static void register_header_check_hds(file_stat_t *file_stat)
+static int header_check_hds(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, hds_header,sizeof(hds_header), &header_check_hds, file_stat);
+ const struct parallels_header *hdr=(const struct parallels_header *)buffer;
+ if(le32(hdr->heads)==0 ||
+ le32(hdr->cylinders)==0 ||
+ le32(hdr->tracks)==0 ||
+ le32(hdr->nb_sectors)==0)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_hds.extension;
+ return 1;
}
-static int header_check_hds(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_hds(file_stat_t *file_stat)
{
- if(memcmp(buffer,hds_header,sizeof(hds_header))==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_hds.extension;
- return 1;
- }
- return 0;
+ static const unsigned char hds_header[20]= {
+ 'W','i','t','h','o','u','t','F','r','e','e','S','p','a','c','e',
+ 0x02, 0x00, 0x00, 0x00
+ };
+ register_header_check(0, hds_header,sizeof(hds_header), &header_check_hds, file_stat);
}