From f29c37c87b097e8761ec359165f27a0ff786368f Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Mon, 10 Sep 2012 22:19:38 +0200 Subject: [PATCH] Make some variables more local --- src/file_asf.c | 8 ++++---- src/file_mkv.c | 10 +++++----- src/file_mpg.c | 2 +- src/file_mrw.c | 2 +- src/file_qdf.c | 18 ++++++++++-------- src/file_txt.c | 12 ++++-------- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/file_asf.c b/src/file_asf.c index c0ff20f4..8f9fbd40 100644 --- a/src/file_asf.c +++ b/src/file_asf.c @@ -73,10 +73,6 @@ static int header_check_asf(const unsigned char *buffer, const unsigned int buff 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }; - static const unsigned char asf_file_prop_id[16]= { - 0xa1, 0xdc, 0xab, 0x8c, 0x47, 0xa9, 0xcf, 0x11, - 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 - }; if(memcmp(buffer, asf_header_id, sizeof(asf_header_id))==0) { unsigned int i; @@ -89,6 +85,10 @@ static int header_check_asf(const unsigned char *buffer, const unsigned int buff (const unsigned char *)(asf_file_prop+1) < buffer + buffer_size; i++) { + static const unsigned char asf_file_prop_id[16]= { + 0xa1, 0xdc, 0xab, 0x8c, 0x47, 0xa9, 0xcf, 0x11, + 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 + }; if(memcmp(asf_file_prop->object_id, asf_file_prop_id, sizeof(asf_file_prop_id))==0) { file_recovery_new->calculated_file_size=le64(asf_file_prop->file_size); diff --git a/src/file_mkv.c b/src/file_mkv.c index b2cbaf6e..505da769 100644 --- a/src/file_mkv.c +++ b/src/file_mkv.c @@ -134,10 +134,11 @@ static void register_header_check_mkv(file_stat_t *file_stat) static int header_check_mkv(const unsigned char *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 EBML_DocType[2]= { 0x42,0x82}; - const unsigned char EBML_Segment[4]= { 0x18,0x53,0x80,0x67}; - if(memcmp(buffer,EBML_header,sizeof(EBML_header))==0) + if(memcmp(buffer,EBML_header,sizeof(EBML_header))!=0) + return 0; { + const unsigned char EBML_DocType[2]= { 0x42,0x82}; + const unsigned char EBML_Segment[4]= { 0x18,0x53,0x80,0x67}; uint64_t segment_size=0; uint64_t header_data_size=0; char *doctype=NULL; @@ -193,7 +194,6 @@ static int header_check_mkv(const unsigned char *buffer, const unsigned int buff file_recovery_new->data_check=&data_check_size; file_recovery_new->file_check=&file_check_size; } - return 1; } - return 0; + return 1; } diff --git a/src/file_mpg.c b/src/file_mpg.c index 322a2413..ba50ef45 100644 --- a/src/file_mpg.c +++ b/src/file_mpg.c @@ -156,7 +156,6 @@ static int header_check_mpg(const unsigned char *buffer, const unsigned int buff static int data_check_mpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { const unsigned char padding_iso_end[8]= {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xB9}; - const unsigned char sequence_end_iso_end[8]={0x00, 0x00, 0x01, 0xB7, 0x00, 0x00, 0x01, 0xB9}; /* search padding + end code */ if(buffer_size>=8 && memcmp(&buffer[buffer_size/2-4], padding_iso_end, sizeof(padding_iso_end))==0) { @@ -169,6 +168,7 @@ static int data_check_mpg(const unsigned char *buffer, const unsigned int buffer unsigned int i; for(i=buffer_size/2-7; icalculated_file_size=file_recovery->file_size+i+sizeof(sequence_end_iso_end)-buffer_size/2; diff --git a/src/file_mrw.c b/src/file_mrw.c index e0e12833..c6398499 100644 --- a/src/file_mrw.c +++ b/src/file_mrw.c @@ -79,9 +79,9 @@ 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) { - const unsigned char prd_header[4]= { 0x00,'P','R','D'}; 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) { diff --git a/src/file_qdf.c b/src/file_qdf.c index a35ee6d8..bb8b5aa0 100644 --- a/src/file_qdf.c +++ b/src/file_qdf.c @@ -45,19 +45,21 @@ const file_hint_t file_hint_qdf= { }; static const unsigned char qdf_header[6] = { 0xAC, 0x9E, 0xBD, 0x8F, 0x00, 0x00}; +static const unsigned char qdf_header2[0x10] = { + 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; static void register_header_check_qdf(file_stat_t *file_stat) { - register_header_check(0, qdf_header,sizeof(qdf_header), &header_check_qdf, file_stat); + register_header_check(0, qdf_header, sizeof(qdf_header), &header_check_qdf, file_stat); + + register_header_check(0, qdf_header2, sizeof(qdf_header2), &header_check_qdf, file_stat); } static int header_check_qdf(const unsigned char *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,qdf_header,sizeof(qdf_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_qdf.extension; - return 1; - } - return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_qdf.extension; + return 1; } diff --git a/src/file_txt.c b/src/file_txt.c index 8d1ab164..9dcfccbd 100644 --- a/src/file_txt.c +++ b/src/file_txt.c @@ -77,7 +77,6 @@ const file_hint_t file_hint_txt= { .register_header_check=®ister_header_check_txt }; -static const unsigned char header_ReceivedFrom[14]= {'R','e','c','e','i','v','e','d',':',' ','f','r','o','m'}; static unsigned char ascii_char[256]; static void register_header_check_txt(file_stat_t *file_stat) @@ -718,14 +717,13 @@ static int header_check_le16_txt(const unsigned char *buffer, const unsigned int static void file_check_emlx(file_recovery_t *file_recovery) { - const unsigned char emlx_footer[9]= {'<', '/', 'p', 'l', 'i', 's', 't', '>', 0x0a}; if(file_recovery->file_size < file_recovery->calculated_file_size) file_recovery->file_size=0; else { if(file_recovery->file_size > file_recovery->calculated_file_size+2048) file_recovery->file_size=file_recovery->calculated_file_size+2048; - file_search_footer(file_recovery, emlx_footer, sizeof(emlx_footer), 0); + file_search_footer(file_recovery, "\n", 9, 0); } } @@ -734,8 +732,6 @@ static int header_check_txt(const unsigned char *buffer, const unsigned int buff static char *buffer_lower=NULL; static unsigned int buffer_lower_size=0; unsigned int l=0; - const char sign_h[] = "/*"; - static const unsigned char header_ReturnPath[13]= {'R','e','t','u','r','n','-','P','a','t','h',':',' '}; const unsigned int buffer_size_test=(buffer_size < 2048 ? buffer_size : 2048); { unsigned int i; @@ -743,8 +739,8 @@ static int header_check_txt(const unsigned char *buffer, const unsigned int buff for(i=0;i<10 && isdigit(buffer[i]);i++) tmp=tmp*10+buffer[i]-'0'; if(buffer[i]==0x0a && - (memcmp(buffer+i+1, header_ReturnPath, sizeof(header_ReturnPath))==0 || - memcmp(buffer+i+1, header_ReceivedFrom, sizeof(header_ReceivedFrom))==0) && + (memcmp(buffer+i+1, "Return-Path: ", 13)==0 || + memcmp(buffer+i+1, "Received: from", 14)==0) && !(file_recovery!=NULL && file_recovery->file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_fasttxt && strcmp(file_recovery->extension,"mbox")==0)) @@ -940,7 +936,7 @@ static int header_check_txt(const unsigned char *buffer, const unsigned int buff ext="f"; else if(strstr(buffer_lower, "\\score {")!=NULL) ext="ly"; /* LilyPond http://lilypond.org*/ - else if(strstr(buffer_lower, sign_h)!=NULL && l>50) + else if(strstr(buffer_lower, "/*")!=NULL && l>50) ext="h"; else if(l<100 || ind<0.03 || ind>0.90) ext=NULL;