summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/file_ddf.c15
-rw-r--r--src/file_dpx.c12
-rw-r--r--src/file_ds2.c15
-rw-r--r--src/file_dss.c16
-rw-r--r--src/file_fits.c16
-rw-r--r--src/file_pdf.c40
-rw-r--r--src/file_tiff.c14
-rw-r--r--src/file_txt.c15
-rw-r--r--src/filegen.c68
-rw-r--r--src/filegen.h4
10 files changed, 96 insertions, 119 deletions
diff --git a/src/file_ddf.c b/src/file_ddf.c
index 80a87fb..805c95c 100644
--- a/src/file_ddf.c
+++ b/src/file_ddf.c
@@ -81,21 +81,12 @@ struct MasterHeader
static int header_check_aux(const unsigned char *buffer, file_recovery_t *file_recovery_new)
{
+ const char *date_asc=(const char *)&buffer[0x3f];
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_ddf.extension;
- if(buffer[0x43]=='-' && buffer[0x46]=='-' && buffer[0x49]=='_')
+ if(date_asc[4]=='-' && date_asc[7]=='-' && date_asc[10]=='_')
{
- struct tm tm_time;
- memset(&tm_time, 0, sizeof(tm_time));
- tm_time.tm_sec=(buffer[0x4e]-'0')*10+(buffer[0x4f]-'0'); /* seconds 0-59 */
- tm_time.tm_min=(buffer[0x4c]-'0')*10+(buffer[0x4d]-'0'); /* minutes 0-59 */
- tm_time.tm_hour=(buffer[0x4a]-'0')*10+(buffer[0x4b]-'0'); /* hours 0-23*/
- tm_time.tm_mday=(buffer[0x47]-'0')*10+(buffer[0x48]-'0'); /* day of the month 1-31 */
- tm_time.tm_mon=(buffer[0x44]-'0')*10+(buffer[0x45]-'0')-1; /* month 0-11 */
- tm_time.tm_year=(buffer[0x3f]-'0')*1000+(buffer[0x40]-'0')*100+
- (buffer[0x41]-'0')*10+(buffer[0x42]-'0')-1900; /* year */
- tm_time.tm_isdst = -1; /* unknown daylight saving time */
- file_recovery_new->time=mktime(&tm_time);
+ file_recovery_new->time=get_time_from_YYYY_MM_DD_HHMMSS(date_asc);
}
return 1;
}
diff --git a/src/file_dpx.c b/src/file_dpx.c
index 155e969..b764efe 100644
--- a/src/file_dpx.c
+++ b/src/file_dpx.c
@@ -71,24 +71,14 @@ static int header_check_dpx(const unsigned char *buffer, const unsigned int buff
const struct header_dpx *dpx=(const struct header_dpx *)buffer;
if(memcmp(dpx->vers, ver10, sizeof(ver10))==0)
{
- struct tm tm_time;
if(be32(dpx->file_size) < 19)
return 0;
- memset(&tm_time, 0, sizeof(tm_time));
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_dpx.extension;
file_recovery_new->calculated_file_size=be32(dpx->file_size);
file_recovery_new->data_check=&data_check_size;
file_recovery_new->file_check=&file_check_size;
- tm_time.tm_sec=(dpx->create_time[17]-'0')*10+(dpx->create_time[18]-'0'); /* seconds 0-59 */
- tm_time.tm_min=(dpx->create_time[14]-'0')*10+(dpx->create_time[15]-'0'); /* minutes 0-59 */
- tm_time.tm_hour=(dpx->create_time[11]-'0')*10+(dpx->create_time[12]-'0'); /* hours 0-23*/
- tm_time.tm_mday=(dpx->create_time[8]-'0')*10+(dpx->create_time[9]-'0'); /* day of the month 1-31 */
- tm_time.tm_mon=(dpx->create_time[5]-'0')*10+(dpx->create_time[6]-'0')-1; /* month 0-11 */
- tm_time.tm_year=(dpx->create_time[0]-'0')*1000+(dpx->create_time[1]-'0')*100+
- (dpx->create_time[2]-'0')*10+(dpx->create_time[3]-'0')-1900; /* year */
- tm_time.tm_isdst = -1; /* unknown daylight saving time */
- file_recovery_new->time=mktime(&tm_time);
+ file_recovery_new->time=get_time_from_YYYY_MM_DD_HH_MM_SS(dpx->create_time);
return 1;
}
return 0;
diff --git a/src/file_ds2.c b/src/file_ds2.c
index 7757f9e..73b1116 100644
--- a/src/file_ds2.c
+++ b/src/file_ds2.c
@@ -57,8 +57,7 @@ const file_hint_t file_hint_ds2= {
static int header_check_ds2(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
- struct tm tm_time;
- const unsigned char *date_asc=&buffer[0x26];
+ const char *date_asc=(const char *)&buffer[0x26];
unsigned int i;
for(i=0; i<24; i++)
if(!isdigit(date_asc[i]))
@@ -66,17 +65,7 @@ static int header_check_ds2(const unsigned char *buffer, const unsigned int buff
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_ds2.extension;
file_recovery_new->min_filesize=0x200;
- memset(&tm_time, 0, sizeof(tm_time));
- tm_time.tm_sec=(date_asc[10]-'0')*10+(date_asc[11]-'0'); /* seconds 0-59 */
- tm_time.tm_min=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* minutes 0-59 */
- tm_time.tm_hour=(date_asc[6]-'0')*10+(date_asc[7]-'0'); /* hours 0-23*/
- tm_time.tm_mday=(date_asc[4]-'0')*10+(date_asc[5]-'0'); /* day of the month 1-31 */
- tm_time.tm_mon=(date_asc[2]-'0')*10+(date_asc[3]-'0')-1; /* month 1-12 */
- tm_time.tm_year=(date_asc[0]-'0')*10+(date_asc[1]-'0'); /* year */
- if(tm_time.tm_year<80)
- tm_time.tm_year+=100; /* year 2000 - 2079 */
- tm_time.tm_isdst = -1; /* unknown daylight saving time */
- file_recovery_new->time=mktime(&tm_time);
+ file_recovery_new->time=get_time_from_YYMMDDHHMMSS(date_asc);
return 1;
}
diff --git a/src/file_dss.c b/src/file_dss.c
index aa4e45c..8f6de2b 100644
--- a/src/file_dss.c
+++ b/src/file_dss.c
@@ -58,11 +58,9 @@ const file_hint_t file_hint_dss= {
Filesize is always a multiple of 512
*/
-
static int header_check_dss(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
- struct tm tm_time;
- const unsigned char *date_asc=&buffer[0x26];
+ const char *date_asc=(const char *)&buffer[0x26];
unsigned int i;
for(i=0; i<24; i++)
if(!isdigit(date_asc[i]))
@@ -71,17 +69,7 @@ static int header_check_dss(const unsigned char *buffer, const unsigned int buff
file_recovery_new->extension=file_hint_dss.extension;
/* File should be big enough to hold the comments */
file_recovery_new->min_filesize=100+0x31E;
- memset(&tm_time, 0, sizeof(tm_time));
- tm_time.tm_sec=(date_asc[10]-'0')*10+(date_asc[11]-'0'); /* seconds 0-59 */
- tm_time.tm_min=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* minutes 0-59 */
- tm_time.tm_hour=(date_asc[6]-'0')*10+(date_asc[7]-'0'); /* hours 0-23*/
- tm_time.tm_mday=(date_asc[4]-'0')*10+(date_asc[5]-'0'); /* day of the month 1-31 */
- tm_time.tm_mon=(date_asc[2]-'0')*10+(date_asc[3]-'0')-1; /* month 1-12 */
- tm_time.tm_year=(date_asc[0]-'0')*10+(date_asc[1]-'0'); /* year */
- if(tm_time.tm_year<80)
- tm_time.tm_year+=100; /* year 2000 - 2079 */
- tm_time.tm_isdst = -1; /* unknown daylight saving time */
- file_recovery_new->time=mktime(&tm_time);
+ file_recovery_new->time=get_time_from_YYMMDDHHMMSS(date_asc);
return 1;
}
diff --git a/src/file_fits.c b/src/file_fits.c
index ec67aea..a82e438 100644
--- a/src/file_fits.c
+++ b/src/file_fits.c
@@ -95,23 +95,13 @@ static uint64_t fits_info(const unsigned char *buffer, const unsigned int buffer
{
/* CREA_DAT= '2007-08-29T16:22:09' */
/* 0123456789012345678 */
- const unsigned char *date_asc;
+ const char *date_asc;
unsigned int j;
- for(j=0,date_asc=&buffer[i];j<80 && *date_asc!='\'';j++,date_asc++);
+ for(j=0,date_asc=(const char *)&buffer[i];j<80 && *date_asc!='\'';j++,date_asc++);
if(j<60 && *date_asc=='\'')
{
- struct tm tm_time;
- memset(&tm_time, 0, sizeof(tm_time));
date_asc++;
- tm_time.tm_sec=(date_asc[17]-'0')*10+(date_asc[18]-'0'); /* seconds 0-59 */
- tm_time.tm_min=(date_asc[14]-'0')*10+(date_asc[15]-'0'); /* minutes 0-59 */
- tm_time.tm_hour=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* hours 0-23*/
- tm_time.tm_mday=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* day of the month 1-31 */
- tm_time.tm_mon=(date_asc[5]-'0')*10+(date_asc[6]-'0')-1; /* month 0-11 */
- tm_time.tm_year=(date_asc[0]-'0')*1000+(date_asc[1]-'0')*100+
- (date_asc[2]-'0')*10+(date_asc[3]-'0')-1900; /* year */
- tm_time.tm_isdst = -1; /* unknown daylight saving time */
- file_recovery->time=mktime(&tm_time);
+ file_recovery->time=get_time_from_YYYY_MM_DD_HH_MM_SS(date_asc);
}
}
}
diff --git a/src/file_pdf.c b/src/file_pdf.c
index 9be41c3..c62b9bf 100644
--- a/src/file_pdf.c
+++ b/src/file_pdf.c
@@ -245,38 +245,18 @@ static void file_date_pdf(file_recovery_t *file_recovery)
{
if(++j==sizeof(pattern))
{
- const unsigned char *date_asc;
- struct tm tm_time;
- if(my_fseek(file_recovery->handle, offset+i+1, SEEK_SET)<0)
+ if(my_fseek(file_recovery->handle, offset+i+1, SEEK_SET)>=0 &&
+ fread(buffer, 1, 22, file_recovery->handle) == 22)
{
- free(buffer);
- return ;
+ if(buffer[0]=='=' && (buffer[1]=='\'' || buffer[1]=='"'))
+ {
+ file_recovery->time=get_time_from_YYYY_MM_DD_HH_MM_SS((const char *)&buffer[2]);
+ }
+ else if(buffer[0]=='>')
+ {
+ file_recovery->time=get_time_from_YYYY_MM_DD_HH_MM_SS((const char *)&buffer[1]);
+ }
}
- if(fread(buffer, 1, 22, file_recovery->handle) < 22)
- {
- free(buffer);
- return ;
- }
- if(buffer[0]=='=' && (buffer[1]=='\'' || buffer[1]=='"'))
- date_asc=&buffer[2];
- else if(buffer[i]=='>')
- date_asc=&buffer[1];
- else
- {
- free(buffer);
- return ;
- }
- /* */
- memset(&tm_time, 0, sizeof(tm_time));
- tm_time.tm_sec=(date_asc[17]-'0')*10+(date_asc[18]-'0'); /* seconds 0-59 */
- tm_time.tm_min=(date_asc[14]-'0')*10+(date_asc[15]-'0'); /* minutes 0-59 */
- tm_time.tm_hour=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* hours 0-23*/
- tm_time.tm_mday=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* day of the month 1-31 */
- tm_time.tm_mon=(date_asc[5]-'0')*10+(date_asc[6]-'0')-1; /* month 0-11 */
- tm_time.tm_year=(date_asc[0]-'0')*1000+(date_asc[1]-'0')*100+
- (date_asc[2]-'0')*10+(date_asc[3]-'0')-1900; /* year */
- tm_time.tm_isdst = -1; /* unknown daylight saving time */
- file_recovery->time=mktime(&tm_time);
free(buffer);
return ;
}
diff --git a/src/file_tiff.c b/src/file_tiff.c
index a0df566..45a5b44 100644
--- a/src/file_tiff.c
+++ b/src/file_tiff.c
@@ -286,7 +286,6 @@ time_t get_date_from_tiff_header(const TIFFHeader *tiff, const unsigned int tiff
{
const char *potential_error=NULL;
const char *date_asc;
- struct tm tm_time;
/* DateTimeOriginal */
date_asc=find_tag_from_tiff_header(tiff, tiff_size, 0x9003, &potential_error);
/* DateTimeDigitalized*/
@@ -296,18 +295,7 @@ time_t get_date_from_tiff_header(const TIFFHeader *tiff, const unsigned int tiff
date_asc=find_tag_from_tiff_header(tiff, tiff_size, 0x132, &potential_error);
if(date_asc==NULL || date_asc < (const char *)tiff || &date_asc[18] >= (const char *)tiff + tiff_size)
return (time_t)0;
- if(memcmp(date_asc, "0000", 4)==0)
- return (time_t)0;
- memset(&tm_time, 0, sizeof(tm_time));
- tm_time.tm_sec=(date_asc[17]-'0')*10+(date_asc[18]-'0'); /* seconds 0-59 */
- tm_time.tm_min=(date_asc[14]-'0')*10+(date_asc[15]-'0'); /* minutes 0-59 */
- tm_time.tm_hour=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* hours 0-23*/
- tm_time.tm_mday=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* day of the month 1-31 */
- tm_time.tm_mon=(date_asc[5]-'0')*10+(date_asc[6]-'0')-1; /* month 0-11 */
- tm_time.tm_year=(date_asc[0]-'0')*1000+(date_asc[1]-'0')*100+
- (date_asc[2]-'0')*10+(date_asc[3]-'0')-1900; /* year */
- tm_time.tm_isdst = -1; /* unknown daylight saving time */
- return mktime(&tm_time);
+ return get_time_from_YYYY_MM_DD_HH_MM_SS(date_asc);
}
static int header_check_tiff_be_new(const unsigned char *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_txt.c b/src/file_txt.c
index b558020..a65842f 100644
--- a/src/file_txt.c
+++ b/src/file_txt.c
@@ -573,20 +573,9 @@ static int header_check_ics(const unsigned char *buffer, const unsigned int buff
date_asc=strstr(buffer2, "DTSTART");
if(date_asc!=NULL)
date_asc=strchr(date_asc, ':');
- if(date_asc!=NULL && date_asc-buffer2<=buffer_size-14)
+ if(date_asc!=NULL && date_asc+1+14 < buffer2+buffer_size)
{
- struct tm tm_time;
- memset(&tm_time, 0, sizeof(tm_time));
- date_asc++;
- tm_time.tm_sec=(date_asc[13]-'0')*10+(date_asc[14]-'0'); /* seconds 0-59 */
- tm_time.tm_min=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* minutes 0-59 */
- tm_time.tm_hour=(date_asc[9]-'0')*10+(date_asc[10]-'0'); /* hours 0-23*/
- tm_time.tm_mday=(date_asc[6]-'0')*10+(date_asc[7]-'0'); /* day of the month 1-31 */
- tm_time.tm_mon=(date_asc[4]-'0')*10+(date_asc[5]-'0')-1; /* month 0-11 */
- tm_time.tm_year=(date_asc[0]-'0')*1000+(date_asc[1]-'0')*100+
- (date_asc[2]-'0')*10+(date_asc[3]-'0')-1900; /* year */
- tm_time.tm_isdst = -1; /* unknown daylight saving time */
- file_recovery_new->time=mktime(&tm_time);
+ file_recovery_new->time=get_time_from_YYYYMMDD_HHMMSS(date_asc+1);
}
free(buffer2);
return 1;
diff --git a/src/filegen.c b/src/filegen.c
index 7a6169c..814d1c7 100644
--- a/src/filegen.c
+++ b/src/filegen.c
@@ -32,6 +32,9 @@
#include <stdio.h>
#include <ctype.h>
#include <assert.h>
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
#include "types.h"
#include "common.h"
#include "filegen.h"
@@ -704,3 +707,68 @@ int my_fseek(FILE *stream, off_t offset, int whence)
#endif
return fseek(stream, offset, whence);
}
+
+time_t get_time_from_YYMMDDHHMMSS(const char *date_asc)
+{
+ struct tm tm_time;
+ memset(&tm_time, 0, sizeof(tm_time));
+ tm_time.tm_sec=(date_asc[10]-'0')*10+(date_asc[11]-'0'); /* seconds 0-59 */
+ tm_time.tm_min=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* minutes 0-59 */
+ tm_time.tm_hour=(date_asc[6]-'0')*10+(date_asc[7]-'0'); /* hours 0-23*/
+ tm_time.tm_mday=(date_asc[4]-'0')*10+(date_asc[5]-'0'); /* day of the month 1-31 */
+ tm_time.tm_mon=(date_asc[2]-'0')*10+(date_asc[3]-'0')-1; /* month 1-12 */
+ tm_time.tm_year=(date_asc[0]-'0')*10+(date_asc[1]-'0'); /* year */
+ if(tm_time.tm_year<80)
+ tm_time.tm_year+=100; /* year 2000 - 2079 */
+ tm_time.tm_isdst = -1; /* unknown daylight saving time */
+ return mktime(&tm_time);
+}
+
+time_t get_time_from_YYYY_MM_DD_HH_MM_SS(const char *date_asc)
+{
+ struct tm tm_time;
+ if(memcmp(date_asc, "0000", 4)==0)
+ return (time_t)0;
+ memset(&tm_time, 0, sizeof(tm_time));
+ tm_time.tm_sec=(date_asc[17]-'0')*10+(date_asc[18]-'0'); /* seconds 0-59 */
+ tm_time.tm_min=(date_asc[14]-'0')*10+(date_asc[15]-'0'); /* minutes 0-59 */
+ tm_time.tm_hour=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* hours 0-23*/
+ tm_time.tm_mday=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* day of the month 1-31 */
+ tm_time.tm_mon=(date_asc[5]-'0')*10+(date_asc[6]-'0')-1; /* month 0-11 */
+ tm_time.tm_year=(date_asc[0]-'0')*1000+(date_asc[1]-'0')*100+
+ (date_asc[2]-'0')*10+(date_asc[3]-'0')-1900; /* year */
+ tm_time.tm_isdst = -1; /* unknown daylight saving time */
+ return mktime(&tm_time);
+}
+
+time_t get_time_from_YYYY_MM_DD_HHMMSS(const char *date_asc)
+{
+ struct tm tm_time;
+ if(memcmp(date_asc, "0000", 4)==0)
+ return (time_t)0;
+ memset(&tm_time, 0, sizeof(tm_time));
+ tm_time.tm_sec=(date_asc[15]-'0')*10+(date_asc[16]-'0'); /* seconds 0-59 */
+ tm_time.tm_min=(date_asc[13]-'0')*10+(date_asc[14]-'0'); /* minutes 0-59 */
+ tm_time.tm_hour=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* hours 0-23*/
+ tm_time.tm_mday=(date_asc[8]-'0')*10+(date_asc[9]-'0'); /* day of the month 1-31 */
+ tm_time.tm_mon=(date_asc[5]-'0')*10+(date_asc[6]-'0')-1; /* month 0-11 */
+ tm_time.tm_year=(date_asc[0]-'0')*1000+(date_asc[1]-'0')*100+
+ (date_asc[2]-'0')*10+(date_asc[3]-'0')-1900; /* year */
+ tm_time.tm_isdst = -1; /* unknown daylight saving time */
+ return mktime(&tm_time);
+}
+
+time_t get_time_from_YYYYMMDD_HHMMSS(const char *date_asc)
+{
+ struct tm tm_time;
+ memset(&tm_time, 0, sizeof(tm_time));
+ tm_time.tm_sec=(date_asc[13]-'0')*10+(date_asc[14]-'0'); /* seconds 0-59 */
+ tm_time.tm_min=(date_asc[11]-'0')*10+(date_asc[12]-'0'); /* minutes 0-59 */
+ tm_time.tm_hour=(date_asc[9]-'0')*10+(date_asc[10]-'0'); /* hours 0-23*/
+ tm_time.tm_mday=(date_asc[6]-'0')*10+(date_asc[7]-'0'); /* day of the month 1-31 */
+ tm_time.tm_mon=(date_asc[4]-'0')*10+(date_asc[5]-'0')-1; /* month 0-11 */
+ tm_time.tm_year=(date_asc[0]-'0')*1000+(date_asc[1]-'0')*100+
+ (date_asc[2]-'0')*10+(date_asc[3]-'0')-1900; /* year */
+ tm_time.tm_isdst = -1; /* unknown daylight saving time */
+ return mktime(&tm_time);
+}
diff --git a/src/filegen.h b/src/filegen.h
index 7d220e1..af8e793 100644
--- a/src/filegen.h
+++ b/src/filegen.h
@@ -138,6 +138,10 @@ int file_rename_unicode(file_recovery_t *file_recovery, const void *buffer, cons
void header_ignored(const file_recovery_t *file_recovery_new);
int header_ignored_adv(const file_recovery_t *file_recovery, const file_recovery_t *file_recovery_new);
int my_fseek(FILE *stream, off_t offset, int whence);
+time_t get_time_from_YYMMDDHHMMSS(const char *date_asc);
+time_t get_time_from_YYYY_MM_DD_HH_MM_SS(const char *date_asc);
+time_t get_time_from_YYYY_MM_DD_HHMMSS(const char *date_asc);
+time_t get_time_from_YYYYMMDD_HHMMSS(const char *date_asc);
#ifdef __cplusplus
} /* closing brace for extern "C" */