summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2007-12-23 13:07:59 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2007-12-23 13:07:59 +0100
commit745062401f92300b9c54cb3fa4ef91e608d1cf04 (patch)
tree2af338e95b58400cc3e2d65661b6efa53223605f
parentc75bcf2b025255a8ec83b184798b0ec8ee887297 (diff)
Rename find_in_mem() to td_memmem()
Add Maya .mb and .mp file support to PhotoRec
-rwxr-xr-xcompile.sh5
-rw-r--r--src/Makefile.am2
-rw-r--r--src/file_doc.c46
-rw-r--r--src/file_mb.c79
-rw-r--r--src/file_mov.c24
-rw-r--r--src/file_pdf.c6
-rw-r--r--src/file_tar.c4
-rw-r--r--src/file_tar.h (renamed from src/fnd_mem.h)27
-rw-r--r--src/file_tiff.c10
-rw-r--r--src/file_txt.c22
-rw-r--r--src/memmem.h47
-rw-r--r--src/photorec.c2
-rw-r--r--src/phrecn.c4
13 files changed, 194 insertions, 84 deletions
diff --git a/compile.sh b/compile.sh
index 4ccfdb2..5247170 100755
--- a/compile.sh
+++ b/compile.sh
@@ -236,12 +236,7 @@ then
if [ -e $compiledir/Makefile ];
then
cd $compiledir
-if [ "X$crosscompile_target" = "Xpowerpc-apple-darwin" ];
-then
make
-else
- make static
-fi
cd $pwd_saved
fi
fi
diff --git a/src/Makefile.am b/src/Makefile.am
index e230c95..d2b247c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,7 +19,7 @@ fs_H = analyse.h bfs.h bsd.h cramfs.h fat.h fatx.h ext2.h jfs_superblock.h jfs
testdisk_SOURCES = testdisk.c $(base_C) $(base_H) $(fs_C) $(fs_H) testdisk.h adv.c adv.h dir.c dir.h dirpart.c dirpart.h edit.c edit.h ext2_dir.c ext2_dir.h ext2_inc.h fat_adv.c fat_dir.c fat_dir.h geometry.c godmode.c godmode.h intrface.c intrface.h ntfs_adv.c ntfs_dir.c ntfs_dir.h ntfs_fix.c ntfs_inc.h rfs_dir.c rfs_dir.h $(ICON_TESTDISK) next.c next.h
#ntfs_udl.c ntfs_udl.h
-photorec_SOURCES = photorec.c photorec.h phrecn.c phrecn.h dir.c dir.h ext2p.c ext2p.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h fatp.c fatp.h filegen.c filegen.h file_7z.c file_a.c file_ab.c file_ace.c file_aif.c file_all.c file_asf.c file_au.c file_bkf.c file_bld.c file_bmp.c file_bz2.c file_cab.c file_cam.c file_cm.c file_crw.c file_ctg.c file_cwk.c file_dat.c file_dbf.c file_dir.c file_djv.c file_doc.c file_dpx.c file_dsc.c file_dta.c file_dv.c file_dwg.c file_elf.c file_evt.c file_exe.c pe.h file_ext.c file_fh10.c file_fh5.c file_flac.c file_flv.c file_fs.c file_gif.c file_gz.c file_imb.c file_indd.c file_dump.c file_itu.c file_jpg.c file_jpg.h file_kdb.c file_max.c file_mdb.c file_mdf.c file_mid.c file_mkv.c file_mov.c file_mp3.c file_mpg.c file_mrw.c file_mus.c file_mysql.c file_njx.c file_ogg.c file_one.c file_orf.c file_pap.c file_pcx.c file_pdf.c file_png.c file_prc.c file_ps.c file_psd.c file_pst.c file_ptb.c file_qbb.c file_qdf.c file_qxd.c file_ra.c file_raf.c file_rar.c file_raw.c file_rdc.c file_reg.c file_riff.c file_rm.c file_rns.c file_rpm.c file_sit.c file_skp.c file_spe.c file_spss.c file_stu.c file_swf.c file_tar.c file_tib.c file_tiff.c file_txt.c file_vmdk.c file_wpd.c file_wmf.c file_x3f.c file_xcf.c file_xm.c file_zip.c fnd_mem.h geometry.c list.c list.h ole.h ntfs_dir.c ntfs_dir.h ntfsp.c ntfsp.h ntfs_inc.h sessionp.c sessionp.h $(base_C) $(base_H) $(fs_C) $(fs_H) $(ICON_PHOTOREC)
+photorec_SOURCES = photorec.c photorec.h phrecn.c phrecn.h dir.c dir.h ext2p.c ext2p.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h fatp.c fatp.h filegen.c filegen.h file_7z.c file_a.c file_ab.c file_ace.c file_aif.c file_all.c file_asf.c file_au.c file_bkf.c file_bld.c file_bmp.c file_bz2.c file_cab.c file_cam.c file_cm.c file_crw.c file_ctg.c file_cwk.c file_dat.c file_dbf.c file_dir.c file_djv.c file_doc.c file_dpx.c file_dsc.c file_dta.c file_dv.c file_dwg.c file_elf.c file_evt.c file_exe.c pe.h file_ext.c file_fh10.c file_fh5.c file_flac.c file_flv.c file_fs.c file_gif.c file_gz.c file_imb.c file_indd.c file_dump.c file_itu.c file_jpg.c file_jpg.h file_kdb.c file_max.c file_mb.c file_mdb.c file_mdf.c file_mid.c file_mkv.c file_mov.c file_mp3.c file_mpg.c file_mrw.c file_mus.c file_mysql.c file_njx.c file_ogg.c file_one.c file_orf.c file_pap.c file_pcx.c file_pdf.c file_png.c file_prc.c file_ps.c file_psd.c file_pst.c file_ptb.c file_qbb.c file_qdf.c file_qxd.c file_ra.c file_raf.c file_rar.c file_raw.c file_rdc.c file_reg.c file_riff.c file_rm.c file_rns.c file_rpm.c file_sit.c file_skp.c file_spe.c file_spss.c file_stu.c file_swf.c file_tar.c file_tar.h file_tib.c file_tiff.c file_txt.c file_vmdk.c file_wpd.c file_wmf.c file_x3f.c file_xcf.c file_xm.c file_zip.c memmem.h geometry.c list.c list.h ole.h ntfs_dir.c ntfs_dir.h ntfsp.c ntfsp.h ntfs_inc.h sessionp.c sessionp.h $(base_C) $(base_H) $(fs_C) $(fs_H) $(ICON_PHOTOREC)
#diskcp_SOURCES = diskcp.c types.h
diff --git a/src/file_doc.c b/src/file_doc.c
index eadb7b2..4324a63 100644
--- a/src/file_doc.c
+++ b/src/file_doc.c
@@ -35,7 +35,7 @@
#include "filegen.h"
#include "ole.h"
#include "log.h"
-#include "fnd_mem.h"
+#include "memmem.h"
static void register_header_check_doc(file_stat_t *file_stat);
static void file_check_doc(file_recovery_t *file_recovery);
@@ -85,76 +85,76 @@ static int header_check_doc(const unsigned char *buffer, const unsigned int buff
/* TODO read the Root Directory */
reset_file_recovery(file_recovery_new);
file_recovery_new->file_check=&file_check_doc;
- if(find_in_mem(buffer,buffer_size,"S\0c\0e\0n\0e\0",10)!=NULL)
+ if(td_memmem(buffer,buffer_size,"S\0c\0e\0n\0e\0",10)!=NULL)
{
file_recovery_new->extension="max";
}
- else if(find_in_mem(buffer,buffer_size,"WordDocument",12)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"WordDocument",12)!=NULL)
{
file_recovery_new->extension="doc";
}
- else if(find_in_mem(buffer,buffer_size,"StarDraw",8)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"StarDraw",8)!=NULL)
{
file_recovery_new->extension="sda";
}
- else if(find_in_mem(buffer,buffer_size,"StarCalc",8)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"StarCalc",8)!=NULL)
{
file_recovery_new->extension="sdc";
}
- else if(find_in_mem(buffer,buffer_size,"StarImpress",11)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"StarImpress",11)!=NULL)
{
file_recovery_new->extension="sdd";
}
- else if(find_in_mem(buffer,buffer_size,"W\0k\0s\0S\0S\0W\0o\0r\0k\0B\0o\0o\0k\0",26)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"W\0k\0s\0S\0S\0W\0o\0r\0k\0B\0o\0o\0k\0",26)!=NULL)
{
file_recovery_new->extension="xlr";
}
- else if(find_in_mem(buffer,buffer_size,"I\0m\0a\0g\0e\0s\0S\0t\0o\0r\0e\0",22)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"I\0m\0a\0g\0e\0s\0S\0t\0o\0r\0e\0",22)!=NULL)
{ /* HP Photosmart Photo Printing Album */
file_recovery_new->extension="albm";
}
- else if(find_in_mem(buffer,buffer_size,"Worksheet",9)!=NULL ||
- find_in_mem(buffer,buffer_size,"Book",4)!=NULL ||
- find_in_mem(buffer,buffer_size,"Workbook",8)!=NULL ||
- find_in_mem(buffer,buffer_size,"W\0o\0r\0k\0b\0o\0o\0k\0",16)!=NULL ||
- find_in_mem(buffer,buffer_size,"Calc",4)!=NULL)
+ 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,"W\0o\0r\0k\0b\0o\0o\0k\0",16)!=NULL ||
+ td_memmem(buffer,buffer_size,"Calc",4)!=NULL)
{
file_recovery_new->extension="xls";
}
- else if(find_in_mem(buffer,buffer_size,"Power",5)!=NULL ||
- find_in_mem(buffer,buffer_size,"P\0o\0w\0e\0r\0",10)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"Power",5)!=NULL ||
+ td_memmem(buffer,buffer_size,"P\0o\0w\0e\0r\0",10)!=NULL)
{
file_recovery_new->extension="ppt";
}
- else if(find_in_mem(buffer,buffer_size,"AccessObjSiteData",17)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"AccessObjSiteData",17)!=NULL)
{
file_recovery_new->extension="mdb";
}
- else if(find_in_mem(buffer,buffer_size,"Visio",5)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"Visio",5)!=NULL)
{
file_recovery_new->extension="vis";
}
- else if(find_in_mem(buffer,buffer_size,"Sfx",3)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"Sfx",3)!=NULL)
{
file_recovery_new->extension="sdw";
}
- else if(find_in_mem(buffer,buffer_size,"CPicPage",8)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"CPicPage",8)!=NULL)
{ /* Flash */
file_recovery_new->extension="fla";
}
- else if(find_in_mem(buffer,buffer_size,"Microsoft Publisher",19)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"Microsoft Publisher",19)!=NULL)
{
file_recovery_new->extension="pub";
}
- else if(find_in_mem(buffer,buffer_size,"C\0O\0N\0T\0E\0N\0T\0S\0",16)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"C\0O\0N\0T\0E\0N\0T\0S\0",16)!=NULL)
{
file_recovery_new->extension="wps";
}
- else if(find_in_mem(buffer,buffer_size,"MetaStock",9)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"MetaStock",9)!=NULL)
{
file_recovery_new->extension="mws";
}
- else if(find_in_mem(buffer,buffer_size,"_\0_\0n\0a\0m\0e\0i\0d\0_\0v\0e\0r\0s\0i\0o\0n\0001\0.\0000\0",38)!=NULL)
+ else if(td_memmem(buffer,buffer_size,"_\0_\0n\0a\0m\0e\0i\0d\0_\0v\0e\0r\0s\0i\0o\0n\0001\0.\0000\0",38)!=NULL)
{ /* Outlook */
file_recovery_new->extension="msg";
}
diff --git a/src/file_mb.c b/src/file_mb.c
new file mode 100644
index 0000000..01c5acd
--- /dev/null
+++ b/src/file_mb.c
@@ -0,0 +1,79 @@
+/*
+
+ File: file_mb.c
+
+ Copyright (C) 2007 Christophe GRENIER <grenier@cgsecurity.org>
+
+ 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.
+
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <stdio.h>
+#include "types.h"
+#include "filegen.h"
+#include "log.h"
+
+static void register_header_check_mb(file_stat_t *file_stat);
+static int header_check_mb(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_mb= {
+ .extension="mb",
+ .description="Maya",
+ .min_header_distance=0,
+ .max_filesize=PHOTOREC_MAX_FILE_SIZE,
+ .recover=1,
+ .header_check=&header_check_mb,
+ .register_header_check=&register_header_check_mb
+};
+
+static const unsigned char mb_header[8]= {'M','a','y','a','F','O','R','4'};
+static const unsigned char mb_header2[8]= {'M','A','Y','A','F','O','R','4'};
+static const unsigned char mp_header[8]= {'M','P','L','E','F','O','R','4'};
+
+static void register_header_check_mb(file_stat_t *file_stat)
+{
+ register_header_check(8, mb_header, sizeof(mb_header), &header_check_mb, file_stat);
+ register_header_check(8, mb_header2, sizeof(mb_header2), &header_check_mb, file_stat);
+ register_header_check(8, mp_header, sizeof(mp_header), &header_check_mb, file_stat);
+}
+
+static int header_check_mb(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], mb_header, sizeof(mb_header))==0 ||
+ memcmp(&buffer[8], mb_header2, sizeof(mb_header2))==0)
+ {
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_mb.extension;
+ file_recovery_new->min_filesize=8;
+ file_recovery_new->calculated_file_size=(uint64_t)(buffer[4]<<24)+(buffer[5]<<16)+(buffer[6]<<8)+buffer[7]+8;
+ file_recovery_new->data_check=&data_check_size;
+ file_recovery_new->file_check=&file_check_size;
+ return 1;
+ }
+ if(memcmp(&buffer[8], mp_header, sizeof(mp_header))==0)
+ {
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension="mp";
+ file_recovery_new->min_filesize=8;
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/file_mov.c b/src/file_mov.c
index 189c336..4f2e0cc 100644
--- a/src/file_mov.c
+++ b/src/file_mov.c
@@ -31,7 +31,7 @@
#include "filegen.h"
#include "common.h"
#include "log.h"
-#include "fnd_mem.h"
+#include "memmem.h"
static void register_header_check_mov(file_stat_t *file_stat);
static int header_check_mov(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);
@@ -101,13 +101,13 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
unsigned int search_size=atom_size;
if(search_size>buffer_size-i)
search_size=buffer_size-i;
- if(find_in_mem(&buffer[i+8], search_size-8, "isom", 4)!=NULL ||
- find_in_mem(&buffer[i+8], search_size-8, "mp41", 4)!=NULL ||
- find_in_mem(&buffer[i+8], search_size-8, "mp42", 4)!=NULL ||
- find_in_mem(&buffer[i+8], search_size-8, "mmp4", 4)!=NULL ||
- find_in_mem(&buffer[i+8], search_size-8, "M4A", 3)!=NULL ||
- find_in_mem(&buffer[i+8], search_size-8, "M4B", 3)!=NULL ||
- find_in_mem(&buffer[i+8], search_size-8, "M4P", 3)!=NULL)
+ if(td_memmem(&buffer[i+8], search_size-8, "isom", 4)!=NULL ||
+ td_memmem(&buffer[i+8], search_size-8, "mp41", 4)!=NULL ||
+ td_memmem(&buffer[i+8], search_size-8, "mp42", 4)!=NULL ||
+ td_memmem(&buffer[i+8], search_size-8, "mmp4", 4)!=NULL ||
+ td_memmem(&buffer[i+8], search_size-8, "M4A", 3)!=NULL ||
+ td_memmem(&buffer[i+8], search_size-8, "M4B", 3)!=NULL ||
+ td_memmem(&buffer[i+8], search_size-8, "M4P", 3)!=NULL)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="mp4";
@@ -116,7 +116,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
}
- else if(find_in_mem(&buffer[i+8], search_size-8, "3gp", 3)!=NULL)
+ else if(td_memmem(&buffer[i+8], search_size-8, "3gp", 3)!=NULL)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="3gp";
@@ -125,7 +125,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
}
- else if(find_in_mem(&buffer[i+8], search_size-8, "3g2", 3)!=NULL)
+ else if(td_memmem(&buffer[i+8], search_size-8, "3g2", 3)!=NULL)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="3g2";
@@ -134,7 +134,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
}
- else if(find_in_mem(&buffer[i+8], search_size-8, "jp2", 3)!=NULL)
+ else if(td_memmem(&buffer[i+8], search_size-8, "jp2", 3)!=NULL)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="jp2";
@@ -143,7 +143,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
}
- else if(find_in_mem(&buffer[i+8], search_size-8, "qt", 2)!=NULL)
+ else if(td_memmem(&buffer[i+8], search_size-8, "qt", 2)!=NULL)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="mov";
diff --git a/src/file_pdf.c b/src/file_pdf.c
index 3487e87..ce605cf 100644
--- a/src/file_pdf.c
+++ b/src/file_pdf.c
@@ -29,7 +29,7 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
-#include "fnd_mem.h"
+#include "memmem.h"
static void register_header_check_pdf(file_stat_t *file_stat);
static int header_check_pdf(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);
@@ -61,11 +61,11 @@ static int header_check_pdf(const unsigned char *buffer, const unsigned int buff
const unsigned char sig_linearized[10]={'L','i','n','e','a','r','i','z','e','d'};
const unsigned char *linearized;
reset_file_recovery(file_recovery_new);
- if(find_in_mem(buffer, 512, sig_illustrator,sizeof(sig_illustrator)) != NULL)
+ if(td_memmem(buffer, 512, sig_illustrator,sizeof(sig_illustrator)) != NULL)
file_recovery_new->extension="ai";
else
file_recovery_new->extension=file_hint_pdf.extension;
- if((linearized=find_in_mem(buffer, 512, sig_linearized,sizeof(sig_linearized))) != NULL)
+ if((linearized=td_memmem(buffer, 512, sig_linearized,sizeof(sig_linearized))) != NULL)
{
linearized+=sizeof(sig_linearized);
while(*linearized!='>' && linearized<=buffer+512)
diff --git a/src/file_tar.c b/src/file_tar.c
index 268346e..2333796 100644
--- a/src/file_tar.c
+++ b/src/file_tar.c
@@ -29,9 +29,9 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
+#include "file_tar.h"
static void register_header_check_tar(file_stat_t *file_stat);
-static int header_check_tar(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_tar= {
.extension="tar",
@@ -52,7 +52,7 @@ static void register_header_check_tar(file_stat_t *file_stat)
register_header_check(0x101, tar_header_posix,sizeof(tar_header_posix), &header_check_tar, file_stat);
}
-static int header_check_tar(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)
+int header_check_tar(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(file_recovery!=NULL && file_recovery->file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_tar)
return 0;
diff --git a/src/fnd_mem.h b/src/file_tar.h
index 2cd6640..6938e54 100644
--- a/src/fnd_mem.h
+++ b/src/file_tar.h
@@ -1,37 +1,24 @@
/*
- File: fnd_mem.h
-
- Copyright (C) 2005-2007 Christophe GRENIER <grenier@cgsecurity.org>
+ File: file_tar.h
+ Copyright (C) 1998-2005,2007 Christophe GRENIER <grenier@cgsecurity.org>
+
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.
*/
-static inline const unsigned char *find_in_mem(const unsigned char *haystack, const unsigned int haystack_size,
- const unsigned char *needle, const unsigned int needle_length)
-{
- const unsigned char *haystack_end=haystack+haystack_size;
- while(haystack_end-haystack>=needle_length)
- {
- haystack=memchr(haystack,needle[0],haystack_end-haystack);
- if(haystack==NULL)
- return NULL;
- if(memcmp(haystack,needle,needle_length)==0)
- return haystack;
- haystack++;
- };
- return NULL;
-}
+int header_check_tar(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_tiff.c b/src/file_tiff.c
index 7be8b86..1c1c45b 100644
--- a/src/file_tiff.c
+++ b/src/file_tiff.c
@@ -29,7 +29,7 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
-#include "fnd_mem.h"
+#include "memmem.h"
static void register_header_check_tiff(file_stat_t *file_stat);
static int header_check_tiff(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);
@@ -71,16 +71,16 @@ static int header_check_tiff(const unsigned char *buffer, const unsigned int buf
if(buffer[8]=='C' && buffer[9]=='R' && buffer[10]==2)
file_recovery_new->extension="cr2";
/* Pentax RAW */
- else if(find_in_mem(buffer, buffer_size, pentax_sig, sizeof(pentax_sig))!=NULL)
+ else if(td_memmem(buffer, buffer_size, pentax_sig, sizeof(pentax_sig))!=NULL)
file_recovery_new->extension="pef";
/* Nikon RAW */
- else if(find_in_mem(buffer, buffer_size, nikon_sig, sizeof(nikon_sig))!=NULL)
+ else if(td_memmem(buffer, buffer_size, nikon_sig, sizeof(nikon_sig))!=NULL)
file_recovery_new->extension="nef";
/* Kodak RAW */
- else if(find_in_mem(buffer, buffer_size, dcr_sig, sizeof(dcr_sig))!=NULL)
+ else if(td_memmem(buffer, buffer_size, dcr_sig, sizeof(dcr_sig))!=NULL)
file_recovery_new->extension="dcr";
/* Sony RAW */
- else if(find_in_mem(buffer, buffer_size, sony_sig, sizeof(sony_sig))!=NULL)
+ else if(td_memmem(buffer, buffer_size, sony_sig, sizeof(sony_sig))!=NULL)
file_recovery_new->extension="sr2";
else
file_recovery_new->extension=file_hint_tiff.extension;
diff --git a/src/file_txt.c b/src/file_txt.c
index bab4072..7575011 100644
--- a/src/file_txt.c
+++ b/src/file_txt.c
@@ -35,7 +35,7 @@
#include "common.h"
#include "filegen.h"
#include "log.h"
-#include "fnd_mem.h"
+#include "memmem.h"
extern const file_hint_t file_hint_doc;
extern const file_hint_t file_hint_jpg;
@@ -360,11 +360,11 @@ static int header_check_fasttxt(const unsigned char *buffer, const unsigned int
{
reset_file_recovery(file_recovery_new);
file_recovery_new->data_check=&data_check_txt;
- if(find_in_mem(buffer, buffer_size, sign_grisbi, sizeof(sign_grisbi))!=NULL)
+ if(td_memmem(buffer, buffer_size, sign_grisbi, sizeof(sign_grisbi))!=NULL)
file_recovery_new->extension="gsb";
- else if(find_in_mem(buffer, buffer_size, sign_fst, sizeof(sign_fst))!=NULL)
+ else if(td_memmem(buffer, buffer_size, sign_fst, sizeof(sign_fst))!=NULL)
file_recovery_new->extension="fst";
- else if(find_in_mem(buffer, buffer_size, sign_html, sizeof(sign_html))!=NULL)
+ else if(td_memmem(buffer, buffer_size, sign_html, sizeof(sign_html))!=NULL)
{
file_recovery_new->extension="html";
file_recovery_new->file_check=&file_check_html;
@@ -451,13 +451,13 @@ static int header_check_txt(const unsigned char *buffer, const unsigned int buff
}
if(buffer[0]=='#' && buffer[1]=='!')
{
- unsigned int l=buffer_size;
+ unsigned int l=i-2;
const unsigned char *haystack=buffer_lower+2;
const unsigned char *res;
res=memchr(haystack,'\n',l);
if(res!=NULL)
l=res-haystack;
- if(find_in_mem(haystack, l, header_sig_perl, sizeof(header_sig_perl)) != NULL)
+ if(td_memmem(haystack, l, header_sig_perl, sizeof(header_sig_perl)) != NULL)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->data_check=&data_check_txt;
@@ -465,7 +465,7 @@ static int header_check_txt(const unsigned char *buffer, const unsigned int buff
file_recovery_new->extension="pl";
return 1;
}
- if(find_in_mem(haystack, l, header_sig_python, sizeof(header_sig_python)) != NULL)
+ if(td_memmem(haystack, l, header_sig_python, sizeof(header_sig_python)) != NULL)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->data_check=&data_check_txt;
@@ -473,7 +473,7 @@ static int header_check_txt(const unsigned char *buffer, const unsigned int buff
file_recovery_new->extension="py";
return 1;
}
- if(find_in_mem(haystack, l, header_sig_ruby, sizeof(header_sig_ruby)) != NULL)
+ if(td_memmem(haystack, l, header_sig_ruby, sizeof(header_sig_ruby)) != NULL)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->data_check=&data_check_txt;
@@ -580,10 +580,10 @@ Doc: \r (0xD)
strstr(file_recovery->filename,".html")!=NULL) ||
/* Text should not be found in JPEG */
(file_recovery->file_stat->file_hint==&file_hint_jpg &&
- find_in_mem(buffer, buffer_size, "8BIM", 4)==NULL &&
- find_in_mem(buffer, buffer_size, "adobe", 5)==NULL) ||
+ td_memmem(buffer, buffer_size, "8BIM", 4)==NULL &&
+ td_memmem(buffer, buffer_size, "adobe", 5)==NULL) ||
/* Text should not be found in zip because of compression */
- (file_recovery->file_stat->file_hint==&file_hint_zip && find_in_mem(buffer, buffer_size, zip_header, 4)==NULL))
+ (file_recovery->file_stat->file_hint==&file_hint_zip && td_memmem(buffer, buffer_size, zip_header, 4)==NULL))
{
reset_file_recovery(file_recovery_new);
file_recovery_new->data_check=&data_check_txt;
diff --git a/src/memmem.h b/src/memmem.h
new file mode 100644
index 0000000..8a700f1
--- /dev/null
+++ b/src/memmem.h
@@ -0,0 +1,47 @@
+/*
+
+ File: memmem.h
+
+ Copyright (C) 2005-2007 Christophe GRENIER <grenier@cgsecurity.org>
+ Copyright (C) 1991,92,93,94,96,97,98,2000,2004 Free Software Foundation, Inc.
+ The function has been copied from glibc 2.7
+
+ 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.
+
+ */
+
+static inline const void *td_memmem(const void *haystack, const unsigned int haystack_len, const void *needle, const unsigned int needle_len)
+{
+ const char *begin;
+ const char *const last_possible = (const char *) haystack + haystack_len - needle_len;
+
+ if (needle_len == 0)
+ /* The first occurrence of the empty string is deemed to occur at
+ the beginning of the string. */
+ return (const void *) haystack;
+
+ /* Sanity check, otherwise the loop might search through the whole
+ memory. */
+ if (haystack_len < needle_len)
+ return NULL;
+
+ for (begin = (const char *) haystack; begin <= last_possible; ++begin)
+ if (begin[0] == ((const char *) needle)[0] &&
+ !memcmp ((const void *) &begin[1],
+ (const void *) ((const char *) needle + 1),
+ needle_len - 1))
+ return (const void *) begin;
+ return NULL;
+}
diff --git a/src/photorec.c b/src/photorec.c
index 93a0fc8..c70c79c 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -137,6 +137,7 @@ extern const file_hint_t file_hint_itunes;
extern const file_hint_t file_hint_jpg;
extern const file_hint_t file_hint_kdb;
extern const file_hint_t file_hint_max;
+extern const file_hint_t file_hint_mb;
extern const file_hint_t file_hint_mdb;
extern const file_hint_t file_hint_mdf;
extern const file_hint_t file_hint_mid;
@@ -805,6 +806,7 @@ int main( int argc, char **argv )
{ .enable=1, .file_hint=&file_hint_kdb },
{ .enable=1, .file_hint=&file_hint_jpg },
{ .enable=1, .file_hint=&file_hint_max },
+ { .enable=1, .file_hint=&file_hint_mb },
{ .enable=1, .file_hint=&file_hint_mdb },
{ .enable=1, .file_hint=&file_hint_mdf },
{ .enable=1, .file_hint=&file_hint_mid },
diff --git a/src/phrecn.c b/src/phrecn.c
index d33b3ae..c9ff0e4 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -60,6 +60,7 @@
#include "partauto.h"
#include "log.h"
#include "hdaccess.h"
+#include "file_tar.h"
/* #define DEBUG */
/* #define DEBUG_GET_NEXT_SECTOR */
@@ -69,7 +70,6 @@
extern const file_hint_t file_hint_tar;
extern const file_hint_t file_hint_dir;
-extern const file_hint_t file_hint_txt;
extern file_check_t *file_check_list;
#ifdef HAVE_NCURSES
@@ -859,7 +859,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const int verb
{
}
else if(file_recovery.file_stat!=NULL && file_recovery.file_stat->file_hint==&file_hint_tar &&
- file_hint_tar.header_check(buffer-0x200,0x200,0,&file_recovery,&file_recovery_new))
+ header_check_tar(buffer-0x200,0x200,0,&file_recovery,&file_recovery_new))
{ /* Currently saving a tar, do not check the data for know header */
if(verbose>1)
{