summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-12-14 21:36:24 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2013-12-14 21:40:04 +0100
commit3213247d998d58627eb4029afce6be8680de3b30 (patch)
tree96d4a64aca2201410703b5c15589715fe1557aa1 /src
parent5de0329f2184bdf89e087f414b651448df096c1f (diff)
PhotoRec: use an enum for values returned by data_check()
rename .m2ts and .ts using pid from header
Diffstat (limited to 'src')
-rw-r--r--src/file_ab.c54
-rw-r--r--src/file_ace.c11
-rw-r--r--src/file_amr.c4
-rw-r--r--src/file_bac.c6
-rw-r--r--src/file_bld.c32
-rw-r--r--src/file_caf.c8
-rw-r--r--src/file_dir.c4
-rw-r--r--src/file_dv.c8
-rw-r--r--src/file_dxf.c8
-rw-r--r--src/file_emf.c10
-rw-r--r--src/file_evt.c10
-rw-r--r--src/file_ext.c4
-rw-r--r--src/file_fits.c8
-rw-r--r--src/file_gif.c16
-rw-r--r--src/file_jpg.c26
-rw-r--r--src/file_m2ts.c54
-rw-r--r--src/file_mov.c29
-rw-r--r--src/file_mp3.c24
-rw-r--r--src/file_mpg.c8
-rw-r--r--src/file_oci.c6
-rw-r--r--src/file_ogg.c10
-rw-r--r--src/file_par2.c8
-rw-r--r--src/file_png.c18
-rw-r--r--src/file_ps.c8
-rw-r--r--src/file_psb.c24
-rw-r--r--src/file_psd.c24
-rw-r--r--src/file_psp.c6
-rw-r--r--src/file_qbb.c8
-rw-r--r--src/file_riff.c14
-rw-r--r--src/file_tib.c6
-rw-r--r--src/file_txt.c20
-rw-r--r--src/file_vault.c6
-rw-r--r--src/file_win.c8
-rw-r--r--src/file_wv.c10
-rw-r--r--src/filegen.c10
-rw-r--r--src/filegen.h9
-rw-r--r--src/phbf.c8
-rw-r--r--src/phbs.c4
-rw-r--r--src/qphbs.cpp7
-rw-r--r--src/qpsearch.cpp16
40 files changed, 303 insertions, 251 deletions
diff --git a/src/file_ab.c b/src/file_ab.c
index e0816ce..04b97ba 100644
--- a/src/file_ab.c
+++ b/src/file_ab.c
@@ -25,12 +25,11 @@
#endif
#include <stdio.h>
#include "types.h"
+#include "common.h"
#include "filegen.h"
#include "log.h"
static void register_header_check_ab(file_stat_t *file_stat);
-static int header_check_addressbook(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 int data_check_addressbook(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_addressbook= {
.extension="ab",
@@ -42,28 +41,7 @@ const file_hint_t file_hint_addressbook= {
.register_header_check=&register_header_check_ab
};
-static const unsigned char ab_header[2]={ 'L', 'J' };
-
-static void register_header_check_ab(file_stat_t *file_stat)
-{
- register_header_check(0, ab_header,sizeof(ab_header), &header_check_addressbook, file_stat);
-}
-
-static int header_check_addressbook(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)
-{
- if(buffer[0]=='L' && buffer[1]=='J' && (buffer[2]==0x1a || buffer[2]==0x0a) && buffer[3]==0x00)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->calculated_file_size=(buffer[4]<<24)+(buffer[5]<<16)+(buffer[6]<<8)+buffer[7];
- file_recovery_new->data_check=&data_check_addressbook;
- file_recovery_new->file_check=&file_check_size;
- file_recovery_new->extension=file_hint_addressbook.extension;
- return 1;
- }
- return 0;
-}
-
-static int data_check_addressbook(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_addressbook(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -78,17 +56,37 @@ static int data_check_addressbook(const unsigned char *buffer, const unsigned in
#endif
if(buffer[i+0]=='L' && buffer[i+1]=='J' && buffer[i+3]==0x00)
{
- const unsigned int length=(buffer[i+4]<<24)+(buffer[i+5]<<16)+(buffer[i+6]<<8)+buffer[i+7];
+ const unsigned int length=((const unsigned int)buffer[i+4]<<24)+(buffer[i+5]<<16)+(buffer[i+6]<<8)+buffer[i+7];
if(length<8)
{
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size+=length;
}
else
{
- return 2;
+ return DC_STOP;
}
}
- return 1;
+ return DC_CONTINUE;
+}
+
+static int header_check_addressbook(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)
+{
+ if(buffer[0]=='L' && buffer[1]=='J' && (buffer[2]==0x1a || buffer[2]==0x0a) && buffer[3]==0x00)
+ {
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->calculated_file_size=(buffer[4]<<24)+(buffer[5]<<16)+(buffer[6]<<8)+buffer[7];
+ file_recovery_new->data_check=&data_check_addressbook;
+ file_recovery_new->file_check=&file_check_size;
+ file_recovery_new->extension=file_hint_addressbook.extension;
+ return 1;
+ }
+ return 0;
+}
+
+static void register_header_check_ab(file_stat_t *file_stat)
+{
+ static const unsigned char ab_header[2]={ 'L', 'J' };
+ register_header_check(0, ab_header,sizeof(ab_header), &header_check_addressbook, file_stat);
}
diff --git a/src/file_ace.c b/src/file_ace.c
index 3fdda08..7cfa8fa 100644
--- a/src/file_ace.c
+++ b/src/file_ace.c
@@ -114,7 +114,7 @@ static void file_check_ace(file_recovery_t *file_recovery)
}
/* Minimal size is type+flags */
- if (le16(h.size) < 1+2)
+ if (le16(h.size) < 1U + 2U)
{
#ifdef DEBUG_ACE
log_trace("file_ace: Invalid block size %u\n", le16(h.size));
@@ -128,12 +128,11 @@ static void file_check_ace(file_recovery_t *file_recovery)
/* Header hardly ever bigger than a filename */
#define BUF_SIZE 4096
unsigned char buffer[BUF_SIZE];
- int len=le16(h.size);
+ unsigned int len=le16(h.size);
uint32_t crc32=0xFFFFFFFF;
-
while (len>0)
{
- const int count = ((len>BUF_SIZE) ? BUF_SIZE : len);
+ const unsigned int count = ((len>BUF_SIZE) ? BUF_SIZE : len);
const int bytes = fread(buffer, 1, count, file_recovery->handle);
if (bytes != count)
@@ -146,7 +145,7 @@ static void file_check_ace(file_recovery_t *file_recovery)
return ;
}
crc32=get_crc32(buffer, count, crc32);
- len -= count;
+ len -= count;
}
if (le16(h.crc16) != (crc32&0xFFFF))
{
@@ -159,7 +158,7 @@ static void file_check_ace(file_recovery_t *file_recovery)
}
}
/* Add its header size */
- file_recovery->file_size += 2 + 2 + le16(h.size); /* +2: CRC16, +2: size */
+ file_recovery->file_size += 2U + 2 + le16(h.size); /* +2: CRC16, +2: size */
/* If addsize flag, add complementary size */
if (le16(h.flags)&1)
{
diff --git a/src/file_amr.c b/src/file_amr.c
index 81e7ef4..ee3df23 100644
--- a/src/file_amr.c
+++ b/src/file_amr.c
@@ -56,7 +56,7 @@ static void register_header_check_amr(file_stat_t *file_stat)
}
#if 0
-static int data_check_amr(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_amr(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 2 < file_recovery->file_size + buffer_size/2)
@@ -74,7 +74,7 @@ static int data_check_amr(const unsigned char *buffer, const unsigned int buffer
case 0x70: file_recovery->calculated_file_size+=32; break;
}
}
- return 1;
+ return DC_CONTINUE;
}
#endif
static int header_check_amr(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)
diff --git a/src/file_bac.c b/src/file_bac.c
index f20eeec..deb0877 100644
--- a/src/file_bac.c
+++ b/src/file_bac.c
@@ -45,7 +45,7 @@ const file_hint_t file_hint_bac= {
.register_header_check=&register_header_check_bac
};
-static int data_check_bac(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_bac(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 0x18 < file_recovery->file_size + buffer_size/2)
@@ -62,7 +62,7 @@ static int data_check_bac(const unsigned char *buffer, const unsigned int buffer
{
log_error("file_bac.c: invalid block at %llu\n",
(long long unsigned)file_recovery->calculated_file_size);
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size+=(uint64_t)block_size;
}
@@ -70,7 +70,7 @@ static int data_check_bac(const unsigned char *buffer, const unsigned int buffer
log_trace("file_bac.c: new calculated_file_size %llu\n",
(long long unsigned)file_recovery->calculated_file_size);
#endif
- return 1;
+ return DC_CONTINUE;
}
static int header_check_bac(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)
diff --git a/src/file_bld.c b/src/file_bld.c
index 5fdb2ad..ad8777b 100644
--- a/src/file_bld.c
+++ b/src/file_bld.c
@@ -33,10 +33,10 @@
static void register_header_check_blend(file_stat_t *file_stat);
static int header_check_blend(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 int data_check_blend4le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
-static int data_check_blend8le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
-static int data_check_blend4be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
-static int data_check_blend8be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_blend4le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_blend8le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_blend4be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_blend8be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_blend= {
.extension="blend",
@@ -83,7 +83,7 @@ static int header_check_blend(const unsigned char *buffer, const unsigned int bu
return 0;
}
-static int data_check_blend4le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_blend4le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 0x14 < file_recovery->file_size + buffer_size/2)
@@ -100,14 +100,14 @@ static int data_check_blend4le(const unsigned char *buffer, const unsigned int b
if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0)
{
file_recovery->calculated_file_size+=0x14;
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size+=0x14+len;
}
- return 1;
+ return DC_CONTINUE;
}
-static int data_check_blend8le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_blend8le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + 0x18 < file_recovery->file_size + buffer_size/2)
{
@@ -123,14 +123,14 @@ static int data_check_blend8le(const unsigned char *buffer, const unsigned int b
if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0)
{
file_recovery->calculated_file_size+=0x18;
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size+=0x18+len;
}
- return 1;
+ return DC_CONTINUE;
}
-static int data_check_blend4be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_blend4be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + 0x14 < file_recovery->file_size + buffer_size/2)
{
@@ -146,14 +146,14 @@ static int data_check_blend4be(const unsigned char *buffer, const unsigned int b
if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0)
{
file_recovery->calculated_file_size+=0x14;
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size+=0x14+len;
}
- return 1;
+ return DC_CONTINUE;
}
-static int data_check_blend8be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_blend8be(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + 0x18 < file_recovery->file_size + buffer_size/2)
{
@@ -169,9 +169,9 @@ static int data_check_blend8be(const unsigned char *buffer, const unsigned int b
if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0)
{
file_recovery->calculated_file_size+=0x18;
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size+=0x18+len;
}
- return 1;
+ return DC_CONTINUE;
}
diff --git a/src/file_caf.c b/src/file_caf.c
index 3d64a05..4ac581f 100644
--- a/src/file_caf.c
+++ b/src/file_caf.c
@@ -60,7 +60,7 @@ struct chunk_struct
int64_t size;
} __attribute__ ((__packed__));
-static int data_check_caf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_caf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 12 < file_recovery->file_size + buffer_size/2)
@@ -80,7 +80,7 @@ static int data_check_caf(const unsigned char *buffer, const unsigned int buffer
if(buffer[i]==0)
{
file_recovery->calculated_file_size--;
- return 2;
+ return DC_STOP;
}
if(chunk_size >= 0)
{
@@ -90,14 +90,14 @@ static int data_check_caf(const unsigned char *buffer, const unsigned int buffer
{
file_recovery->data_check=NULL;
file_recovery->file_check=NULL;
- return 2;
+ return DC_STOP;
}
}
#ifdef DEBUG_CAF
log_trace("file_caf.c: new calculated_file_size %llu\n",
(long long unsigned)file_recovery->calculated_file_size);
#endif
- return 1;
+ return DC_CONTINUE;
}
static int header_check_caf(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)
diff --git a/src/file_dir.c b/src/file_dir.c
index a82788d..5035bf7 100644
--- a/src/file_dir.c
+++ b/src/file_dir.c
@@ -69,11 +69,11 @@ static void file_rename_fatdir(const char *old_filename)
file_rename(old_filename, buffer_cluster, strlen(buffer_cluster), 0, NULL, 1);
}
-static int data_check_fatdir(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_fatdir(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
/* Save only one cluster */
file_recovery->calculated_file_size=buffer_size/2;
- return 2;
+ return DC_STOP;
}
static int header_check_dir(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)
diff --git a/src/file_dv.c b/src/file_dv.c
index 6eed052..4d92bc4 100644
--- a/src/file_dv.c
+++ b/src/file_dv.c
@@ -32,7 +32,7 @@
static void register_header_check_dv(file_stat_t *file_stat);
static int header_check_dv(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 int data_check_dv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_dv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_dv= {
.extension="dv",
@@ -67,7 +67,7 @@ static int header_check_dv(const unsigned char *buffer, const unsigned int buffe
return 0;
}
-static int data_check_dv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_dv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -77,8 +77,8 @@ static int data_check_dv(const unsigned char *buffer, const unsigned int buffer_
buffer[i+5]==0x78 && buffer[i+6]==0x78 && buffer[i+7]==0x78)
file_recovery->calculated_file_size+=120000;
else
- return 2;
+ return DC_STOP;
}
- return 1;
+ return DC_CONTINUE;
}
diff --git a/src/file_dxf.c b/src/file_dxf.c
index e06479e..663a9f6 100644
--- a/src/file_dxf.c
+++ b/src/file_dxf.c
@@ -33,7 +33,7 @@
static void register_header_check_dxf(file_stat_t *file_stat);
static int header_check_dxf(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 int data_check_dxf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_dxf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
static void file_check_dxf(file_recovery_t *file_recovery);
const file_hint_t file_hint_dxf= {
@@ -79,7 +79,7 @@ static int header_check_dxf(const unsigned char *buffer, const unsigned int buff
return 0;
}
-static int data_check_dxf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_dxf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
unsigned int i;
for(i=(buffer_size/2)-3;i+3<buffer_size;i++)
@@ -87,11 +87,11 @@ static int data_check_dxf(const unsigned char *buffer, const unsigned int buffer
if(buffer[i]=='\n' && buffer[i+1]=='E' && buffer[i+2]=='O' && buffer[i+3]=='F')
{
file_recovery->calculated_file_size=file_recovery->file_size+i+4-(buffer_size/2);
- return 2;
+ return DC_STOP;
}
}
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
- return 1;
+ return DC_CONTINUE;
}
static void file_check_dxf(file_recovery_t *file_recovery)
diff --git a/src/file_emf.c b/src/file_emf.c
index 38ab0a6..7f18652 100644
--- a/src/file_emf.c
+++ b/src/file_emf.c
@@ -33,7 +33,7 @@
static void register_header_check_emf(file_stat_t *file_stat);
static int header_check_emf(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 int data_check_emf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_emf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_emf= {
.extension="emf",
@@ -230,7 +230,7 @@ static int header_check_emf(const unsigned char *buffer, const unsigned int buff
return 0;
}
-static int data_check_emf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_emf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -367,11 +367,11 @@ static int data_check_emf(const unsigned char *buffer, const unsigned int buffer
log_trace(" (%08x) \t%08x\n", itype, atom_size);
#endif
if(atom_size<8 || atom_size%4!=0 || atom_size>1024*1024)
- return 0;
+ return DC_ERROR;
file_recovery->calculated_file_size+=(uint64_t)atom_size;
if(itype==EMR_EOF)
- return 2;
+ return DC_STOP;
}
- return 1;
+ return DC_CONTINUE;
}
diff --git a/src/file_evt.c b/src/file_evt.c
index a3812ca..2b0d126 100644
--- a/src/file_evt.c
+++ b/src/file_evt.c
@@ -34,7 +34,7 @@
static void register_header_check_evt(file_stat_t *file_stat);
static int header_check_evt(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 int data_check_evt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_evt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_evt= {
.extension="evt",
@@ -62,7 +62,7 @@ static int header_check_evt(const unsigned char *buffer, const unsigned int buff
return 1;
}
-static int data_check_evt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_evt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -78,19 +78,19 @@ static int data_check_evt(const unsigned char *buffer, const unsigned int buffer
const unsigned int length=le32(chunk->size);
if(length<8)
{
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size+=length;
}
else
{
- return 2;
+ return DC_STOP;
}
}
/*
log_trace("data_check_evt record_offset=0x%x\n\n",record_offset);
*/
- return 1;
+ return DC_CONTINUE;
}
static void register_header_check_evt(file_stat_t *file_stat)
diff --git a/src/file_ext.c b/src/file_ext.c
index dd7eb1b..dfd89ce 100644
--- a/src/file_ext.c
+++ b/src/file_ext.c
@@ -78,11 +78,11 @@ static int header_check_ext2_sb(const unsigned char *buffer, const unsigned int
return 1;
}
-static int data_check_extdir(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_extdir(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
/* Save only one block */
file_recovery->calculated_file_size=buffer_size/2;
- return 2;
+ return DC_STOP;
}
static void file_rename_extdir(const char *old_filename)
diff --git a/src/file_fits.c b/src/file_fits.c
index ce655a7..e177b73 100644
--- a/src/file_fits.c
+++ b/src/file_fits.c
@@ -120,7 +120,7 @@ static uint64_t fits_info(const unsigned char *buffer, const unsigned int buffer
return naxis_size;
}
-static int data_check_fits(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_fits(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -141,7 +141,7 @@ static int data_check_fits(const unsigned char *buffer, const unsigned int buffe
{
file_recovery->data_check=NULL;
file_recovery->file_check=NULL;
- return 1;
+ return DC_CONTINUE;
}
file_recovery->calculated_file_size+=(i-i_org+2880-1)/2880*2880+(tmp+2880-1)/2880*2880;
}
@@ -149,9 +149,9 @@ static int data_check_fits(const unsigned char *buffer, const unsigned int buffe
if(file_recovery->file_size>=file_recovery->calculated_file_size)
{
file_recovery->file_size=file_recovery->calculated_file_size;
- return 2;
+ return DC_STOP;
}
- return 1;
+ return DC_CONTINUE;
}
static int header_check_fits(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)
diff --git a/src/file_gif.c b/src/file_gif.c
index f2cbf68..e8f29d5 100644
--- a/src/file_gif.c
+++ b/src/file_gif.c
@@ -33,8 +33,8 @@
static void register_header_check_gif(file_stat_t *file_stat);
static int header_check_gif(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_gif(file_recovery_t *file_recovery);
-static int data_check_gif(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
-static int data_check_gif2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_gif(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_gif2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_gif= {
.extension="gif",
@@ -85,7 +85,7 @@ static void file_check_gif(file_recovery_t *file_recovery)
file_search_footer(file_recovery, gif_footer, sizeof(gif_footer), 0);
}
-static int data_check_gif(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_gif(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 20 < file_recovery->file_size + buffer_size/2)
@@ -118,16 +118,16 @@ static int data_check_gif(const unsigned char *buffer, const unsigned int buffer
case 0x3b:
/* Trailer */
file_recovery->calculated_file_size++;
- return 2;
+ return DC_STOP;
default:
- return 0;
+ return DC_ERROR;
}
}
file_recovery->data_check=&data_check_gif;
- return 1;
+ return DC_CONTINUE;
}
-static int data_check_gif2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_gif2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 2 < file_recovery->file_size + buffer_size/2)
@@ -140,5 +140,5 @@ static int data_check_gif2(const unsigned char *buffer, const unsigned int buffe
}
}
file_recovery->data_check=&data_check_gif2;
- return 1;
+ return DC_CONTINUE;
}
diff --git a/src/file_jpg.c b/src/file_jpg.c
index 53d89c1..f21f60b 100644
--- a/src/file_jpg.c
+++ b/src/file_jpg.c
@@ -53,12 +53,12 @@ extern const file_hint_t file_hint_doc;
extern const file_hint_t file_hint_indd;
extern const file_hint_t file_hint_mov;
extern const file_hint_t file_hint_riff;
-extern int data_check_avi_stream(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+extern data_check_t data_check_avi_stream(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
static void register_header_check_jpg(file_stat_t *file_stat);
static int header_check_jpg(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_jpg(file_recovery_t *file_recovery);
-int data_check_jpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+data_check_t data_check_jpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_jpg= {
.extension="jpg",
@@ -1564,7 +1564,7 @@ static void file_check_jpg(file_recovery_t *file_recovery)
#endif
}
-static int data_check_jpg2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_jpg2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
#if 0
unsigned int old_marker=0;
@@ -1582,7 +1582,7 @@ static int data_check_jpg2(const unsigned char *buffer, const unsigned int buffe
log_info("%s data_check_jpg2 0xffd8 at 0x%llx\n", file_recovery->filename,
(long long unsigned)file_recovery->calculated_file_size);
#endif
- return 2;
+ return DC_STOP;
}
while(file_recovery->calculated_file_size + buffer_size/2 > file_recovery->file_size &&
file_recovery->calculated_file_size < file_recovery->file_size + buffer_size/2)
@@ -1594,7 +1594,7 @@ static int data_check_jpg2(const unsigned char *buffer, const unsigned int buffe
{
/* JPEG_EOI */
file_recovery->calculated_file_size++;
- return 2;
+ return DC_STOP;
}
else if(buffer[i] >= 0xd0 && buffer[i] <= 0xd7)
{
@@ -1607,7 +1607,7 @@ static int data_check_jpg2(const unsigned char *buffer, const unsigned int buffe
log_info("Rejected due to JPEG_RST marker\n");
#endif
file_recovery->calculated_file_size++;
- return 2;
+ return DC_STOP;
}
/* TODO: store old_marker in file_recovery */
old_marker=buffer[i];
@@ -1620,21 +1620,21 @@ static int data_check_jpg2(const unsigned char *buffer, const unsigned int buffe
(long long unsigned)file_recovery->calculated_file_size);
#endif
file_recovery->offset_error=file_recovery->calculated_file_size;
- return 2;
+ return DC_STOP;
}
}
file_recovery->calculated_file_size++;
}
- return 1;
+ return DC_CONTINUE;
}
-int data_check_jpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+data_check_t data_check_jpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
if(buffer[buffer_size/2]==0xff && buffer[buffer_size/2]==0xd8 &&
file_recovery->calculated_file_size != file_recovery->file_size)
{
log_info("data_check_jpg ffd8\n");
- return 2;
+ return DC_STOP;
}
/* Skip the SOI */
if(file_recovery->calculated_file_size==0)
@@ -1658,7 +1658,7 @@ int data_check_jpg(const unsigned char *buffer, const unsigned int buffer_size,
if(buffer[i+1]==0xc4) /* DHT */
{
if(jpg_check_dht(buffer, buffer_size, i, 2+size)!=0)
- return 2;
+ return DC_STOP;
}
if(buffer[i+1]==0xda) /* SOS: Start Of Scan */
{
@@ -1672,10 +1672,10 @@ int data_check_jpg(const unsigned char *buffer, const unsigned int buffer_size,
log_info("data_check_jpg %02x at %llu\n", buffer[i],
(long long unsigned)file_recovery->calculated_file_size);
#endif
- return 2;
+ return DC_STOP;
}
}
- return 1;
+ return DC_CONTINUE;
}
const char*td_jpeg_version(void)
diff --git a/src/file_m2ts.c b/src/file_m2ts.c
index 92d4ed9..47d5591 100644
--- a/src/file_m2ts.c
+++ b/src/file_m2ts.c
@@ -58,17 +58,57 @@ static const unsigned char hdpr_header[4] = { 'H','D','P','R'};
static const unsigned char tshv_header[4] = { 'T','S','H','V'};
static const unsigned char sdvs_header[4] = { 'S','D','V','S'};
-static int data_check_ts_192(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_ts_192(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 5 < file_recovery->file_size + buffer_size/2)
{
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
if(buffer[i+4]!=0x47) /* TS_SYNC_BYTE */
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=192;
}
- return 1;
+ return DC_CONTINUE;
+}
+
+static void file_rename_ts_188(const char *old_filename)
+{
+ FILE *file;
+ unsigned char buffer[188];
+ char buffer_pid[32];
+ unsigned int pid;
+ if((file=fopen(old_filename, "rb"))==NULL)
+ return;
+ if(fseek(file, 0, SEEK_SET) < 0 ||
+ fread(&buffer, sizeof(buffer), 1, file) != 1)
+ {
+ fclose(file);
+ return ;
+ }
+ fclose(file);
+ pid=((buffer[1]<<8)|buffer[2])&0x1fff;
+ sprintf(buffer_pid, "pid_%u", pid);
+ file_rename(old_filename, (const unsigned char*)buffer_pid, strlen(buffer_pid), 0, NULL, 1);
+}
+
+static void file_rename_ts_192(const char *old_filename)
+{
+ FILE *file;
+ unsigned char buffer[192];
+ char buffer_pid[32];
+ unsigned int pid;
+ if((file=fopen(old_filename, "rb"))==NULL)
+ return;
+ if(fseek(file, 0, SEEK_SET) < 0 ||
+ fread(&buffer, sizeof(buffer), 1, file) != 1)
+ {
+ fclose(file);
+ return ;
+ }
+ fclose(file);
+ pid=((buffer[5]<<8)|buffer[6])&0x1fff;
+ sprintf(buffer_pid, "pid_%u", pid);
+ file_rename(old_filename, (const unsigned char*)buffer_pid, strlen(buffer_pid), 0, NULL, 1);
}
static int header_check_m2ts(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)
@@ -111,19 +151,20 @@ static int header_check_m2ts(const unsigned char *buffer, const unsigned int buf
{
file_recovery_new->file_check=&file_check_size_lax;
}
+ file_recovery_new->file_rename=&file_rename_ts_192;
return 1;
}
-static int data_check_ts_188(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_ts_188(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + 1 < file_recovery->file_size + buffer_size/2)
{
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
if(buffer[i]!=0x47) /* TS_SYNC_BYTE */
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=188;
}
- return 1;
+ return DC_CONTINUE;
}
static int header_check_m2t(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)
@@ -146,6 +187,7 @@ static int header_check_m2t(const unsigned char *buffer, const unsigned int buff
file_recovery_new->calculated_file_size=0;
file_recovery_new->data_check=&data_check_ts_188;
file_recovery_new->file_check=&file_check_size_lax;
+ file_recovery_new->file_rename=&file_rename_ts_188;
return 1;
}
diff --git a/src/file_mov.c b/src/file_mov.c
index 0de8c42..2da4ca7 100644
--- a/src/file_mov.c
+++ b/src/file_mov.c
@@ -34,7 +34,7 @@
static void register_header_check_mov(file_stat_t *file_stat);
static int header_check_mov(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 int data_check_mov(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_mov(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_mov= {
.extension="mov",
@@ -243,10 +243,10 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
return 0;
}
-static int data_check_mov(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_mov(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
- file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
+ file_recovery->calculated_file_size + 8 <= file_recovery->file_size + buffer_size/2)
{
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
const struct atom_struct *atom=(const struct atom_struct*)&buffer[i];
@@ -254,12 +254,14 @@ static int data_check_mov(const unsigned char *buffer, const unsigned int buffer
if(atom_size==1)
{
const struct atom64_struct *atom64=(const struct atom64_struct*)&buffer[i];
+ if(file_recovery->calculated_file_size + 16 > file_recovery->file_size + buffer_size/2)
+ return DC_CONTINUE;
atom_size=be64(atom64->size);
if(atom_size<16)
- return 2;
+ return DC_STOP;
}
else if(atom_size<8)
- return 2;
+ return DC_STOP;
#ifdef DEBUG_MOV
log_trace("file_mov.c: %s atom %c%c%c%c (0x%02x%02x%02x%02x) size %llu, calculated_file_size %llu\n",
file_recovery->filename,
@@ -268,13 +270,22 @@ static int data_check_mov(const unsigned char *buffer, const unsigned int buffer
(long long unsigned)atom_size,
(long long unsigned)file_recovery->calculated_file_size);
#endif
- if( (buffer[i+4]=='c' && buffer[i+5]=='m' && buffer[i+6]=='o' && buffer[i+7]=='v') ||
+ if(buffer[i+4]=='m' && buffer[i+5]=='d' && buffer[i+6]=='a' && buffer[i+7]=='t')
+ {
+ file_recovery->calculated_file_size+=atom_size;
+#if 0
+ if(i+8 == buffer_size)
+ {
+ return -((file_recovery->calculated_file_size-1) / (buffer_size/2));
+ }
+#endif
+ }
+ else if( (buffer[i+4]=='c' && buffer[i+5]=='m' && buffer[i+6]=='o' && buffer[i+7]=='v') ||
(buffer[i+4]=='c' && buffer[i+5]=='m' && buffer[i+6]=='v' && buffer[i+7]=='d') ||
(buffer[i+4]=='d' && buffer[i+5]=='c' && buffer[i+6]=='o' && buffer[i+7]=='m') ||
(buffer[i+4]=='f' && buffer[i+5]=='r' && buffer[i+6]=='e' && buffer[i+7]=='e') ||
(buffer[i+4]=='f' && buffer[i+5]=='t' && buffer[i+6]=='y' && buffer[i+7]=='p') ||
(buffer[i+4]=='j' && buffer[i+5]=='p' && buffer[i+6]=='2' && buffer[i+7]=='h') ||
- (buffer[i+4]=='m' && buffer[i+5]=='d' && buffer[i+6]=='a' && buffer[i+7]=='t') ||
(buffer[i+4]=='m' && buffer[i+5]=='d' && buffer[i+6]=='i' && buffer[i+7]=='a') ||
(buffer[i+4]=='m' && buffer[i+5]=='o' && buffer[i+6]=='o' && buffer[i+7]=='v') ||
(buffer[i+4]=='P' && buffer[i+5]=='I' && buffer[i+6]=='C' && buffer[i+7]=='T') ||
@@ -293,13 +304,13 @@ static int data_check_mov(const unsigned char *buffer, const unsigned int buffer
log_warning("file_mov.c: unknown atom 0x%02x%02x%02x%02x at %llu\n",
buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7],
(long long unsigned)file_recovery->calculated_file_size);
- return 2;
+ return DC_STOP;
}
}
#ifdef DEBUG_MOV
log_trace("file_mov.c: new calculated_file_size %llu\n",
(long long unsigned)file_recovery->calculated_file_size);
#endif
- return 1;
+ return DC_CONTINUE;
}
diff --git a/src/file_mp3.c b/src/file_mp3.c
index fb239c5..1142b7e 100644
--- a/src/file_mp3.c
+++ b/src/file_mp3.c
@@ -35,8 +35,8 @@
extern const file_hint_t file_hint_mkv;
static void register_header_check_mp3(file_stat_t *file_stat);
-static int data_check_id3(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
-static int data_check_mp3(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_id3(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_mp3(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
static unsigned int pos_in_mem(const unsigned char *haystack, const unsigned int haystack_size, const unsigned char *needle, const unsigned int needle_size);
static unsigned int search_MMT(const unsigned char *buffer, const unsigned int i, const unsigned int buffer_size);
@@ -223,7 +223,7 @@ static int header_check_mp3(const unsigned char *buffer, const unsigned int buff
return 0;
}
-static int data_check_id3(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_id3(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 1 < file_recovery->file_size + buffer_size/2)
@@ -240,10 +240,10 @@ static int data_check_id3(const unsigned char *buffer, const unsigned int buffer
return data_check_mp3(buffer, buffer_size, file_recovery);
}
}
- return 1;
+ return DC_CONTINUE;
}
-static int data_check_mp3(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_mp3(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
#ifdef DEBUG_MP3
log_info("data_check_mp3 file_size=%llu, calculated_file_size=%llu\n",
@@ -277,7 +277,7 @@ static int data_check_mp3(const unsigned char *buffer, const unsigned int buffer
log_info("frameLengthInBytes=%u\n",frameLengthInBytes);
*/
if(sample_rate==0 || bit_rate==0 || mpeg_layer==MPEG_L1)
- return 2;
+ return DC_STOP;
if(mpeg_layer==MPEG_L3)
{
if(mpeg_version==MPEG_V1)
@@ -290,7 +290,7 @@ static int data_check_mp3(const unsigned char *buffer, const unsigned int buffer
else
frameLengthInBytes = (12000 * bit_rate / sample_rate + padding)*4;
if(frameLengthInBytes<3)
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=frameLengthInBytes;
}
else if(buffer[i]=='L' && buffer[i+1]=='Y' && buffer[i+2]=='R' && buffer[i+3]=='I' && buffer[i+4]=='C' && buffer[i+5]=='S' && buffer[i+6]=='B' && buffer[i+7]=='E' && buffer[i+8]=='G' && buffer[i+9]=='I' && buffer[i+10]=='N')
@@ -308,7 +308,7 @@ static int data_check_mp3(const unsigned char *buffer, const unsigned int buffer
unsigned int pos_lyrics=0;
/* FIXME */
if(file_recovery->calculated_file_size + 5100 >= file_recovery->file_size + buffer_size/2)
- return 1;
+ return DC_CONTINUE;
if((pos_lyrics=pos_in_mem(&buffer[i], 4096, (const unsigned char*)"LYRICS200", 9)) != 0)
{
file_recovery->calculated_file_size+=pos_lyrics;
@@ -322,7 +322,7 @@ static int data_check_mp3(const unsigned char *buffer, const unsigned int buffer
/*
log_warning("End of Lyrics not found \n");
*/
- return 2;
+ return DC_STOP;
}
}
else if(buffer[i]=='A' && buffer[i+1]=='P' && buffer[i+2]=='E' && buffer[i+3]=='T' && buffer[i+4]=='A' && buffer[i+5]=='G' && buffer[i+6]=='E' && buffer[i+7]=='X')
@@ -336,20 +336,20 @@ static int data_check_mp3(const unsigned char *buffer, const unsigned int buffer
}
else if(file_recovery->calculated_file_size > file_recovery->file_size)
{
- return 1;
+ return DC_CONTINUE;
}
else
{
const unsigned int MMT_size=search_MMT(buffer,i,buffer_size);
if(MMT_size==0)
- return 2;
+ return DC_STOP;
/*
log_info("MusicMatch Tag found at offset 0x%x with size 0x%x \n", file_recovery->calculated_file_size, MMT_size);
*/
file_recovery->calculated_file_size+=MMT_size;
}
}
- return 1;
+ return DC_CONTINUE;
}
static unsigned int pos_in_mem(const unsigned char *haystack, const unsigned int haystack_size, const unsigned char *needle, const unsigned int needle_size)
diff --git a/src/file_mpg.c b/src/file_mpg.c
index f7135e9..8d9b6bd 100644
--- a/src/file_mpg.c
+++ b/src/file_mpg.c
@@ -42,14 +42,14 @@ const file_hint_t file_hint_mpg= {
.register_header_check=&register_header_check_mpg
};
-static int data_check_mpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_mpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
const unsigned char padding_iso_end[8]= {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xB9};
/* search padding + end code */
if(buffer_size>=8 && memcmp(&buffer[buffer_size/2-4], padding_iso_end, sizeof(padding_iso_end))==0)
{
file_recovery->calculated_file_size=file_recovery->file_size+4;
- return 2;
+ return DC_STOP;
}
/* search video sequence end followed by iso end code*/
if(buffer_size>=14)
@@ -61,13 +61,13 @@ static int data_check_mpg(const unsigned char *buffer, const unsigned int buffer
if(buffer[i]==0x00 && memcmp(&buffer[i], sequence_end_iso_end, sizeof(sequence_end_iso_end))==0)
{
file_recovery->calculated_file_size=file_recovery->file_size+i+sizeof(sequence_end_iso_end)-buffer_size/2;
- return 2;
+ return DC_STOP;
}
}
}
/* some files don't end by iso end code, so continue... */
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
- return 1;
+ return DC_CONTINUE;
}
static int header_check_mpg_Pack(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)
diff --git a/src/file_oci.c b/src/file_oci.c
index 8575648..5614983 100644
--- a/src/file_oci.c
+++ b/src/file_oci.c
@@ -46,7 +46,7 @@ static const unsigned char oci_header[8]= {
'O' , 'P' , 'I' , 'M' , '0' , 0x00, 0x00, 0x00
};
-static int data_check_oci(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_oci(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -70,14 +70,14 @@ static int data_check_oci(const unsigned char *buffer, const unsigned int buffer
}
else
{
- return 2;
+ return DC_STOP;
}
}
#ifdef DEBUG_MOV
log_trace("file_oci.c: new calculated_file_size %llu\n",
(long long unsigned)file_recovery->calculated_file_size);
#endif
- return 1;
+ return DC_CONTINUE;
}
static int header_check_oci(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)
diff --git a/src/file_ogg.c b/src/file_ogg.c
index d2a349e..023e0fd 100644
--- a/src/file_ogg.c
+++ b/src/file_ogg.c
@@ -32,7 +32,7 @@
#include "log.h"
static void register_header_check_ogg(file_stat_t *file_stat);
-static int data_check_ogg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_ogg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_ogg= {
.extension="ogg",
@@ -74,7 +74,7 @@ static int header_check_ogg(const unsigned char *buffer, const unsigned int buff
}
/* http://www.ietf.org/rfc/rfc3533.txt */
-static int data_check_ogg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_ogg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 27 +255 < file_recovery->file_size + buffer_size/2)
@@ -91,7 +91,7 @@ static int data_check_ogg(const unsigned char *buffer, const unsigned int buffer
page_size+=buffer[i+27+j];
if(page_size<27)
{
- return 2;
+ return DC_STOP;
}
/* By definition, page_size<=27+255+255*255=65307 */
file_recovery->calculated_file_size+=page_size;
@@ -101,10 +101,10 @@ static int data_check_ogg(const unsigned char *buffer, const unsigned int buffer
}
else
{
- return 2;
+ return DC_STOP;
}
}
- return 1;
+ return DC_CONTINUE;
}
static void register_header_check_ogg(file_stat_t *file_stat)
diff --git a/src/file_par2.c b/src/file_par2.c
index c786be7..94c2c0c 100644
--- a/src/file_par2.c
+++ b/src/file_par2.c
@@ -48,7 +48,7 @@ static const unsigned char par2_header[8]= {
'P' , 'A' , 'R' , '2' , 0x00, 'P' , 'K' , 'T'
};
-static int data_check_par2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_par2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 16 < file_recovery->file_size + buffer_size/2)
@@ -56,12 +56,12 @@ static int data_check_par2(const unsigned char *buffer, const unsigned int buffe
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
const uint64_t length=le64((*(const uint64_t *)(&buffer[i+8])));
if(memcmp(&buffer[i], &par2_header, sizeof(par2_header))!=0)
- return 2;
+ return DC_STOP;
if(length % 4 !=0 || length < 16)
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=length;
}
- return 1;
+ return DC_CONTINUE;
}
static void file_rename_par2(const char *old_filename)
diff --git a/src/file_png.c b/src/file_png.c
index ec7e1a6..9aa7917 100644
--- a/src/file_png.c
+++ b/src/file_png.c
@@ -41,8 +41,8 @@
extern const file_hint_t file_hint_doc;
static void register_header_check_png(file_stat_t *file_stat);
-static int data_check_png(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
-static int data_check_mng(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_png(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_mng(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_png= {
.extension="png",
@@ -98,7 +98,7 @@ static int header_check_png(const unsigned char *buffer, const unsigned int buff
return 1;
}
-static int data_check_mng(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_mng(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
static const unsigned char mng_footer[4]= {'M','E','N','D'};
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
@@ -108,12 +108,12 @@ static int data_check_mng(const unsigned char *buffer, const unsigned int buffer
const struct png_chunk *chunk=(const struct png_chunk *)&buffer[i];
file_recovery->calculated_file_size+=12 + be32(chunk->length);
if(memcmp(&buffer[i+4], mng_footer, sizeof(mng_footer))==0)
- return 2;
+ return DC_STOP;
}
- return 1;
+ return DC_CONTINUE;
}
-static int data_check_png(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_png(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -122,7 +122,7 @@ static int data_check_png(const unsigned char *buffer, const unsigned int buffer
const struct png_chunk *chunk=(const struct png_chunk *)&buffer[i];
file_recovery->calculated_file_size+=12 + be32(chunk->length);
if(memcmp(&buffer[i+4], "IEND", 4)==0)
- return 2;
+ return DC_STOP;
// PNG chunk code
// IDAT IHDR PLTE bKGD cHRM fRAc gAMA gIFg gIFt gIFx hIST iCCP
// iTXt oFFs pCAL pHYs sBIT sCAL sPLT sRGB sTER tEXt tRNS zTXt
@@ -131,10 +131,10 @@ static int data_check_png(const unsigned char *buffer, const unsigned int buffer
(isupper(buffer[i+6]) || islower(buffer[i+6])) &&
(isupper(buffer[i+7]) || islower(buffer[i+7]))))
{
- return 2;
+ return DC_STOP;
}
}
- return 1;
+ return DC_CONTINUE;
}
static void register_header_check_png(file_stat_t *file_stat)
diff --git a/src/file_ps.c b/src/file_ps.c
index 28830ec..f572013 100644
--- a/src/file_ps.c
+++ b/src/file_ps.c
@@ -34,7 +34,7 @@
static void register_header_check_ps(file_stat_t *file_stat);
static int header_check_ps(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 int data_check_ps(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_ps(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_ps= {
.extension="ps",
@@ -87,7 +87,7 @@ static int header_check_ps(const unsigned char *buffer, const unsigned int buffe
return 0;
}
-static int data_check_ps(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_ps(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
if(buffer_size>8)
{
@@ -97,10 +97,10 @@ static int data_check_ps(const unsigned char *buffer, const unsigned int buffer_
if(buffer[i]=='%' && buffer[i+1]=='%' && buffer[i+2]=='E' && buffer[i+3]=='O' && buffer[i+4]=='F')
{
file_recovery->calculated_file_size=file_recovery->file_size+i+5-(buffer_size/2);
- return 2;
+ return DC_STOP;
}
}
}
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
- return 1;
+ return DC_CONTINUE;
}
diff --git a/src/file_psb.c b/src/file_psb.c
index 5194a38..9e6aeb1 100644
--- a/src/file_psb.c
+++ b/src/file_psb.c
@@ -37,7 +37,7 @@
static void register_header_check_psb(file_stat_t *file_stat);
static int header_check_psb(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 int psb_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t psb_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
static void file_check_psb(file_recovery_t *file_recovery);
const file_hint_t file_hint_psb= {
@@ -91,13 +91,13 @@ static uint64_t get_be64(const void *buffer, const unsigned int offset)
return be64(*val);
}
-static int psb_skip_image_data(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t psb_skip_image_data(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
file_recovery->file_check=NULL;
- return 1;
+ return DC_CONTINUE;
}
-static int psb_skip_layer_info(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t psb_skip_layer_info(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 16 < file_recovery->file_size + buffer_size/2)
@@ -108,15 +108,15 @@ static int psb_skip_layer_info(const unsigned char *buffer, const unsigned int b
log_info("Image data at 0x%lx\n", (long unsigned)(l + file_recovery->calculated_file_size));
#endif
if(l<4)
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=l;
file_recovery->data_check=&psb_skip_image_data;
return psb_skip_image_data(buffer, buffer_size, file_recovery);
}
- return 1;
+ return DC_CONTINUE;
}
-static int psb_skip_image_resources(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t psb_skip_image_resources(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 16 < file_recovery->file_size + buffer_size/2)
@@ -127,15 +127,15 @@ static int psb_skip_image_resources(const unsigned char *buffer, const unsigned
log_info("Layer info at 0x%lx\n", (long unsigned)(l + file_recovery->calculated_file_size));
#endif
if(l<4)
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=l;
file_recovery->data_check=&psb_skip_layer_info;
return psb_skip_layer_info(buffer, buffer_size, file_recovery);
}
- return 1;
+ return DC_CONTINUE;
}
-static int psb_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t psb_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
const struct psb_file_header *psb=(const struct psb_file_header *)&buffer[buffer_size/2];
psb_image_data_size_max=(uint64_t)le16(psb->channels) * le32(psb->height) * le32(psb->width) * le16(psb->depth) / 8;
@@ -151,12 +151,12 @@ static int psb_skip_color_mode(const unsigned char *buffer, const unsigned int b
log_info("Color mode at 0x%lx\n", (long unsigned)(l + file_recovery->calculated_file_size));
#endif
if(l<4)
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=l;
file_recovery->data_check=&psb_skip_image_resources;
return psb_skip_image_resources(buffer, buffer_size, file_recovery);
}
- return 1;
+ return DC_CONTINUE;
}
static void file_check_psb(file_recovery_t *file_recovery)
diff --git a/src/file_psd.c b/src/file_psd.c
index 83e8be6..7d85d0d 100644
--- a/src/file_psd.c
+++ b/src/file_psd.c
@@ -37,7 +37,7 @@
static void register_header_check_psd(file_stat_t *file_stat);
static int header_check_psd(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 int psd_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t psd_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
static void file_check_psd(file_recovery_t *file_recovery);
const file_hint_t file_hint_psd= {
@@ -82,13 +82,13 @@ static uint32_t get_be32(const void *buffer, const unsigned int offset)
return be32(*val);
}
-static int psd_skip_image_data(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t psd_skip_image_data(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
file_recovery->file_check=NULL;
- return 1;
+ return DC_CONTINUE;
}
-static int psd_skip_layer_info(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t psd_skip_layer_info(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 16 < file_recovery->file_size + buffer_size/2)
@@ -99,15 +99,15 @@ static int psd_skip_layer_info(const unsigned char *buffer, const unsigned int b
log_info("Image data at 0x%lx\n", (long unsigned)(l + file_recovery->calculated_file_size));
#endif
if(l<4)
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=l;
file_recovery->data_check=&psd_skip_image_data;
return psd_skip_image_data(buffer, buffer_size, file_recovery);
}
- return 1;
+ return DC_CONTINUE;
}
-static int psd_skip_image_resources(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t psd_skip_image_resources(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 16 < file_recovery->file_size + buffer_size/2)
@@ -118,15 +118,15 @@ static int psd_skip_image_resources(const unsigned char *buffer, const unsigned
log_info("Layer info at 0x%lx\n", (long unsigned)(l + file_recovery->calculated_file_size));
#endif
if(l<4)
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=l;
file_recovery->data_check=&psd_skip_layer_info;
return psd_skip_layer_info(buffer, buffer_size, file_recovery);
}
- return 1;
+ return DC_CONTINUE;
}
-static int psd_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t psd_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
const struct psd_file_header *psd=(const struct psd_file_header *)&buffer[buffer_size/2];
psd_image_data_size_max=(uint64_t)le16(psd->channels) * le32(psd->height) * le32(psd->width) * le16(psd->depth) / 8;
@@ -142,12 +142,12 @@ static int psd_skip_color_mode(const unsigned char *buffer, const unsigned int b
log_info("Color mode at 0x%lx\n", (long unsigned)(l + file_recovery->calculated_file_size));
#endif
if(l<4)
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size+=l;
file_recovery->data_check=&psd_skip_image_resources;
return psd_skip_image_resources(buffer, buffer_size, file_recovery);
}
- return 1;
+ return DC_CONTINUE;
}
static void file_check_psd(file_recovery_t *file_recovery)
diff --git a/src/file_psp.c b/src/file_psp.c
index f5ad532..f961f33 100644
--- a/src/file_psp.c
+++ b/src/file_psp.c
@@ -55,7 +55,7 @@ struct psp_chunk {
uint32_t size;
} __attribute__ ((__packed__));
-static int data_check_psp(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_psp(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 10 < file_recovery->file_size + buffer_size/2)
@@ -63,12 +63,12 @@ static int data_check_psp(const unsigned char *buffer, const unsigned int buffer
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
const struct psp_chunk *chunk=(const struct psp_chunk *)&buffer[i];
if(memcmp(&buffer[i], "~BK\0", 4) != 0)
- return 2;
+ return DC_STOP;
/* chunk: header, id, total_length */
file_recovery->calculated_file_size+=10;
file_recovery->calculated_file_size+=le32(chunk->size);
}
- return 1;
+ return DC_CONTINUE;
}
static int header_check_psp(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)
diff --git a/src/file_qbb.c b/src/file_qbb.c
index d3dcd8f..8ee4794 100644
--- a/src/file_qbb.c
+++ b/src/file_qbb.c
@@ -33,7 +33,7 @@
static void register_header_check_qbb(file_stat_t *file_stat);
static int header_check_qbb(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 int data_check_qbb(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_qbb(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
static void file_check_qbb(file_recovery_t *file_recovery);
const file_hint_t file_hint_qbb= {
@@ -91,13 +91,13 @@ static int header_check_qbb(const unsigned char *buffer, const unsigned int buff
return 0;
}
-static int data_check_qbb(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_qbb(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
if(file_recovery->file_size > file_recovery->calculated_file_size+512)
{
- return 2;
+ return DC_STOP;
}
- return 1;
+ return DC_CONTINUE;
}
static void file_check_qbb(file_recovery_t *file_recovery)
diff --git a/src/file_riff.c b/src/file_riff.c
index 77b811c..e1c591e 100644
--- a/src/file_riff.c
+++ b/src/file_riff.c
@@ -34,7 +34,7 @@
#include "log.h"
#endif
-int data_check_avi_stream(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+data_check_t data_check_avi_stream(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
static void register_header_check_riff(file_stat_t *file_stat);
const file_hint_t file_hint_riff= {
@@ -171,7 +171,7 @@ static void file_check_avi(file_recovery_t *fr)
}
}
-static int data_check_avi(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_avi(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 12 < file_recovery->file_size + buffer_size/2)
@@ -181,12 +181,12 @@ static int data_check_avi(const unsigned char *buffer, const unsigned int buffer
if(memcmp(&buffer[i], "RIFF", 4)==0 && memcmp(&buffer[i+8], "AVIX", 4)==0)
file_recovery->calculated_file_size += 8 + le32(chunk_header->dwSize);
else
- return 2;
+ return DC_STOP;
}
- return 1;
+ return DC_CONTINUE;
}
-int data_check_avi_stream(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+data_check_t data_check_avi_stream(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -194,10 +194,10 @@ int data_check_avi_stream(const unsigned char *buffer, const unsigned int buffer
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
const riff_chunk_header *chunk_header=(const riff_chunk_header*)&buffer[i];
if(buffer[i+2]!='d' || buffer[i+3]!='b') /* Video Data Binary ?*/
- return 2;
+ return DC_STOP;
file_recovery->calculated_file_size += 8 + le32(chunk_header->dwSize);
}
- return 1;
+ return DC_CONTINUE;
}
static void file_check_size_rifx(file_recovery_t *file_recovery)
diff --git a/src/file_tib.c b/src/file_tib.c
index 0c359b3..cdfae1e 100644
--- a/src/file_tib.c
+++ b/src/file_tib.c
@@ -57,7 +57,7 @@ static void register_header_check_tib(file_stat_t *file_stat)
register_header_check(0, tib2_header,sizeof(tib2_header), &header_check_tib, file_stat);
}
-static int data_check_tib2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_tib2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 512 <= file_recovery->file_size + buffer_size/2)
@@ -65,9 +65,9 @@ static int data_check_tib2(const unsigned char *buffer, const unsigned int buffe
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
file_recovery->calculated_file_size+=512;
if(memcmp(&buffer[i + 512 - sizeof(tib2_footer)], tib2_footer, sizeof(tib2_footer))==0)
- return 2;
+ return DC_STOP;
}
- return 1;
+ return DC_CONTINUE;
}
static void file_check_tib(file_recovery_t *file_recovery)
diff --git a/src/file_txt.c b/src/file_txt.c
index 1ce5021..4debec8 100644
--- a/src/file_txt.c
+++ b/src/file_txt.c
@@ -418,7 +418,7 @@ static int UTFsize(const unsigned char *buffer, const unsigned int buf_len)
return i;
}
-static int data_check_html(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_html(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
const char sign_html_end[] = "</html>";
const unsigned int i=UTFsize(&buffer[buffer_size/2], buffer_size/2);
@@ -430,33 +430,33 @@ static int data_check_html(const unsigned char *buffer, const unsigned int buffe
if(buffer[j]=='<' && strncasecmp((const char *)&buffer[j], sign_html_end, sizeof(sign_html_end)-1)==0)
{
file_recovery->calculated_file_size+=j-buffer_size/2+sizeof(sign_html_end)-1;
- return 2;
+ return DC_STOP;
}
}
if(i<buffer_size/2)
{
if(i>=10)
file_recovery->calculated_file_size=file_recovery->file_size+i;
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
- return 1;
+ return DC_CONTINUE;
}
-static int data_check_txt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_txt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
const unsigned int i=UTFsize(&buffer[buffer_size/2], buffer_size/2);
if(i<buffer_size/2)
{
if(i>=10)
file_recovery->calculated_file_size=file_recovery->file_size+i;
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
- return 1;
+ return DC_CONTINUE;
}
-static int data_check_ttd(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_ttd(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
unsigned int i;
for(i=buffer_size/2; i<buffer_size; i++)
@@ -465,10 +465,10 @@ static int data_check_ttd(const unsigned char *buffer, const unsigned int buffer
if((car>='A' && car<='F') || (car >='0' && car <='9') || car==' ' || car=='\n')
continue;
file_recovery->calculated_file_size=file_recovery->file_size + i - buffer_size/2;
- return 2;
+ return DC_STOP;
}
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
- return 1;
+ return DC_CONTINUE;
}
static int header_check_ttd(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)
diff --git a/src/file_vault.c b/src/file_vault.c
index f1e7eff..0ed7a60 100644
--- a/src/file_vault.c
+++ b/src/file_vault.c
@@ -59,7 +59,7 @@ static void register_header_check_vault(file_stat_t *file_stat)
* 03200bf0 2d 34 36 33 33 2d 61 33 34 66 2d 34 61 66 64 36 |-4633-a34f-4afd6|
* 03200c00 30 64 61 62 64 64 37 00 |0dabdd7.|
* */
-static int data_check_vault(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_vault(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
if(buffer_size>8)
{
@@ -69,12 +69,12 @@ static int data_check_vault(const unsigned char *buffer, const unsigned int buff
if(buffer[i]=='-' && buffer[i+5]=='-' && buffer[i+10]=='-' && buffer[i+15]=='-' && buffer[i+28]=='\0')
{
file_recovery->calculated_file_size=file_recovery->file_size+i+28+1-(buffer_size/2);
- return 2;
+ return DC_STOP;
}
}
}
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
- return 1;
+ return DC_CONTINUE;
}
static int header_check_vault(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)
diff --git a/src/file_win.c b/src/file_win.c
index eb390cb..21c4025 100644
--- a/src/file_win.c
+++ b/src/file_win.c
@@ -37,7 +37,7 @@
static void register_header_check_win(file_stat_t *file_stat);
static int header_check_win(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 int data_check_win(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_win(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_win= {
.extension="win",
@@ -74,7 +74,7 @@ static int header_check_win(const unsigned char *buffer, const unsigned int buff
return 0;
}
-static int data_check_win(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_win(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
unsigned int i;
char *buffer_lower=(char *)MALLOC(buffer_size+16);
@@ -87,9 +87,9 @@ static int data_check_win(const unsigned char *buffer, const unsigned int buffer
if(i>=10)
file_recovery->calculated_file_size=file_recovery->file_size+offset+i;
free(buffer_lower);
- return 2;
+ return DC_STOP;
}
free(buffer_lower);
file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2);
- return 1;
+ return DC_CONTINUE;
}
diff --git a/src/file_wv.c b/src/file_wv.c
index 80bbeb5..cfaacbe 100644
--- a/src/file_wv.c
+++ b/src/file_wv.c
@@ -33,7 +33,7 @@
static void register_header_check_wv(file_stat_t *file_stat);
static int header_check_wv(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 int data_check_wv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+static data_check_t data_check_wv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
const file_hint_t file_hint_wv= {
.extension="wv",
@@ -83,7 +83,7 @@ static int header_check_wv(const unsigned char *buffer, const unsigned int buffe
return 0;
}
-static int data_check_wv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+static data_check_t data_check_wv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
@@ -105,13 +105,13 @@ static int data_check_wv(const unsigned char *buffer, const unsigned int buffer_
}
else if(file_recovery->calculated_file_size > file_recovery->file_size)
{
- return 1;
+ return DC_CONTINUE;
}
else
{
- return 2;
+ return DC_STOP;
}
}
- return 1;
+ return DC_CONTINUE;
}
diff --git a/src/filegen.c b/src/filegen.c
index 93c5c22..9635a71 100644
--- a/src/filegen.c
+++ b/src/filegen.c
@@ -150,15 +150,17 @@ void free_header_check(void)
{
#ifdef DEBUG_HEADER_CHECK
unsigned int j;
+ const unsigned char *data;
#endif
file_check_t *current_check;
current_check=td_list_entry(tmp, file_check_t, list);
#ifdef DEBUG_HEADER_CHECK
+ data=(const char *)current_check->value;
log_info("[%u]=%02x length=%u offset=%u", pos->offset, i, current_check->length, current_check->offset);
if(current_check->file_stat!=NULL && current_check->file_stat->file_hint!=NULL)
log_info(" %s", current_check->file_stat->file_hint->description);
for(j=0; j<current_check->length; j++)
- log_info(" %02x", current_check->value[j]);
+ log_info(" %02x", data[j]);
log_info("\n");
#endif
td_list_del(tmp);
@@ -271,14 +273,14 @@ void file_search_lc_footer(file_recovery_t *file_recovery, const unsigned char*f
}
#endif
-int data_check_size(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
+data_check_t data_check_size(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
if(file_recovery->file_size>=file_recovery->calculated_file_size)
{
file_recovery->file_size=file_recovery->calculated_file_size;
- return 2;
+ return DC_STOP;
}
- return 1;
+ return DC_CONTINUE;
}
void file_check_size(file_recovery_t *file_recovery)
diff --git a/src/filegen.h b/src/filegen.h
index c29eaea..cef597b 100644
--- a/src/filegen.h
+++ b/src/filegen.h
@@ -35,6 +35,7 @@ extern "C" {
#define PHOTOREC_MAX_SIZE_16 (((uint64_t)1<<15)-1)
#define PHOTOREC_MAX_SIZE_32 (((uint64_t)1<<31)-1)
+typedef enum { DC_SCAN=0, DC_CONTINUE=1, DC_STOP=2, DC_ERROR=3} data_check_t;
typedef struct file_hint_struct file_hint_t;
typedef struct file_recovery_struct file_recovery_t;
typedef struct file_enable_struct file_enable_t;
@@ -77,10 +78,8 @@ struct file_recovery_struct
uint64_t offset_error;
uint64_t extra; /* extra bytes between offset_ok and offset_error */
uint64_t calculated_file_size;
- int (*data_check)(const unsigned char*buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
- /* data_check returns 0: bad, 1: EOF not found, 2: EOF
- It can modify file_recovery->calculated_file_size, not must not modify file_recovery->file_size
- */
+ data_check_t (*data_check)(const unsigned char*buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+ /* It can modify file_recovery->calculated_file_size, not must not modify file_recovery->file_size */
void (*file_check)(file_recovery_t *file_recovery);
void (*file_rename)(const char *old_filename);
uint64_t checkpoint_offset;
@@ -130,7 +129,7 @@ uint64_t file_rsearch(FILE *handle, uint64_t offset, const void*footer, const un
void file_search_footer(file_recovery_t *file_recovery, const void*footer, const unsigned int footer_length, const unsigned int extra_length);
void file_search_lc_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length);
void del_search_space(alloc_data_t *list_search_space, const uint64_t start, const uint64_t end);
-int data_check_size(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
+data_check_t data_check_size(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
void file_check_size_lax(file_recovery_t *file_recovery);
void file_check_size(file_recovery_t *file_recovery);
void reset_file_recovery(file_recovery_t *file_recovery);
diff --git a/src/phbf.c b/src/phbf.c
index 5091d5f..e0d6b77 100644
--- a/src/phbf.c
+++ b/src/phbf.c
@@ -261,14 +261,14 @@ pstatus_t photorec_bf(struct ph_param *params, const struct ph_options *options,
}
if(file_recovery.file_stat!=NULL)
{
- int res=1;
+ data_check_t res=DC_CONTINUE;
// log_info("add sector %llu\n", (long long unsigned)(offset/512));
list_append_block(&file_recovery.location, offset, blocksize,1);
if(file_recovery.data_check!=NULL)
res=file_recovery.data_check(buffer_olddata, 2*blocksize, &file_recovery);
file_recovery.file_size+=blocksize;
file_recovery.file_size_on_disk+=blocksize;
- if(res==2)
+ if(res==DC_STOP || res==DC_ERROR)
{ /* EOF found */
need_to_check_file=1;
}
@@ -381,7 +381,7 @@ static bf_status_t photorec_bf_pad(struct ph_param *params, file_recovery_t *fil
(*current_search_space)->file_stat->file_hint==NULL)
{
params->disk->pread(params->disk, block_buffer, blocksize, *offset);
- if(file_recovery->data_check(buffer, 2*blocksize, file_recovery)!=1)
+ if(file_recovery->data_check(buffer, 2*blocksize, file_recovery)!=DC_CONTINUE)
{
stop=1;
}
@@ -539,7 +539,7 @@ static bf_status_t photorec_bf_frag_fast(struct ph_param *params, file_recovery_
for(k=original_offset_ok/blocksize+1; k<original_offset_error/blocksize; k++)
{
params->disk->pread(params->disk, block_buffer, blocksize, *offset);
- if(file_recovery->data_check(buffer, 2*blocksize, file_recovery)!=1)
+ if(file_recovery->data_check(buffer, 2*blocksize, file_recovery)!=DC_CONTINUE)
{
/* TODO handle this problem */
}
diff --git a/src/phbs.c b/src/phbs.c
index f121813..b9fb674 100644
--- a/src/phbs.c
+++ b/src/phbs.c
@@ -141,12 +141,12 @@ pstatus_t photorec_find_blocksize(struct ph_param *params, const struct ph_optio
/* Check for data EOF */
if(file_recovery.file_stat!=NULL)
{
- int res=1;
+ data_check_t res=DC_CONTINUE;
if(file_recovery.data_check!=NULL)
res=file_recovery.data_check(buffer_olddata, 2*blocksize, &file_recovery);
file_recovery.file_size+=blocksize;
file_recovery.file_size_on_disk+=blocksize;
- if(res==2)
+ if(res==DC_STOP || res==DC_ERROR)
{
/* EOF found */
reset_file_recovery(&file_recovery);
diff --git a/src/qphbs.cpp b/src/qphbs.cpp
index 0d81d73..f319f72 100644
--- a/src/qphbs.cpp
+++ b/src/qphbs.cpp
@@ -139,12 +139,12 @@ pstatus_t QPhotorec::photorec_find_blocksize(alloc_data_t *list_search_space)
/* Check for data EOF */
if(file_recovery.file_stat!=NULL)
{
- int res=1;
+ data_check_t res=DC_CONTINUE;
if(file_recovery.data_check!=NULL)
res=file_recovery.data_check(buffer_olddata, 2*blocksize, &file_recovery);
file_recovery.file_size+=blocksize;
file_recovery.file_size_on_disk+=blocksize;
- if(res==2)
+ if(res==DC_STOP || res==DC_ERROR)
{
/* EOF found */
reset_file_recovery(&file_recovery);
@@ -163,13 +163,14 @@ pstatus_t QPhotorec::photorec_find_blocksize(alloc_data_t *list_search_space)
else
{
get_next_sector(list_search_space, &current_search_space, &offset, blocksize);
- params->offset=offset;
}
if(current_search_space==list_search_space)
{
/* End of disk found => EOF */
reset_file_recovery(&file_recovery);
}
+ else
+ params->offset=offset;
buffer_olddata+=blocksize;
buffer+=blocksize;
if( old_offset+blocksize!=offset ||
diff --git a/src/qpsearch.cpp b/src/qpsearch.cpp
index 06a10e0..87962f3 100644
--- a/src/qpsearch.cpp
+++ b/src/qpsearch.cpp
@@ -262,7 +262,7 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
}
if(file_recovery.file_stat!=NULL)
{
- int res=1;
+ data_check_t res=DC_CONTINUE;
/* try to skip ext2/ext3 indirect block */
if((params->status==STATUS_EXT2_ON || params->status==STATUS_EXT2_ON_SAVE_EVERYTHING) &&
file_recovery.file_size_on_disk>=12*blocksize &&
@@ -288,7 +288,7 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
if(errno==EFBIG)
{
/* File is too big for the destination filesystem */
- res=2;
+ res=DC_STOP;
}
else
{
@@ -305,26 +305,26 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
res=file_recovery.data_check(buffer_olddata,2*blocksize,&file_recovery);
file_recovery.file_size+=blocksize;
file_recovery.file_size_on_disk+=blocksize;
- if(res==2)
+ if(res==DC_STOP)
{
if(options->verbose > 1)
log_trace("EOF found\n");
}
}
}
- if(res!=2 && file_recovery.file_stat->file_hint->max_filesize>0 && file_recovery.file_size>=file_recovery.file_stat->file_hint->max_filesize)
+ if(res!=DC_STOP && res!=DC_ERROR && file_recovery.file_stat->file_hint->max_filesize>0 && file_recovery.file_size>=file_recovery.file_stat->file_hint->max_filesize)
{
- res=2;
+ res=DC_STOP;
log_verbose("File should not be bigger than %llu, stop adding data\n",
(long long unsigned)file_recovery.file_stat->file_hint->max_filesize);
}
- if(res!=2 && file_recovery.file_size + blocksize >= PHOTOREC_MAX_SIZE_32 && is_fat(params->partition))
+ if(res!=DC_STOP && res!=DC_ERROR && file_recovery.file_size + blocksize >= PHOTOREC_MAX_SIZE_32 && is_fat(params->partition))
{
- res=2;
+ res=DC_STOP;
log_verbose("File should not be bigger than %llu, stop adding data\n",
(long long unsigned)file_recovery.file_stat->file_hint->max_filesize);
}
- if(res==2)
+ if(res==DC_STOP || res==DC_ERROR)
{
file_recovered=file_finish2(&file_recovery, params, options, list_search_space, &current_search_space, &offset);
reset_file_recovery(&file_recovery);