summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--INSTALL23
-rw-r--r--src/file_type.c371
-rw-r--r--src/magic_block_scan.c191
-rw-r--r--src/util.h11
5 files changed, 452 insertions, 163 deletions
diff --git a/ChangeLog b/ChangeLog
index 8424b6a..ba45ee3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+0.2.0-pv2 new: support and modification for some filetype
+ change :adjusting settings for version file-5.04
+ change :stabilization of the magic scan functions
+ BUG: segfault if filesystem can not open.
+ BUG: #017625; #017618
BUG: #017547; #017556; #017557; #017559; #017562
BUG: #017561 change Install HOWTO
diff --git a/INSTALL b/INSTALL
index e495f41..0f7d95e 100644
--- a/INSTALL
+++ b/INSTALL
@@ -32,17 +32,20 @@ The following illustrates the installation of a second version
# tar -xzf file-5.04.tar.gz
# cd file-5.04
# ./configure
- # ./make
+ # make
# su -
- # ./make install
+ # cd ????/file-5.04
+ # make install
# ldconfig
+( If use a 64-bit system, the library path can also be /usr/lib64 and /usr/local/lib64 )
The following command should now show both, the version in "/usr/lib/" and in "/usr/local/lib/"
# ldconfig -p | grep libmagic
libmagic.so.1 (libc6) => /usr/local/lib/libmagic.so.1
libmagic.so.1 (libc6) => /usr/lib/libmagic.so.1
libmagic.so (libc6) => /usr/local/lib/libmagic.so
+
In this case, the symlink "/usr/lib/libmagic.so" should not exist. (see follow)
@@ -52,12 +55,13 @@ Which of the two libmagic versions the finished ext4magic use, you can check wit
-If you get the following error:
+
+If you get the following error if configure ext4magic:
"error: The library libmagic.so not found, install the package "file" to build ext4magic"
and "file" is installed, probably the devel package it is not installed. Not for all distributions
-it is available. You can work around that by generate a symlink to the existing version of this library.
+it is available. You can work around that by generate a symlink to the existing version of this library. (on a 64-bit system, the library path can also be /usr/lib64 )
see the following log:
# cd /usr/lib
@@ -174,11 +178,13 @@ Die Installation einer zweiten Version hier im Überblick.
# tar -xzf file-5.04.tar.gz
# cd file-5.04
# ./configure
- # ./make
+ # make
# su -
- # ./make install
+ # cd ????/file-5.04
+ # make install
# ldconfig
+( Auf einem 64-bit System könnten die Library Verzeichnisse auch /usr/lib64 und /usr/local/lib64 sein)
Das folgenden Kommando sollte jetzt beide Versionen von libmagic zeigen, unterhalb "/usr/lib/" und unterhalb "/usr/local/lib/"
# ldconfig -p | grep libmagic
libmagic.so.1 (libc6) => /usr/local/lib/libmagic.so.1
@@ -193,12 +199,15 @@ Welche der beiden libmagic Versionen das fertig ext4magic nutzt, kann wie folgt
libmagic.so.1 => /usr/local/lib/libmagic.so.1 (0xb7741000)
-Erzeugt configure trotz installiertem "file" Paket folgende Fehlermeldung:
+
+
+Erzeugt configure bei ext4magic trotz installiertem "file" Paket folgende Fehlermeldung:
"error: The library libmagic.so not found, install the package "file" to build ext4magic"
dann als root in das Verzeichnis /usr/lib wechseln und einen Symlink libmagic.so
auf die dort vorhandene Version dieser Library erzeugen. Folgender Konsollog zeigt das Vorgehen.
+(auf einem 64-bit System könnte dieses Verzeichnis auch /usr/lib64 sein)
# ls -l /usr/lib/libmagic*
lrwxrwxrwx 1 root root 17 Aug 28 16:09 /usr/lib/libmagic.so.1 -> libmagic.so.1.0.0
diff --git a/src/file_type.c b/src/file_type.c
index 7d21d87..df165c7 100644
--- a/src/file_type.c
+++ b/src/file_type.c
@@ -46,11 +46,11 @@ int ident_file(struct found_data_t *new, __u32 *scan, char *magic_buf, char *buf
//they are used for indices to the filestypes
char typestr[] ="application/ audio/ image/ message/ model/ text/ video/ ";
char imagestr[] ="gif jp2 jpeg png svg+xml tiff vnd.adobe.photoshop vnd.djvu x-coreldraw x-cpi x-ico x-ms-bmp x-niff x-portable-bitmap x-portable-greymap x-portable-pixmap x-psion-sketch x-quicktime x-unknown x-xcursor x-xpmi x-tga ";
- char videostr[] ="3gpp h264 mp2p mp2t mp4 mp4v-es mpeg mpv quicktime x-flc x-fli x-flv x-jng x-mng x-msvideo x-sgi-movie x-unknown ";
+ char videostr[] ="3gpp h264 mp2p mp2t mp4 mp4v-es mpeg mpv quicktime x-flc x-fli x-flv x-jng x-mng x-msvideo x-sgi-movie x-unknown x-ms-asf ";
char audiostr[] ="basic midi mp4 mpeg x-adpcm x-aiff x-dec-basic x-flac x-hx-aac-adif x-hx-aac-adts x-mod x-mp4a-latm x-pn-realaudio x-unknown x-wav ";
char messagestr[] ="news rfc822 ";
char modelstr[] ="vrml x3d ";
- char applistr[] ="dicom mac-binhex40 msword octet-stream ogg pdf pgp pgp-encrypted pgp-keys pgp-signature postscript unknown+zip vnd.google-earth.kml+xml vnd.google-earth.kmz vnd.lotus-wordpro vnd.ms-cab-compressed vnd.ms-excel vnd.ms-tnef vnd.oasis.opendocument. vnd.rn-realmedia vnd.symbian.install x-123 x-adrift x-archive x-arc x-arj x-bittorrent x-bzip2 x-compress x-coredump x-cpio x-dbf x-dbm x-debian-package x-dosexec x-dvi x-eet x-elc x-executable x-gdbm x-gnucash x-gnumeric x-gnupg-keyring x-gzip x-hdf x-hwp x-ichitaro4 x-ichitaro5 x-ichitaro6 x-iso9660-image x-java-applet x-java-jce-keystore x-java-keystore x-java-pack200 x-kdelnk x-lha x-lharc x-lzip x-mif xml xml-sitemap x-msaccess x-ms-reader x-object x-pgp-keyring x-quark-xpress-3 x-quicktime-player x-rar x-rpm x-sc x-setupscript x-sharedlib x-shockwave-flash x-stuffit x-svr4-package x-tar x-tex-tfm x-tokyocabinet-btree x-tokyocabinet-fixed x-tokyocabinet-hash x-tokyocabinet-table x-xz x-zoo zip ";
+ char applistr[] ="dicom mac-binhex40 msword octet-stream ogg pdf pgp pgp-encrypted pgp-keys pgp-signature postscript unknown+zip vnd.google-earth.kml+xml vnd.google-earth.kmz vnd.lotus-wordpro vnd.ms-cab-compressed vnd.ms-excel vnd.ms-tnef vnd.oasis.opendocument. vnd.rn-realmedia vnd.symbian.install x-123 x-adrift x-archive x-arc x-arj x-bittorrent x-bzip2 x-compress x-coredump x-cpio x-dbf x-dbm x-debian-package x-dosexec x-dvi x-eet x-elc x-executable x-gdbm x-gnucash x-gnumeric x-gnupg-keyring x-gzip x-hdf x-hwp x-ichitaro4 x-ichitaro5 x-ichitaro6 x-iso9660-image x-java-applet x-java-jce-keystore x-java-keystore x-java-pack200 x-kdelnk x-lha x-lharc x-lzip x-mif xml xml-sitemap x-msaccess x-ms-reader x-object x-pgp-keyring x-quark-xpress-3 x-quicktime-player x-rar x-rpm x-sc x-setupscript x-sharedlib x-shockwave-flash x-stuffit x-svr4-package x-tar x-tex-tfm x-tokyocabinet-btree x-tokyocabinet-fixed x-tokyocabinet-hash x-tokyocabinet-table x-xz x-zoo zip x-font-ttf ";
char textstr[] = "html PGP rtf texmacs troff vnd.graphviz x-awk x-diff x-fortran x-gawk x-info x-lisp x-lua x-msdos-batch x-nawk x-perl x-php x-shellscript x-texinfo x-tex x-vcard x-xmcd plain x-pascal x-c++ x-c x-mail x-makefile x-asm text ";
char undefstr[] ="MPEG Targa 7-zip cpio CD-ROM DVD 9660 Kernel boot Linux filesystem x86 Image CDF SQLite OpenOffice.org Microsoft";
//-----------------------------------------------------------------------------------
@@ -157,7 +157,7 @@ int file_default(unsigned char *buf, int *size, __u32 scan , int flag, struct fo
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -169,10 +169,11 @@ int file_default(unsigned char *buf, int *size, __u32 scan , int flag, struct fo
int file_txt(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
switch (flag){
case 0 :
- if (*size < current_fs->blocksize)
- return (buf[(*size)-1] == (char)0x0a);
+ if (*size < current_fs->blocksize){
+ if (buf[(*size)-1] == (unsigned char)0x0a) return 1;
+ }
else {
- if (buf[(*size)-1] == (char)0x0a)
+ if (buf[(*size)-1] == (unsigned char)0x0a)
return 2;
}
break;
@@ -180,6 +181,7 @@ int file_txt(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
return (scan & M_TXT);
break;
}
+ return 0;
}
@@ -188,12 +190,19 @@ int file_txt(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
int file_bin_txt(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
switch (flag){
case 0 :
- return (*size < current_fs->blocksize);
+ if (*size < current_fs->blocksize){
+ return 1;
+ }
+ else {
+ if (buf[(*size)-1] == (unsigned char)0x0a)
+ return 2;
+ }
break;
case 1 :
return (scan & M_TXT);
break;
}
+ return 0;
}
@@ -209,14 +218,14 @@ int file_gzip(unsigned char *buf, int *size, __u32 scan , int flag, struct found
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT | M_BLANK)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1 | M_BLANK)) ? 0 :1 ;
break;
}
return ret;
}
-//zip ???????????
+//zip
int file_zip(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
int ret = 0;
int j,i;
@@ -245,11 +254,34 @@ int file_zip(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
ret = 2;
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT | M_BLANK)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1 | M_BLANK)) ? 0 :1 ;
+ break;
+ }
+ return ret;
+}
+
+
+//ttf
+int file_ttf(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
+ int ret = 0;
+
+ switch (flag){
+ case 0 :
+ if((*size) < (current_fs->blocksize - 16)){
+ *size = ((*size ) + 3) & ~3 ;
+ ret =1;
+ }
+ else {
+ *size = ((*size ) + 3) & ~3 ;
+ ret =2;
+ }
+ break;
+ case 1 :return (scan & (M_IS_META | M_CLASS_1 | M_BLANK)) ? 0 :1 ;
break;
}
return ret;
}
+
//iso9660 CD-ROM
@@ -327,20 +359,8 @@ int ret = 0;
}
break;
-
-/* if ((f_data->size) && (f_data->size <= (__u64)f_data->inode->i_size | ((__u64)f_data->inode->i_size_high<<32))){
- ssize = (f_data->size % current_fs->blocksize);
- if (*size < ssize)
- *size = ssize;
- ret = 1;
- }
- else{
- // *size +=7;
- ret = 0;
- }
- break;*/
case 1 :
- return ( scan & (M_IS_META | M_IS_FILE | M_TXT | M_BLANK)) ? 0 :1 ;
+ return ( scan & (M_IS_META | M_CLASS_1 | M_BLANK)) ? 0 :1 ;
break;
case 2 :
p = (__u64*)(buf+12);
@@ -354,8 +374,36 @@ int ret = 0;
}
return ret;
}
-
-
+
+
+//rar
+int file_rar(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
+ int i,j;
+ int ret = 0;
+ unsigned char token[7]={0xc4, 0x3d, 0x7b, 0x00, 0x40, 0x07, 0x00 };
+
+ switch (flag){
+ case 0 :
+ j = 5;
+ i = (*size) -1;
+ while ((i >= 0) && (j >= 0) && (buf[i] == token[j])){
+ i--;
+ j--;
+ }
+ if ((i == -1) || (j == -1)){
+ *size = (*size) + 1;
+ ret = 1;
+ }
+ break;
+ case 1 :
+ return (scan & (M_IS_META | M_CLASS_1 | M_BLANK)) ? 0 :1 ;
+ break;
+ }
+ return ret;
+}
+
+
+
//cpio
int file_cpio(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
@@ -365,27 +413,19 @@ int file_cpio(unsigned char *buf, int *size, __u32 scan , int flag, struct found
switch (flag){
case 0 :
- /* if (*size>10) {
- if (strstr(buf+(*size)-10,token)){
- *size = ((*size) + 0x01FF) & 0xfe00 ;
- ret=1;
- }
+ j = strlen(token) -1;
+ i = (*size) -1;
+ while ((i >= 0) && (j >= 0) && (buf[i] == token[j])){
+ i--;
+ j--;
}
- else{*/
- j = strlen(token) -1;
- i = (*size) -1;
- while ((i >= 0) && (j >= 0) && (buf[i] == token[j])){
- i--;
- j--;
- }
- if ((i == -1) || (j == -1)){
- *size = ((*size) + 0x01FF) & 0xfe00 ;
- ret=1;
- }
- //}
+ if ((i == -1) || (j == -1)){
+ *size = ((*size) + 0x01FF) & 0xfe00 ;
+ ret=1;
+ }
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -420,7 +460,7 @@ int file_pdf(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
}
break;
case 1 :
- return (scan & (M_IS_META)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -451,7 +491,7 @@ int file_tar(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
if (scan & M_TAR)
ret = 1;
else
- ret = (scan & (M_IS_META | (M_IS_FILE & (~ M_TXT)))) ? 0 :1 ;
+ ret = (scan & M_IS_META | M_CLASS_1 ) ? 0 :1 ;
break;
}
return ret;
@@ -488,7 +528,7 @@ int file_binary(unsigned char *buf, int *size, __u32 scan , int flag, struct fou
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -516,7 +556,7 @@ int file_object(unsigned char *buf, int *size, __u32 scan , int flag, struct fou
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1 )) ? 0 :1 ;
break;
}
return ret;
@@ -537,7 +577,7 @@ int file_jpeg(unsigned char *buf, int *size, __u32 scan , int flag, struct found
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -555,7 +595,7 @@ int file_gif(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
ret = 1;
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -576,7 +616,7 @@ int file_bmp(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
}
break;
case 1 :
- return (scan & M_IS_META) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1 )) ? 0 :1 ;
break;
case 2 :
@@ -606,7 +646,7 @@ int file_png(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -626,7 +666,7 @@ int file_mng(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
ret = 1;
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -653,13 +693,146 @@ int file_tga(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT )) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
}
+//midi
+int file_midi(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
+ int ret = 0;
+
+ switch (flag){
+ case 0 :
+ if ((*size>1) && (buf[(*size)-1] == (unsigned char)0x2f) && (buf[(*size)-2] == (unsigned char)0xff)){
+ *size +=1;
+ ret = 1;
+ }
+ else
+ if ((*size == 1) && (buf[(*size)-1] == (unsigned char)0x2f)){
+ *size +=1 ;
+ ret = 1;
+ }
+ break;
+ case 1 :return (scan & (M_IS_META | M_CLASS_1 | M_BLANK)) ? 0 :1 ;
+ break;
+ }
+ return ret;
+}
+
+
+//swf
+int file_swf(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
+ int ret = 0;
+ __u32 *p_32;
+ __u32 ssize;
+
+ switch (flag){
+ case 0 :
+ if (f_data->size ) {
+ ssize = f_data->size % current_fs->blocksize;
+ if (f_data->inode->i_size >= (f_data->size - ssize)){
+ *size = ssize;
+ ret =1;
+ }
+ }
+ else{
+ if ((*size) < (current_fs->blocksize - 2)){
+ ret=1;
+ }
+ }
+ break;
+ case 1:
+ return (scan & (M_IS_META | M_CLASS_1 | M_BLANK )) ? 0 :1 ;
+ break;
+
+ case 2:
+ if (buf[0] == 'F'){
+ p_32 = (__u32*)(buf+4);
+ ssize = ext2fs_le32_to_cpu(*p_32);
+ f_data->size = ssize;
+ ret = 1;
+ }
+ break;
+ }
+ return ret;
+}
+
+
+
+//aiff
+int file_aiff(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
+ int ret = 0;
+ __u32 *p_32;
+ __u32 ssize;
+
+ switch (flag){
+ case 0 :
+ if (f_data->size ) {
+ ssize = f_data->size % current_fs->blocksize;
+ if (f_data->inode->i_size >= (f_data->size - ssize)){
+ *size = ssize;
+ ret =1;
+ }
+ }
+ break;
+ case 1:
+ return (scan & (M_IS_META | M_CLASS_1 | M_BLANK )) ? 0 :1 ;
+ break;
+
+ case 2:
+ if (buf[8] == 'A'){
+ p_32 = (__u32*)(buf+4);
+ ssize = ext2fs_be32_to_cpu(*p_32) +8;
+ f_data->size = ssize;
+ ret = 1;
+ }
+ break;
+ }
+ return ret;
+}
+
+
+//asf
+int file_asf(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
+ int ret = 0;
+ __u32 *p_32;
+ __u32 ssize;
+
+ switch (flag){
+ case 0 :
+ if (f_data->size ) {
+ ssize = f_data->size % current_fs->blocksize;
+ if (f_data->inode->i_size >= (f_data->size - ssize)){
+ *size = ssize;
+ ret =1;
+ }
+ }
+ else{
+ if ((*size) < (current_fs->blocksize - 16)){
+ ret = 2;
+ }
+ }
+ break;
+ case 1:
+ return (scan & (M_IS_META | M_CLASS_1 | M_BLANK )) ? 0 :1 ;
+ break;
+
+ case 2:
+ if (buf[3] == 0x75){
+ p_32 = (__u32*)(buf+70);
+ ssize = ext2fs_le32_to_cpu(*p_32);
+ f_data->size = ssize;
+ ret = 1;
+ }
+ break;
+ }
+ return ret;
+}
+
+
//mpeg
int file_mpeg(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
int i,j;
@@ -679,7 +852,7 @@ int file_mpeg(unsigned char *buf, int *size, __u32 scan , int flag, struct found
}
break;
case 1 :
- return (scan & (M_IS_META | M_TXT )) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1 )) ? 0 :1 ;
break;
}
return ret;
@@ -705,7 +878,7 @@ int file_riff(unsigned char *buf, int *size, __u32 scan , int flag, struct found
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1 )) ? 0 :1 ;
break;
case 2 :
p_32 = (__u32*)buf;
@@ -727,6 +900,32 @@ int file_riff(unsigned char *buf, int *size, __u32 scan , int flag, struct found
return ret;
}
+
+//psd
+int file_psd(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
+ int ret = 0;
+
+ switch (flag){
+ case 0 :
+ if (*size < (current_fs->blocksize - 16)){
+ if ((!buf[(*size)-2]) && (!buf[(*size)-4]))
+ (*size)++;
+ ret = 1;
+ }
+ else {
+ if (*size < (current_fs->blocksize - 2))
+ ret = 3;
+ }
+ break;
+ case 1 :
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
+ break;
+ }
+ return ret;
+}
+
+
+
// tiff
int file_tiff(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
__u32 *p_32 ;
@@ -737,18 +936,19 @@ int file_tiff(unsigned char *buf, int *size, __u32 scan , int flag, struct found
case 0 :
if (f_data->size ){
if (f_data->inode->i_size > f_data->size){ //FIXME
- *size +=1;
+ *size += 8;
ret =1;
}
}
else{
if (f_data->inode->i_block[12]){ //FIXME for ext4
+ *size += 8;
ret = 2;
}
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
case 2 :
p_32 = (__u32*)buf;
@@ -780,7 +980,7 @@ int file_mod(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -799,7 +999,7 @@ int file_CDF(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
}
break;
case 1:
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
}
return ret;
@@ -807,7 +1007,7 @@ int file_CDF(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
-//SQLite FIXME ????????????????
+//SQLite FIXME
int file_SQLite(unsigned char *buf, int *size, __u32 scan , int flag, struct found_data_t* f_data){
int ret = 0;
__u16 *p_16;
@@ -829,7 +1029,7 @@ int file_SQLite(unsigned char *buf, int *size, __u32 scan , int flag, struct fou
}
break;
case 1:
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
case 2:
@@ -864,7 +1064,7 @@ int file_ogg(unsigned char *buf, int *size, __u32 scan , int flag, struct found_
}
break;
case 1 :
- return (scan & (M_IS_META | M_IS_FILE | M_TXT)) ? 0 :1 ;
+ return (scan & (M_IS_META | M_CLASS_1)) ? 0 :1 ;
break;
case 2 :
@@ -977,19 +1177,19 @@ void get_file_property(struct found_data_t* this){
case 0x0113 : //vnd.oasis.opendocument.
this->func = file_zip ;
if (strstr(this->scan_result,"text")){
- strncat(this->name,".ott",7);
+ strncat(this->name,".odt",7);
break;
}
if (strstr(this->scan_result,"presentation")){
- strncat(this->name,".otp",7);
+ strncat(this->name,".odp",7);
break;
}
if (strstr(this->scan_result,"spreadsheet")){
- strncat(this->name,".ots",7);
+ strncat(this->name,".ods",7);
break;
}
if (strstr(this->scan_result,"graphics")){
- strncat(this->name,".otg",7);
+ strncat(this->name,".odg",7);
break;
}
break;
@@ -1019,7 +1219,7 @@ void get_file_property(struct found_data_t* this){
strncat(this->name,".a",7);
break;
- case 0x0119 : //x-arc
+ case 0x0119 : //x-arc deaktiv
// this->func = file_x-arc ;
// strncat(this->name,".x-arc",7);
break;
@@ -1109,7 +1309,7 @@ void get_file_property(struct found_data_t* this){
// strncat(this->name,".x-gnumeric",7);
break;
- case 0x012b : //x-gnupg-keyring
+ case 0x012b : //x-gnupg-keyring deaktiv
// this->func = file_x-gnupg-keyring ;
// strncat(this->name,".x-gnupg-keyring",7);
break;
@@ -1219,7 +1419,7 @@ void get_file_property(struct found_data_t* this){
strncat(this->name,".o",7);
break;
- case 0x0141 : //x-pgp-keyring
+ case 0x0141 : //x-pgp-keyring deaktiv
// this->func = file_x-pgp-keyring ;
// strncat(this->name,".x-pgp-keyring",7);
break;
@@ -1235,7 +1435,7 @@ void get_file_property(struct found_data_t* this){
break;
case 0x0144 : //x-rar
- // this->func = file_x-rar ;
+ this->func = file_rar ;
strncat(this->name,".rar",7);
break;
@@ -1260,7 +1460,7 @@ void get_file_property(struct found_data_t* this){
break;
case 0x0149 : //x-shockwave-flash
- // this->func = file_x-shockwave-flash ;
+ this->func = file_swf ;
strncat(this->name,".swf",7);
break;
@@ -1318,7 +1518,11 @@ void get_file_property(struct found_data_t* this){
this->func = file_zip ;
strncat(this->name,".zip",7);
break;
-
+
+ case 0x0155 : //x-font-ttf
+ this->func = file_ttf ;
+ strncat(this->name,".ttf",7);
+ break;
//----------------------------------------------------------------
//Audio
@@ -1328,7 +1532,7 @@ void get_file_property(struct found_data_t* this){
break;
case 0x0202 : //midi
- // this->func = file_midi ;
+ this->func = file_midi ;
strncat(this->name,".mid",7);
break;
@@ -1348,8 +1552,8 @@ void get_file_property(struct found_data_t* this){
break;
case 0x0206 : //x-aiff
- // this->func = file_x-aiff ;
- strncat(this->name,".aif",7);
+ this->func = file_aiff ;
+ strncat(this->name,".aiff",7);
break;
case 0x0207 : //x-dec-basic
@@ -1362,12 +1566,12 @@ void get_file_property(struct found_data_t* this){
// strncat(this->name,".x-flac",7);
break;
- case 0x0209 : //x-hx-aac-adif
+ case 0x0209 : //x-hx-aac-adif
// this->func = file_x-hx-aac-adif ;
strncat(this->name,".aac",7);
break;
- case 0x020a : //x-hx-aac-adts
+ case 0x020a : //x-hx-aac-adts deaktiv
// this->func = file_x-hx-aac-adts ;
strncat(this->name,".aac",7);
break;
@@ -1377,7 +1581,7 @@ void get_file_property(struct found_data_t* this){
strncat(this->name,".mod",7);
break;
- case 0x020c : //x-mp4a-latm
+ case 0x020c : //x-mp4a-latm deaktiv
// this->func = file_x-mp4a-latm ;
// strncat(this->name,".x-mp4a-latm",7);
break;
@@ -1431,7 +1635,7 @@ void get_file_property(struct found_data_t* this){
break;
case 0x0307 : //vnd.adobe.photoshop
- // this->func = file_vnd.adobe.photoshop ;
+ this->func = file_psd;
strncat(this->name,".psd",7);
break;
@@ -1579,7 +1783,7 @@ void get_file_property(struct found_data_t* this){
strncat(this->name,".diff",7);
break;
- case 0x0609 : //x-fortran (often c files)
+ case 0x0609 : //x-fortran
this->func = file_txt ;
strncat(this->name,".f",7);
break;
@@ -1594,7 +1798,7 @@ void get_file_property(struct found_data_t* this){
strncat(this->name,".info",7);
break;
- case 0x060c : //x-lisp (often c files)
+ case 0x060c : //x-lisp
this->func = file_txt ;
strncat(this->name,".l",7);
break;
@@ -1775,6 +1979,11 @@ void get_file_property(struct found_data_t* this){
// this->func = file_x-unknown ;
// strncat(this->name,".x-unknown",7);
break;
+
+ case 0x0712 : //x-ms-asf
+ this->func = file_asf ;
+ strncat(this->name,".asf",7);
+ break;
diff --git a/src/magic_block_scan.c b/src/magic_block_scan.c
index 1a10176..6190b9d 100644
--- a/src/magic_block_scan.c
+++ b/src/magic_block_scan.c
@@ -193,6 +193,7 @@ static int check_data_passage(char *a_buf, unsigned char *b_buf){
static int check_file_data_possible(struct found_data_t* this, __u32 scan ,unsigned char *buf){
int ret = 0;
int size ;
+ size = (scan & M_SIZE );
ret = this->func(buf, &size ,scan ,1 , this);
return ret;
}
@@ -256,6 +257,7 @@ static int check_indirect_meta3(unsigned char *block_buf){
}
+
static int check_dindirect_meta3(unsigned char * block_buf){
__u32 *p_blk;
__u32 block;
@@ -441,16 +443,15 @@ static int magic_check_block(unsigned char* buf,magic_t cookie , magic_t cookie_
char text[100] = "";
char *p_search;
__u32 retval = 0;
- char searchstr[] = "7-zip cpio CD-ROM MPEG 9660 Targa Kernel boot SQLite OpenOffice.org ";
char token[20];
strncpy(text,magic_buffer(cookie_f,buf , size),60);
strncpy(magic_buf, magic_buffer(cookie , buf , size),60);
while (count >= 0 && (*(buf+count) == 0)) count-- ;
-#ifdef DEBUG_MAGIC_SCAN
+/*#ifdef DEBUG_MAGIC_SCAN
printf("Scan Result : %s %d\n", magic_buf , count+1) ;
printf("RESULT : %s \n",text);
-#endif
+#endif */
if (!strncmp(text,"data",4)){
if (count == -1) {
@@ -459,7 +460,7 @@ static int magic_check_block(unsigned char* buf,magic_t cookie , magic_t cookie_
}
}
if (strstr(magic_buf,"application/vnd.oasis.opendocument")){
- retval |= (M_APPLI | M_BINARY);
+ retval |= (M_APPLI | M_BINARY | M_CLASS_1);
goto out;
}
@@ -471,10 +472,25 @@ static int magic_check_block(unsigned char* buf,magic_t cookie , magic_t cookie_
if (strstr(magic_buf,"charset=binary")){
retval |= M_BINARY ;
}
-
- if (!(retval & M_TXT) && (strstr(magic_buf,"application/octet-stream")) && ((!(strncmp(text,"data",4))) || (!(strncmp(text,"text",4))))){
- retval |= M_DATA;
+ //FIXME test: catch of properties from file-5.04
+ if ((retval & M_TXT) &&
+ ((retval & M_BINARY) || (strstr(magic_buf,"charset=unknown-8bit") && (count > 8)) ||
+ (strstr(text,"very long lines, with no")))){
+
+// retval -= M_TXT;
+ retval |= M_DATA;
}
+ else{
+ if ((strstr(magic_buf,"application/octet-stream")) && (!(strncmp(text,"data",4)))){
+ retval |= M_DATA;
+ }
+ }
+
+/*
+//FIXME only for test
+if ((strstr(magic_buf,"application/octet-stream")) && (!(strncmp(text,"text",4))))
+ printf("application/octet-stream + text in BlockNR; %ul\n",blk);
+*/
if ((retval & M_DATA) || (*(buf+7) < EXT2_FT_MAX) || (count < 32) || (ext2fs_le32_to_cpu(*(blk_t*)buf) == blk +1)) {
if (check_meta3_block(buf, blk, count+1)){
@@ -499,22 +515,30 @@ static int magic_check_block(unsigned char* buf,magic_t cookie , magic_t cookie_
goto out;
if (retval & M_TXT){
- if (strstr(magic_buf,"ascii")){
- retval |= M_ASCII ;
+ char searchstr[] = "html PGP rtf texmacs vnd.graphviz x-awk x-gawk x-info x-msdos-batch x-nawk x-perl x-php x-shellscript x-texinfo x-tex x-vcard x-xmcd ";
+ p_search = searchstr;
+ while (*p_search){
+ len=0;
+ while((*p_search) != 0x20){
+ token[len] = *p_search;
+ p_search++;
+ len++;
+ }
+ token[len] = 0;
+ if (strstr(text,token)){
+ strncpy(magic_buf,text,60);
+ retval |= M_CLASS_1;
+ break;
+ }
+ p_search++;
}
-
- if(strstr(magic_buf,"iso")){
- retval |= M_ASCII ;
- }
-
- if(strstr(magic_buf,"utf")){
- retval |= M_UTF ;
- }
+ if (! (retval & M_CLASS_1))
+ retval |= M_CLASS_2 ;
goto out;
}
-
if (strstr(magic_buf,"application/octet-stream")){
+ char searchstr[] = "7-zip cpio CD-ROM MPEG 9660 Targa Kernel boot SQLite OpenOffice.org ";
p_search = searchstr;
while (*p_search){
len=0;
@@ -525,60 +549,87 @@ static int magic_check_block(unsigned char* buf,magic_t cookie , magic_t cookie_
}
token[len] = 0;
if (strstr(text,token)){
- strncpy(magic_buf,text,90);
- retval |= (M_APPLI | M_ARCHIV);
+ strncpy(magic_buf,text,60);
+ retval |= ( M_APPLI | M_ARCHIV | M_CLASS_1 );
break;
}
p_search++;
}
if (! (retval & M_APPLI))
retval |= M_DATA ;
+// This is the place for globale extensions if binary filetypes not included in the magic file
goto out;
}
-
- if (strstr(magic_buf,"application/")){
- retval |= M_APPLI;
- if (strstr(magic_buf,"x-tar"))
- retval |= M_TAR ;
- goto out;
- }
-
- if (strstr(magic_buf,"image/")){
- retval |= M_IMAGE;
- goto out;
- }
-
- if (strstr(magic_buf,"audio/")){
- retval |= M_AUDIO;
- goto out;
- }
-
- if (strstr(magic_buf,"video/")){
- retval |= M_VIDEO;
- goto out;
- }
-
- if (strstr(magic_buf,"message/")){
- retval |= M_MESSAGE;
- goto out;
- }
-
- if (strstr(magic_buf,"model/")){
- retval |= M_MODEL;
- goto out;
- }
-
- if (strstr(magic_buf,"CDF V2 Document")){
- retval |= (M_APPLI | M_ARCHIV);
- goto out;
+ else {
+ if (strstr(magic_buf,"application/")){
+ if (strstr(magic_buf,"x-tar"))
+ retval |= ( M_APPLI | M_TAR | M_CLASS_1) ;
+ else{
+ if(strstr(magic_buf,"x-elc") || strstr(magic_buf,"keyring") || strstr(magic_buf,"x-arc"))
+ retval = M_DATA;
+ else {
+ if (strstr(magic_buf,"encrypted") || strstr(magic_buf,"x-tex-tfm"))
+ retval |= ( M_APPLI | M_CLASS_2 );
+ else
+ retval |= ( M_APPLI | M_CLASS_1 );
+ }
+ }
+ goto out;
+ }
+ else {
+
+ if (strstr(magic_buf,"image/")){
+ retval |= ( M_IMAGE | M_CLASS_1 );
+ goto out;
+ }
+ else {
+ if (strstr(magic_buf,"audio/")){
+ if (strstr(magic_buf,"x-mp4a-latm") || strstr(magic_buf,"x-hx-aac-adts"))
+ retval = M_DATA;
+ else {
+ if(strstr(magic_buf,"mpeg"))
+ retval |= ( M_AUDIO | M_CLASS_2 );
+ else
+ retval |= ( M_AUDIO | M_CLASS_1 );
+ }
+ goto out;
+ }
+ else{
+ if (strstr(magic_buf,"video/")){
+ retval |= ( M_VIDEO | M_CLASS_1 );
+ goto out;
+ }
+ else {
+ if (strstr(magic_buf,"message/")){
+ retval |= ( M_MESSAGE | M_CLASS_2);
+ goto out;
+ }
+ else{
+
+ if (strstr(magic_buf,"model/")){
+ retval |= ( M_MODEL | M_CLASS_2);
+ goto out;
+ }
+ else{
+ if (strstr(magic_buf,"CDF V2 Document")){
+ retval |= (M_APPLI | M_ARCHIV | M_CLASS_1 );
+ goto out;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
-
out:
+/*
#ifdef DEBUG_MAGIC_SCAN
printf("BLOCK_SCAN : Block = %010u ; 0x%08x\n",blk, retval & 0xffffe000);
blockhex(stdout,buf,0,(count < (64)) ? count : 64 );
#endif
+*/
retval |= (count+1);
return retval;
@@ -592,7 +643,6 @@ static struct found_data_t* soft_border(char *des_dir, unsigned char *buf, struc
file_data = recover_file_data(des_dir, file_data, follow);
else{
file_data = forget_file_data(file_data, follow);
-// printf("Don't recover this file, current block %d \n",blk);
}
return file_data;
}
@@ -605,7 +655,7 @@ static int get_range(blk_t* p_blk ,struct ext2fs_struct_loc_generic_bitmap *ds_b
for (begin = *p_blk; begin <= ds_bmap->end ; begin++){
if((!(begin & 0x7)) && skip_block(&begin, ds_bmap)){
#ifdef DEBUG_MAGIC_SCAN
- printf("jump to %d \n",begin);
+ printf("jump to %ul \n",begin);
#endif
}
*p_blk = begin;
@@ -749,7 +799,7 @@ while (ds_retval){
ds_bmap = (struct ext2fs_struct_loc_generic_bitmap *) d_bmap;
count = 0;
- blk[0] = 0;
+ blk[0] = 0;
count = get_range(blk ,ds_bmap, buf);
while (count){
@@ -758,7 +808,7 @@ while (ds_retval){
#endif
for (i = 0; i< ((count>12) ? MAX_RANGE - 12 : count) ;i++){
scan = magic_check_block(buf+(i*blocksize), cookie, cookie_f , magic_buf , blocksize * ((count >=9) ? 9 : count) ,blk[0]+i);
- if(scan & (M_DATA | M_BLANK | M_IS_META)){
+ if(scan & (M_DATA | M_BLANK | M_IS_META | M_TXT)){
if (scan & (M_ACL | M_EXT4_META | M_DIR))
ext2fs_mark_generic_bitmap(bmap, blk[0]+i);
continue;
@@ -805,13 +855,14 @@ while (ds_retval){
scan = magic_check_block(buf+(i*blocksize), cookie, cookie_f , magic_buf , blocksize ,blk[0]+i);
if(scan & (M_DATA | M_BLANK | M_IS_META)){
if ((!fragment_flag) && (scan & M_EXT3_META) && (check_indirect_meta3(buf+(i*blocksize)))){
-#ifdef DEBUG_MAGIC_SCAN
- printf("try a fragment recover for metablock %ld\n",flag[i]);
-#endif
+
blk[1] = block_backward(flag[i] , 13);
- if (blk[1]){
+ if (blk[1] && (blk[1] < (flag[i]-12))){
blk[0] = blk[1];
fragment_flag = flag[i];
+#ifdef DEBUG_MAGIC_SCAN
+ printf("Try a fragment recover for metablock: %lu at blk: %lu\n",flag[i],blk[1] );
+#endif
goto load_new;
}
}
@@ -819,7 +870,7 @@ while (ds_retval){
continue;
}
#ifdef DEBUG_MAGIC_SCAN
- printf("SCAN %d : %09x : %s\n",blk[0]+i,scan,magic_buf);
+ printf("SCAN %d : %09x : %s\n",flag[i],scan,magic_buf);
#endif
if (((count -i) > 12) && (ext2fs_le32_to_cpu(*(__u32*)(buf +((i+12)*blocksize))) == flag[12+i]+1)){
file_data = new_file_data(flag[i],scan,magic_buf,buf+(i*blocksize),&follow);
@@ -855,13 +906,13 @@ while (ds_retval){
j--;
file_data = soft_border(des_dir,buf+(j*blocksize), file_data, &follow, flag[j]);
if ((!fragment_flag) && (scan & M_EXT3_META) && (check_indirect_meta3(buf+((j+1)*blocksize)))){
-#ifdef DEBUG_MAGIC_SCAN
- printf("try a fragment recover for metablock %ld\n",flag[j]+1);
-#endif
blk[1] = block_backward(flag[j] , 12);
- if (blk[1]){
+ if (blk[1] && (blk[1] < flag[j]-12)){
blk[0] = blk[1];
fragment_flag = flag[j+1];
+#ifdef DEBUG_MAGIC_SCAN
+ printf("Try fragment recover for metablock: %lu at blk: %lu\n",flag[j]+1, blk[0]);
+#endif
goto load_new;
}
}
diff --git a/src/util.h b/src/util.h
index d630ce6..d999509 100644
--- a/src/util.h
+++ b/src/util.h
@@ -50,16 +50,17 @@
#define M_APPLI 0x00400000
#define M_MESSAGE 0x00800000
#define M_MODEL 0x00004000
+#define M_TAR 0x00008000
#define M_IS_FILE 0x00FC4000
-#define M_IS_DATA 0x00060000
+#define M_IS_DATA 0x00030000
#define M_BINARY 0x01000000
-#define M_ASCII 0x02000000
-#define M_UTF 0x04000000
-#define M_IS_CHARSET 0x07000000
+
+#define M_CLASS_1 0x02000000
+#define M_CLASS_2 0x04000000
+#define M_IS_CLASS 0x06000000
#define M_ARCHIV 0x08000000
-#define M_TAR 0x00008000
#define M_ACL 0x80000000
#define M_EXT4_META 0x40000000