From e1ca4010307fb53d83c5036f6c8269eb9066c928 Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Mon, 11 May 2015 09:25:39 +0200 Subject: [PATCH] remove always-true memcmp --- src/file_DB.c | 24 ++-- src/file_ahn.c | 25 ++-- src/file_all.c | 21 ++- src/file_als.c | 58 ++++----- src/file_amd.c | 73 +++++------ src/file_apple.c | 24 ++-- src/file_asf.c | 4 +- src/file_atd.c | 24 ++-- src/file_au.c | 17 +-- src/file_bim.c | 30 ++--- src/file_bld.c | 191 ++++++++++++++------------- src/file_caf.c | 6 +- src/file_cam.c | 21 +-- src/file_catdrawing.c | 19 +-- src/file_cdt.c | 38 +++--- src/file_cm.c | 19 +-- src/file_compress.c | 20 +-- src/file_ctg.c | 22 +--- src/file_dar.c | 10 +- src/file_dbn.c | 29 ++--- src/file_dim.c | 19 +-- src/file_doc.c | 20 ++- src/file_dsc.c | 24 ++-- src/file_dta.c | 30 ++--- src/file_emf.c | 18 +-- src/file_exe.c | 2 +- src/file_fbk.c | 20 +-- src/file_fcp.c | 25 ++-- src/file_fcs.c | 4 +- src/file_fdb.c | 24 ++-- src/file_fh10.c | 38 +++--- src/file_filevault.c | 31 ++--- src/file_fp5.c | 26 ++-- src/file_freeway.c | 27 ++-- src/file_gam.c | 17 +-- src/file_gct.c | 25 ++-- src/file_gho.c | 29 ++--- src/file_gm6.c | 45 +++---- src/file_gp5.c | 43 +++---- src/file_gpg.c | 4 +- src/file_gsm.c | 3 +- src/file_hr9.c | 43 +++---- src/file_ifo.c | 37 ++---- src/file_imb.c | 23 ++-- src/file_indd.c | 11 +- src/file_iso.c | 24 ++-- src/file_jpg.c | 8 +- src/file_kdb.c | 25 ++-- src/file_lit.c | 19 +-- src/file_lnk.c | 292 +++++++++++++++++++++--------------------- src/file_logic.c | 24 ++-- src/file_lso.c | 41 +++--- src/file_lxo.c | 2 +- src/file_lzo.c | 26 ++-- src/file_mat.c | 19 ++- src/file_mcd.c | 23 ++-- src/file_mdb.c | 42 +++--- src/file_mfa.c | 36 ++---- src/file_mfg.c | 41 +++--- src/file_mft.c | 2 +- src/file_mig.c | 22 ++-- src/file_mk5.c | 25 ++-- src/file_mov.c | 4 +- src/file_mp3.c | 22 ++-- src/file_mpg.c | 6 +- src/file_mrw.c | 57 ++++----- src/file_mus.c | 38 +++--- src/file_mxf.c | 27 ++-- src/file_nk2.c | 34 ++--- src/file_oci.c | 4 +- src/file_ogg.c | 2 +- src/file_paf.c | 20 +-- src/file_par2.c | 2 +- src/file_pct.c | 14 +- src/file_pds.c | 23 ++-- src/file_pfx.c | 2 +- src/file_plt.c | 27 ++-- src/file_prc.c | 16 +-- src/file_prt.c | 40 +++--- src/file_ps.c | 47 ++++--- src/file_ptb.c | 16 +-- src/file_ptf.c | 21 ++- src/file_pzf.c | 39 +++--- src/file_pzh.c | 25 ++-- src/file_qkt.c | 24 ++-- src/file_r3d.c | 4 +- src/file_rar.c | 36 +++--- src/file_raw.c | 25 ++-- src/file_rdc.c | 25 ++-- src/file_res.c | 22 ++-- src/file_rfp.c | 26 ++-- src/file_rns.c | 22 +--- src/file_save.c | 17 +-- src/file_sib.c | 20 +-- src/file_skd.c | 30 ++--- src/file_skp.c | 24 ++-- src/file_sp3.c | 22 ++-- src/file_spe.c | 2 +- src/file_spf.c | 39 +++--- src/file_sqm.c | 21 +-- src/file_stu.c | 20 +-- src/file_tax.c | 20 +-- src/file_template.c | 25 ++-- src/file_tivo.c | 22 ++-- src/file_ttf.c | 16 +-- src/file_txt.c | 78 +++++------ src/file_tz.c | 55 ++++---- src/file_vault.c | 43 +++---- src/file_vfb.c | 40 +++--- src/file_vmg.c | 27 ++-- src/file_win.c | 47 +++---- src/file_wks.c | 39 ++---- src/file_wnk.c | 20 +-- src/file_wpb.c | 17 +-- src/file_wtv.c | 40 +++--- src/file_wv.c | 4 +- src/file_xfi.c | 23 ++-- src/file_xfs.c | 10 +- src/file_xm.c | 24 ++-- src/file_xsv.c | 25 ++-- src/file_xz.c | 23 ++-- 121 files changed, 1411 insertions(+), 1986 deletions(-) diff --git a/src/file_DB.c b/src/file_DB.c index 469a4ea7..5ffa215f 100644 --- a/src/file_DB.c +++ b/src/file_DB.c @@ -30,7 +30,6 @@ #include "filegen.h" static void register_header_check_DB(file_stat_t *file_stat); -static int header_check_DB(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_DB= { .extension="DB", @@ -42,22 +41,17 @@ const file_hint_t file_hint_DB= { .register_header_check=®ister_header_check_DB }; -static const unsigned char DB_header[6]= { - 0x19, 0x01, 0x00, 0x08, 0x02, 0x20 -}; +static int header_check_DB(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_DB.extension; + return 1; +} static void register_header_check_DB(file_stat_t *file_stat) { + static const unsigned char DB_header[6]= { + 0x19, 0x01, 0x00, 0x08, 0x02, 0x20 + }; register_header_check(0, DB_header,sizeof(DB_header), &header_check_DB, file_stat); } - -static int header_check_DB(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(memcmp(buffer,DB_header,sizeof(DB_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_DB.extension; - return 1; - } - return 0; -} diff --git a/src/file_ahn.c b/src/file_ahn.c index 3cbc951b..f67b10b5 100644 --- a/src/file_ahn.c +++ b/src/file_ahn.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_ahn(file_stat_t *file_stat); -static int header_check_ahn(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_ahn= { .extension="ahn", @@ -43,22 +42,18 @@ const file_hint_t file_hint_ahn= { .register_header_check=®ister_header_check_ahn }; -static const unsigned char ahn_header[4] = {'d','b','f',0x00}; -static const unsigned char ahn_magic[10] = {'A','H','N','E','N','B','L','A','T','T'}; +static int header_check_ahn(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 const unsigned char ahn_header[4] = {'d','b','f',0x00}; + if(memcmp(buffer, ahn_header, sizeof(ahn_header))!=0) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_ahn.extension; + return 1; +} static void register_header_check_ahn(file_stat_t *file_stat) { + static const unsigned char ahn_magic[10] = {'A','H','N','E','N','B','L','A','T','T'}; register_header_check(8, ahn_magic, sizeof(ahn_magic), &header_check_ahn, file_stat); } - -static int header_check_ahn(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(memcmp(buffer, ahn_header, sizeof(ahn_header))==0 && - memcmp(&buffer[8], ahn_magic, sizeof(ahn_magic))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_ahn.extension; - return 1; - } - return 0; -} diff --git a/src/file_all.c b/src/file_all.c index 91d9aeae..36eb3084 100644 --- a/src/file_all.c +++ b/src/file_all.c @@ -43,21 +43,16 @@ const file_hint_t file_hint_all= { .register_header_check=®ister_header_check_all }; -static const unsigned char all_header[8]= { 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x06, 0x04}; +static int header_check_all(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->min_filesize=122; + file_recovery_new->extension=file_hint_all.extension; + return 1; +} static void register_header_check_all(file_stat_t *file_stat) { + static const unsigned char all_header[8]= { 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x06, 0x04}; register_header_check(0, all_header,sizeof(all_header), &header_check_all, file_stat); } - -static int header_check_all(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(memcmp(buffer,all_header,8)==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->min_filesize=122; - file_recovery_new->extension=file_hint_all.extension; - return 1; - } - return 0; -} diff --git a/src/file_als.c b/src/file_als.c index c83c3dfa..1218805a 100644 --- a/src/file_als.c +++ b/src/file_als.c @@ -31,8 +31,6 @@ #include "filegen.h" static void register_header_check_als(file_stat_t *file_stat); -static int header_check_als(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_als(file_recovery_t *file_recovery); const file_hint_t file_hint_als= { .extension="als", @@ -44,36 +42,6 @@ const file_hint_t file_hint_als= { .register_header_check=®ister_header_check_als }; -/* Header - * 0000 ab 1e 56 78 03 XX 00 00 00 00 XX 0c 4c 69 76 65 | Vx Live| - * 0010 44 6f 63 75 6d 65 6e 74 XX 00 00 00 00 XX XX XX |Document | - */ -static const unsigned char als_header[5]= { - 0xab, 0x1e, 'V', 'x', 0x03 -}; -static const unsigned char als_header2[13]= { - 0x0c, 'L', 'i', 'v', 'e', 'D', 'o', 'c', - 'u', 'm', 'e', 'n', 't' -}; - -static void register_header_check_als(file_stat_t *file_stat) -{ - register_header_check(0, als_header,sizeof(als_header), &header_check_als, file_stat); -} - -static int header_check_als(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(memcmp(buffer,als_header,sizeof(als_header))==0 && - memcmp(buffer+11,als_header2,sizeof(als_header2))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_als.extension; - file_recovery_new->file_check=file_check_als; - return 1; - } - return 0; -} - static void file_check_als(file_recovery_t *file_recovery) { static const unsigned char als_footer[0x16]= { @@ -83,3 +51,29 @@ static void file_check_als(file_recovery_t *file_recovery) }; file_search_footer(file_recovery, als_footer, sizeof(als_footer), 7); } + +static int header_check_als(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 const unsigned char als_header2[13]= { + 0x0c, 'L', 'i', 'v', 'e', 'D', 'o', 'c', + 'u', 'm', 'e', 'n', 't' + }; + if(memcmp(buffer+11,als_header2,sizeof(als_header2))!=0) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_als.extension; + file_recovery_new->file_check=file_check_als; + return 1; +} + +/* Header + * 0000 ab 1e 56 78 03 XX 00 00 00 00 XX 0c 4c 69 76 65 | Vx Live| + * 0010 44 6f 63 75 6d 65 6e 74 XX 00 00 00 00 XX XX XX |Document | + */ +static void register_header_check_als(file_stat_t *file_stat) +{ + static const unsigned char als_header[5]= { + 0xab, 0x1e, 'V', 'x', 0x03 + }; + register_header_check(0, als_header,sizeof(als_header), &header_check_als, file_stat); +} diff --git a/src/file_amd.c b/src/file_amd.c index 87b9e92d..a0695294 100644 --- a/src/file_amd.c +++ b/src/file_amd.c @@ -45,52 +45,43 @@ const file_hint_t file_hint_amd= { .register_header_check=®ister_header_check_amd }; -/* amd 1.36 - * atd 1.19 */ -static const unsigned char amd_header[16]={ - 'L', 'i', 'c', 'o', 'm', '-', 'A', 'P', - 'S', ' ', 'F', 'i', 'l', 'e', ' ', 'V' }; - -/* amt 1.19 - * att 1.08 */ -static const unsigned char amt_header[20]={ - 'L', 'i', 'c', 'o', 'm', '-', 'A', 'P', - 'S', ' ', 'T', 'o', 'o', 'l', ' ', 'F', - 'i', 'l', 'e', ' '}; - -static void register_header_check_amd(file_stat_t *file_stat) -{ - register_header_check(0, amd_header,sizeof(amd_header), &header_check_amd, file_stat); - register_header_check(0, amt_header,sizeof(amt_header), &header_check_amt, file_stat); -} - static int header_check_amd(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(memcmp(buffer, amd_header, sizeof(amd_header))==0) - { - reset_file_recovery(file_recovery_new); - /* FIXME: I don't think it's a valid way to distinguish between files */ - if(buffer[16]=='1' && buffer[17]=='.' && buffer[18]=='1' && buffer[19]=='9') - file_recovery_new->extension="atd"; - else - file_recovery_new->extension=file_hint_amd.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + /* FIXME: I don't think it's a valid way to distinguish between files */ + if(buffer[16]=='1' && buffer[17]=='.' && buffer[18]=='1' && buffer[19]=='9') + file_recovery_new->extension="atd"; + else + file_recovery_new->extension=file_hint_amd.extension; + return 1; } static int header_check_amt(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(memcmp(buffer, amt_header, sizeof(amt_header))==0) - { - reset_file_recovery(file_recovery_new); - /* FIXME: I don't think it's a valid way to distinguish between files */ - if(buffer[21]=='1' && buffer[22]=='.' && buffer[23]=='0' && buffer[24]=='8') - file_recovery_new->extension="att"; - else - file_recovery_new->extension="amt"; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + /* FIXME: I don't think it's a valid way to distinguish between files */ + if(buffer[21]=='1' && buffer[22]=='.' && buffer[23]=='0' && buffer[24]=='8') + file_recovery_new->extension="att"; + else + file_recovery_new->extension="amt"; + return 1; } +static void register_header_check_amd(file_stat_t *file_stat) +{ + /* amd 1.36 + * atd 1.19 */ + static const unsigned char amd_header[16]={ + 'L', 'i', 'c', 'o', 'm', '-', 'A', 'P', + 'S', ' ', 'F', 'i', 'l', 'e', ' ', 'V' }; + + /* amt 1.19 + * att 1.08 */ + static const unsigned char amt_header[20]={ + 'L', 'i', 'c', 'o', 'm', '-', 'A', 'P', + 'S', ' ', 'T', 'o', 'o', 'l', ' ', 'F', + 'i', 'l', 'e', ' '}; + + register_header_check(0, amd_header,sizeof(amd_header), &header_check_amd, file_stat); + register_header_check(0, amt_header,sizeof(amt_header), &header_check_amt, file_stat); +} diff --git a/src/file_apple.c b/src/file_apple.c index 4ec0920b..882b3a60 100644 --- a/src/file_apple.c +++ b/src/file_apple.c @@ -30,7 +30,6 @@ #include "filegen.h" static void register_header_check_apple(file_stat_t *file_stat); -static int header_check_apple(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_apple= { .extension="apple", @@ -42,22 +41,17 @@ const file_hint_t file_hint_apple= { .register_header_check=®ister_header_check_apple }; -static const unsigned char apple_header[8]= { - 0x00, 0x05, 0x16, 0x07, 0x00, 0x02, 0x00, 0x00 -}; +static int header_check_apple(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_apple.extension; + return 1; +} static void register_header_check_apple(file_stat_t *file_stat) { + static const unsigned char apple_header[8]= { + 0x00, 0x05, 0x16, 0x07, 0x00, 0x02, 0x00, 0x00 + }; register_header_check(0, apple_header,sizeof(apple_header), &header_check_apple, file_stat); } - -static int header_check_apple(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(memcmp(buffer,apple_header,sizeof(apple_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_apple.extension; - return 1; - } - return 0; -} diff --git a/src/file_asf.c b/src/file_asf.c index cd95a71e..ef0acc68 100644 --- a/src/file_asf.c +++ b/src/file_asf.c @@ -88,7 +88,7 @@ static int header_check_asf(const unsigned char *buffer, const unsigned int buff // ASF_File_Properties_Object // 8CABDCA1-A947-11CF-8EE4-00C00C205365 // ASF_Stream_Properties_Object // B7DC0791-A9B7-11CF-8EE6-00C00C205365 static const unsigned char asf_file_prop_id[16]= { - 0xa1, 0xdc, 0xab, 0x8c, 0x47, 0xa9, 0xcf, 0x11, + 0xa1, 0xdc, 0xab, 0x8c, 0x47, 0xa9, 0xcf, 0x11, 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }; static const unsigned char asf_stream_prop_s[16]= { @@ -143,7 +143,7 @@ static int header_check_asf(const unsigned char *buffer, const unsigned int buff static void register_header_check_asf(file_stat_t *file_stat) { static const unsigned char asf_header[16]= { - 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, + 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }; register_header_check(0, asf_header,sizeof(asf_header), &header_check_asf, file_stat); diff --git a/src/file_atd.c b/src/file_atd.c index e85c1c86..3a206963 100644 --- a/src/file_atd.c +++ b/src/file_atd.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_atd(file_stat_t *file_stat); -static int header_check_atd(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_atd= { .extension="atd", @@ -43,22 +42,17 @@ const file_hint_t file_hint_atd= { .register_header_check=®ister_header_check_atd }; -static const unsigned char atd_header[16]= { - 'A' ,'B' ,'S' ,'0' ,'L' ,'U' ,'T' ,'E' , - 'D' ,'A' ,'T' ,'A' ,'B' ,'A' ,'S' ,'E' }; +static int header_check_atd(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_atd.extension; + return 1; +} static void register_header_check_atd(file_stat_t *file_stat) { + static const unsigned char atd_header[16]= { + 'A' ,'B' ,'S' ,'0' ,'L' ,'U' ,'T' ,'E' , + 'D' ,'A' ,'T' ,'A' ,'B' ,'A' ,'S' ,'E' }; register_header_check(0, atd_header,sizeof(atd_header), &header_check_atd, file_stat); } - -static int header_check_atd(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(memcmp(buffer,atd_header,sizeof(atd_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_atd.extension; - return 1; - } - return 0; -} diff --git a/src/file_au.c b/src/file_au.c index 0269453f..38928c1e 100644 --- a/src/file_au.c +++ b/src/file_au.c @@ -32,7 +32,6 @@ #include "filegen.h" static void register_header_check_au(file_stat_t *file_stat); -static int header_check_au(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_au= { .extension="au", @@ -44,13 +43,6 @@ const file_hint_t file_hint_au= { .register_header_check=®ister_header_check_au }; -static const unsigned char au_header[4]= {'.','s','n','d'}; - -static void register_header_check_au(file_stat_t *file_stat) -{ - register_header_check(0, au_header,sizeof(au_header), &header_check_au, file_stat); -} - /* http://en.wikipedia.org/wiki/Au_file_format */ struct header_au_s { @@ -65,8 +57,7 @@ struct header_au_s static int header_check_au(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 struct header_au_s *au=(const struct header_au_s *)buffer; - if(memcmp(buffer,au_header,sizeof(au_header))==0 && - (const uint32_t)be32(au->offset) >= sizeof(struct header_au_s) && + if((const uint32_t)be32(au->offset) >= sizeof(struct header_au_s) && be32(au->encoding)>0 && be32(au->encoding)<=27 && be32(au->channels)>0 && be32(au->channels)<=256) { @@ -89,3 +80,9 @@ static int header_check_au(const unsigned char *buffer, const unsigned int buffe } return 0; } + +static void register_header_check_au(file_stat_t *file_stat) +{ + static const unsigned char au_header[4]= {'.','s','n','d'}; + register_header_check(0, au_header,sizeof(au_header), &header_check_au, file_stat); +} diff --git a/src/file_bim.c b/src/file_bim.c index c486f04f..0121b6e6 100644 --- a/src/file_bim.c +++ b/src/file_bim.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_bim(file_stat_t *file_stat); -static int header_check_bim(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_bim= { .extension="bim", @@ -43,25 +42,20 @@ const file_hint_t file_hint_bim= { .register_header_check=®ister_header_check_bim }; -static const unsigned char bim_header[0x20]= { - 0x00, 0x1f, 0x01, '4' , 'u' , 'r' , 'n' , ':', - 's' , 'c' , 'h' , 'e' , 'm' , 'a' , 's' , '-', - 'p' , 'r' , 'o' , 'f' , 'e' , 's' , 's' , 'i' , - 'o' , 'n' , 'a' , 'l' , 'D' , 'i' , 's' , 'c' -}; +static int header_check_bim(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_bim.extension; + return 1; +} static void register_header_check_bim(file_stat_t *file_stat) { + static const unsigned char bim_header[0x20]= { + 0x00, 0x1f, 0x01, '4' , 'u' , 'r' , 'n' , ':', + 's' , 'c' , 'h' , 'e' , 'm' , 'a' , 's' , '-', + 'p' , 'r' , 'o' , 'f' , 'e' , 's' , 's' , 'i' , + 'o' , 'n' , 'a' , 'l' , 'D' , 'i' , 's' , 'c' + }; register_header_check(0, bim_header, sizeof(bim_header), &header_check_bim, file_stat); } - -static int header_check_bim(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(memcmp(buffer, bim_header, sizeof(bim_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_bim.extension; - return 1; - } - return 0; -} diff --git a/src/file_bld.c b/src/file_bld.c index 34015a26..2a93bc21 100644 --- a/src/file_bld.c +++ b/src/file_bld.c @@ -32,11 +32,6 @@ #include "log.h" 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 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", @@ -48,12 +43,99 @@ const file_hint_t file_hint_blend= { .register_header_check=®ister_header_check_blend }; -static const unsigned char blend_header[7] = { 'B', 'L', 'E', 'N', 'D', 'E', 'R'}; static const unsigned char blend_header_footer[4] = { 'E', 'N', 'D', 'B'}; -static void register_header_check_blend(file_stat_t *file_stat) +static data_check_t data_check_blend4le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { - register_header_check(0, blend_header,sizeof(blend_header), &header_check_blend, file_stat); + 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) + { + const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; + const unsigned int len=buffer[i+4]+ ((buffer[i+5])<<8)+ ((buffer[i+6])<<16)+ ((buffer[i+7])<<24); +#ifdef DEBUG_BLEND + log_debug("file_mov.c: atom %c%c%c%c (0x%02x%02x%02x%02x) size %u, calculated_file_size %llu\n", + buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], + buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], + len, + (long long unsigned)file_recovery->calculated_file_size); +#endif + if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0) + { + file_recovery->calculated_file_size+=0x14; + return DC_STOP; + } + file_recovery->calculated_file_size+=0x14+len; + } + return DC_CONTINUE; +} + +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) + { + const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; + const unsigned int len=buffer[i+4]+ ((buffer[i+5])<<8)+ ((buffer[i+6])<<16)+ ((buffer[i+7])<<24); +#ifdef DEBUG_BLEND + log_debug("file_mov.c: atom %c%c%c%c (0x%02x%02x%02x%02x) size %u, calculated_file_size %llu\n", + buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], + buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], + len, + (long long unsigned)file_recovery->calculated_file_size); +#endif + if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0) + { + file_recovery->calculated_file_size+=0x18; + return DC_STOP; + } + file_recovery->calculated_file_size+=0x18+len; + } + return DC_CONTINUE; +} + +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) + { + const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; + const unsigned int len=(buffer[i+4]<<24)+ ((buffer[i+5])<<16)+ ((buffer[i+6])<<8)+ buffer[i+7]; +#ifdef DEBUG_BLEND + log_debug("file_mov.c: atom %c%c%c%c (0x%02x%02x%02x%02x) size %u, calculated_file_size %llu\n", + buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], + buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], + len, + (long long unsigned)file_recovery->calculated_file_size); +#endif + if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0) + { + file_recovery->calculated_file_size+=0x14; + return DC_STOP; + } + file_recovery->calculated_file_size+=0x14+len; + } + return DC_CONTINUE; +} + +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) + { + const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; + const unsigned int len=(buffer[i+4]<<24)+ ((buffer[i+5])<<16)+ ((buffer[i+6])<<8)+ buffer[i+7]; +#ifdef DEBUG_BLEND + log_debug("file_mov.c: atom %c%c%c%c (0x%02x%02x%02x%02x) size %u, calculated_file_size %llu\n", + buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], + buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], + len, + (long long unsigned)file_recovery->calculated_file_size); +#endif + if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0) + { + file_recovery->calculated_file_size+=0x18; + return DC_STOP; + } + file_recovery->calculated_file_size+=0x18+len; + } + return DC_CONTINUE; } 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) @@ -83,95 +165,8 @@ static int header_check_blend(const unsigned char *buffer, const unsigned int bu return 1; } -static data_check_t data_check_blend4le(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) +static void register_header_check_blend(file_stat_t *file_stat) { - 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) - { - const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; - const unsigned int len=buffer[i+4]+ ((buffer[i+5])<<8)+ ((buffer[i+6])<<16)+ ((buffer[i+7])<<24); -#ifdef DEBUG_BLEND - log_debug("file_mov.c: atom %c%c%c%c (0x%02x%02x%02x%02x) size %u, calculated_file_size %llu\n", - buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], - buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], - len, - (long long unsigned)file_recovery->calculated_file_size); -#endif - if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0) - { - file_recovery->calculated_file_size+=0x14; - return DC_STOP; - } - file_recovery->calculated_file_size+=0x14+len; - } - return DC_CONTINUE; -} - -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) - { - const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; - const unsigned int len=buffer[i+4]+ ((buffer[i+5])<<8)+ ((buffer[i+6])<<16)+ ((buffer[i+7])<<24); -#ifdef DEBUG_BLEND - log_debug("file_mov.c: atom %c%c%c%c (0x%02x%02x%02x%02x) size %u, calculated_file_size %llu\n", - buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], - buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], - len, - (long long unsigned)file_recovery->calculated_file_size); -#endif - if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0) - { - file_recovery->calculated_file_size+=0x18; - return DC_STOP; - } - file_recovery->calculated_file_size+=0x18+len; - } - return DC_CONTINUE; -} - -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) - { - const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; - const unsigned int len=(buffer[i+4]<<24)+ ((buffer[i+5])<<16)+ ((buffer[i+6])<<8)+ buffer[i+7]; -#ifdef DEBUG_BLEND - log_debug("file_mov.c: atom %c%c%c%c (0x%02x%02x%02x%02x) size %u, calculated_file_size %llu\n", - buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], - buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], - len, - (long long unsigned)file_recovery->calculated_file_size); -#endif - if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0) - { - file_recovery->calculated_file_size+=0x14; - return DC_STOP; - } - file_recovery->calculated_file_size+=0x14+len; - } - return DC_CONTINUE; -} - -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) - { - const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; - const unsigned int len=(buffer[i+4]<<24)+ ((buffer[i+5])<<16)+ ((buffer[i+6])<<8)+ buffer[i+7]; -#ifdef DEBUG_BLEND - log_debug("file_mov.c: atom %c%c%c%c (0x%02x%02x%02x%02x) size %u, calculated_file_size %llu\n", - buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], - buffer[i+0],buffer[i+1],buffer[i+2],buffer[i+3], - len, - (long long unsigned)file_recovery->calculated_file_size); -#endif - if(memcmp(&buffer[i],blend_header_footer,sizeof(blend_header_footer))==0) - { - file_recovery->calculated_file_size+=0x18; - return DC_STOP; - } - file_recovery->calculated_file_size+=0x18+len; - } - return DC_CONTINUE; + static const unsigned char blend_header[7] = { 'B', 'L', 'E', 'N', 'D', 'E', 'R'}; + register_header_check(0, blend_header,sizeof(blend_header), &header_check_blend, file_stat); } diff --git a/src/file_caf.c b/src/file_caf.c index 8d801961..fd31a4c4 100644 --- a/src/file_caf.c +++ b/src/file_caf.c @@ -66,8 +66,8 @@ static data_check_t data_check_caf(const unsigned char *buffer, const unsigned i #ifdef DEBUG_CAF log_trace("file_caf.c: %s chunk %c%c%c%c (0x%02x%02x%02x%02x) size %llu, calculated_file_size %llu (0x%llx)\n", file_recovery->filename, - buffer[i],buffer[i+1],buffer[i+2],buffer[i+3], - buffer[i],buffer[i+1],buffer[i+2],buffer[i+3], + buffer[i],buffer[i+1],buffer[i+2],buffer[i+3], + buffer[i],buffer[i+1],buffer[i+2],buffer[i+3], (long long unsigned)chunk_size, (long long unsigned)file_recovery->calculated_file_size, (long long unsigned)file_recovery->calculated_file_size); @@ -117,7 +117,7 @@ static void register_header_check_caf(file_stat_t *file_stat) { static const unsigned char caf_header[12]= { 'c' , 'a' , 'f' , 'f' , 0x00, 0x01, 0x00, 0x00, - 'd' , 'e' , 's' , 'c' + 'd' , 'e' , 's' , 'c' }; register_header_check(0, caf_header, sizeof(caf_header), &header_check_caf, file_stat); } diff --git a/src/file_cam.c b/src/file_cam.c index ff25a45e..1e4f54c4 100644 --- a/src/file_cam.c +++ b/src/file_cam.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_cam(file_stat_t *file_stat); -static int header_check_cam(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_cam= { .extension="cam", @@ -43,21 +42,15 @@ const file_hint_t file_hint_cam= { .register_header_check=®ister_header_check_cam }; -static const unsigned char cam_header[4]= {0x07, 0x20, 'M', 'M'}; +static int header_check_cam(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_cam.extension; + return 1; +} static void register_header_check_cam(file_stat_t *file_stat) { + static const unsigned char cam_header[4]= {0x07, 0x20, 'M', 'M'}; register_header_check(0, cam_header,sizeof(cam_header), &header_check_cam, file_stat); } - -static int header_check_cam(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(memcmp(buffer,cam_header,sizeof(cam_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_cam.extension; - return 1; - } - return 0; -} - diff --git a/src/file_catdrawing.c b/src/file_catdrawing.c index 7afcfc8f..638f39d7 100644 --- a/src/file_catdrawing.c +++ b/src/file_catdrawing.c @@ -42,23 +42,18 @@ const file_hint_t file_hint_catdrawing= { .register_header_check=®ister_header_check_catdrawing }; -static const unsigned char catdrawing_header[9]= { - 'V' , '5' , '_' , 'C' , 'F' , 'V' , '2' , 0x00, - 0x00 -}; - static int header_check_catdrawing(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(memcmp(&buffer[0], catdrawing_header, sizeof(catdrawing_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_catdrawing.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_catdrawing.extension; + return 1; } static void register_header_check_catdrawing(file_stat_t *file_stat) { + static const unsigned char catdrawing_header[9]= { + 'V' , '5' , '_' , 'C' , 'F' , 'V' , '2' , 0x00, + 0x00 + }; register_header_check(0, catdrawing_header, sizeof(catdrawing_header), &header_check_catdrawing, file_stat); } diff --git a/src/file_cdt.c b/src/file_cdt.c index dcb446d5..7ce19abd 100644 --- a/src/file_cdt.c +++ b/src/file_cdt.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_cdt(file_stat_t *file_stat); -static int header_check_cdt(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_cdt= { .extension="cdt", @@ -43,29 +42,24 @@ const file_hint_t file_hint_cdt= { .register_header_check=®ister_header_check_cdt }; -static const unsigned char cdt_header[7]= { - 'C' , 'O' , 'N' , 'C' , 'E' , 'P' , 'T' -}; +static int header_check_cdt(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) +{ + reset_file_recovery(file_recovery_new); + if(buffer[0]==0xee) + file_recovery_new->extension="cdl"; /* ConceptDraw PRO Library File */ + else if(buffer[0]==0xef) + file_recovery_new->extension="cdd"; /* ConceptDraw PRO Document */ + else if(buffer[0]==0xf0) + file_recovery_new->extension="cdt"; /* ConceptDraw PRO Template */ + else + file_recovery_new->extension=file_hint_cdt.extension; + return 1; +} static void register_header_check_cdt(file_stat_t *file_stat) { + static const unsigned char cdt_header[7]= { + 'C' , 'O' , 'N' , 'C' , 'E' , 'P' , 'T' + }; register_header_check(12, cdt_header, sizeof(cdt_header), &header_check_cdt, file_stat); } - -static int header_check_cdt(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(memcmp(&buffer[12], cdt_header, sizeof(cdt_header))==0) - { - reset_file_recovery(file_recovery_new); - if(buffer[0]==0xee) - file_recovery_new->extension="cdl"; /* ConceptDraw PRO Library File */ - else if(buffer[0]==0xef) - file_recovery_new->extension="cdd"; /* ConceptDraw PRO Document */ - else if(buffer[0]==0xf0) - file_recovery_new->extension="cdt"; /* ConceptDraw PRO Template */ - else - file_recovery_new->extension=file_hint_cdt.extension; - return 1; - } - return 0; -} diff --git a/src/file_cm.c b/src/file_cm.c index be8a21f8..30fdd7fc 100644 --- a/src/file_cm.c +++ b/src/file_cm.c @@ -43,20 +43,15 @@ const file_hint_t file_hint_cm= { .register_header_check=®ister_header_check_cm }; -static const unsigned char cm_header[8] = { 'f','L','m','C','0','0','0','1'}; +static int header_check_cm(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_cm.extension; + return 1; +} static void register_header_check_cm(file_stat_t *file_stat) { + static const unsigned char cm_header[8] = { 'f','L','m','C','0','0','0','1'}; register_header_check(0x0, cm_header,sizeof(cm_header), &header_check_cm, file_stat); } - -static int header_check_cm(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(memcmp(&buffer[0x0],cm_header,sizeof(cm_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_cm.extension; - return 1; - } - return 0; -} diff --git a/src/file_compress.c b/src/file_compress.c index c2747616..b02685a6 100644 --- a/src/file_compress.c +++ b/src/file_compress.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_compress(file_stat_t *file_stat); -static int header_check_compress(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_compress= { .extension="cp_", @@ -43,20 +42,15 @@ const file_hint_t file_hint_compress= { .register_header_check=®ister_header_check_compress }; -static const unsigned char compress_header[9] = {'S', 'Z', 'D', 'D', 0x88, 0xf0, 0x27, 0x33, 'A'}; +static int header_check_compress(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_compress.extension; + return 1; +} static void register_header_check_compress(file_stat_t *file_stat) { + static const unsigned char compress_header[9] = {'S', 'Z', 'D', 'D', 0x88, 0xf0, 0x27, 0x33, 'A'}; register_header_check(0, compress_header, sizeof(compress_header), &header_check_compress, file_stat); } - -static int header_check_compress(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(memcmp(buffer, compress_header, sizeof(compress_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_compress.extension; - return 1; - } - return 0; -} diff --git a/src/file_ctg.c b/src/file_ctg.c index 98c0af36..52593e6d 100644 --- a/src/file_ctg.c +++ b/src/file_ctg.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_ctg(file_stat_t *file_stat); -static int header_check_ctg(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_ctg= { .extension="ctg", @@ -43,22 +42,15 @@ const file_hint_t file_hint_ctg= { .register_header_check=®ister_header_check_ctg }; -static const unsigned char ctg_header[7]= {':','\\','D','C','I','M','\\'}; +static int header_check_ctg(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_ctg.extension; + return 1; +} static void register_header_check_ctg(file_stat_t *file_stat) { + static const unsigned char ctg_header[7]= {':','\\','D','C','I','M','\\'}; register_header_check(1, ctg_header,sizeof(ctg_header), &header_check_ctg, file_stat); } - -static int header_check_ctg(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(memcmp(buffer+1, ctg_header,sizeof(ctg_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_ctg.extension; - return 1; - } - return 0; -} - - diff --git a/src/file_dar.c b/src/file_dar.c index 48b46609..b3d0df44 100644 --- a/src/file_dar.c +++ b/src/file_dar.c @@ -42,15 +42,10 @@ const file_hint_t file_hint_dar= { .register_header_check=®ister_header_check_dar }; -static const unsigned char dar_header[4]= { - 0, 0, 0, 0x7b -}; - static int header_check_dar(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) { /* http://darbinding.sourceforge.net/specs/dar3.html */ - if(memcmp(buffer, dar_header, sizeof(dar_header))==0 && - (buffer[0xe]=='N' || buffer[0xe]=='T') && + if((buffer[0xe]=='N' || buffer[0xe]=='T') && (buffer[0xf]=='N' || buffer[0xf]=='S')) { reset_file_recovery(file_recovery_new); @@ -62,5 +57,8 @@ static int header_check_dar(const unsigned char *buffer, const unsigned int buff static void register_header_check_dar(file_stat_t *file_stat) { + static const unsigned char dar_header[4]= { + 0, 0, 0, 0x7b + }; register_header_check(0, dar_header, sizeof(dar_header), &header_check_dar, file_stat); } diff --git a/src/file_dbn.c b/src/file_dbn.c index 8b233ba7..b9a1f74f 100644 --- a/src/file_dbn.c +++ b/src/file_dbn.c @@ -32,7 +32,6 @@ #include "memmem.h" static void register_header_check_dbn(file_stat_t *file_stat); -static int header_check_dbn(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_dbn= { .extension="dbn", @@ -44,24 +43,20 @@ const file_hint_t file_hint_dbn= { .register_header_check=®ister_header_check_dbn }; -static const unsigned char dbn_header[16]= { - 'F' , 'i' , 'l' , 'e' , ' ' , 'c' , 'r' , 'e' , - 'a' , 't' , 'e' , 'd' , ' ' , 'o' , 'n' , ' ' -}; +static int header_check_dbn(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(td_memmem(buffer, 512, "[HEADER]", 8)==NULL) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_dbn.extension; + return 1; +} static void register_header_check_dbn(file_stat_t *file_stat) { + static const unsigned char dbn_header[16]= { + 'F' , 'i' , 'l' , 'e' , ' ' , 'c' , 'r' , 'e' , + 'a' , 't' , 'e' , 'd' , ' ' , 'o' , 'n' , ' ' + }; register_header_check(0, dbn_header, sizeof(dbn_header), &header_check_dbn, file_stat); } - -static int header_check_dbn(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(memcmp(buffer, dbn_header, sizeof(dbn_header))==0 && - td_memmem(buffer, 512, "[HEADER]", 8)!=NULL) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_dbn.extension; - return 1; - } - return 0; -} diff --git a/src/file_dim.c b/src/file_dim.c index 3f46d8ed..70c41b76 100644 --- a/src/file_dim.c +++ b/src/file_dim.c @@ -42,20 +42,15 @@ const file_hint_t file_hint_dim= { .register_header_check=®ister_header_check_dim }; -static const unsigned char dim_header[4]= { 'S', 'P','C','I'}; +static int header_check_dim(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_dim.extension; + return 1; +} static void register_header_check_dim(file_stat_t *file_stat) { + static const unsigned char dim_header[4]= { 'S', 'P','C','I'}; register_header_check(0x0c, dim_header,sizeof(dim_header), &header_check_dim, file_stat); } - -static int header_check_dim(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(memcmp(&buffer[0x0c],dim_header,sizeof(dim_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_dim.extension; - return 1; - } - return 0; -} diff --git a/src/file_doc.c b/src/file_doc.c index f5cda30e..44f00682 100644 --- a/src/file_doc.c +++ b/src/file_doc.c @@ -61,12 +61,6 @@ const file_hint_t file_hint_doc= { .register_header_check=®ister_header_check_doc }; -static const unsigned char doc_header[]= { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1}; - -static void register_header_check_doc(file_stat_t *file_stat) -{ - register_header_check(0, doc_header,sizeof(doc_header), &header_check_doc, file_stat); -} const char WilcomDesignInformationDDD[56]= { @@ -85,7 +79,7 @@ static void file_check_doc(file_recovery_t *file_recovery) uint64_t doc_file_size; uint32_t *fat; unsigned long int i; - unsigned int freesect_count=0; + unsigned int freesect_count=0; const struct OLE_HDR *header=(const struct OLE_HDR*)&buffer_header; const uint64_t doc_file_size_org=file_recovery->file_size; file_recovery->file_size=0; @@ -378,8 +372,6 @@ static const char *ole_get_file_extension(const unsigned char *buffer, const uns static int header_check_doc(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 struct OLE_HDR *header=(const struct OLE_HDR *)buffer; - if(memcmp(buffer,doc_header,sizeof(doc_header))!=0) - return 0; /* Check for Little Endian */ if(le16(header->uByteOrder)!=0xFFFE) return 0; @@ -444,8 +436,8 @@ static int header_check_doc(const unsigned char *buffer, const unsigned int buff file_recovery_new->extension="sdd"; } else if(td_memmem(buffer,buffer_size,"Worksheet",9)!=NULL || - td_memmem(buffer,buffer_size,"Book",4)!=NULL || - td_memmem(buffer,buffer_size,"Workbook",8)!=NULL || + td_memmem(buffer,buffer_size,"Book",4)!=NULL || + td_memmem(buffer,buffer_size,"Workbook",8)!=NULL || td_memmem(buffer,buffer_size,"Calc",4)!=NULL) { file_recovery_new->extension="xls"; @@ -1075,3 +1067,9 @@ static void file_rename_doc(const char *old_filename) else file_rename(old_filename, NULL, 0, 0, ext, 1); } + +static void register_header_check_doc(file_stat_t *file_stat) +{ + static const unsigned char doc_header[]= { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1}; + register_header_check(0, doc_header,sizeof(doc_header), &header_check_doc, file_stat); +} diff --git a/src/file_dsc.c b/src/file_dsc.c index 08574a85..f515ff8a 100644 --- a/src/file_dsc.c +++ b/src/file_dsc.c @@ -30,7 +30,6 @@ #include "filegen.h" static void register_header_check_dsc(file_stat_t *file_stat); -static int header_check_dsc(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_dsc= { .extension="dsc", @@ -42,22 +41,17 @@ const file_hint_t file_hint_dsc= { .register_header_check=®ister_header_check_dsc }; -static const unsigned char dsc_header[3]= { 'M','L','T'}; - -static void register_header_check_dsc(file_stat_t *file_stat) -{ - register_header_check(588, dsc_header,sizeof(dsc_header), &header_check_dsc, file_stat); -} - static int header_check_dsc(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_size<1024) return 0; - if(memcmp(&buffer[588],dsc_header,sizeof(dsc_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_dsc.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_dsc.extension; + return 1; +} + +static void register_header_check_dsc(file_stat_t *file_stat) +{ + static const unsigned char dsc_header[3]= { 'M','L','T'}; + register_header_check(588, dsc_header,sizeof(dsc_header), &header_check_dsc, file_stat); } diff --git a/src/file_dta.c b/src/file_dta.c index 3b611097..cda52792 100644 --- a/src/file_dta.c +++ b/src/file_dta.c @@ -43,15 +43,6 @@ const file_hint_t file_hint_dta= { .register_header_check=®ister_header_check_dta }; -static const unsigned char dta_header_71le[3]= {0x71, 0x02, 0x01}; -static const unsigned char dta_header_72le[3]= {0x72, 0x02, 0x01}; - -static void register_header_check_dta(file_stat_t *file_stat) -{ - register_header_check(0, dta_header_71le,sizeof(dta_header_71le), &header_check_dta, file_stat); - register_header_check(0, dta_header_72le,sizeof(dta_header_72le), &header_check_dta, file_stat); -} - static int header_check_dta(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) { /* @@ -63,13 +54,16 @@ static int header_check_dta(const unsigned char *buffer, const unsigned int buff nobs (number of obs) 4 int encoded per byteorder data_label 81 char dataset label, \0 terminated time_stamp 18 char date/time saved, \0 terminated - */ - if(memcmp(buffer,dta_header_71le,sizeof(dta_header_71le))==0 || - memcmp(buffer,dta_header_72le,sizeof(dta_header_72le))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_dta.extension; - return 1; - } - return 0; + */ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_dta.extension; + return 1; +} + +static void register_header_check_dta(file_stat_t *file_stat) +{ + static const unsigned char dta_header_71le[3]= {0x71, 0x02, 0x01}; + static const unsigned char dta_header_72le[3]= {0x72, 0x02, 0x01}; + register_header_check(0, dta_header_71le,sizeof(dta_header_71le), &header_check_dta, file_stat); + register_header_check(0, dta_header_72le,sizeof(dta_header_72le), &header_check_dta, file_stat); } diff --git a/src/file_emf.c b/src/file_emf.c index ec9e2eb8..e23b6b2d 100644 --- a/src/file_emf.c +++ b/src/file_emf.c @@ -77,13 +77,9 @@ struct EMF_HDR uint32_t offDescription; uint32_t nPalEntries; U_SIZEL szlDevice; - U_SIZEL szlMillimeters; + U_SIZEL szlMillimeters; } __attribute__ ((gcc_struct, __packed__)); - -static const unsigned char emf_header[4]= { 0x01, 0x00, 0x00, 0x00}; -static const unsigned char emf_sign[4]= { ' ','E', 'M','F'}; - #define EMR_HEADER 1 #define EMR_POLYBEZIER 2 #define EMR_POLYGON 3 @@ -206,17 +202,12 @@ static const unsigned char emf_sign[4]= { ' ','E', 'M','F'}; #define EMR_COLORMATCHTOTARGETW 121 #define EMR_CREATECOLORSPACEW 122 -static void register_header_check_emf(file_stat_t *file_stat) -{ - register_header_check(0x28, emf_sign,sizeof(emf_sign), &header_check_emf, 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 const unsigned char emf_header[4]= { 0x01, 0x00, 0x00, 0x00}; const struct EMF_HDR *hdr=(const struct EMF_HDR *)buffer; const unsigned int atom_size=le32(hdr->emr.nSize); if(memcmp(buffer,emf_header,sizeof(emf_header))==0 && - memcmp(&buffer[0x28],emf_sign,sizeof(emf_sign))==0 && le32(hdr->nBytes) >= 88 && le16(hdr->sReserved)==0 && atom_size>=0x34 && atom_size%4==0) @@ -379,3 +370,8 @@ static data_check_t data_check_emf(const unsigned char *buffer, const unsigned i return DC_CONTINUE; } +static void register_header_check_emf(file_stat_t *file_stat) +{ + static const unsigned char emf_sign[4]= { ' ','E', 'M','F'}; + register_header_check(0x28, emf_sign,sizeof(emf_sign), &header_check_emf, file_stat); +} diff --git a/src/file_exe.c b/src/file_exe.c index 17097dbc..05aa35b7 100644 --- a/src/file_exe.c +++ b/src/file_exe.c @@ -138,7 +138,7 @@ static int header_check_exe(const unsigned char *buffer, const unsigned int buff if(le16(pe_image_section->NumberOfRelocations)>0) { #ifdef DEBUG_EXE - log_debug("relocations 0x%lx-0x%lx\n", + log_debug("relocations 0x%lx-0x%lx\n", (unsigned long)le32(pe_image_section->PointerToRelocations), (unsigned long)le32(pe_image_section->PointerToRelocations)+1*le16(pe_image_section->NumberOfRelocations)-1); #endif diff --git a/src/file_fbk.c b/src/file_fbk.c index fd3e2ec1..a58cac20 100644 --- a/src/file_fbk.c +++ b/src/file_fbk.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_fbk(file_stat_t *file_stat); -static int header_check_fbk(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_fbk= { .extension="fbk", @@ -43,20 +42,15 @@ const file_hint_t file_hint_fbk= { .register_header_check=®ister_header_check_fbk }; -static const unsigned char fbk_header[10] = {'T','a','b','l','e','D','a','t','a',' '}; +static int header_check_fbk(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_fbk.extension; + return 1; +} static void register_header_check_fbk(file_stat_t *file_stat) { + static const unsigned char fbk_header[10] = {'T','a','b','l','e','D','a','t','a',' '}; register_header_check(0, fbk_header, sizeof(fbk_header), &header_check_fbk, file_stat); } - -static int header_check_fbk(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(memcmp(buffer, fbk_header, sizeof(fbk_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_fbk.extension; - return 1; - } - return 0; -} diff --git a/src/file_fcp.c b/src/file_fcp.c index bf825a8b..8876c2f0 100644 --- a/src/file_fcp.c +++ b/src/file_fcp.c @@ -30,7 +30,6 @@ #include "filegen.h" static void register_header_check_fcp(file_stat_t *file_stat); -static int header_check_fcp(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_fcp= { .extension="fcp", @@ -42,25 +41,21 @@ const file_hint_t file_hint_fcp= { .register_header_check=®ister_header_check_fcp }; -static const unsigned char fcp_header[5]= { 0xA2, 'K','e','y','G'}; /* Final Cut Pro is a professional non-linear editing system developed by Apple Inc. - Mac Creator code: KeyG + Mac Creator code: KeyG */ -static void register_header_check_fcp(file_stat_t *file_stat) -{ - register_header_check(0, fcp_header,sizeof(fcp_header), &header_check_fcp, file_stat); -} - static int header_check_fcp(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(memcmp(buffer,fcp_header,sizeof(fcp_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_fcp.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_fcp.extension; + return 1; +} + +static void register_header_check_fcp(file_stat_t *file_stat) +{ + static const unsigned char fcp_header[5]= { 0xA2, 'K','e','y','G'}; + register_header_check(0, fcp_header,sizeof(fcp_header), &header_check_fcp, file_stat); } diff --git a/src/file_fcs.c b/src/file_fcs.c index fded067b..40d090a3 100644 --- a/src/file_fcs.c +++ b/src/file_fcs.c @@ -124,10 +124,10 @@ static int header_check_fcs(const unsigned char *buffer, const unsigned int buff if(i+1+8+1file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_fdb) return 0; - if(memcmp(&buffer[5], fdb_header, sizeof(fdb_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_fdb.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_fdb.extension; + return 1; +} + +static void register_header_check_fdb(file_stat_t *file_stat) +{ + static const unsigned char fdb_header[7] = { 0x00, 0x00, 0x00, 0x5c, 0xa0, 0x83, 0x02}; + register_header_check(5, fdb_header, sizeof(fdb_header), &header_check_fdb, file_stat); } diff --git a/src/file_fh10.c b/src/file_fh10.c index ea9b2e4a..abd6c08c 100644 --- a/src/file_fh10.c +++ b/src/file_fh10.c @@ -33,7 +33,6 @@ #include "filegen.h" static void register_header_check_fh10(file_stat_t *file_stat); -static int header_check_fh10(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_fh10= { .extension="fh10", @@ -45,29 +44,24 @@ const file_hint_t file_hint_fh10= { .register_header_check=®ister_header_check_fh10 }; -static const unsigned char fh10_header[] = { - 0x1c, 0x01 ,0x00, 0x00, 0x02, 0x00, 0x04, 0x1c, 0x01 , 0x14, 0x00, 0x02, 0x00, 0x14, 0x1c, 0x01, - 0x16, 0x00 ,0x02, 0x00, 0x08, 0x1c, 0x01, 0x1e, 0x00 , 0xa , 0x46, 0x72, 0x65, 0x65, 0x48, 0x61, - 0x6e, 0x64, 0x31, 0x30 -}; +static int header_check_fh10(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->min_filesize=4096; +#ifdef DJGPP + file_recovery_new->extension="fh1"; +#else + file_recovery_new->extension=file_hint_fh10.extension; +#endif + return 1; +} static void register_header_check_fh10(file_stat_t *file_stat) { + static const unsigned char fh10_header[] = { + 0x1c, 0x01 ,0x00, 0x00, 0x02, 0x00, 0x04, 0x1c, 0x01 , 0x14, 0x00, 0x02, 0x00, 0x14, 0x1c, 0x01, + 0x16, 0x00 ,0x02, 0x00, 0x08, 0x1c, 0x01, 0x1e, 0x00 , 0xa , 0x46, 0x72, 0x65, 0x65, 0x48, 0x61, + 0x6e, 0x64, 0x31, 0x30 + }; register_header_check(0, fh10_header,sizeof(fh10_header), &header_check_fh10, file_stat); } - -static int header_check_fh10(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(memcmp(buffer,fh10_header,sizeof(fh10_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->min_filesize=4096; -#ifdef DJGPP - file_recovery_new->extension="fh1"; -#else - file_recovery_new->extension=file_hint_fh10.extension; -#endif - return 1; - } - return 0; -} diff --git a/src/file_filevault.c b/src/file_filevault.c index e928f524..c5de1744 100644 --- a/src/file_filevault.c +++ b/src/file_filevault.c @@ -43,26 +43,21 @@ const file_hint_t file_hint_filevault= { .register_header_check=®ister_header_check_filevault }; -static const unsigned char filevault_header[8]= { - 'e', 'n', 'c', 'r', 'c', 'd', 's', 'a' -}; +static int header_check_filevault(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) +{ + reset_file_recovery(file_recovery_new); +#ifdef DJGPP + file_recovery_new->extension="img"; +#else + file_recovery_new->extension=file_hint_filevault.extension; +#endif + return 1; +} static void register_header_check_filevault(file_stat_t *file_stat) { + static const unsigned char filevault_header[8]= { + 'e', 'n', 'c', 'r', 'c', 'd', 's', 'a' + }; register_header_check(0, filevault_header, sizeof(filevault_header), &header_check_filevault, file_stat); } - -static int header_check_filevault(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(memcmp(&buffer[0], filevault_header, sizeof(filevault_header))==0) - { - reset_file_recovery(file_recovery_new); -#ifdef DJGPP - file_recovery_new->extension="img"; -#else - file_recovery_new->extension=file_hint_filevault.extension; -#endif - return 1; - } - return 0; -} diff --git a/src/file_fp5.c b/src/file_fp5.c index e431696d..ae8a7b38 100644 --- a/src/file_fp5.c +++ b/src/file_fp5.c @@ -30,7 +30,6 @@ #include "filegen.h" static void register_header_check_fp5(file_stat_t *file_stat); -static int header_check_fp5(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_fp5= { .extension="fp5", @@ -42,23 +41,18 @@ const file_hint_t file_hint_fp5= { .register_header_check=®ister_header_check_fp5 }; -static const unsigned char fp5_header[0x10]= { - 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, - 0x00, 0x05, 0x00, 0x02, 0x00, 0x02, 0xc0, 0x00 -}; +static int header_check_fp5(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_fp5.extension; + return 1; +} static void register_header_check_fp5(file_stat_t *file_stat) { + static const unsigned char fp5_header[0x10]= { + 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, + 0x00, 0x05, 0x00, 0x02, 0x00, 0x02, 0xc0, 0x00 + }; register_header_check(0, fp5_header,sizeof(fp5_header), &header_check_fp5, file_stat); } - -static int header_check_fp5(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(memcmp(buffer,fp5_header,sizeof(fp5_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_fp5.extension; - return 1; - } - return 0; -} diff --git a/src/file_freeway.c b/src/file_freeway.c index 1aae1d43..3711771e 100644 --- a/src/file_freeway.c +++ b/src/file_freeway.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_freeway(file_stat_t *file_stat); -static int header_check_freeway(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_freeway= { .extension="freeway", @@ -43,24 +42,18 @@ const file_hint_t file_hint_freeway= { .register_header_check=®ister_header_check_freeway }; -static const unsigned char freeway_header[0x10]= { - 0x13, 'F' , 'r' , 'e' , 'e' , 'w' , 'a' , 'y' , - ' ' , '5' , ' ' , 'P' , 'r' , 'o' , ' ' , '5' , -}; +static int header_check_freeway(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_freeway.extension; + return 1; +} static void register_header_check_freeway(file_stat_t *file_stat) { + static const unsigned char freeway_header[0x10]= { + 0x13, 'F' , 'r' , 'e' , 'e' , 'w' , 'a' , 'y' , + ' ' , '5' , ' ' , 'P' , 'r' , 'o' , ' ' , '5' , + }; register_header_check(0x10, freeway_header, sizeof(freeway_header), &header_check_freeway, file_stat); } - -static int header_check_freeway(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(memcmp(&buffer[0x10], freeway_header, sizeof(freeway_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_freeway.extension; - return 1; - } - return 0; -} - diff --git a/src/file_gam.c b/src/file_gam.c index 0e90c0be..58c16d57 100644 --- a/src/file_gam.c +++ b/src/file_gam.c @@ -42,22 +42,17 @@ const file_hint_t file_hint_gam= { .register_header_check=®ister_header_check_gam }; -static const unsigned char gam_header[6]= { - 'G' , 'A' , 'P' , 'P' , 0x07, 0x02 -}; - static int header_check_gam(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(memcmp(&buffer[0], gam_header, sizeof(gam_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_gam.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_gam.extension; + return 1; } static void register_header_check_gam(file_stat_t *file_stat) { + static const unsigned char gam_header[6]= { + 'G' , 'A' , 'P' , 'P' , 0x07, 0x02 + }; register_header_check(0, gam_header, sizeof(gam_header), &header_check_gam, file_stat); } diff --git a/src/file_gct.c b/src/file_gct.c index aab098fe..21e34a1b 100644 --- a/src/file_gct.c +++ b/src/file_gct.c @@ -42,26 +42,21 @@ const file_hint_t file_hint_gct= { .register_header_check=®ister_header_check_gct }; -static const unsigned char gct_header[9]= { - 'J' , 'L' , 'G' , 'E' , 'N' , '2' , 'X' , 'F' , - 'I' -}; - static int header_check_gct(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(memcmp(&buffer[0], gct_header, sizeof(gct_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_gct.extension; - file_recovery_new->calculated_file_size=2416; - file_recovery_new->data_check=&data_check_size; - file_recovery_new->file_check=&file_check_size; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_gct.extension; + file_recovery_new->calculated_file_size=2416; + file_recovery_new->data_check=&data_check_size; + file_recovery_new->file_check=&file_check_size; + return 1; } static void register_header_check_gct(file_stat_t *file_stat) { + static const unsigned char gct_header[9]= { + 'J' , 'L' , 'G' , 'E' , 'N' , '2' , 'X' , 'F' , + 'I' + }; register_header_check(0, gct_header, sizeof(gct_header), &header_check_gct, file_stat); } diff --git a/src/file_gho.c b/src/file_gho.c index 4e235d08..9c946093 100644 --- a/src/file_gho.c +++ b/src/file_gho.c @@ -30,9 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_gho(file_stat_t *file_stat); -static int header_check_db(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_gho= { .extension="gho", @@ -44,25 +42,18 @@ const file_hint_t file_hint_gho= { .register_header_check=®ister_header_check_gho }; - -static const unsigned char gho_header[3]= { 0xfe, 0xef, 0x01 }; -static const unsigned char gho_header_next[8]= { 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static int header_check_db(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 const unsigned char gho_header_next[8]= { 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + if(memcmp (buffer+8, gho_header_next, sizeof(gho_header_next))!=0) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_gho.extension; + return 1; +} static void register_header_check_gho(file_stat_t *file_stat) { + static const unsigned char gho_header[3]= { 0xfe, 0xef, 0x01 }; register_header_check(0, gho_header,sizeof(gho_header), &header_check_db, file_stat); } - -static int header_check_db(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(memcmp (buffer, gho_header, sizeof(gho_header))==0 && - memcmp (buffer+8, gho_header_next, sizeof(gho_header_next))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_gho.extension; - return 1; - } - return 0; -} - - diff --git a/src/file_gm6.c b/src/file_gm6.c index cda0d555..fc30e29d 100644 --- a/src/file_gm6.c +++ b/src/file_gm6.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_gm6(file_stat_t *file_stat); -static int header_check_gm6(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_gm6= { .extension="gm6", @@ -43,34 +42,28 @@ const file_hint_t file_hint_gm6= { .register_header_check=®ister_header_check_gm6 }; -static const unsigned char gm6_header[8]= { - 0x91, 0xd5, 0x12, 0x00, 0x58, 0x02, 0x00, 0x00 -}; +static int header_check_gm6(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_gm6.extension; + return 1; +} -static const unsigned char gmd_header[8]= { - 0x91, 0xd5, 0x12, 0x00, 0xf4, 0x01, 0x00, 0x00 -}; +static int header_check_gmd(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension="gmd"; + return 1; +} static void register_header_check_gm6(file_stat_t *file_stat) { + static const unsigned char gm6_header[8]= { + 0x91, 0xd5, 0x12, 0x00, 0x58, 0x02, 0x00, 0x00 + }; + static const unsigned char gmd_header[8]= { + 0x91, 0xd5, 0x12, 0x00, 0xf4, 0x01, 0x00, 0x00 + }; register_header_check(0, gm6_header, sizeof(gm6_header), &header_check_gm6, file_stat); - register_header_check(0, gmd_header, sizeof(gmd_header), &header_check_gm6, file_stat); + register_header_check(0, gmd_header, sizeof(gmd_header), &header_check_gmd, file_stat); } - -static int header_check_gm6(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(memcmp(buffer, gm6_header, sizeof(gm6_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_gm6.extension; - return 1; - } - if(memcmp(buffer, gmd_header, sizeof(gmd_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension="gmd"; - return 1; - } - return 0; -} - diff --git a/src/file_gp5.c b/src/file_gp5.c index 41dd7cbc..66908e94 100644 --- a/src/file_gp5.c +++ b/src/file_gp5.c @@ -31,8 +31,6 @@ #include "filegen.h" static void register_header_check_gp5(file_stat_t *file_stat); -static int header_check_gp5(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_gp5(file_recovery_t *file_recovery); const file_hint_t file_hint_gp5= { .extension="gp5", @@ -44,29 +42,6 @@ const file_hint_t file_hint_gp5= { .register_header_check=®ister_header_check_gp5 }; -static const unsigned char gp5_header[23]= { - 0x18, 'F' , 'I' , 'C' , 'H' , 'I' , 'E' , 'R' , - ' ' , 'G' , 'U' , 'I' , 'T' , 'A' , 'R' , ' ' , - 'P' , 'R' , 'O' , ' ' , 'v' , '5' , '.' -}; - -static void register_header_check_gp5(file_stat_t *file_stat) -{ - register_header_check(0, gp5_header, sizeof(gp5_header), &header_check_gp5, file_stat); -} - -static int header_check_gp5(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(memcmp(buffer, gp5_header, sizeof(gp5_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_gp5.extension; - file_recovery_new->file_check=&file_check_gp5; - return 1; - } - return 0; -} - static void file_check_gp5(file_recovery_t *file_recovery) { const unsigned char gp5_footer[13]= { @@ -75,3 +50,21 @@ static void file_check_gp5(file_recovery_t *file_recovery) }; file_search_footer(file_recovery, gp5_footer, sizeof(gp5_footer), 0); } + +static int header_check_gp5(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_gp5.extension; + file_recovery_new->file_check=&file_check_gp5; + return 1; +} + +static void register_header_check_gp5(file_stat_t *file_stat) +{ + static const unsigned char gp5_header[23]= { + 0x18, 'F' , 'I' , 'C' , 'H' , 'I' , 'E' , 'R' , + ' ' , 'G' , 'U' , 'I' , 'T' , 'A' , 'R' , ' ' , + 'P' , 'R' , 'O' , ' ' , 'v' , '5' , '.' + }; + register_header_check(0, gp5_header, sizeof(gp5_header), &header_check_gp5, file_stat); +} diff --git a/src/file_gpg.c b/src/file_gpg.c index daf7d456..154992e6 100644 --- a/src/file_gpg.c +++ b/src/file_gpg.c @@ -264,7 +264,7 @@ static void file_check_gpg(file_recovery_t *file_recovery) if(partial_body_length==0) { - if((buffer[i]&0x80)==0) + if((buffer[i]&0x80)==0) break; /* Invalid */ tag=openpgp_packet_tag(&buffer[i]); if((buffer[i]&0x40)==0) @@ -431,7 +431,7 @@ static int header_check_gpg(const unsigned char *buffer, const unsigned int buff const int old_partial_body_length=partial_body_length; if(partial_body_length==0) { - if((buffer[i]&0x80)==0) + if((buffer[i]&0x80)==0) break; /* Invalid */ packet_tag[nbr]=openpgp_packet_tag(&buffer[i]); if((buffer[i]&0x40)==0) diff --git a/src/file_gsm.c b/src/file_gsm.c index 368fcc83..930ba914 100644 --- a/src/file_gsm.c +++ b/src/file_gsm.c @@ -60,7 +60,7 @@ static data_check_t data_check_gsm(const unsigned char *buffer, const unsigned i const struct block_header *hdr=(const struct block_header *)&buffer[i]; if(hdr->marker < 0xd0 || hdr->marker > 0xdf) return DC_STOP; - file_recovery->calculated_file_size+=sizeof(struct block_header); + file_recovery->calculated_file_size+=sizeof(struct block_header); } return DC_CONTINUE; } @@ -81,7 +81,6 @@ static int header_check_gsm(const unsigned char *buffer, const unsigned int buff } if(i<3) return 0; - reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_gsm.extension; file_recovery_new->min_filesize=sizeof(struct block_header); diff --git a/src/file_hr9.c b/src/file_hr9.c index a725180c..95182017 100644 --- a/src/file_hr9.c +++ b/src/file_hr9.c @@ -30,8 +30,6 @@ #include "filegen.h" static void register_header_check_hr9(file_stat_t *file_stat); -static int header_check_hr9(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_hr9(file_recovery_t *file_recovery); const file_hint_t file_hint_hr9= { .extension="hr9", @@ -43,31 +41,26 @@ const file_hint_t file_hint_hr9= { .register_header_check=®ister_header_check_hr9 }; -static const unsigned char hr9_header[17]= { - 0xc0, 0xde, 0xca, 0xfe, 0x00, 0x00, 0x00, 0x00, - 'H', 'e', 'r', 'e', 'd', 'i', 's', 0x99, - 0x20 -}; - -static void register_header_check_hr9(file_stat_t *file_stat) -{ - register_header_check(0, hr9_header,sizeof(hr9_header), &header_check_hr9, file_stat); -} - -static int header_check_hr9(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(memcmp(buffer,hr9_header,sizeof(hr9_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_hr9.extension; - file_recovery_new->file_check=file_check_hr9; - return 1; - } - return 0; -} - static void file_check_hr9(file_recovery_t *file_recovery) { const unsigned char hr9_footer[4]= {0xc0, 0xde, 0xca, 0xfe}; file_search_footer(file_recovery, hr9_footer, sizeof(hr9_footer), 0x50-4); } + +static int header_check_hr9(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_hr9.extension; + file_recovery_new->file_check=file_check_hr9; + return 1; +} + +static void register_header_check_hr9(file_stat_t *file_stat) +{ + static const unsigned char hr9_header[17]= { + 0xc0, 0xde, 0xca, 0xfe, 0x00, 0x00, 0x00, 0x00, + 'H', 'e', 'r', 'e', 'd', 'i', 's', 0x99, + 0x20 + }; + register_header_check(0, hr9_header,sizeof(hr9_header), &header_check_hr9, file_stat); +} diff --git a/src/file_ifo.c b/src/file_ifo.c index f30939f2..69f42e81 100644 --- a/src/file_ifo.c +++ b/src/file_ifo.c @@ -32,7 +32,6 @@ #include "common.h" static void register_header_check_ifo(file_stat_t *file_stat); -static int header_check_ifo(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_ifo= { .extension="ifo", @@ -44,15 +43,6 @@ const file_hint_t file_hint_ifo= { .register_header_check=®ister_header_check_ifo }; -static const unsigned char ifo_header_vmg[12]= { 'D', 'V', 'D', 'V', 'I', 'D', 'E', 'O', '-', 'V', 'M', 'G'}; -static const unsigned char ifo_header_vts[12]= { 'D', 'V', 'D', 'V', 'I', 'D', 'E', 'O', '-', 'V', 'T', 'S'}; - -static void register_header_check_ifo(file_stat_t *file_stat) -{ - register_header_check(0, ifo_header_vmg, sizeof(ifo_header_vmg), &header_check_ifo, file_stat); - register_header_check(0, ifo_header_vts, sizeof(ifo_header_vts), &header_check_ifo, file_stat); -} - struct ifo_hdr { char name[12]; @@ -62,18 +52,19 @@ struct ifo_hdr static int header_check_ifo(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(memcmp(buffer, ifo_header_vmg, sizeof(ifo_header_vmg))==0 || - memcmp(buffer, ifo_header_vts, sizeof(ifo_header_vts))==0) - { - const struct ifo_hdr *hdr=(const struct ifo_hdr *)buffer; - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_ifo.extension; - file_recovery_new->calculated_file_size=((uint64_t)be32(hdr->ls_IFO)+1)*2048; - file_recovery_new->data_check=&data_check_size; - file_recovery_new->file_check=&file_check_size; - return 1; - } - return 0; + const struct ifo_hdr *hdr=(const struct ifo_hdr *)buffer; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_ifo.extension; + file_recovery_new->calculated_file_size=((uint64_t)be32(hdr->ls_IFO)+1)*2048; + file_recovery_new->data_check=&data_check_size; + file_recovery_new->file_check=&file_check_size; + return 1; } - +static void register_header_check_ifo(file_stat_t *file_stat) +{ + static const unsigned char ifo_header_vmg[12]= { 'D', 'V', 'D', 'V', 'I', 'D', 'E', 'O', '-', 'V', 'M', 'G'}; + static const unsigned char ifo_header_vts[12]= { 'D', 'V', 'D', 'V', 'I', 'D', 'E', 'O', '-', 'V', 'T', 'S'}; + register_header_check(0, ifo_header_vmg, sizeof(ifo_header_vmg), &header_check_ifo, file_stat); + register_header_check(0, ifo_header_vts, sizeof(ifo_header_vts), &header_check_ifo, file_stat); +} diff --git a/src/file_imb.c b/src/file_imb.c index 5e330b7d..76b4fc05 100644 --- a/src/file_imb.c +++ b/src/file_imb.c @@ -30,9 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_imb(file_stat_t *file_stat); -static int header_check_imb(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_imb= { .extension="imb", @@ -44,21 +42,16 @@ const file_hint_t file_hint_imb= { .register_header_check=®ister_header_check_imb }; -static const unsigned char imb_header[15]= { 0x00, 0x00, 0x00, 'I','n','c','r','e','d','i','m','a','i','l',' '}; +static int header_check_imb(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_imb.extension; + file_recovery_new->min_filesize=16; + return 1; +} static void register_header_check_imb(file_stat_t *file_stat) { + static const unsigned char imb_header[15]= { 0x00, 0x00, 0x00, 'I','n','c','r','e','d','i','m','a','i','l',' '}; register_header_check(1, imb_header,sizeof(imb_header), &header_check_imb, file_stat); } - -static int header_check_imb(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(memcmp(buffer+1,imb_header,sizeof(imb_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_imb.extension; - file_recovery_new->min_filesize=16; - return 1; - } - return 0; -} diff --git a/src/file_indd.c b/src/file_indd.c index eb2bba9e..8016389b 100644 --- a/src/file_indd.c +++ b/src/file_indd.c @@ -56,11 +56,6 @@ const file_hint_t file_hint_indd= { /* See http://www.adobe.com/content/dam/Adobe/en/devnet/xmp/pdfs/cs6/XMPSpecificationPart3.pdf * for more information about the file format */ -static const unsigned char indd_header[24]={ - 0x06, 0x06, 0xed, 0xf5, 0xd8, 0x1d, 0x46, 0xe5, - 0xbd, 0x31, 0xef, 0xe7, 0xfe, 0x74, 0xb7, 0x1d, - 0x44, 0x4f, 0x43, 0x55, 0x4d, 0x45, 0x4e, 0x54 }; - // Headers are: DE393979-5188-4b6c-8E63-EEF8AEE0DD38 // Trailers are: FDCEDB70-F786-4b4f-A4D3-C728B3417106 static const unsigned char kINDDContigObjHeaderGUID [16] = @@ -128,8 +123,6 @@ static int header_check_indd(const unsigned char *buffer, const unsigned int buf const struct InDesignMasterPage *hdr; const struct InDesignMasterPage *hdr0 = (const struct InDesignMasterPage *)buffer; const struct InDesignMasterPage *hdr1 = (const struct InDesignMasterPage *)&buffer[4096]; - if(memcmp(hdr1, indd_header, sizeof(indd_header))!=0) - return 0; hdr=(le64(hdr0->fSequenceNumber) > le64(hdr1->fSequenceNumber) ? hdr0 : hdr1); if(hdr->fObjectStreamEndian!=1 && hdr->fObjectStreamEndian!=2) return 0; @@ -152,5 +145,9 @@ static int header_check_indd(const unsigned char *buffer, const unsigned int buf static void register_header_check_indd(file_stat_t *file_stat) { + static const unsigned char indd_header[24]={ + 0x06, 0x06, 0xed, 0xf5, 0xd8, 0x1d, 0x46, 0xe5, + 0xbd, 0x31, 0xef, 0xe7, 0xfe, 0x74, 0xb7, 0x1d, + 0x44, 0x4f, 0x43, 0x55, 0x4d, 0x45, 0x4e, 0x54 }; register_header_check(0, indd_header,sizeof(indd_header), &header_check_indd, file_stat); } diff --git a/src/file_iso.c b/src/file_iso.c index c94e7d88..c9df0d39 100644 --- a/src/file_iso.c +++ b/src/file_iso.c @@ -44,18 +44,10 @@ const file_hint_t file_hint_iso= { .register_header_check=®ister_header_check_iso }; -static const unsigned char iso_header[6]= { 0x01, 'C', 'D', '0', '0', '1'}; - -static void register_header_check_iso(file_stat_t *file_stat) -{ - register_header_check(0x8000, iso_header,sizeof(iso_header), &header_check_db, file_stat); -} - static int header_check_db(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_size<0x8000+512) /* +2048 for the full mapping */ return 0; - if(memcmp (&buffer[0x8000], iso_header, sizeof(iso_header))==0) { const struct iso_primary_descriptor *iso1=(const struct iso_primary_descriptor*)&buffer[0x8000]; const unsigned int volume_space_size=iso1->volume_space_size[0] | (iso1->volume_space_size[1]<<8) | (iso1->volume_space_size[2]<<16) | (iso1->volume_space_size[3]<<24); @@ -75,10 +67,16 @@ static int header_check_db(const unsigned char *buffer, const unsigned int buffe file_recovery_new->min_filesize=0x8000+512; return 1; } - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_iso.extension; - file_recovery_new->min_filesize=0x8000+512; - return 1; } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_iso.extension; + file_recovery_new->min_filesize=0x8000+512; + return 1; } + +static void register_header_check_iso(file_stat_t *file_stat) +{ + static const unsigned char iso_header[6]= { 0x01, 'C', 'D', '0', '0', '1'}; + register_header_check(0x8000, iso_header,sizeof(iso_header), &header_check_db, file_stat); +} + diff --git a/src/file_jpg.c b/src/file_jpg.c index dd675707..b6be793c 100644 --- a/src/file_jpg.c +++ b/src/file_jpg.c @@ -794,7 +794,7 @@ static void jpeg_session_start(struct jpeg_session_struct *jpeg_session) { log_critical("jpeg_session_start: fseek failed.\n"); } - jpeg_create_decompress(&jpeg_session->cinfo); + jpeg_create_decompress(&jpeg_session->cinfo); jpeg_testdisk_src(&jpeg_session->cinfo, jpeg_session->handle, jpeg_session->offset, jpeg_session->blocksize); (void) jpeg_read_header(&jpeg_session->cinfo, TRUE); jpeg_session->cinfo.two_pass_quantize = FALSE; @@ -831,7 +831,7 @@ static uint64_t jpg_xy_to_offset(FILE *infile, const unsigned int x, const unsig jerr.pub.output_message = my_output_message; jerr.pub.error_exit = my_error_exit; /* Establish the setjmp return context for my_error_exit to use. */ - if (setjmp(jerr.setjmp_buffer)) + if (setjmp(jerr.setjmp_buffer)) { if(jpeg_session.frame!=NULL && jpeg_session.cinfo.output_scanline >= y) { @@ -1109,7 +1109,7 @@ static uint64_t jpg_check_thumb(FILE *infile, const uint64_t offset, const unsig jerr.pub.trace_level= 3; #endif /* Establish the setjmp return context for my_error_exit to use. */ - if (setjmp(jerr.setjmp_buffer)) + if (setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object and return. @@ -1176,7 +1176,7 @@ static void jpg_check_picture(file_recovery_t *file_recovery) jerr.pub.trace_level= 3; #endif /* Establish the setjmp return context for my_error_exit to use. */ - if (setjmp(jerr.setjmp_buffer)) + if (setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object and return. diff --git a/src/file_kdb.c b/src/file_kdb.c index 2b536b6e..0eac1f68 100644 --- a/src/file_kdb.c +++ b/src/file_kdb.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_kdb(file_stat_t *file_stat); -static int header_check_kdb(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_kdb= { .extension="kdb", @@ -43,20 +42,16 @@ const file_hint_t file_hint_kdb= { .register_header_check=®ister_header_check_kdb }; -static const unsigned char kdb_header[8]= {0x03, 0xd9, 0xa2, 0x9a, 0x65, 0xfb, 0x4b, 0xb5}; -static void register_header_check_kdb(file_stat_t *file_stat) -{ - register_header_check(0, kdb_header,sizeof(kdb_header), &header_check_kdb, file_stat); -} - static int header_check_kdb(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(memcmp(buffer, kdb_header, sizeof(kdb_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_kdb.extension; - file_recovery_new->min_filesize=124; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_kdb.extension; + file_recovery_new->min_filesize=124; + return 1; +} + +static void register_header_check_kdb(file_stat_t *file_stat) +{ + static const unsigned char kdb_header[8]= {0x03, 0xd9, 0xa2, 0x9a, 0x65, 0xfb, 0x4b, 0xb5}; + register_header_check(0, kdb_header,sizeof(kdb_header), &header_check_kdb, file_stat); } diff --git a/src/file_lit.c b/src/file_lit.c index d4f18cd4..ca66bdb7 100644 --- a/src/file_lit.c +++ b/src/file_lit.c @@ -42,24 +42,19 @@ const file_hint_t file_hint_lit= { .register_header_check=®ister_header_check_lit }; -static const unsigned char lit_header[12]= { - 'I' , 'T' , 'O' , 'L' , 'I' , 'T' , 'L' , 'S' , - 0x01, 0x00, 0x00, 0x00 -}; - static int header_check_lit(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) { /* TODO: file may be a chm (MS Help) or .lit e-book */ - if(memcmp(&buffer[0], lit_header, sizeof(lit_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_lit.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_lit.extension; + return 1; } static void register_header_check_lit(file_stat_t *file_stat) { + static const unsigned char lit_header[12]= { + 'I' , 'T' , 'O' , 'L' , 'I' , 'T' , 'L' , 'S' , + 0x01, 0x00, 0x00, 0x00 + }; register_header_check(0, lit_header, sizeof(lit_header), &header_check_lit, file_stat); } diff --git a/src/file_lnk.c b/src/file_lnk.c index 542be84f..a5c698ea 100644 --- a/src/file_lnk.c +++ b/src/file_lnk.c @@ -47,11 +47,6 @@ const file_hint_t file_hint_lnk= { .register_header_check=®ister_header_check_lnk }; -static const unsigned char lnk_header[20]= { - 'L', 0x00, 0x00, 0x00, /* magic */ - 0x01, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 /* GUID */ - }; static const unsigned char lnk_reserved[10]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -83,156 +78,159 @@ struct lnk_header_s { #define SCF_COMPONENT 0x1000 /* */ -static void register_header_check_lnk(file_stat_t *file_stat) -{ - register_header_check(0, lnk_header,sizeof(lnk_header), &header_check_lnk, file_stat); -} static int header_check_lnk(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(memcmp(buffer, lnk_header, sizeof(lnk_header))==0 && - memcmp(&buffer[0x42], lnk_reserved, sizeof(lnk_reserved))==0) - { - const struct lnk_header_s* lnk_head=(const struct lnk_header_s*)buffer; - const uint32_t flags=le32(lnk_head->flags); - unsigned int i=0x4c; /* .LNK File Header */ - unsigned int len; - if((flags&SCF_PIDL)!=0) - { /* The Shell Item Id List */ - len=buffer[i]+(buffer[i+1]<<8); + const struct lnk_header_s* lnk_head=(const struct lnk_header_s*)buffer; + const uint32_t flags=le32(lnk_head->flags); + unsigned int i=0x4c; /* .LNK File Header */ + unsigned int len; + if(memcmp(&buffer[0x42], lnk_reserved, sizeof(lnk_reserved))!=0) + return 0; + if((flags&SCF_PIDL)!=0) + { /* The Shell Item Id List */ + len=buffer[i]+(buffer[i+1]<<8); #ifdef DEBUG_LNK - log_debug("LNK Shell Item Id List at 0x%04x=%04x\n", - i, len); + log_debug("LNK Shell Item Id List at 0x%04x=%04x\n", + i, len); #endif - i+=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+4>=buffer_size) - return 0; - if((flags&SCF_LOCATION)!=0) - { /* File location info */ - len=buffer[i] + (buffer[i+1]<<8) + (buffer[i+2]<<16) + (buffer[i+3]<<24); -#ifdef DEBUG_LNK - log_debug("LNK File location info at 0x%04x=%04x\n", i, len); -#endif - i+=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+2>=buffer_size) - return 0; - if((flags&SCF_DESCRIPTION)!=0) - { /* Description string */ - len=buffer[i]+(buffer[i+1]<<8); -#ifdef DEBUG_LNK - log_debug("LNK description string at 0x%04x=%04x\n", i, len); -#endif - i+=2; - if((flags& SCF_UNICODE)!=0) - len*=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+2>=buffer_size) - return 0; - if((flags&SCF_RELATIVE)!=0) - { /* Relative path */ - len=buffer[i]+(buffer[i+1]<<8); -#ifdef DEBUG_LNK - log_debug("LNK relative path at 0x%04x=%04x\n", i, len); -#endif - i+=2; - if((flags& SCF_UNICODE)!=0) - len*=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+2>=buffer_size) - return 0; - if((flags&SCF_WORKDIR)!=0) - { /* Working directory */ - len=buffer[i]+(buffer[i+1]<<8); -#ifdef DEBUG_LNK - log_debug("LNK Working directory at 0x%04x=%04x\n", i, len); -#endif - i+=2; - if((flags& SCF_UNICODE)!=0) - len*=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+2>=buffer_size) - return 0; - if((flags&SCF_ARGS)!=0) - { /* Command line string */ - len=buffer[i]+(buffer[i+1]<<8); -#ifdef DEBUG_LNK - log_debug("LNK Command line string at 0x%04x=%04x\n", i, len); -#endif - i+=2; - if((flags& SCF_UNICODE)!=0) - len*=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+2>=buffer_size) - return 0; - if((flags&SCF_CUSTOMICON)!=0) - { /* Icon filename string */ - len=buffer[i]+(buffer[i+1]<<8); -#ifdef DEBUG_LNK - log_debug("LNK Icon filename string at 0x%04x=%04x\n", i, len); -#endif - i+=2; - if((flags& SCF_UNICODE)!=0) - len*=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+2>=buffer_size) - return 0; - if((flags&SCF_PRODUCT)!=0) - { - len=buffer[i]+(buffer[i+1]<<8); -#ifdef DEBUG_LNK - log_debug("LNK Icon product at 0x%04x=%04x\n", i, len); -#endif - i+=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+2>=buffer_size) - return 0; - if((flags&SCF_COMPONENT)!=0) - { - len=buffer[i]+(buffer[i+1]<<8); -#ifdef DEBUG_LNK - log_debug("LNK Icon component at 0x%04x=%04x\n", i, len); -#endif - i+=2; - i+=len; - } - /* avoid out of bound read access */ - if(i+4>=buffer_size) - return 0; - /* Extra stuff */ + i+=2; + i+=len; + } + /* avoid out of bound read access */ + if(i+4>=buffer_size) + return 0; + if((flags&SCF_LOCATION)!=0) + { /* File location info */ len=buffer[i] + (buffer[i+1]<<8) + (buffer[i+2]<<16) + (buffer[i+3]<<24); #ifdef DEBUG_LNK - log_debug("LNK extra stuff at 0x%04x=%04x\n", i, len); + log_debug("LNK File location info at 0x%04x=%04x\n", i, len); #endif - i+=4; + i+=2; i+=len; -#ifdef DEBUG_LNK - log_debug("LNK size %u (0x%04x)\n", i, i); -#endif - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_lnk.extension; - file_recovery_new->calculated_file_size=i; - file_recovery_new->data_check=&data_check_size; - file_recovery_new->file_check=&file_check_size; -// file_recovery_new->time=td_ntfs2utc(le64(lnk_head->ctime)); - return 1; } - return 0; + /* avoid out of bound read access */ + if(i+2>=buffer_size) + return 0; + if((flags&SCF_DESCRIPTION)!=0) + { /* Description string */ + len=buffer[i]+(buffer[i+1]<<8); +#ifdef DEBUG_LNK + log_debug("LNK description string at 0x%04x=%04x\n", i, len); +#endif + i+=2; + if((flags& SCF_UNICODE)!=0) + len*=2; + i+=len; + } + /* avoid out of bound read access */ + if(i+2>=buffer_size) + return 0; + if((flags&SCF_RELATIVE)!=0) + { /* Relative path */ + len=buffer[i]+(buffer[i+1]<<8); +#ifdef DEBUG_LNK + log_debug("LNK relative path at 0x%04x=%04x\n", i, len); +#endif + i+=2; + if((flags& SCF_UNICODE)!=0) + len*=2; + i+=len; + } + /* avoid out of bound read access */ + if(i+2>=buffer_size) + return 0; + if((flags&SCF_WORKDIR)!=0) + { /* Working directory */ + len=buffer[i]+(buffer[i+1]<<8); +#ifdef DEBUG_LNK + log_debug("LNK Working directory at 0x%04x=%04x\n", i, len); +#endif + i+=2; + if((flags& SCF_UNICODE)!=0) + len*=2; + i+=len; + } + /* avoid out of bound read access */ + if(i+2>=buffer_size) + return 0; + if((flags&SCF_ARGS)!=0) + { /* Command line string */ + len=buffer[i]+(buffer[i+1]<<8); +#ifdef DEBUG_LNK + log_debug("LNK Command line string at 0x%04x=%04x\n", i, len); +#endif + i+=2; + if((flags& SCF_UNICODE)!=0) + len*=2; + i+=len; + } + /* avoid out of bound read access */ + if(i+2>=buffer_size) + return 0; + if((flags&SCF_CUSTOMICON)!=0) + { /* Icon filename string */ + len=buffer[i]+(buffer[i+1]<<8); +#ifdef DEBUG_LNK + log_debug("LNK Icon filename string at 0x%04x=%04x\n", i, len); +#endif + i+=2; + if((flags& SCF_UNICODE)!=0) + len*=2; + i+=len; + } + /* avoid out of bound read access */ + if(i+2>=buffer_size) + return 0; + if((flags&SCF_PRODUCT)!=0) + { + len=buffer[i]+(buffer[i+1]<<8); +#ifdef DEBUG_LNK + log_debug("LNK Icon product at 0x%04x=%04x\n", i, len); +#endif + i+=2; + i+=len; + } + /* avoid out of bound read access */ + if(i+2>=buffer_size) + return 0; + if((flags&SCF_COMPONENT)!=0) + { + len=buffer[i]+(buffer[i+1]<<8); +#ifdef DEBUG_LNK + log_debug("LNK Icon component at 0x%04x=%04x\n", i, len); +#endif + i+=2; + i+=len; + } + /* avoid out of bound read access */ + if(i+4>=buffer_size) + return 0; + /* Extra stuff */ + len=buffer[i] + (buffer[i+1]<<8) + (buffer[i+2]<<16) + (buffer[i+3]<<24); +#ifdef DEBUG_LNK + log_debug("LNK extra stuff at 0x%04x=%04x\n", i, len); +#endif + i+=4; + i+=len; +#ifdef DEBUG_LNK + log_debug("LNK size %u (0x%04x)\n", i, i); +#endif + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_lnk.extension; + file_recovery_new->calculated_file_size=i; + file_recovery_new->data_check=&data_check_size; + file_recovery_new->file_check=&file_check_size; + // file_recovery_new->time=td_ntfs2utc(le64(lnk_head->ctime)); + return 1; +} + +static void register_header_check_lnk(file_stat_t *file_stat) +{ + static const unsigned char lnk_header[20]= { + 'L', 0x00, 0x00, 0x00, /* magic */ + 0x01, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 /* GUID */ + }; + register_header_check(0, lnk_header,sizeof(lnk_header), &header_check_lnk, file_stat); } diff --git a/src/file_logic.c b/src/file_logic.c index 1e418d66..ac3bc5aa 100644 --- a/src/file_logic.c +++ b/src/file_logic.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_logic(file_stat_t *file_stat); -static int header_check_logic(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_logic= { .extension="logic", @@ -43,22 +42,17 @@ const file_hint_t file_hint_logic= { .register_header_check=®ister_header_check_logic }; -static const unsigned char logic_header[12]= { - 0xab, 0xc0, 0x47, 0x13, 0x05, 0x17, 0x00, 0x15, 0x00, 0x04, 0x00, 0x24 -}; +static int header_check_logic(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_logic.extension; + return 1; +} static void register_header_check_logic(file_stat_t *file_stat) { + static const unsigned char logic_header[12]= { + 0xab, 0xc0, 0x47, 0x13, 0x05, 0x17, 0x00, 0x15, 0x00, 0x04, 0x00, 0x24 + }; register_header_check(0, logic_header,sizeof(logic_header), &header_check_logic, file_stat); } - -static int header_check_logic(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(memcmp(buffer,logic_header,sizeof(logic_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_logic.extension; - return 1; - } - return 0; -} diff --git a/src/file_lso.c b/src/file_lso.c index 5cfd088d..02166721 100644 --- a/src/file_lso.c +++ b/src/file_lso.c @@ -31,8 +31,6 @@ #include "filegen.h" static void register_header_check_lso(file_stat_t *file_stat); -static int header_check_lso(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_lso(file_recovery_t *file_recovery); const file_hint_t file_hint_lso= { .extension="lso", @@ -44,30 +42,25 @@ const file_hint_t file_hint_lso= { .register_header_check=®ister_header_check_lso }; -static const unsigned char lso_header[14]= { - 0x13, 'G' , 0xc0, 0xab, 0x17, 0x05, 0x15, 0x00, - 0x03, 0x00, 0x24, 0x00, 0x24, 0x00 -}; - -static void register_header_check_lso(file_stat_t *file_stat) -{ - register_header_check(0, lso_header, sizeof(lso_header), &header_check_lso, file_stat); -} - -static int header_check_lso(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(memcmp(buffer, lso_header, sizeof(lso_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_lso.extension; - file_recovery_new->file_check=&file_check_lso; - return 1; - } - return 0; -} - static void file_check_lso(file_recovery_t *file_recovery) { const unsigned char lso_footer[6]= {0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x7F}; file_search_footer(file_recovery, lso_footer, sizeof(lso_footer), 0x46); } + +static int header_check_lso(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_lso.extension; + file_recovery_new->file_check=&file_check_lso; + return 1; +} + +static void register_header_check_lso(file_stat_t *file_stat) +{ + static const unsigned char lso_header[14]= { + 0x13, 'G' , 0xc0, 0xab, 0x17, 0x05, 0x15, 0x00, + 0x03, 0x00, 0x24, 0x00, 0x24, 0x00 + }; + register_header_check(0, lso_header, sizeof(lso_header), &header_check_lso, file_stat); +} diff --git a/src/file_lxo.c b/src/file_lxo.c index 10dc3bcc..71b4794e 100644 --- a/src/file_lxo.c +++ b/src/file_lxo.c @@ -80,7 +80,7 @@ static int header_check_lxo(const unsigned char *buffer, const unsigned int buff static void register_header_check_lxo(file_stat_t *file_stat) { static const unsigned char lxo_header[4]= { - 'F' , 'O' , 'R' , 'M' + 'F' , 'O' , 'R' , 'M' }; register_header_check(0, lxo_header, sizeof(lxo_header), &header_check_lxo, file_stat); } diff --git a/src/file_lzo.c b/src/file_lzo.c index 70011248..4aa5a6e9 100644 --- a/src/file_lzo.c +++ b/src/file_lzo.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_lzo(file_stat_t *file_stat); -static int header_check_lzo(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_lzo= { .extension="lzo", @@ -43,23 +42,18 @@ const file_hint_t file_hint_lzo= { .register_header_check=®ister_header_check_lzo }; -static const unsigned char lzo_header[9]= { - 0x89, 'L', 'Z', 'O', 0x00, 0x0d, 0x0a, 0x1a, - 0x0a -}; +static int header_check_lzo(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_lzo.extension; + return 1; +} static void register_header_check_lzo(file_stat_t *file_stat) { + static const unsigned char lzo_header[9]= { + 0x89, 'L', 'Z', 'O', 0x00, 0x0d, 0x0a, 0x1a, + 0x0a + }; register_header_check(0, lzo_header, sizeof(lzo_header), &header_check_lzo, file_stat); } - -static int header_check_lzo(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(memcmp(buffer, lzo_header, sizeof(lzo_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_lzo.extension; - return 1; - } - return 0; -} diff --git a/src/file_mat.c b/src/file_mat.c index c5de6459..93bb002a 100644 --- a/src/file_mat.c +++ b/src/file_mat.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_mat(file_stat_t *file_stat); -static int header_check_mat(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_mat= { .extension="mat", @@ -43,20 +42,12 @@ const file_hint_t file_hint_mat= { .register_header_check=®ister_header_check_mat }; -static const unsigned char mat_header[7]= {'M', 'A', 'T', 'L', 'A', 'B', ' '}; - -static void register_header_check_mat(file_stat_t *file_stat) -{ - register_header_check(0, mat_header,sizeof(mat_header), &header_check_mat, file_stat); -} - static int header_check_mat(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 unsigned char mat_le[4]={0x00, 0x01, 'I', 'M'}; const unsigned char mat_be[4]={0x01, 0x00, 'M', 'I'}; - if(memcmp(buffer,mat_header,sizeof(mat_header))==0 && - (memcmp(&buffer[0x7c], mat_le, sizeof(mat_le))==0 || - memcmp(&buffer[0x7c], mat_be, sizeof(mat_be))==0)) + if(memcmp(&buffer[0x7c], mat_le, sizeof(mat_le))==0 || + memcmp(&buffer[0x7c], mat_be, sizeof(mat_be))==0) { reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_mat.extension; @@ -64,3 +55,9 @@ static int header_check_mat(const unsigned char *buffer, const unsigned int buff } return 0; } + +static void register_header_check_mat(file_stat_t *file_stat) +{ + static const unsigned char mat_header[7]= {'M', 'A', 'T', 'L', 'A', 'B', ' '}; + register_header_check(0, mat_header,sizeof(mat_header), &header_check_mat, file_stat); +} diff --git a/src/file_mcd.c b/src/file_mcd.c index ae52af96..c07fef83 100644 --- a/src/file_mcd.c +++ b/src/file_mcd.c @@ -30,7 +30,6 @@ #include "filegen.h" static void register_header_check_mcd(file_stat_t *file_stat); -static int header_check_mcd(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_mcd= { .extension="mcd", @@ -42,21 +41,17 @@ const file_hint_t file_hint_mcd= { .register_header_check=®ister_header_check_mcd }; -static const unsigned char mcd_header[11]= { 'V', 'e','c','t','o','r','W','o','r','k','s'}; +static int header_check_mcd(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]!=0x00 || buffer[1]!=0x00) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_mcd.extension; + return 1; +} static void register_header_check_mcd(file_stat_t *file_stat) { + static const unsigned char mcd_header[11]= { 'V', 'e','c','t','o','r','W','o','r','k','s'}; register_header_check(0x0e, mcd_header,sizeof(mcd_header), &header_check_mcd, file_stat); } - -static int header_check_mcd(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]==0x00 && buffer[1]==0x00 && - memcmp(buffer+0x0e,mcd_header,sizeof(mcd_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_mcd.extension; - return 1; - } - return 0; -} diff --git a/src/file_mdb.c b/src/file_mdb.c index 8753a404..1401e186 100644 --- a/src/file_mdb.c +++ b/src/file_mdb.c @@ -30,10 +30,8 @@ #include "types.h" #include "filegen.h" - static void register_header_check_mdb(file_stat_t *file_stat); static void register_header_check_accdb(file_stat_t *file_stat); -static int header_check_db(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_mdb= { .extension="mdb", @@ -55,36 +53,28 @@ const file_hint_t file_hint_accdb= { .register_header_check=®ister_header_check_accdb }; +static int header_check_accdb(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_accdb.extension; + return 1; +} -static const unsigned char mdb_header[]= { 0x00, 0x01, 0x00, 0x00, 'S', 't', 'a', 'n', 'd','a','r','d',' ','J','e','t',' ', 'D','B', 0x00}; - -static const unsigned char accdb_header[]= { 0x00, 0x01, 0x00, 0x00, 'S', 't', 'a', 'n', 'd','a','r','d',' ','A','C','E',' ', 'D','B', 0x00}; +static int header_check_mdb(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_mdb.extension; + return 1; +} static void register_header_check_mdb(file_stat_t *file_stat) { - register_header_check(0, mdb_header,sizeof(mdb_header), &header_check_db, file_stat); + static const unsigned char mdb_header[]= { 0x00, 0x01, 0x00, 0x00, 'S', 't', 'a', 'n', 'd','a','r','d',' ','J','e','t',' ', 'D','B', 0x00}; + register_header_check(0, mdb_header,sizeof(mdb_header), &header_check_mdb, file_stat); } static void register_header_check_accdb(file_stat_t *file_stat) { - register_header_check(0, accdb_header,sizeof(accdb_header), &header_check_db, file_stat); + static const unsigned char accdb_header[]= { 0x00, 0x01, 0x00, 0x00, 'S', 't', 'a', 'n', 'd','a','r','d',' ','A','C','E',' ', 'D','B', 0x00}; + register_header_check(0, accdb_header,sizeof(accdb_header), &header_check_accdb, file_stat); } - -static int header_check_db(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(memcmp (buffer, mdb_header, sizeof(mdb_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_mdb.extension; - return 1; - } - else if(memcmp (buffer, accdb_header, sizeof(accdb_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_accdb.extension; - return 1; - } - return 0; -} - - diff --git a/src/file_mfa.c b/src/file_mfa.c index 6afd6095..f7659495 100644 --- a/src/file_mfa.c +++ b/src/file_mfa.c @@ -29,10 +29,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_mfa(file_stat_t *file_stat); -static int header_check_mfa(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_mfa(file_recovery_t *file_recovery); const file_hint_t file_hint_mfa= { .extension="mfa", @@ -44,27 +41,22 @@ const file_hint_t file_hint_mfa= { .register_header_check=®ister_header_check_mfa }; -static const unsigned char mfa_header[8]= { 'M', 'M', 'F', '2', 0x04, 0x00, 0x00, 0x00}; - -static void register_header_check_mfa(file_stat_t *file_stat) -{ - register_header_check(0, mfa_header,sizeof(mfa_header), &header_check_mfa, file_stat); -} - -static int header_check_mfa(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(memcmp(buffer,mfa_header,sizeof(mfa_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->file_check=file_check_mfa; - file_recovery_new->extension=file_hint_mfa.extension; - return 1; - } - return 0; -} - static void file_check_mfa(file_recovery_t *file_recovery) { const unsigned char mfa_footer[5]= {'!','D','N','E', '!'}; file_search_footer(file_recovery, mfa_footer, sizeof(mfa_footer), 0x84); } + +static int header_check_mfa(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->file_check=file_check_mfa; + file_recovery_new->extension=file_hint_mfa.extension; + return 1; +} + +static void register_header_check_mfa(file_stat_t *file_stat) +{ + static const unsigned char mfa_header[8]= { 'M', 'M', 'F', '2', 0x04, 0x00, 0x00, 0x00}; + register_header_check(0, mfa_header,sizeof(mfa_header), &header_check_mfa, file_stat); +} diff --git a/src/file_mfg.c b/src/file_mfg.c index 60e0b78a..3cf90325 100644 --- a/src/file_mfg.c +++ b/src/file_mfg.c @@ -30,10 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_mfg(file_stat_t *file_stat); -static int header_check_mfg(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_mfg(file_recovery_t *file_recovery); const file_hint_t file_hint_mfg= { .extension="mfg", @@ -45,27 +42,6 @@ const file_hint_t file_hint_mfg= { .register_header_check=®ister_header_check_mfg }; -static const unsigned char mfg_header[16]= { - '#', 'U', 'G', 'C', ':', '2', ' ', 'M', - 'F', 'G', '_', 'A', 'S', 'S', 'E', 'M'}; - -static void register_header_check_mfg(file_stat_t *file_stat) -{ - register_header_check(0, mfg_header,sizeof(mfg_header), &header_check_mfg, file_stat); -} - -static int header_check_mfg(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(memcmp(buffer,mfg_header,sizeof(mfg_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->file_check=file_check_mfg; - file_recovery_new->extension=file_hint_mfg.extension; - return 1; - } - return 0; -} - static void file_check_mfg(file_recovery_t *file_recovery) { const unsigned char mfg_footer[11]= { @@ -73,3 +49,20 @@ static void file_check_mfg(file_recovery_t *file_recovery) 'U', 'G', 'C'}; file_search_footer(file_recovery, mfg_footer, sizeof(mfg_footer), 1); } + +static int header_check_mfg(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->file_check=file_check_mfg; + file_recovery_new->extension=file_hint_mfg.extension; + return 1; +} + +static void register_header_check_mfg(file_stat_t *file_stat) +{ + static const unsigned char mfg_header[16]= { + '#', 'U', 'G', 'C', ':', '2', ' ', 'M', + 'F', 'G', '_', 'A', 'S', 'S', 'E', 'M'}; + + register_header_check(0, mfg_header,sizeof(mfg_header), &header_check_mfg, file_stat); +} diff --git a/src/file_mft.c b/src/file_mft.c index 9b28c213..40bd1f29 100644 --- a/src/file_mft.c +++ b/src/file_mft.c @@ -70,7 +70,7 @@ static int header_check_mft(const unsigned char *buffer, const unsigned int buff const unsigned int attrs_offset = le16(mft_rec->attrs_offset); const unsigned int bytes_in_use = le32(mft_rec->bytes_in_use); const unsigned int bytes_allocated = le32(mft_rec->bytes_allocated); - if(!(memcmp(buffer,"FILE",4)==0 && + if(!(memcmp(buffer,"FILE",4)==0 && usa_ofs+usa_count <= attrs_offset && 42 <= attrs_offset && attrs_offset%8==0 && diff --git a/src/file_mig.c b/src/file_mig.c index eb9c29dc..d9eb5c1b 100644 --- a/src/file_mig.c +++ b/src/file_mig.c @@ -101,24 +101,20 @@ static void file_check_mig(file_recovery_t *file_recovery) } } -static const unsigned char mig_header[8]= { - '1' , 'g' , 'i' , 'M' , 0x02, 0x00, 0x00, 0x00 -}; - static int header_check_mig(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(memcmp(&buffer[0], mig_header, sizeof(mig_header))==0 && - memcmp(&buffer[0x34], "MRTS", 4)==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_mig.extension; - file_recovery_new->file_check=&file_check_mig; - return 1; - } - return 0; + if(memcmp(&buffer[0x34], "MRTS", 4)!=0) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_mig.extension; + file_recovery_new->file_check=&file_check_mig; + return 1; } static void register_header_check_mig(file_stat_t *file_stat) { + static const unsigned char mig_header[8]= { + '1' , 'g' , 'i' , 'M' , 0x02, 0x00, 0x00, 0x00 + }; register_header_check(0, mig_header, sizeof(mig_header), &header_check_mig, file_stat); } diff --git a/src/file_mk5.c b/src/file_mk5.c index 44d11fd0..e6882beb 100644 --- a/src/file_mk5.c +++ b/src/file_mk5.c @@ -30,7 +30,6 @@ #include "filegen.h" static void register_header_check_mk5(file_stat_t *file_stat); -static int header_check_mk5(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_mk5= { .extension="mk5", @@ -42,22 +41,18 @@ const file_hint_t file_hint_mk5= { .register_header_check=®ister_header_check_mk5 }; -static const unsigned char mk5_header[4]= { 0x36, 0xff, 0xff, 0xff }; -static const unsigned char mk5_header2[4]= { 0x00, 0x40, 0x1c, 0x46 }; +static int header_check_mk5(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 const unsigned char mk5_header2[4]= { 0x00, 0x40, 0x1c, 0x46 }; + if(memcmp(buffer+0x1c,mk5_header2,sizeof(mk5_header2))!=0) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_mk5.extension; + return 1; +} static void register_header_check_mk5(file_stat_t *file_stat) { + static const unsigned char mk5_header[4]= { 0x36, 0xff, 0xff, 0xff }; register_header_check(0, mk5_header,sizeof(mk5_header), &header_check_mk5, file_stat); } - -static int header_check_mk5(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(memcmp(buffer,mk5_header,sizeof(mk5_header))==0 && - memcmp(buffer+0x1c,mk5_header2,sizeof(mk5_header2))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_mk5.extension; - return 1; - } - return 0; -} diff --git a/src/file_mov.c b/src/file_mov.c index 4cc4b051..62df9be9 100644 --- a/src/file_mov.c +++ b/src/file_mov.c @@ -287,8 +287,8 @@ static data_check_t data_check_mov(const unsigned char *buffer, const unsigned i #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, - buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7], - buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7], + buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7], + buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7], (long long unsigned)atom_size, (long long unsigned)file_recovery->calculated_file_size); #endif diff --git a/src/file_mp3.c b/src/file_mp3.c index 51810124..0672a574 100644 --- a/src/file_mp3.c +++ b/src/file_mp3.c @@ -3,17 +3,17 @@ File: file_mp3.c Copyright (C) 1998-2008 Christophe GRENIER - + This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -107,7 +107,7 @@ static const unsigned int bit_rate_table[4][4][16]= /* MPEG_L3 */ { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0}, /* MPEG_L2 */ - { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0}, + { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0}, /* MPEG_L1 */ { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 294, 416, 448, 0} }, @@ -305,10 +305,10 @@ static data_check_t data_check_mp3(const unsigned char *buffer, const unsigned i /* Lyrics3 tag http://www.id3.org/Lyrics3 Lyrics3 v2.00 tag http://www.id3.org/Lyrics3v2 - Lyrics Header : + Lyrics Header : 'LYRICSBEGIN' (both version) - Lyrics Footer : - 'LYRICSEND' Lyrics3 tags + Lyrics Footer : + 'LYRICSEND' Lyrics3 tags 'LYRICS200' Lyrics3v2 Tags The maximum length of the lyrics is 5100 bytes for Lyrics3 and 4096 bytes for Lyrics3 v2. */ @@ -324,7 +324,7 @@ static data_check_t data_check_mp3(const unsigned char *buffer, const unsigned i { file_recovery->calculated_file_size+=pos_lyrics; } - else + else { /* log_warning("End of Lyrics not found \n"); @@ -337,7 +337,7 @@ static data_check_t data_check_mp3(const unsigned char *buffer, const unsigned i const unsigned int ape_tag_size = (buffer[i+12] + (buffer[i+13]<<8) + (buffer[i+14]<<16) + (buffer[i+15]<<24))+32; file_recovery->calculated_file_size+=ape_tag_size; } - else if(buffer[i]=='T' && buffer[i+1]=='A' && buffer[i+2]=='G') + else if(buffer[i]=='T' && buffer[i+1]=='A' && buffer[i+2]=='G') { /* http://www.id3.org/ID3v1 TAGv1 size = 128 bytes with header "TAG" */ file_recovery->calculated_file_size+=128; } @@ -375,7 +375,7 @@ static unsigned int search_MMT(const unsigned char *buffer, const unsigned int i http://freenet-homepage.de/StefanRypalla/stuff/musicmatch.txt min size = 8192bytes header is optional - structure : + structure : header 256 bytes optional image extension 4 bytes image binary >= 4 bytes @@ -387,7 +387,7 @@ static unsigned int search_MMT(const unsigned char *buffer, const unsigned int i All subsequent versions allowed three possible lengths for this section: 7936, 8004, and 8132 bytes. data offsets 20 bytes Footer 48 bytes (optional?!) - */ + */ const unsigned char mm_header[10]= {'1','8','2','7','3','6','4','5',0x00, 0x00}; const unsigned char mm_pad_version_info[14] = {0x00,0x00,0x00,0x00,'1','8','2','7','3','6','4','5',0x00,0x00}; const char *mm_footer="Brava Software Inc."; diff --git a/src/file_mpg.c b/src/file_mpg.c index 20e1fbed..19e60863 100644 --- a/src/file_mpg.c +++ b/src/file_mpg.c @@ -71,13 +71,13 @@ static int calculate_packet_size(const unsigned char *buffer) /* Extension */ case 0xB5: /* Sequence_Extension */ - if((buffer[4]&0xF0)==0x10 && (buffer[7]&1)==1) + if((buffer[4]&0xF0)==0x10 && (buffer[7]&1)==1) return 10; /* Sequence_Display_Extension without color description */ - if((buffer[4]&0xF0)==0x20 && (buffer[4]&1)==0 && (buffer[6]&2)==2) + if((buffer[4]&0xF0)==0x20 && (buffer[4]&1)==0 && (buffer[6]&2)==2) return 9; /* Sequence_Display_Extension with color description */ - if((buffer[4]&0xF0)==0x20 && (buffer[4]&1)==1 && (buffer[9]&2)==2) + if((buffer[4]&0xF0)==0x20 && (buffer[4]&1)==1 && (buffer[9]&2)==2) return 12; /* Picture_Coding_Extension */ if((buffer[4]&0xF0)==0x40) diff --git a/src/file_mrw.c b/src/file_mrw.c index 2a478d7b..4b5edd20 100644 --- a/src/file_mrw.c +++ b/src/file_mrw.c @@ -33,7 +33,6 @@ #include "log.h" static void register_header_check_mrw(file_stat_t *file_stat); -static int header_check_mrw(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_mrw= { .extension="mrw", @@ -45,13 +44,6 @@ const file_hint_t file_hint_mrw= { .register_header_check=®ister_header_check_mrw }; -static const unsigned char mrw_header[4]= { 0x00,'M','R','M'}; /* Minolta Raw */ - -static void register_header_check_mrw(file_stat_t *file_stat) -{ - register_header_check(0, mrw_header,sizeof(mrw_header), &header_check_mrw, file_stat); -} - struct hdr { uint32_t fourcc; uint32_t size; @@ -79,28 +71,29 @@ struct prd { /* Minolta */ static int header_check_mrw(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(memcmp(buffer,mrw_header,sizeof(mrw_header))==0) - { - const unsigned char prd_header[4]= { 0x00,'P','R','D'}; - const struct hdr *mrmhdr = (const struct hdr*)buffer; - if(memcmp(mrmhdr->data,prd_header,sizeof(prd_header))==0) - { - const struct hdr *prdhdr = (const struct hdr*)&mrmhdr->data; - /* Picture Raw Dimensions */ - const struct prd *prd = (const struct prd*)&prdhdr->data; - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_mrw.extension; - file_recovery_new->calculated_file_size= be32(mrmhdr->size)+ 8 + - ((uint64_t)be16(prd->ccd.x) * be16(prd->ccd.y) * prd->datasize + 8 - 1) / 8; - file_recovery_new->data_check=&data_check_size; - file_recovery_new->file_check=&file_check_size; - /* - log_debug("size=%lu x=%lu y=%lu datasize=%lu\n", be32(mrmhdr->size), - be16(prd->ccd.x), be16(prd->ccd.y), prd->datasize); - log_debug("mrw_file_size %lu\n", (long unsigned)file_recovery_new->calculated_file_size); - */ - return 1; - } - } - return 0; + const unsigned char prd_header[4]= { 0x00,'P','R','D'}; + const struct hdr *mrmhdr = (const struct hdr*)buffer; + const struct hdr *prdhdr = (const struct hdr*)&mrmhdr->data; + /* Picture Raw Dimensions */ + const struct prd *prd = (const struct prd*)&prdhdr->data; + if(memcmp(mrmhdr->data,prd_header,sizeof(prd_header))!=0) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_mrw.extension; + file_recovery_new->calculated_file_size= be32(mrmhdr->size)+ 8 + + ((uint64_t)be16(prd->ccd.x) * be16(prd->ccd.y) * prd->datasize + 8 - 1) / 8; + file_recovery_new->data_check=&data_check_size; + file_recovery_new->file_check=&file_check_size; + /* + log_debug("size=%lu x=%lu y=%lu datasize=%lu\n", be32(mrmhdr->size), + be16(prd->ccd.x), be16(prd->ccd.y), prd->datasize); + log_debug("mrw_file_size %lu\n", (long unsigned)file_recovery_new->calculated_file_size); + */ + return 1; +} + +static void register_header_check_mrw(file_stat_t *file_stat) +{ + static const unsigned char mrw_header[4]= { 0x00,'M','R','M'}; /* Minolta Raw */ + register_header_check(0, mrw_header,sizeof(mrw_header), &header_check_mrw, file_stat); } diff --git a/src/file_mus.c b/src/file_mus.c index 459460dd..fcfa88c5 100644 --- a/src/file_mus.c +++ b/src/file_mus.c @@ -30,10 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_mus(file_stat_t *file_stat); -static int header_check_mus(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_mus(file_recovery_t *file_recovery); const file_hint_t file_hint_mus= { .extension="mus", @@ -45,28 +42,23 @@ const file_hint_t file_hint_mus= { .register_header_check=®ister_header_check_mus }; -static const unsigned char mus_header[18] = { 'E','N','I','G','M','A',' ','B','I','N','A','R','Y',' ','F','I','L','E' }; - -static void register_header_check_mus(file_stat_t *file_stat) -{ - register_header_check(0, mus_header,sizeof(mus_header), &header_check_mus, file_stat); -} - -static int header_check_mus(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(memcmp(buffer,mus_header,sizeof(mus_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->min_filesize=18; - file_recovery_new->file_check=&file_check_mus; - file_recovery_new->extension=file_hint_mus.extension; - return 1; - } - return 0; -} - static void file_check_mus(file_recovery_t *file_recovery) { const unsigned char mus_footer[5]= {'-','^','e','n','d'}; file_search_footer(file_recovery, mus_footer, sizeof(mus_footer), 0); } + +static int header_check_mus(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->min_filesize=18; + file_recovery_new->file_check=&file_check_mus; + file_recovery_new->extension=file_hint_mus.extension; + return 1; +} + +static void register_header_check_mus(file_stat_t *file_stat) +{ + static const unsigned char mus_header[18] = { 'E','N','I','G','M','A',' ','B','I','N','A','R','Y',' ','F','I','L','E' }; + register_header_check(0, mus_header,sizeof(mus_header), &header_check_mus, file_stat); +} diff --git a/src/file_mxf.c b/src/file_mxf.c index 4d1a6111..c9905e0e 100644 --- a/src/file_mxf.c +++ b/src/file_mxf.c @@ -29,9 +29,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_mxf(file_stat_t *file_stat); -static int header_check_mxf(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_mxf= { .extension="mxf", @@ -49,23 +47,18 @@ const file_hint_t file_hint_mxf= { * Material Exchange Format (MXF) * */ -static const unsigned char mxf_header[11]= { - 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, - 0x0d, 0x01, 0x02 -}; +static int header_check_mxf(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_mxf.extension; + return 1; +} static void register_header_check_mxf(file_stat_t *file_stat) { + static const unsigned char mxf_header[11]= { + 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, + 0x0d, 0x01, 0x02 + }; register_header_check(0, mxf_header,sizeof(mxf_header), &header_check_mxf, file_stat); } - -static int header_check_mxf(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(memcmp(buffer,mxf_header,sizeof(mxf_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_mxf.extension; - return 1; - } - return 0; -} diff --git a/src/file_nk2.c b/src/file_nk2.c index 624d7dc1..bf193ba9 100644 --- a/src/file_nk2.c +++ b/src/file_nk2.c @@ -39,8 +39,6 @@ #endif static void register_header_check_nk2(file_stat_t *file_stat); -static int header_check_nk2(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_nk2(file_recovery_t *file_recovery); const file_hint_t file_hint_nk2= { .extension="nk2", @@ -52,8 +50,6 @@ const file_hint_t file_hint_nk2= { .register_header_check=®ister_header_check_nk2 }; -static const unsigned char nk2_header[8]= { 0x0d, 0xf0, 0xad, 0xba, 0x0a, 0x00, 0x00, 0x00 }; - typedef struct { uint32_t magic; uint32_t magic2; @@ -73,23 +69,6 @@ typedef struct { uint32_t unk3; } entryHeader; -static void register_header_check_nk2(file_stat_t *file_stat) -{ - register_header_check(0, nk2_header, sizeof(nk2_header), &header_check_nk2, file_stat); -} - -static int header_check_nk2(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(memcmp(buffer, nk2_header, sizeof(nk2_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_nk2.extension; - file_recovery_new->file_check=&file_check_nk2; - return 1; - } - return 0; -} - #define PT_UNSPECIFIED 0x0000 #define PT_NULL 0x0001 #define PT_I2 0x0002 @@ -205,3 +184,16 @@ static void file_check_nk2(file_recovery_t *fr) fr->file_size+=12; } +static int header_check_nk2(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_nk2.extension; + file_recovery_new->file_check=&file_check_nk2; + return 1; +} + +static void register_header_check_nk2(file_stat_t *file_stat) +{ + static const unsigned char nk2_header[8]= { 0x0d, 0xf0, 0xad, 0xba, 0x0a, 0x00, 0x00, 0x00 }; + register_header_check(0, nk2_header, sizeof(nk2_header), &header_check_nk2, file_stat); +} diff --git a/src/file_oci.c b/src/file_oci.c index 19a29b99..f7c1d21d 100644 --- a/src/file_oci.c +++ b/src/file_oci.c @@ -60,8 +60,8 @@ static data_check_t data_check_oci(const unsigned char *buffer, const unsigned i #ifdef DEBUG_MOV log_trace("file_oci.c: %s atom %c%c%c%c (0x%02x%02x%02x%02x) size %llu, calculated_file_size %llu\n", file_recovery->filename, - buffer[i],buffer[i+1],buffer[i+2],buffer[i+3], - buffer[i],buffer[i+1],buffer[i+2],buffer[i+3], + buffer[i],buffer[i+1],buffer[i+2],buffer[i+3], + buffer[i],buffer[i+1],buffer[i+2],buffer[i+3], (long long unsigned)atom_size, (long long unsigned)file_recovery->calculated_file_size); #endif diff --git a/src/file_ogg.c b/src/file_ogg.c index b629b710..e5b94880 100644 --- a/src/file_ogg.c +++ b/src/file_ogg.c @@ -46,10 +46,10 @@ const file_hint_t file_hint_ogg= { /* header=OggS, version=0 */ static const unsigned char ogg_header[5]= {'O','g','g','S', 0x00}; -static const unsigned char sign_theora[7]= {0x80, 't', 'h', 'e', 'o', 'r', 'a'}; static int header_check_ogg(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 const unsigned char sign_theora[7]= {0x80, 't', 'h', 'e', 'o', 'r', 'a'}; /* http://en.wikipedia.org/wiki/Ogg#File_format */ /* Return if not Beginning Of Stream and already saving the file */ if((buffer[5]&0x02)!=0x02 && diff --git a/src/file_paf.c b/src/file_paf.c index 9df33218..71dd8807 100644 --- a/src/file_paf.c +++ b/src/file_paf.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_paf(file_stat_t *file_stat); -static int header_check_paf(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_paf= { .extension="paf", @@ -46,20 +45,15 @@ const file_hint_t file_hint_paf= { /* Personal Ancestral File Family Database is handled by * The Church of Jesus Christ of Latter-day Saints */ -static const unsigned char paf_header[11]= {'5', '0', '0', '\0', '5', '0', '0', '\0', 'P','A','F'}; +static int header_check_paf(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_paf.extension; + return 1; +} static void register_header_check_paf(file_stat_t *file_stat) { + static const unsigned char paf_header[11]= {'5', '0', '0', '\0', '5', '0', '0', '\0', 'P','A','F'}; register_header_check(0, paf_header,sizeof(paf_header), &header_check_paf, file_stat); } - -static int header_check_paf(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(memcmp(buffer,paf_header,sizeof(paf_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_paf.extension; - return 1; - } - return 0; -} diff --git a/src/file_par2.c b/src/file_par2.c index d131f00f..f63f0eea 100644 --- a/src/file_par2.c +++ b/src/file_par2.c @@ -51,7 +51,7 @@ const file_hint_t file_hint_par2= { }; static const unsigned char par2_header[8]= { - 'P' , 'A' , 'R' , '2' , 0x00, 'P' , 'K' , 'T' + 'P' , 'A' , 'R' , '2' , 0x00, 'P' , 'K' , 'T' }; static data_check_t data_check_par2(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) diff --git a/src/file_pct.c b/src/file_pct.c index 1a58f647..a24d6103 100644 --- a/src/file_pct.c +++ b/src/file_pct.c @@ -45,7 +45,6 @@ const file_hint_t file_hint_pct= { .register_header_check=®ister_header_check_pct }; -static const unsigned char pct_header[6]= { 0x00, 0x11, 0x02, 0xff, 0x0c, 0x00}; /* We are searching for PICTv2 files http://www.fileformat.info/format/macpict/ SHORT Version operator (0x0011) @@ -80,16 +79,10 @@ struct pct_file_entry { uint32_t Reserved2; /* 0x24 */ } __attribute__ ((gcc_struct, __packed__)); -static void register_header_check_pct(file_stat_t *file_stat) -{ - register_header_check(0x20a, pct_header,sizeof(pct_header), &header_check_pct, file_stat); -} - static int header_check_pct(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 struct pct_file_entry *pct=(const struct pct_file_entry *)(&buffer[0x200]); - if(memcmp(&buffer[0x20a],pct_header,sizeof(pct_header))==0 && - be16(pct->XMin) <= be16(pct->XMax) && + if(be16(pct->XMin) <= be16(pct->XMax) && be16(pct->YMin) <= be16(pct->YMax) && ((be16(pct->OXMin) <= be16(pct->OXMax) && be16(pct->OYMin) <= be16(pct->OYMax)) || @@ -130,3 +123,8 @@ static void file_check_pct(file_recovery_t *file_recovery) file_recovery->file_size-=((file_recovery->file_size-file_recovery->min_filesize)&0xFFFF); } +static void register_header_check_pct(file_stat_t *file_stat) +{ + static const unsigned char pct_header[6]= { 0x00, 0x11, 0x02, 0xff, 0x0c, 0x00}; + register_header_check(0x20a, pct_header,sizeof(pct_header), &header_check_pct, file_stat); +} diff --git a/src/file_pds.c b/src/file_pds.c index bf305f6c..aee3231b 100644 --- a/src/file_pds.c +++ b/src/file_pds.c @@ -42,25 +42,20 @@ const file_hint_t file_hint_pds= { .register_header_check=®ister_header_check_pds }; -static const unsigned char pds_header[25]= { - 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, - 0x04, 0x5b, 'H' , 'E' , 'A' , 'D' , 'E' , 'R' , - 0x5d -}; - static int header_check_pds(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(memcmp(&buffer[0], pds_header, sizeof(pds_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_pds.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_pds.extension; + return 1; } static void register_header_check_pds(file_stat_t *file_stat) { + static const unsigned char pds_header[25]= { + 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x04, 0x5b, 'H' , 'E' , 'A' , 'D' , 'E' , 'R' , + 0x5d + }; register_header_check(0, pds_header, sizeof(pds_header), &header_check_pds, file_stat); } diff --git a/src/file_pfx.c b/src/file_pfx.c index 13e583df..99caf843 100644 --- a/src/file_pfx.c +++ b/src/file_pfx.c @@ -55,7 +55,7 @@ const file_hint_t file_hint_pfx= { * 30 82 XX XX XXXX + 4 = filesize * 4:d=1 hl=2 l= 1 prim: INTEGER * 02 01 03 version 3 - * 7:d=1 hl=4 l=XXXX cons: SEQUENCE + * 7:d=1 hl=4 l=XXXX cons: SEQUENCE * 30 82 XX XX * 11:d=2 hl=2 l= 9 prim: OBJECT :pkcs7-data * 06 09 2a 86 48 86 f7 0d 01 07 01 diff --git a/src/file_plt.c b/src/file_plt.c index a09c6e18..c0c951f4 100644 --- a/src/file_plt.c +++ b/src/file_plt.c @@ -42,27 +42,22 @@ const file_hint_t file_hint_plt= { .register_header_check=®ister_header_check_plt }; -static const unsigned char plt_header[44]= { - 'G', 'e', 'r', 'b', 'e', 'r', ' ', 'S', - 'c', 'i', 'e', 'n', 't', 'i', 'f', 'i', - 'c', ' ', 'P', 'r', 'o', 'd', 'u', 'c', - 't', 's', ' ', 'G', 'R', 'A', 'P', 'H', - 'I', 'X', ' ', 'A', 'D', 'V', 'A', 'N', - 'T', 'A', 'G', 'E', -}; - static int header_check_plt(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(memcmp(&buffer[2], plt_header, sizeof(plt_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_plt.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_plt.extension; + return 1; } static void register_header_check_plt(file_stat_t *file_stat) { + static const unsigned char plt_header[44]= { + 'G', 'e', 'r', 'b', 'e', 'r', ' ', 'S', + 'c', 'i', 'e', 'n', 't', 'i', 'f', 'i', + 'c', ' ', 'P', 'r', 'o', 'd', 'u', 'c', + 't', 's', ' ', 'G', 'R', 'A', 'P', 'H', + 'I', 'X', ' ', 'A', 'D', 'V', 'A', 'N', + 'T', 'A', 'G', 'E', + }; register_header_check(2, plt_header, sizeof(plt_header), &header_check_plt, file_stat); } diff --git a/src/file_prc.c b/src/file_prc.c index c94d90a5..9f539811 100644 --- a/src/file_prc.c +++ b/src/file_prc.c @@ -44,13 +44,6 @@ const file_hint_t file_hint_prc= { .register_header_check=®ister_header_check_prc }; -static const unsigned char prc_header[16]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'a','p','p','l'}; - -static void register_header_check_prc(file_stat_t *file_stat) -{ - register_header_check(0x30, prc_header,sizeof(prc_header), &header_check_prc, file_stat); -} - struct DatabaseHdrType_s { unsigned char name[32]; uint16_t attributes; /* 0x20 */ @@ -69,8 +62,7 @@ struct DatabaseHdrType_s { static int header_check_prc(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 struct DatabaseHdrType_s *prc=(const struct DatabaseHdrType_s *)buffer; - if(memcmp(&buffer[0x30],prc_header,sizeof(prc_header))==0 && - be32(prc->uniqueIDSeed)==0) + if(be32(prc->uniqueIDSeed)==0) { reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_prc.extension; @@ -79,3 +71,9 @@ static int header_check_prc(const unsigned char *buffer, const unsigned int buff } return 0; } + +static void register_header_check_prc(file_stat_t *file_stat) +{ + static const unsigned char prc_header[16]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'a','p','p','l'}; + register_header_check(0x30, prc_header,sizeof(prc_header), &header_check_prc, file_stat); +} diff --git a/src/file_prt.c b/src/file_prt.c index e45d1e28..29b2d02e 100644 --- a/src/file_prt.c +++ b/src/file_prt.c @@ -30,10 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_prt(file_stat_t *file_stat); -static int header_check_prt(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_prt(file_recovery_t *file_recovery); const file_hint_t file_hint_prt= { .extension="prt", @@ -45,27 +42,6 @@ const file_hint_t file_hint_prt= { .register_header_check=®ister_header_check_prt }; -static const unsigned char prt_header[12]= { - '#', 'U', 'G', 'C', ':', '2', ' ', 'P', - 'A', 'R', 'T', ' '}; - -static void register_header_check_prt(file_stat_t *file_stat) -{ - register_header_check(0, prt_header,sizeof(prt_header), &header_check_prt, file_stat); -} - -static int header_check_prt(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(memcmp(buffer,prt_header,sizeof(prt_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->file_check=file_check_prt; - file_recovery_new->extension=file_hint_prt.extension; - return 1; - } - return 0; -} - static void file_check_prt(file_recovery_t *file_recovery) { const unsigned char prt_footer[11]= { @@ -73,3 +49,19 @@ static void file_check_prt(file_recovery_t *file_recovery) 'U', 'G', 'C'}; file_search_footer(file_recovery, prt_footer, sizeof(prt_footer), 1); } + +static int header_check_prt(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->file_check=file_check_prt; + file_recovery_new->extension=file_hint_prt.extension; + return 1; +} + +static void register_header_check_prt(file_stat_t *file_stat) +{ + static const unsigned char prt_header[12]= { + '#', 'U', 'G', 'C', ':', '2', ' ', 'P', + 'A', 'R', 'T', ' '}; + register_header_check(0, prt_header,sizeof(prt_header), &header_check_prt, file_stat); +} diff --git a/src/file_ps.c b/src/file_ps.c index f5720132..55517449 100644 --- a/src/file_ps.c +++ b/src/file_ps.c @@ -55,36 +55,33 @@ 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) { - if(memcmp(buffer,ps_header,sizeof(ps_header))==0) - { /* PS or EPSF */ - int i; - for(i=sizeof(ps_header);i<20;i++) + /* PS or EPSF */ + int i; + for(i=sizeof(ps_header);i<20;i++) + { + switch(buffer[i]) { - switch(buffer[i]) - { - case '\n': + case '\n': + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_ps.extension; + file_recovery_new->data_check=&data_check_ps; + file_recovery_new->file_check=&file_check_size; + return 1; + case 'E': + if(memcmp(&buffer[i],"EPSF-",5)==0) + { reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_ps.extension; - file_recovery_new->data_check=&data_check_ps; - file_recovery_new->file_check=&file_check_size; + file_recovery_new->extension="eps"; return 1; - case 'E': - if(memcmp(&buffer[i],"EPSF-",5)==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension="eps"; - return 1; - } - break; - } + } + break; } - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_ps.extension; - file_recovery_new->data_check=&data_check_ps; - file_recovery_new->file_check=&file_check_size; - return 1; } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_ps.extension; + file_recovery_new->data_check=&data_check_ps; + file_recovery_new->file_check=&file_check_size; + return 1; } static data_check_t data_check_ps(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) diff --git a/src/file_ptb.c b/src/file_ptb.c index 5a32b002..4d6fab3d 100644 --- a/src/file_ptb.c +++ b/src/file_ptb.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_ptb(file_stat_t *file_stat); -static int header_check_ptb(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_ptb= { .extension="ptb", @@ -43,17 +42,10 @@ const file_hint_t file_hint_ptb= { .register_header_check=®ister_header_check_ptb }; -static const unsigned char ptb_header[4]= {'p', 't', 'a', 'b'}; - -static void register_header_check_ptb(file_stat_t *file_stat) -{ - register_header_check(0, ptb_header,sizeof(ptb_header), &header_check_ptb, file_stat); -} - static int header_check_ptb(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 unsigned int file_version=buffer[4]|(buffer[5]<<8); - if(memcmp(buffer,ptb_header,sizeof(ptb_header))==0 && file_version>=1 && file_version<=4) + if(file_version>=1 && file_version<=4) { reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_ptb.extension; @@ -61,3 +53,9 @@ static int header_check_ptb(const unsigned char *buffer, const unsigned int buff } return 0; } + +static void register_header_check_ptb(file_stat_t *file_stat) +{ + static const unsigned char ptb_header[4]= {'p', 't', 'a', 'b'}; + register_header_check(0, ptb_header,sizeof(ptb_header), &header_check_ptb, file_stat); +} diff --git a/src/file_ptf.c b/src/file_ptf.c index 0ef18f61..0fddd37b 100644 --- a/src/file_ptf.c +++ b/src/file_ptf.c @@ -42,24 +42,19 @@ const file_hint_t file_hint_ptf= { .register_header_check=®ister_header_check_ptf }; -static const unsigned char ptf_header[19]= { - 0x03, '0' , '0' , '1' , '0' , '1' , '1' , '1' , - '1', '0' , '0' , '1' , '0' , '1' , '0' , '1' , - '1', 0x00, 0x01 -}; - static int header_check_ptf(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(memcmp(&buffer[0], ptf_header, sizeof(ptf_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_ptf.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_ptf.extension; + return 1; } static void register_header_check_ptf(file_stat_t *file_stat) { + static const unsigned char ptf_header[19]= { + 0x03, '0' , '0' , '1' , '0' , '1' , '1' , '1' , + '1', '0' , '0' , '1' , '0' , '1' , '0' , '1' , + '1', 0x00, 0x01 + }; register_header_check(0, ptf_header, sizeof(ptf_header), &header_check_ptf, file_stat); } diff --git a/src/file_pzf.c b/src/file_pzf.c index 0c0d5c77..9852cf10 100644 --- a/src/file_pzf.c +++ b/src/file_pzf.c @@ -31,8 +31,6 @@ #include "filegen.h" static void register_header_check_pzf(file_stat_t *file_stat); -static int header_check_pzf(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_pzf(file_recovery_t *file_recovery); const file_hint_t file_hint_pzf= { .extension="pzf", @@ -44,27 +42,6 @@ const file_hint_t file_hint_pzf= { .register_header_check=®ister_header_check_pzf }; -static const unsigned char pzf_header[8]= { - 'P' , 'C' , 'F' , 'F' , 'G' , 'R' , 'A' , '4' -}; - -static void register_header_check_pzf(file_stat_t *file_stat) -{ - register_header_check(0, pzf_header, sizeof(pzf_header), &header_check_pzf, file_stat); -} - -static int header_check_pzf(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(memcmp(buffer, pzf_header, sizeof(pzf_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_pzf.extension; - file_recovery_new->file_check=&file_check_pzf; - return 1; - } - return 0; -} - static void file_check_pzf(file_recovery_t *file_recovery) { const unsigned char pzf_footer[17]= { @@ -74,3 +51,19 @@ static void file_check_pzf(file_recovery_t *file_recovery) }; file_search_footer(file_recovery, pzf_footer, sizeof(pzf_footer), 0); } + +static int header_check_pzf(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_pzf.extension; + file_recovery_new->file_check=&file_check_pzf; + return 1; +} + +static void register_header_check_pzf(file_stat_t *file_stat) +{ + static const unsigned char pzf_header[8]= { + 'P' , 'C' , 'F' , 'F' , 'G' , 'R' , 'A' , '4' + }; + register_header_check(0, pzf_header, sizeof(pzf_header), &header_check_pzf, file_stat); +} diff --git a/src/file_pzh.c b/src/file_pzh.c index 5b0d30ec..692878e5 100644 --- a/src/file_pzh.c +++ b/src/file_pzh.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_pzh(file_stat_t *file_stat); -static int header_check_pzh(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); /* Presto http://www.soft.es/ */ @@ -50,11 +49,6 @@ static const unsigned char pzh_header[10]= { 0x05, 0x03 }; -static void register_header_check_pzh(file_stat_t *file_stat) -{ - register_header_check(0x9c4, pzh_header, sizeof(pzh_header), &header_check_pzh, file_stat); -} - static void file_rename_pzh(const char *old_filename) { unsigned char buffer[512]; @@ -75,13 +69,14 @@ static void file_rename_pzh(const char *old_filename) static int header_check_pzh(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(memcmp(&buffer[0x9c4], pzh_header, sizeof(pzh_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_pzh.extension; - file_recovery_new->file_rename=&file_rename_pzh; - file_recovery_new->min_filesize=0x9c4 + sizeof(pzh_header); - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_pzh.extension; + file_recovery_new->file_rename=&file_rename_pzh; + file_recovery_new->min_filesize=0x9c4 + sizeof(pzh_header); + return 1; +} + +static void register_header_check_pzh(file_stat_t *file_stat) +{ + register_header_check(0x9c4, pzh_header, sizeof(pzh_header), &header_check_pzh, file_stat); } diff --git a/src/file_qkt.c b/src/file_qkt.c index 701dab7f..5e2ad5b1 100644 --- a/src/file_qkt.c +++ b/src/file_qkt.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_qkt(file_stat_t *file_stat); -static int header_check_qkt(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_qkt= { .extension="qkt", @@ -43,22 +42,17 @@ const file_hint_t file_hint_qkt= { .register_header_check=®ister_header_check_qkt }; -static const unsigned char qkt_header[8]= { - 'q' , 'k' , 't' , 'k' , 0x00, 0x00, 0x00, 0x08 -}; +static int header_check_qkt(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_qkt.extension; + return 1; +} static void register_header_check_qkt(file_stat_t *file_stat) { + static const unsigned char qkt_header[8]= { + 'q' , 'k' , 't' , 'k' , 0x00, 0x00, 0x00, 0x08 + }; register_header_check(0, qkt_header, sizeof(qkt_header), &header_check_qkt, file_stat); } - -static int header_check_qkt(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(memcmp(buffer, qkt_header, sizeof(qkt_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_qkt.extension; - return 1; - } - return 0; -} diff --git a/src/file_r3d.c b/src/file_r3d.c index 4b797673..8477c0ee 100644 --- a/src/file_r3d.c +++ b/src/file_r3d.c @@ -69,8 +69,8 @@ static data_check_t data_check_r3d(const unsigned char *buffer, const unsigned i #ifdef DEBUG_R3D log_trace("file_r3d.c: %s atom %c%c%c%c (0x%02x%02x%02x%02x) size %llu, calculated_file_size %llu\n", file_recovery->filename, - buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7], - buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7], + buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7], + buffer[i+4],buffer[i+5],buffer[i+6],buffer[i+7], (long long unsigned)atom_size, (long long unsigned)file_recovery->calculated_file_size); #endif diff --git a/src/file_rar.c b/src/file_rar.c index 06f6d385..b8acbb6b 100644 --- a/src/file_rar.c +++ b/src/file_rar.c @@ -45,30 +45,26 @@ const file_hint_t file_hint_rar= { .register_header_check=®ister_header_check_rar }; -static const unsigned char rar_header[7]={0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 }; - -static void register_header_check_rar(file_stat_t *file_stat) -{ - register_header_check(0, rar_header,sizeof(rar_header), &header_check_rar, file_stat); -} #define MHD_PASSWORD 0x0080U -static int header_check_rar(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(memcmp(buffer,rar_header,sizeof(rar_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->min_filesize=70; - if((buffer[0xa] & MHD_PASSWORD)==0) - file_recovery_new->file_check=file_check_rar; - file_recovery_new->extension=file_hint_rar.extension; - return 1; - } - return 0; -} - static void file_check_rar(file_recovery_t *file_recovery) { static const unsigned char rar_footer[7]={0xc4, 0x3d, 0x7b, 0x00, 0x40, 0x07, 0x00 }; file_search_footer(file_recovery, rar_footer, sizeof(rar_footer), 0); } + +static int header_check_rar(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->min_filesize=70; + if((buffer[0xa] & MHD_PASSWORD)==0) + file_recovery_new->file_check=file_check_rar; + file_recovery_new->extension=file_hint_rar.extension; + return 1; +} + +static void register_header_check_rar(file_stat_t *file_stat) +{ + static const unsigned char rar_header[7]={0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 }; + register_header_check(0, rar_header,sizeof(rar_header), &header_check_rar, file_stat); +} diff --git a/src/file_raw.c b/src/file_raw.c index 6dfeac52..12eba46f 100644 --- a/src/file_raw.c +++ b/src/file_raw.c @@ -30,9 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_raw(file_stat_t *file_stat); -static int header_check_raw(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_raw= { .extension="raw", /* What is the correct extension ? */ @@ -44,23 +42,16 @@ const file_hint_t file_hint_raw= { .register_header_check=®ister_header_check_raw }; -static const unsigned char raw_header_contax[7]= {'A','R','E','C','O','Y','K'}; - -static void register_header_check_raw(file_stat_t *file_stat) -{ - register_header_check(25, raw_header_contax,sizeof(raw_header_contax), &header_check_raw, file_stat); -} - static int header_check_raw(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) { /* Contax Kyocera */ - if(memcmp (buffer+25, raw_header_contax, 7)==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_raw.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_raw.extension; + return 1; } - +static void register_header_check_raw(file_stat_t *file_stat) +{ + static const unsigned char raw_header_contax[7]= {'A','R','E','C','O','Y','K'}; + register_header_check(25, raw_header_contax,sizeof(raw_header_contax), &header_check_raw, file_stat); +} diff --git a/src/file_rdc.c b/src/file_rdc.c index 8575327e..883bc299 100644 --- a/src/file_rdc.c +++ b/src/file_rdc.c @@ -30,9 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_rdc(file_stat_t *file_stat); -static int header_check_rdc(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_rdc= { .extension="rdc", @@ -44,23 +42,16 @@ const file_hint_t file_hint_rdc= { .register_header_check=®ister_header_check_rdc }; -static const unsigned char rdc_header[9]= {'D','S','C','-','I','m','a','g','e'}; - -static void register_header_check_rdc(file_stat_t *file_stat) -{ - register_header_check(0, rdc_header,sizeof(rdc_header), &header_check_rdc, file_stat); -} - static int header_check_rdc(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) { /* Rollei */ - if(memcmp(buffer, rdc_header, sizeof(rdc_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_rdc.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_rdc.extension; + return 1; } - +static void register_header_check_rdc(file_stat_t *file_stat) +{ + static const unsigned char rdc_header[9]= {'D','S','C','-','I','m','a','g','e'}; + register_header_check(0, rdc_header,sizeof(rdc_header), &header_check_rdc, file_stat); +} diff --git a/src/file_res.c b/src/file_res.c index 5efb1ec8..728bf75e 100644 --- a/src/file_res.c +++ b/src/file_res.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_res(file_stat_t *file_stat); -static int header_check_res(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_res= { .extension="res", @@ -43,21 +42,16 @@ const file_hint_t file_hint_res= { .register_header_check=®ister_header_check_res }; -static const unsigned char MS_res_header[14]= {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0, 0, 0xFF, 0xFF}; +static int header_check_res(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_res.extension; + return 1; +} static void register_header_check_res(file_stat_t *file_stat) { + static const unsigned char MS_res_header[14]= {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0, 0, 0xFF, 0xFF}; register_header_check(0, MS_res_header,sizeof(MS_res_header), &header_check_res, file_stat); } - -static int header_check_res(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(memcmp(buffer,MS_res_header,sizeof(MS_res_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_res.extension; - return 1; - } - return 0; -} diff --git a/src/file_rfp.c b/src/file_rfp.c index c56d5b32..879988b2 100644 --- a/src/file_rfp.c +++ b/src/file_rfp.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_rfp(file_stat_t *file_stat); -static int header_check_rfp(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_rfp= { .extension="rfp", @@ -43,23 +42,18 @@ const file_hint_t file_hint_rfp= { .register_header_check=®ister_header_check_rfp }; -static const unsigned char rfp_header[10]= { - 'U' , 'R' , 'L' , '3' , ':', 'v' , 'e' , 'r' , - '3' , ':', -}; +static int header_check_rfp(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_rfp.extension; + return 1; +} static void register_header_check_rfp(file_stat_t *file_stat) { + static const unsigned char rfp_header[10]= { + 'U' , 'R' , 'L' , '3' , ':', 'v' , 'e' , 'r' , + '3' , ':', + }; register_header_check(0, rfp_header, sizeof(rfp_header), &header_check_rfp, file_stat); } - -static int header_check_rfp(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(memcmp(buffer, rfp_header, sizeof(rfp_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_rfp.extension; - return 1; - } - return 0; -} diff --git a/src/file_rns.c b/src/file_rns.c index 98290588..58bf0ebd 100644 --- a/src/file_rns.c +++ b/src/file_rns.c @@ -30,9 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_rns(file_stat_t *file_stat); -static int header_check_rns(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_rns= { .extension="rns", @@ -44,21 +42,15 @@ const file_hint_t file_hint_rns= { .register_header_check=®ister_header_check_rns }; -static const unsigned char rns_header[] = "Propellerheads Reason Song File"; +static int header_check_rns(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_rns.extension; + return 1; +} static void register_header_check_rns(file_stat_t *file_stat) { + static const unsigned char rns_header[] = "Propellerheads Reason Song File"; register_header_check(0, rns_header,sizeof(rns_header)-1, &header_check_rns, file_stat); } - -static int header_check_rns(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(memcmp(buffer,rns_header,sizeof(rns_header)-1)==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_rns.extension; - return 1; - } - return 0; -} diff --git a/src/file_save.c b/src/file_save.c index a1a76849..112735c0 100644 --- a/src/file_save.c +++ b/src/file_save.c @@ -42,22 +42,17 @@ const file_hint_t file_hint_save= { .register_header_check=®ister_header_check_save }; -static const unsigned char save_header[8]= { - 'A' , 0x00, 'C' , 0x00, 'I' , 0x00, 'I' , 0x00 -}; - static int header_check_save(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(memcmp(&buffer[8], save_header, sizeof(save_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_save.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_save.extension; + return 1; } static void register_header_check_save(file_stat_t *file_stat) { + static const unsigned char save_header[8]= { + 'A' , 0x00, 'C' , 0x00, 'I' , 0x00, 'I' , 0x00 + }; register_header_check(8, save_header, sizeof(save_header), &header_check_save, file_stat); } diff --git a/src/file_sib.c b/src/file_sib.c index 907dc52c..6e6d77aa 100644 --- a/src/file_sib.c +++ b/src/file_sib.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_sib(file_stat_t *file_stat); -static int header_check_sib(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_sib= { .extension="sib", @@ -43,20 +42,15 @@ const file_hint_t file_hint_sib= { .register_header_check=®ister_header_check_sib }; -static const unsigned char sib_header[9]= {0x0F, 'S', 'I', 'B', 'E', 'L', 'I', 'U', 'S'}; +static int header_check_sib(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_sib.extension; + return 1; +} static void register_header_check_sib(file_stat_t *file_stat) { + static const unsigned char sib_header[9]= {0x0F, 'S', 'I', 'B', 'E', 'L', 'I', 'U', 'S'}; register_header_check(0, sib_header,sizeof(sib_header), &header_check_sib, file_stat); } - -static int header_check_sib(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(memcmp(buffer, sib_header, sizeof(sib_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_sib.extension; - return 1; - } - return 0; -} diff --git a/src/file_skd.c b/src/file_skd.c index 18d539ee..f9ca138d 100644 --- a/src/file_skd.c +++ b/src/file_skd.c @@ -30,7 +30,6 @@ #include "filegen.h" static void register_header_check_skd(file_stat_t *file_stat); -static int header_check_skd(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_skd= { .extension="skd", @@ -42,25 +41,20 @@ const file_hint_t file_hint_skd= { .register_header_check=®ister_header_check_skd }; -static const unsigned char skd_header[29]= { - 'A', 'u', 't', 'o', 'S', 'k', 'e', 't', - 'c', 'h', 0x20, 'd', 'r', 'a', 'w', 'i', - 'n', 'g', 0x20, 'd', 'a', 't', 'a', 'b', - 'a', 's', 'e', 0x0d, 0x0a -}; +static int header_check_skd(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_skd.extension; + return 1; +} static void register_header_check_skd(file_stat_t *file_stat) { + static const unsigned char skd_header[29]= { + 'A', 'u', 't', 'o', 'S', 'k', 'e', 't', + 'c', 'h', 0x20, 'd', 'r', 'a', 'w', 'i', + 'n', 'g', 0x20, 'd', 'a', 't', 'a', 'b', + 'a', 's', 'e', 0x0d, 0x0a + }; register_header_check(0, skd_header,sizeof(skd_header), &header_check_skd, file_stat); } - -static int header_check_skd(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(memcmp(buffer,skd_header,sizeof(skd_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_skd.extension; - return 1; - } - return 0; -} diff --git a/src/file_skp.c b/src/file_skp.c index 94c1aac7..ab89e8dc 100644 --- a/src/file_skp.c +++ b/src/file_skp.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_skp(file_stat_t *file_stat); -static int header_check_skp(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_skp= { .extension="skp", @@ -43,22 +42,17 @@ const file_hint_t file_hint_skp= { .register_header_check=®ister_header_check_skp }; -static const unsigned char skp_header[32]= { - 0xff, 0xfe, 0xff, 0x0e, 'S', 0x00, 'k', 0x00, 'e', 0x00, 't', 0x00, 'c', 0x00, 'h', 0x00, - 'U', 0x00, 'p', 0x00, ' ', 0x00, 'M', 0x00, 'o', 0x00, 'd', 0x00, 'e', 0x00, 'l', 0x00 }; +static int header_check_skp(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_skp.extension; + return 1; +} static void register_header_check_skp(file_stat_t *file_stat) { + static const unsigned char skp_header[32]= { + 0xff, 0xfe, 0xff, 0x0e, 'S', 0x00, 'k', 0x00, 'e', 0x00, 't', 0x00, 'c', 0x00, 'h', 0x00, + 'U', 0x00, 'p', 0x00, ' ', 0x00, 'M', 0x00, 'o', 0x00, 'd', 0x00, 'e', 0x00, 'l', 0x00 }; register_header_check(0, skp_header,sizeof(skp_header), &header_check_skp, file_stat); } - -static int header_check_skp(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(memcmp(buffer,skp_header, sizeof(skp_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_skp.extension; - return 1; - } - return 0; -} diff --git a/src/file_sp3.c b/src/file_sp3.c index e645e975..7f2b5170 100644 --- a/src/file_sp3.c +++ b/src/file_sp3.c @@ -36,7 +36,6 @@ #include "common.h" static void register_header_check_sp3(file_stat_t *file_stat); -static int header_check_sp3(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_sp3= { .extension="sp3", @@ -48,15 +47,6 @@ const file_hint_t file_hint_sp3= { .register_header_check=®ister_header_check_sp3 }; -static const unsigned char sp31_header[8]= { 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static const unsigned char sp32_header[8]= { 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - -static void register_header_check_sp3(file_stat_t *file_stat) -{ - register_header_check(0, sp31_header, sizeof(sp31_header), &header_check_sp3, file_stat); - register_header_check(0, sp32_header, sizeof(sp32_header), &header_check_sp3, file_stat); -} - static uint64_t file_offset_end(uint64_t offset, uint64_t len) { return(offset==0 && len==0?0:offset+len-1); @@ -65,9 +55,7 @@ static uint64_t file_offset_end(uint64_t offset, uint64_t len) static int header_check_sp3(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 struct SP3FileInfo *h=(const struct SP3FileInfo *)buffer; - if((memcmp(buffer, sp31_header, sizeof(sp31_header))==0 || - memcmp(buffer, sp32_header, sizeof(sp32_header))==0) && - le16(h->DataExameAno)>1960 && le16(h->DataExameAno)<2100 && + if(le16(h->DataExameAno)>1960 && le16(h->DataExameAno)<2100 && h->DataExameMes>=1 && h->DataExameMes<=12 && h->DataExameDia>=1 && h->DataExameDia<=31) { @@ -123,3 +111,11 @@ static int header_check_sp3(const unsigned char *buffer, const unsigned int buff } return 0; } + +static void register_header_check_sp3(file_stat_t *file_stat) +{ + static const unsigned char sp31_header[8]= { 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + static const unsigned char sp32_header[8]= { 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + register_header_check(0, sp31_header, sizeof(sp31_header), &header_check_sp3, file_stat); + register_header_check(0, sp32_header, sizeof(sp32_header), &header_check_sp3, file_stat); +} diff --git a/src/file_spe.c b/src/file_spe.c index 0318d6f5..6feca00f 100644 --- a/src/file_spe.c +++ b/src/file_spe.c @@ -179,7 +179,7 @@ struct header_spe char background[120]; /* 1752 Background sub. file name. */ char blemish[120]; /* 1872 Blemish file name. */ float file_header_ver; /* 1992 Version of this file header */ - char UserInfo[1000]; /* 1996-2995 user data. */ + char UserInfo[1000]; /* 1996-2995 user data. */ int32_t WinView_id; /* 2996 Set to 0x01234567L if file was */ /* created by WinX */ diff --git a/src/file_spf.c b/src/file_spf.c index 45030006..09ecb8a2 100644 --- a/src/file_spf.c +++ b/src/file_spf.c @@ -39,8 +39,6 @@ #endif static void register_header_check_spf(file_stat_t *file_stat); -static int header_check_spf(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_spf(file_recovery_t *file_recovery); const file_hint_t file_hint_spf= { .extension="spf", @@ -52,27 +50,6 @@ const file_hint_t file_hint_spf= { .register_header_check=®ister_header_check_spf }; -static const unsigned char spf_header[12]= { - 'S', 'P', 'F', 'I', 0x00, 0x02, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00 -}; - -static void register_header_check_spf(file_stat_t *file_stat) -{ - register_header_check(0, spf_header,sizeof(spf_header), &header_check_spf, file_stat); -} - -static int header_check_spf(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(memcmp(buffer,spf_header,sizeof(spf_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_spf.extension; - file_recovery_new->file_check=file_check_spf; - return 1; - } - return 0; -} - enum { READ_SIZE=32*512 }; static void file_check_spf(file_recovery_t *file_recovery) @@ -112,3 +89,19 @@ static void file_check_spf(file_recovery_t *file_recovery) } } } + +static int header_check_spf(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_spf.extension; + file_recovery_new->file_check=file_check_spf; + return 1; +} + +static void register_header_check_spf(file_stat_t *file_stat) +{ + static const unsigned char spf_header[12]= { + 'S', 'P', 'F', 'I', 0x00, 0x02, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00 + }; + register_header_check(0, spf_header,sizeof(spf_header), &header_check_spf, file_stat); +} diff --git a/src/file_sqm.c b/src/file_sqm.c index 652c289e..0727aeea 100644 --- a/src/file_sqm.c +++ b/src/file_sqm.c @@ -30,9 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_sqm(file_stat_t *file_stat); -static int header_check_sqm(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_sqm= { .extension="sqm", @@ -44,20 +42,15 @@ const file_hint_t file_hint_sqm= { .register_header_check=®ister_header_check_sqm }; -static const unsigned char sqm_header[6]= { 'M', 'S', 'Q', 'M', 'x', 0x00}; +static int header_check_sqm(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_sqm.extension; + return 1; +} static void register_header_check_sqm(file_stat_t *file_stat) { + static const unsigned char sqm_header[6]= { 'M', 'S', 'Q', 'M', 'x', 0x00}; register_header_check(0, sqm_header, sizeof(sqm_header), &header_check_sqm, file_stat); } - -static int header_check_sqm(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(memcmp(buffer, sqm_header, sizeof(sqm_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_sqm.extension; - return 1; - } - return 0; -} diff --git a/src/file_stu.c b/src/file_stu.c index a839378c..48634d0b 100644 --- a/src/file_stu.c +++ b/src/file_stu.c @@ -32,7 +32,6 @@ static void register_header_check_stuffit(file_stat_t *file_stat); -static int header_check_stuffit(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_stuffit= { .extension="sit", @@ -44,20 +43,15 @@ const file_hint_t file_hint_stuffit= { .register_header_check=®ister_header_check_stuffit }; -static const unsigned char stuffit_header[7] = { 'S', 't', 'u', 'f', 'f', 'I', 't'}; +static int header_check_stuffit(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_stuffit.extension; + return 1; +} static void register_header_check_stuffit(file_stat_t *file_stat) { + static const unsigned char stuffit_header[7] = { 'S', 't', 'u', 'f', 'f', 'I', 't'}; register_header_check(0, stuffit_header,sizeof(stuffit_header), &header_check_stuffit, file_stat); } - -static int header_check_stuffit(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(memcmp(buffer,stuffit_header,sizeof(stuffit_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_stuffit.extension; - return 1; - } - return 0; -} diff --git a/src/file_tax.c b/src/file_tax.c index 27846af3..637e69ca 100644 --- a/src/file_tax.c +++ b/src/file_tax.c @@ -32,7 +32,6 @@ static void register_header_check_tax(file_stat_t *file_stat); -static int header_check_tax(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_tax= { .extension="tax", @@ -44,20 +43,15 @@ const file_hint_t file_hint_tax= { .register_header_check=®ister_header_check_tax }; -static const unsigned char tax_header[6]= { 'T', 'T', 'F', 'N', 0x01, 0x01}; +static int header_check_tax(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_tax.extension; + return 1; +} static void register_header_check_tax(file_stat_t *file_stat) { + static const unsigned char tax_header[6]= { 'T', 'T', 'F', 'N', 0x01, 0x01}; register_header_check(0, tax_header, sizeof(tax_header), &header_check_tax, file_stat); } - -static int header_check_tax(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(memcmp(buffer, tax_header, sizeof(tax_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_tax.extension; - return 1; - } - return 0; -} diff --git a/src/file_template.c b/src/file_template.c index 7ceea8d5..2dfa359c 100644 --- a/src/file_template.c +++ b/src/file_template.c @@ -3,17 +3,17 @@ File: file_EXTENSION.c Copyright (C) YEAR Christophe GRENIER - + This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -50,23 +50,18 @@ static void file_check_EXTENSION(file_recovery_t *file_recovery) file_search_footer(file_recovery, EXTENSION_footer, sizeof(EXTENSION_footer), FOOTER_EXTRA); } -static const unsigned char EXTENSION_header[HEADER_SIZE]= { - HEADER_MAGIC -}; - static int header_check_EXTENSION(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(memcmp(&buffer[HEADER_LOC], EXTENSION_header, sizeof(EXTENSION_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_EXTENSION.extension; - file_recovery_new->file_check=&file_check_EXTENSION; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_EXTENSION.extension; + file_recovery_new->file_check=&file_check_EXTENSION; + return 1; } static void register_header_check_EXTENSION(file_stat_t *file_stat) { + static const unsigned char EXTENSION_header[HEADER_SIZE]= { + HEADER_MAGIC + }; register_header_check(HEADER_LOC, EXTENSION_header, sizeof(EXTENSION_header), &header_check_EXTENSION, file_stat); } diff --git a/src/file_tivo.c b/src/file_tivo.c index 0d2764d1..fcbcd3a0 100644 --- a/src/file_tivo.c +++ b/src/file_tivo.c @@ -50,24 +50,20 @@ static void file_check_tivo(file_recovery_t *file_recovery) file_search_footer(file_recovery, tivo_footer, sizeof(tivo_footer), 0); } -static const unsigned char tivo_header[7]= { - 'T' , 'i' , 'V' , 'o' , 0x00, 0x04, 0x00 -}; - static int header_check_tivo(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(memcmp(&buffer[0], tivo_header, sizeof(tivo_header))==0 && - memcmp(&buffer[0x1c], "extension=file_hint_tivo.extension; - file_recovery_new->file_check=&file_check_tivo; - return 1; - } - return 0; + if(memcmp(&buffer[0x1c], "extension=file_hint_tivo.extension; + file_recovery_new->file_check=&file_check_tivo; + return 1; } static void register_header_check_tivo(file_stat_t *file_stat) { + static const unsigned char tivo_header[7]= { + 'T' , 'i' , 'V' , 'o' , 0x00, 0x04, 0x00 + }; register_header_check(0, tivo_header, sizeof(tivo_header), &header_check_tivo, file_stat); } diff --git a/src/file_ttf.c b/src/file_ttf.c index bb15717f..0d926b43 100644 --- a/src/file_ttf.c +++ b/src/file_ttf.c @@ -32,7 +32,6 @@ #include "filegen.h" static void register_header_check_ttf(file_stat_t *file_stat); -static int header_check_ttf(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_ttf= { .extension="ttf", @@ -44,13 +43,6 @@ const file_hint_t file_hint_ttf= { .register_header_check=®ister_header_check_ttf }; -static const unsigned char header_ttf[5]= {0x00 , 0x01, 0x00, 0x00, 0x00}; - -static void register_header_check_ttf(file_stat_t *file_stat) -{ - register_header_check(0, header_ttf, sizeof(header_ttf), &header_check_ttf, file_stat); -} - /* * http://www.microsoft.com/typography/otspec/otff.htm */ @@ -84,8 +76,6 @@ static int header_check_ttf(const unsigned char *buffer, const unsigned int buff { const struct ttf_offset_table *ttf=(const struct ttf_offset_table *)buffer; unsigned int numTables; - if(memcmp(buffer, header_ttf, sizeof(header_ttf))!=0) - return 0; numTables=be16(ttf->numTables); /* searchRange (Maximum power of 2 <= numTables) x 16. * entrySelector Log2(maximum power of 2 <= numTables). @@ -118,3 +108,9 @@ static int header_check_ttf(const unsigned char *buffer, const unsigned int buff } return 1; } + +static void register_header_check_ttf(file_stat_t *file_stat) +{ + static const unsigned char header_ttf[5]= {0x00 , 0x01, 0x00, 0x00, 0x00}; + register_header_check(0, header_ttf, sizeof(header_ttf), &header_check_ttf, file_stat); +} diff --git a/src/file_txt.c b/src/file_txt.c index c4f74f8a..6c61c22e 100644 --- a/src/file_txt.c +++ b/src/file_txt.c @@ -226,27 +226,27 @@ static int filtre(unsigned int car) case 0xd7: /* '×' */ case 0xd9: /* 'Ù' */ case 0xdf: /* 'ß' */ - case 0xe0: /* 'à' */ - case 0xe1: /* 'á' */ - case 0xe2: /* 'â' */ + case 0xe0: /* 'à' */ + case 0xe1: /* 'á' */ + case 0xe2: /* 'â' */ case 0xe3: /* 'ã' */ - case 0xe4: /* 'ä' */ + case 0xe4: /* 'ä' */ case 0xe6: /* 'æ' */ - case 0xe7: /* 'ç' */ - case 0xe8: /* 'è' */ - case 0xe9: /* 'é' */ - case 0xea: /* 'ê' */ - case 0xeb: /* 'ë' */ + case 0xe7: /* 'ç' */ + case 0xe8: /* 'è' */ + case 0xe9: /* 'é' */ + case 0xea: /* 'ê' */ + case 0xeb: /* 'ë' */ case 0xed: /* 'í' */ - case 0xee: /* 'î' */ - case 0xef: /* 'ï' */ - case 0xf4: /* 'ô' */ - case 0xf6: /* 'ö' */ + case 0xee: /* 'î' */ + case 0xef: /* 'ï' */ + case 0xf4: /* 'ô' */ + case 0xf6: /* 'ö' */ case 0xf8: /* 'ø' */ - case 0xf9: /* 'ù' */ + case 0xf9: /* 'ù' */ case 0xfa: /* 'ú' */ - case 0xfb: /* 'û' */ - case 0xfc: /* 'ü' */ + case 0xfb: /* 'û' */ + case 0xfc: /* 'ü' */ return 1; } if(car=='\b' || car=='\t' || car=='\r' || car=='\n' || @@ -261,10 +261,10 @@ static int filtre(unsigned int car) return read size */ int UTF2Lat(unsigned char *buffer_lower, const unsigned char *buffer, const int buf_len) { - const unsigned char *p; /* pointers to actual position in source buffer */ + const unsigned char *p; /* pointers to actual position in source buffer */ unsigned char *q; /* pointers to actual position in destination buffer */ int i; /* counter of remaining bytes available in destination buffer */ - for (i = buf_len, p = buffer, q = buffer_lower; p-buffer 0 && *p!='\0';) + for (i = buf_len, p = buffer, q = buffer_lower; p-buffer 0 && *p!='\0';) { const unsigned char *p_org=p; if((*p & 0xf0)==0xe0 && (*(p+1) & 0xc0)==0x80 && (*(p+2) & 0xc0)==0x80) @@ -275,12 +275,12 @@ int UTF2Lat(unsigned char *buffer_lower, const unsigned char *buffer, const int *q = '\0'; switch (*p) { - case 0xE2 : + case 0xE2 : switch (*(p+1)) - { - case 0x80 : + { + case 0x80 : switch (*(p+2)) - { + { case 0x93 : (*q) = 150; break; case 0x94 : (*q) = 151; break; case 0x98 : (*q) = 145; break; @@ -299,15 +299,15 @@ int UTF2Lat(unsigned char *buffer_lower, const unsigned char *buffer, const int case 0xBA : (*q) = 155; break; } break; - case 0x82 : + case 0x82 : switch (*(p+2)) - { + { case 0xAC : (*q) = 128; break; } break; - case 0x84 : + case 0x84 : switch (*(p+2)) - { + { case 0xA2 : (*q) = 153; break; } break; @@ -321,22 +321,22 @@ int UTF2Lat(unsigned char *buffer_lower, const unsigned char *buffer, const int *q = '\0'; switch (*p) { - case 0xC2 : + case 0xC2 : (*q) = ((*(p+1)) | 0x80) & 0xBF; /* A0-BF and a few 80-9F */ if((*q)==0xA0) (*q)=' '; break; - case 0xC3 : + case 0xC3 : switch (*(p+1)) - { + { case 0xB3 : (*q) = 162; break; default: (*q) = (*(p+1)) | 0xC0; /* C0-FF */ break; } break; - case 0xC5 : - switch (*(p+1)) { + case 0xC5 : + switch (*(p+1)) { case 0x92 : (*q) = 140; break; case 0x93 : (*q) = 156; break; case 0xA0 : (*q) = 138; break; @@ -346,13 +346,13 @@ int UTF2Lat(unsigned char *buffer_lower, const unsigned char *buffer, const int case 0xBE : (*q) = 158; break; } break; - case 0xC6: - switch (*(p+1)) { + case 0xC6: + switch (*(p+1)) { case 0x92 : (*q) = 131; break; } break; - case 0xCB : - switch (*(p+1)) { + case 0xCB : + switch (*(p+1)) { case 0x86 : (*q) = 136; break; case 0x9C : (*q) = 152; break; } @@ -384,7 +384,7 @@ int UTF2Lat(unsigned char *buffer_lower, const unsigned char *buffer, const int static int UTFsize(const unsigned char *buffer, const unsigned int buf_len) { - const unsigned char *p=buffer; /* pointers to actual position in source buffer */ + const unsigned char *p=buffer; /* pointers to actual position in source buffer */ unsigned int i=0; while(itime=mktime(&tm_time); } @@ -1219,7 +1219,7 @@ static void register_header_check_fasttxt(file_stat_t *file_stat) register_header_check(0, header->string, header->len, &header_check_fasttxt, file_stat); header++; } - register_header_check(4, "SC V10", 6, &header_check_dc, file_stat); + register_header_check(4, "SC V10", 6, &header_check_dc, file_stat); register_header_check(0, "DatasetHeader Begin", 19, &header_check_ers, file_stat); // register_header_check(0, "\n", 6, &header_check_smil, file_stat); register_header_check(0, "solid ", 6, &header_check_stl, file_stat); diff --git a/src/file_tz.c b/src/file_tz.c index 1aaaee64..c1d6a765 100644 --- a/src/file_tz.c +++ b/src/file_tz.c @@ -35,7 +35,6 @@ #include "filegen.h" static void register_header_check_tz(file_stat_t *file_stat); -static int header_check_tz(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_tz= { .extension="tz", @@ -47,39 +46,33 @@ const file_hint_t file_hint_tz= { .register_header_check=®ister_header_check_tz }; -/* man 5 tzfile */ -static const unsigned char tz_header[20]= -{ - 'T', 'Z', 'i', 'f', - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, -}; - -static const unsigned char tz2_header[20]= -{ - 'T', 'Z', 'i', 'f', - '2', 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, -}; +static int header_check_tz(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_tz.extension; + return 1; +} static void register_header_check_tz(file_stat_t *file_stat) { + /* man 5 tzfile */ + static const unsigned char tz_header[20]= + { + 'T', 'Z', 'i', 'f', + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; + + static const unsigned char tz2_header[20]= + { + 'T', 'Z', 'i', 'f', + '2', 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; register_header_check(0, tz_header, sizeof(tz_header), &header_check_tz, file_stat); register_header_check(0, tz2_header, sizeof(tz2_header), &header_check_tz, file_stat); } - -static int header_check_tz(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(memcmp(buffer,tz_header,sizeof(tz_header))==0 || - memcmp(buffer,tz2_header,sizeof(tz2_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_tz.extension; - return 1; - } - return 0; -} diff --git a/src/file_vault.c b/src/file_vault.c index 0ed7a607..0a651534 100644 --- a/src/file_vault.c +++ b/src/file_vault.c @@ -3,17 +3,17 @@ File: file_vault.c Copyright (C) 2011 Christophe GRENIER - + This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_vault(file_stat_t *file_stat); -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); const file_hint_t file_hint_vault= { .extension="vault", @@ -43,18 +42,7 @@ const file_hint_t file_hint_vault= { .register_header_check=®ister_header_check_vault }; -static const unsigned char vault_header[0x12]= { - 'S' , 'a' , 'f' , 'e' , 'B' , 'o' , 'o' , 't' , - 'E' , 'n' , 'c' , 'V' , 'o' , 'l' , '1' , 0x00, - 0x01, 0x01 -}; - -static void register_header_check_vault(file_stat_t *file_stat) -{ - register_header_check(0, vault_header, sizeof(vault_header), &header_check_vault, file_stat); -} - -/* +/* * 03200be0 00 00 00 38 65 31 39 37 34 32 30 2d 39 35 65 34 |...8e197420-95e4| * 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.| @@ -79,14 +67,19 @@ static data_check_t data_check_vault(const unsigned char *buffer, const unsigned 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) { - if(memcmp(&buffer[0], vault_header, sizeof(vault_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_vault.extension; - file_recovery_new->data_check=&data_check_vault; - file_recovery_new->file_check=&file_check_size; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_vault.extension; + file_recovery_new->data_check=&data_check_vault; + file_recovery_new->file_check=&file_check_size; + return 1; } +static void register_header_check_vault(file_stat_t *file_stat) +{ + static const unsigned char vault_header[0x12]= { + 'S' , 'a' , 'f' , 'e' , 'B' , 'o' , 'o' , 't' , + 'E' , 'n' , 'c' , 'V' , 'o' , 'l' , '1' , 0x00, + 0x01, 0x01 + }; + register_header_check(0, vault_header, sizeof(vault_header), &header_check_vault, file_stat); +} diff --git a/src/file_vfb.c b/src/file_vfb.c index 421a2e2c..2c66cc3f 100644 --- a/src/file_vfb.c +++ b/src/file_vfb.c @@ -31,8 +31,6 @@ #include "filegen.h" static void register_header_check_vfb(file_stat_t *file_stat); -static int header_check_vfb(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_vfb(file_recovery_t *file_recovery); const file_hint_t file_hint_vfb= { .extension="vfb", @@ -44,27 +42,6 @@ const file_hint_t file_hint_vfb= { .register_header_check=®ister_header_check_vfb }; -static const unsigned char vfb_header[8]= { - 0x1a, 'W' , 'L' , 'F' , '1' , '0' , 0x03, 0x00 -}; - -static void register_header_check_vfb(file_stat_t *file_stat) -{ - register_header_check(0, vfb_header, sizeof(vfb_header), &header_check_vfb, file_stat); -} - -static int header_check_vfb(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(memcmp(buffer, vfb_header, sizeof(vfb_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_vfb.extension; - file_recovery_new->file_check=&file_check_vfb; - return 1; - } - return 0; -} - static void file_check_vfb(file_recovery_t *file_recovery) { const unsigned char vfb_footer[9]= { @@ -73,3 +50,20 @@ static void file_check_vfb(file_recovery_t *file_recovery) }; file_search_footer(file_recovery, vfb_footer, sizeof(vfb_footer), 0); } + +static int header_check_vfb(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_vfb.extension; + file_recovery_new->file_check=&file_check_vfb; + return 1; +} + +static void register_header_check_vfb(file_stat_t *file_stat) +{ + static const unsigned char vfb_header[8]= { + 0x1a, 'W' , 'L' , 'F' , '1' , '0' , 0x03, 0x00 + }; + register_header_check(0, vfb_header, sizeof(vfb_header), &header_check_vfb, file_stat); +} + diff --git a/src/file_vmg.c b/src/file_vmg.c index afa0c9a7..9c33e86f 100644 --- a/src/file_vmg.c +++ b/src/file_vmg.c @@ -52,27 +52,22 @@ static void file_check_vmg(file_recovery_t *file_recovery) file_search_footer(file_recovery, vmg_footer, sizeof(vmg_footer), 0); } -static const unsigned char vmg_header[0x28]= { - 'B' , 0x00, 'E' , 0x00, 'G' , 0x00, 'I' , 0x00, - 'N' , 0x00, ':' , 0x00, 'V' , 0x00, 'M' , 0x00, - 'S' , 0x00, 'G' , 0x00, '\n', 0x00, 'V' , 0x00, - 'E' , 0x00, 'R' , 0x00, 'S' , 0x00, 'I' , 0x00, - 'O' , 0x00, 'N' , 0x00, ':' , 0x00, '1' , 0x00 -}; - static int header_check_vmg(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(memcmp(&buffer[0], vmg_header, sizeof(vmg_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_vmg.extension; - file_recovery_new->file_check=&file_check_vmg; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_vmg.extension; + file_recovery_new->file_check=&file_check_vmg; + return 1; } static void register_header_check_vmg(file_stat_t *file_stat) { + static const unsigned char vmg_header[0x28]= { + 'B' , 0x00, 'E' , 0x00, 'G' , 0x00, 'I' , 0x00, + 'N' , 0x00, ':' , 0x00, 'V' , 0x00, 'M' , 0x00, + 'S' , 0x00, 'G' , 0x00, '\n', 0x00, 'V' , 0x00, + 'E' , 0x00, 'R' , 0x00, 'S' , 0x00, 'I' , 0x00, + 'O' , 0x00, 'N' , 0x00, ':' , 0x00, '1' , 0x00 + }; register_header_check(0, vmg_header, sizeof(vmg_header), &header_check_vmg, file_stat); } diff --git a/src/file_win.c b/src/file_win.c index 21c40254..30d5f0ad 100644 --- a/src/file_win.c +++ b/src/file_win.c @@ -36,8 +36,6 @@ #include "common.h" 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 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", @@ -49,31 +47,6 @@ const file_hint_t file_hint_win= { .register_header_check=®ister_header_check_win }; -static const unsigned char win_header[31]= { - 0xef, 0xbb, 0xbf, 'O' , 'p' , 'e' , 'r' , 'a' , - ' ' , 'P' , 'r' , 'e' , 'f' , 'e' , 'r' , 'e' , - 'n' , 'c' , 'e' , 's' , ' ' , 'v' , 'e' , 'r' , - 's' , 'i' , 'o' , 'n' , ' ' , '2' , '.' -}; - -static void register_header_check_win(file_stat_t *file_stat) -{ - register_header_check(0, win_header, sizeof(win_header), &header_check_win, 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) -{ - if(memcmp(buffer, win_header, sizeof(win_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_win.extension; - file_recovery_new->data_check=&data_check_win; - file_recovery_new->file_check=&file_check_size; - return 1; - } - return 0; -} - static data_check_t data_check_win(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { unsigned int i; @@ -93,3 +66,23 @@ static data_check_t data_check_win(const unsigned char *buffer, const unsigned i file_recovery->calculated_file_size=file_recovery->file_size+(buffer_size/2); return DC_CONTINUE; } + +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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_win.extension; + file_recovery_new->data_check=&data_check_win; + file_recovery_new->file_check=&file_check_size; + return 1; +} + +static void register_header_check_win(file_stat_t *file_stat) +{ + static const unsigned char win_header[31]= { + 0xef, 0xbb, 0xbf, 'O' , 'p' , 'e' , 'r' , 'a' , + ' ' , 'P' , 'r' , 'e' , 'f' , 'e' , 'r' , 'e' , + 'n' , 'c' , 'e' , 's' , ' ' , 'v' , 'e' , 'r' , + 's' , 'i' , 'o' , 'n' , ' ' , '2' , '.' + }; + register_header_check(0, win_header, sizeof(win_header), &header_check_win, file_stat); +} diff --git a/src/file_wks.c b/src/file_wks.c index 65c489c0..5611d361 100644 --- a/src/file_wks.c +++ b/src/file_wks.c @@ -30,10 +30,7 @@ #include "types.h" #include "filegen.h" - static void register_header_check_wks(file_stat_t *file_stat); -static int header_check_wks(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 header_check_wk4(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_wks= { .extension="wks", @@ -45,8 +42,6 @@ const file_hint_t file_hint_wks= { .register_header_check=®ister_header_check_wks }; -static const unsigned char wks_header[10] = { 0x00, 0x00, 0x02, 0x00, 0x04, 0x04, - 0x06, 0x00, 0x08, 0x00}; /* * record type=0 BOF=Beginning of file * record length=2 @@ -58,33 +53,25 @@ static const unsigned char wks_header[10] = { 0x00, 0x00, 0x02, 0x00, 0x04, 0x0 * http://www.schnarff.com/file-formats/lotus-1-2-3/WSFF1.TXT * http://www.schnarff.com/file-formats/lotus-1-2-3/WSFF2.TXT */ -static const unsigned char wk4_header[8] = { 0x00, 0x00, 0x1a, 0x00, 0x02, 0x10, 0x04, 0x00}; - -static void register_header_check_wks(file_stat_t *file_stat) +static int header_check_wk4(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, wks_header,sizeof(wks_header), &header_check_wks, file_stat); - register_header_check(0, wk4_header,sizeof(wk4_header), &header_check_wk4, file_stat); + reset_file_recovery(file_recovery_new); + file_recovery_new->extension="wk4"; + return 1; } static int header_check_wks(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(memcmp(buffer,wks_header,sizeof(wks_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_wks.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_wks.extension; + return 1; } -static int header_check_wk4(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_wks(file_stat_t *file_stat) { - if(memcmp(buffer,wk4_header,sizeof(wk4_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension="wk4"; - return 1; - } - return 0; + static const unsigned char wks_header[10] = { 0x00, 0x00, 0x02, 0x00, 0x04, 0x04, + 0x06, 0x00, 0x08, 0x00}; + static const unsigned char wk4_header[8] = { 0x00, 0x00, 0x1a, 0x00, 0x02, 0x10, 0x04, 0x00}; + register_header_check(0, wks_header,sizeof(wks_header), &header_check_wks, file_stat); + register_header_check(0, wk4_header,sizeof(wk4_header), &header_check_wk4, file_stat); } - diff --git a/src/file_wnk.c b/src/file_wnk.c index 271b1b05..3bd95d2b 100644 --- a/src/file_wnk.c +++ b/src/file_wnk.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_wnk(file_stat_t *file_stat); -static int header_check_wnk(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_wnk= { .extension="wnk", @@ -43,20 +42,15 @@ const file_hint_t file_hint_wnk= { .register_header_check=®ister_header_check_wnk }; -static const unsigned char wnk_header[6]= {'R','P','K','W','I',0x02}; +static int header_check_wnk(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_wnk.extension; + return 1; +} static void register_header_check_wnk(file_stat_t *file_stat) { + static const unsigned char wnk_header[6]= {'R','P','K','W','I',0x02}; register_header_check(0, wnk_header,sizeof(wnk_header), &header_check_wnk, file_stat); } - -static int header_check_wnk(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(memcmp(buffer, wnk_header, sizeof(wnk_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_wnk.extension; - return 1; - } - return 0; -} diff --git a/src/file_wpb.c b/src/file_wpb.c index 5aa47431..a9455ce4 100644 --- a/src/file_wpb.c +++ b/src/file_wpb.c @@ -42,22 +42,17 @@ const file_hint_t file_hint_wpb= { .register_header_check=®ister_header_check_wpb }; -static const unsigned char wpb_header[8]= { - 'W' , 'P' , 'B' , '2' , 0x00, 0x00, 0x00, 0x00 -}; - static int header_check_wpb(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(memcmp(&buffer[0], wpb_header, sizeof(wpb_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_wpb.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_wpb.extension; + return 1; } static void register_header_check_wpb(file_stat_t *file_stat) { + static const unsigned char wpb_header[8]= { + 'W' , 'P' , 'B' , '2' , 0x00, 0x00, 0x00, 0x00 + }; register_header_check(0, wpb_header, sizeof(wpb_header), &header_check_wpb, file_stat); } diff --git a/src/file_wtv.c b/src/file_wtv.c index fe4fbcb3..669b6d99 100644 --- a/src/file_wtv.c +++ b/src/file_wtv.c @@ -44,33 +44,29 @@ const file_hint_t file_hint_wtv= { .register_header_check=®ister_header_check_wtv }; -static const unsigned char wtv_header[16]= { - 0xb7, 0xd8, 0x00, ' ' , '7' , 'I' , 0xda, 0x11, - 0xa6, 'N' , 0x00, 0x07, 0xe9, 0x5e, 0xad, 0x8d -}; - -static void register_header_check_wtv(file_stat_t *file_stat) -{ - register_header_check(0, wtv_header, sizeof(wtv_header), &header_check_wtv, file_stat); -} static int header_check_wtv(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 uint32_t *size=(const uint32_t *)(&buffer[0x5c]); + if(le32(*size)==0) + return 0; if(file_recovery->file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_wtv && file_recovery->file_size<=0x3000) return 0; - if(memcmp(&buffer[0], wtv_header, sizeof(wtv_header))==0) - { - const uint32_t *size=(const uint32_t *)(&buffer[0x5c]); - if(le32(*size)==0) - return 0; - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_wtv.extension; - file_recovery_new->calculated_file_size=((uint64_t)le32(*size))<<12; - file_recovery_new->data_check=&data_check_size; - file_recovery_new->file_check=&file_check_size; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_wtv.extension; + file_recovery_new->calculated_file_size=((uint64_t)le32(*size))<<12; + file_recovery_new->data_check=&data_check_size; + file_recovery_new->file_check=&file_check_size; + return 1; +} + +static void register_header_check_wtv(file_stat_t *file_stat) +{ + static const unsigned char wtv_header[16]= { + 0xb7, 0xd8, 0x00, ' ' , '7' , 'I' , 0xda, 0x11, + 0xa6, 'N' , 0x00, 0x07, 0xe9, 0x5e, 0xad, 0x8d + }; + register_header_check(0, wtv_header, sizeof(wtv_header), &header_check_wtv, file_stat); } diff --git a/src/file_wv.c b/src/file_wv.c index 433bc189..22019dee 100644 --- a/src/file_wv.c +++ b/src/file_wv.c @@ -97,7 +97,7 @@ static data_check_t data_check_wv(const unsigned char *buffer, const unsigned in const unsigned int ape_tag_size = (buffer[i+12] + (buffer[i+13]<<8) + (buffer[i+14]<<16) + (buffer[i+15]<<24))+32; file_recovery->calculated_file_size+=ape_tag_size; } - else if(buffer[i]=='T' && buffer[i+1]=='A' && buffer[i+2]=='G') + else if(buffer[i]=='T' && buffer[i+1]=='A' && buffer[i+2]=='G') { /* http://www.id3.org/ID3v1 TAGv1 size = 128 bytes with header "TAG" */ file_recovery->calculated_file_size+=128; } @@ -105,7 +105,7 @@ static data_check_t data_check_wv(const unsigned char *buffer, const unsigned in { return DC_CONTINUE; } - else + else { return DC_STOP; } diff --git a/src/file_xfi.c b/src/file_xfi.c index a53e0eac..6bd33c90 100644 --- a/src/file_xfi.c +++ b/src/file_xfi.c @@ -42,25 +42,20 @@ const file_hint_t file_hint_xfi= { .register_header_check=®ister_header_check_xfi }; -static const unsigned char xfi_header[0x20]= { - 0x2c, ' ' , 'F' , 'u' , 'e' , 'l' , ' ' , 'A' , - 'i' , 'r' , ' ' , 'S' , 'p' , 'a' , 'r' , 'k' , - ' ' , 'T' , 'e' , 'c' , 'h' , 'n' , 'o' , 'l' , - 'o' , 'g' , 'i' , 'e' , 's' , ' ' , ' ' , ' ' , -}; - static int header_check_xfi(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(memcmp(&buffer[0x10], xfi_header, sizeof(xfi_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_xfi.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_xfi.extension; + return 1; } static void register_header_check_xfi(file_stat_t *file_stat) { + static const unsigned char xfi_header[0x20]= { + 0x2c, ' ' , 'F' , 'u' , 'e' , 'l' , ' ' , 'A' , + 'i' , 'r' , ' ' , 'S' , 'p' , 'a' , 'r' , 'k' , + ' ' , 'T' , 'e' , 'c' , 'h' , 'n' , 'o' , 'l' , + 'o' , 'g' , 'i' , 'e' , 's' , ' ' , ' ' , ' ' , + }; register_header_check(0x10, xfi_header, sizeof(xfi_header), &header_check_xfi, file_stat); } diff --git a/src/file_xfs.c b/src/file_xfs.c index 3b654cd4..f22b0d36 100644 --- a/src/file_xfs.c +++ b/src/file_xfs.c @@ -3,17 +3,17 @@ File: file_xfs.c Copyright (C) 2015 Christophe GRENIER - + This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -81,7 +81,7 @@ typedef struct xfs_timestamp { int32_t t_sec; int32_t t_nsec; -} xfs_timestamp_t; +} xfs_timestamp_t; typedef int64_t xfs_fsize_t; /* bytes in a file */ typedef int32_t xfs_extnum_t; /* # of extents in a file */ @@ -114,7 +114,7 @@ typedef struct xfs_dinode_core uint16_t di_dmstate; uint16_t di_flags; uint32_t di_gen; -} xfs_dinode_core_t; +} xfs_dinode_core_t; static int header_check_xfs_inode(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_xm.c b/src/file_xm.c index 5b18e963..33f29d8e 100644 --- a/src/file_xm.c +++ b/src/file_xm.c @@ -34,7 +34,6 @@ #include "log.h" static void register_header_check_xm(file_stat_t *file_stat); -static int header_check_xm(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_xm= { .extension="xm", @@ -180,22 +179,17 @@ static void file_check_xm(file_recovery_t *fr) } -static const unsigned char xm_header[17] = { 'E','x','t','e','n','d','e','d',' ','M','o','d','u','l','e',':',' '}; +static int header_check_xm(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_xm.extension; + file_recovery_new->min_filesize=336 + 29; /* Header + 1 instrument */ + file_recovery_new->file_check=&file_check_xm; + return 1; +} static void register_header_check_xm(file_stat_t *file_stat) { + static const unsigned char xm_header[17] = { 'E','x','t','e','n','d','e','d',' ','M','o','d','u','l','e',':',' '}; register_header_check(0, xm_header,sizeof(xm_header), &header_check_xm, file_stat); } - -static int header_check_xm(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(memcmp(buffer,xm_header,sizeof(xm_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_xm.extension; - file_recovery_new->min_filesize=336 + 29; /* Header + 1 instrument */ - file_recovery_new->file_check=&file_check_xm; - return 1; - } - return 0; -} diff --git a/src/file_xsv.c b/src/file_xsv.c index 1831bba9..da38a48b 100644 --- a/src/file_xsv.c +++ b/src/file_xsv.c @@ -44,23 +44,18 @@ const file_hint_t file_hint_xsv= { .register_header_check=®ister_header_check_xsv }; -static const unsigned char xsv_header[9]= {'B','L','O','C', 'K', 'L', 0xDC, 0x1D, 'd'}; +static int header_check_xsv(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) +{ + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_xsv.extension; + file_recovery_new->calculated_file_size=202772; + file_recovery_new->data_check=&data_check_size; + file_recovery_new->file_check=&file_check_size; + return 1; +} static void register_header_check_xsv(file_stat_t *file_stat) { + static const unsigned char xsv_header[9]= {'B','L','O','C', 'K', 'L', 0xDC, 0x1D, 'd'}; register_header_check(20, xsv_header,sizeof(xsv_header), &header_check_xsv, file_stat); } - -static int header_check_xsv(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(memcmp(buffer + 20, xsv_header, sizeof(xsv_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_xsv.extension; - file_recovery_new->calculated_file_size=202772; - file_recovery_new->data_check=&data_check_size; - file_recovery_new->file_check=&file_check_size; - return 1; - } - return 0; -} diff --git a/src/file_xz.c b/src/file_xz.c index 37700d80..943870be 100644 --- a/src/file_xz.c +++ b/src/file_xz.c @@ -48,25 +48,20 @@ static void file_check_xz(file_recovery_t *file_recovery) file_search_footer(file_recovery, xz_footer, sizeof(xz_footer), 0); } -/* http://tukaani.org/xz/xz-file-format.txt */ -/* HEADER_MAGIC + Stream Flag[0] */ -static const unsigned char xz_header[7]= { - 0xfd, '7' , 'z' , 'X' , 'Z' , 0x00, 0x00 -}; - static int header_check_xz(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(memcmp(&buffer[0], xz_header, sizeof(xz_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_xz.extension; - file_recovery_new->file_check=&file_check_xz; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_xz.extension; + file_recovery_new->file_check=&file_check_xz; + return 1; } static void register_header_check_xz(file_stat_t *file_stat) { + /* http://tukaani.org/xz/xz-file-format.txt */ + /* HEADER_MAGIC + Stream Flag[0] */ + static const unsigned char xz_header[7]= { + 0xfd, '7' , 'z' , 'X' , 'Z' , 0x00, 0x00 + }; register_header_check(0, xz_header, sizeof(xz_header), &header_check_xz, file_stat); }