1 /*
2
3 File: file_dat.c
4
5 Copyright (C) 2007,2012 Christophe GRENIER <grenier@cgsecurity.org>
6
7 This software is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write the Free Software Foundation, Inc., 51
19 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 #ifdef HAVE_STRING_H
27 #include <string.h>
28 #endif
29 #include <stdio.h>
30 #include "types.h"
31 #include "filegen.h"
32
33 static void register_header_check_dat(file_stat_t *file_stat);
34
35 const file_hint_t file_hint_dat= {
36 .extension="dat",
37 .description="IE History, Glavna Knjiga account data",
38 .max_filesize=2*1024*1024,
39 .recover=1,
40 .enable_by_default=1,
41 .register_header_check=®ister_header_check_dat
42 };
43
header_check_dat(const unsigned char * buffer,const unsigned int buffer_size,const unsigned int safe_header_only,const file_recovery_t * file_recovery,file_recovery_t * file_recovery_new)44 static int header_check_dat(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
45 {
46 reset_file_recovery(file_recovery_new);
47 file_recovery_new->extension=file_hint_dat.extension;
48 file_recovery_new->min_filesize=8;
49 return 1;
50 }
51
header_check_datIE(const unsigned char * buffer,const unsigned int buffer_size,const unsigned int safe_header_only,const file_recovery_t * file_recovery,file_recovery_t * file_recovery_new)52 static int header_check_datIE(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
53 {
54 const uint64_t size=(uint64_t)buffer[0x1C]+(((uint64_t)buffer[0x1D])<<8)+(((uint64_t)buffer[0x1E])<<16)+(((uint64_t)buffer[0x1F])<<24);
55 if(size < 0x20)
56 return 0;
57 reset_file_recovery(file_recovery_new);
58 file_recovery_new->extension=file_hint_dat.extension;
59 file_recovery_new->min_filesize=0x20;
60 file_recovery_new->calculated_file_size=size;
61 file_recovery_new->data_check=&data_check_size;
62 file_recovery_new->file_check=&file_check_size;
63 return 1;
64 }
65
header_check_dat_history4(const unsigned char * buffer,const unsigned int buffer_size,const unsigned int safe_header_only,const file_recovery_t * file_recovery,file_recovery_t * file_recovery_new)66 static int header_check_dat_history4(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
67 {
68 if(memcmp(&buffer[0x30], "BrowserVisit", 12)!=0)
69 return 0;
70 reset_file_recovery(file_recovery_new);
71 file_recovery_new->extension=file_hint_dat.extension;
72 file_recovery_new->min_filesize=60;
73 return 1;
74 }
75
header_check_dat_history10(const unsigned char * buffer,const unsigned int buffer_size,const unsigned int safe_header_only,const file_recovery_t * file_recovery,file_recovery_t * file_recovery_new)76 static int header_check_dat_history10(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
77 {
78 if(memcmp(&buffer[0x36], "BrowserVisit", 12)!=0)
79 return 0;
80 reset_file_recovery(file_recovery_new);
81 file_recovery_new->extension=file_hint_dat.extension;
82 file_recovery_new->min_filesize=66;
83 return 1;
84 }
85
register_header_check_dat(file_stat_t * file_stat)86 static void register_header_check_dat(file_stat_t *file_stat)
87 {
88 static const unsigned char dat_header[8]= {0x30, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
89 /* Found on Sony Ericson phone */
90 static const unsigned char dat_history[8]={ 'N', 'F', 'P', 'K', 'D', 'D', 'A', 'T'};
91 register_header_check(0, dat_header,sizeof(dat_header), &header_check_dat, file_stat);
92 register_header_check(0, "Client UrlCache MMF Ver 5.2", 0x1c, &header_check_datIE, file_stat);
93 register_header_check(4, dat_history, sizeof(dat_history), &header_check_dat_history4, file_stat);
94 register_header_check(10, dat_history, sizeof(dat_history), &header_check_dat_history10, file_stat);
95 }
96