summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2008-06-23 19:08:19 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2008-06-23 19:08:19 +0200
commit50a0862d48da7f0260524b17c3b33281a1b5dcc7 (patch)
tree14ad3852c96c32ac49fa842e607790051d3ddb68
parent92aca2f1a3c05e400394dca4e3f00835152a3c5a (diff)
Mac: ncurses static library may be used
PhotoRec: add Ableton Live Sets .als file format PhotoRec: safer prototype for del_search_space() and update_search_space_aux()
-rwxr-xr-xcompile.sh3
-rw-r--r--configure.ac43
-rw-r--r--src/Makefile.am2
-rw-r--r--src/file_als.c66
-rw-r--r--src/filegen.h2
-rw-r--r--src/photorec.c31
6 files changed, 120 insertions, 27 deletions
diff --git a/compile.sh b/compile.sh
index 2be6e5f..c452651 100755
--- a/compile.sh
+++ b/compile.sh
@@ -228,7 +228,8 @@ then
case "$crosscompile_target" in
powerpc-apple-darwin)
# libewf should work under MacOSX but it hasn't been tested
- $confdir/configure --host=$crosscompile_target --prefix=$prefix $CONFIGUREOPT --without-ewf --enable-sudo --with-sudo-bin=/usr/bin/sudo
+# use --with-ncurses, so the binaries don't need libncurses
+ $confdir/configure --host=$crosscompile_target --prefix=$prefix $CONFIGUREOPT --without-ewf --enable-sudo --with-sudo-bin=/usr/bin/sudo --with-ncurses-lib=$prefix/usr/lib
;;
i586-pc-msdosdjgpp)
$confdir/configure --host=$crosscompile_target --prefix=$prefix $CONFIGUREOPT --without-ewf --without-iconv
diff --git a/configure.ac b/configure.ac
index 5eea384..4a6a095 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,7 +35,7 @@ AC_ARG_WITH([ncurses],
AC_ARG_WITH(ncurses-lib,
AS_HELP_STRING(--with-ncurses-lib=DIR,location of the ncurses library),
- [ ncurses_lib_a="${withval}/libncurses.a"
+ [ ncurses_lib_dir="${withval}"
LDFLAGS="${LDFLAGS} -L${withval}" ])
AC_ARG_WITH(ncurses-includes,
@@ -369,14 +369,37 @@ AC_PROG_GCC_TRADITIONAL
# Checks for libraries.
if test -z "${use_ncurses}"; then
- AC_SEARCH_LIBS(initscr, ncursesw ncurses pdcurses curses,
- [
- AC_DEFINE([HAVE_NCURSES],1,[Define to 1 if you have one of the ncursesw/ncurses/pdcurses/curses library.])
- AC_CHECK_LIB(tinfo,keypad,[
- AC_DEFINE([HAVE_TINFO],1,[Define to 1 if you have the tinfo library (-ltinfo).])
- LIBS="$LIBS -ltinfo"
- ])
- ],AC_MSG_ERROR(No ncurses library detected))
+ AC_CHECK_LIB(ncursesw, initscr, [ ncurses_lib="ncursesw" ])
+ if test -z "${ncurses_lib}"; then
+ AC_CHECK_LIB( ncurses, initscr, [ ncurses_lib="ncurses" ])
+ fi
+ if test -z "${ncurses_lib}"; then
+ AC_CHECK_LIB(pdcurses, initscr, [ ncurses_lib="pdcurses" ])
+ fi
+ if test -z "${ncurses_lib}"; then
+ AC_CHECK_LIB(curses, initscr, [ ncurses_lib="curses" ])
+ fi
+ if test -z "${ncurses_lib}"; then
+ AC_MSG_ERROR(At least one of ncursesw/ncurses/pdcurses/curses library must be present)
+ fi
+ AC_DEFINE([HAVE_NCURSES],1,[Define to 1 if you have one of the ncursesw/ncurses/pdcurses/curses library.])
+ if test "${ncurses_lib_dir}" != "" -a -e "${ncurses_lib_dir}/lib${ncurses_lib}.a"; then
+ LIBS="$LIBS ${ncurses_lib_dir}/lib${ncurses_lib}.a"
+ else
+ LIBS="$LIBS -l${ncurses_lib}"
+ fi
+ AC_CHECK_LIB(tinfo,keypad,[
+ AC_DEFINE([HAVE_TINFO],1,[Define to 1 if you have the tinfo library (-ltinfo).])
+# if lib${ncurses_lib}.a is present, try to use libtinfo.a
+ if test "${ncurses_lib_dir}" != "" -a -e "${ncurses_lib_dir}/lib${ncurses_lib}.a";
+ then
+ if test -e "${ncurses_lib_dir}/libtinfo.a"; then
+ LIBS="$LIBS ${ncurses_lib_dir}/libtinfo.a"
+ fi
+ else
+ LIBS="$LIBS -ltinfo"
+ fi
+ ])
else
AC_MSG_WARN(Use of ncurses library disabled)
fi
@@ -390,7 +413,7 @@ if test -z "${use_ext2fs}"; then
LIBS="$LIBS ${ext2fs_lib_a}"
fi
],AC_MSG_WARN(No ext2fs library detected))
- AC_CHECK_LIB(ext2fs,ext2fs_open,[
+ AC_CHECK_LIB(com_err,com_err,[
AC_DEFINE([HAVE_LIBCOMM_ERR],1,[Define to 1 if you have the com_err library (-lcom_err).])
if test "${com_err_lib_a}" = ""; then
LIBS="$LIBS -lcom_err"
diff --git a/src/Makefile.am b/src/Makefile.am
index 8874ca9..971c620 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_adv.h 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 dimage.c dimage.h
#ntfs_udl.c ntfs_udl.h
-photorec_SOURCES = photorec.c photorec.h phcfg.c phcfg.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_amd.c file_amr.c file_arj.c file_asf.c file_asm.c file_au.c file_bkf.c file_bld.c file_bmp.c file_bz2.c file_cab.c file_cam.c file_chm.c file_cm.c file_crw.c file_ctg.c file_cwk.c file_dat.c file_dbf.c file_dim.c file_dir.c file_djv.c file_doc.c file_dpx.c file_drw.c file_ds2.c file_dsc.c file_dss.c file_dta.c file_dump.c file_dv.c file_dwg.c file_elf.c file_emf.c file_evt.c file_exe.c pe.h file_ext.c file_fcp.c file_fcs.c file_fh10.c file_fh5.c file_fits.c file_flac.c file_flv.c file_frm.c file_fs.c file_gho.c file_gif.c file_gpg.c file_gz.c file_ifo.c file_imb.c file_indd.c file_iso.c file_itu.c file_jpg.c file_jpg.h file_kdb.c file_lnk.c file_m2ts.c file_max.c file_mb.c file_mcd.c file_mdb.c file_mdf.c file_mfg.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_paf.c file_pap.c file_pct.c file_pcx.c file_pdf.c file_pfx.c file_png.c file_prc.c file_prt.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_res.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_sql.c file_stl.c file_stu.c file_swf.c file_tar.c file_tar.h file_tib.c file_tiff.c file_tph.c file_txt.c file_vmdk.c file_wpd.c file_wmf.c file_x3f.c file_xcf.c file_xm.c file_xsv.c file_veg.c file_wks.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)
+photorec_SOURCES = photorec.c photorec.h phcfg.c phcfg.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_als.c file_amd.c file_amr.c file_arj.c file_asf.c file_asm.c file_au.c file_bkf.c file_bld.c file_bmp.c file_bz2.c file_cab.c file_cam.c file_chm.c file_cm.c file_crw.c file_ctg.c file_cwk.c file_dat.c file_dbf.c file_dim.c file_dir.c file_djv.c file_doc.c file_dpx.c file_drw.c file_ds2.c file_dsc.c file_dss.c file_dta.c file_dump.c file_dv.c file_dwg.c file_elf.c file_emf.c file_evt.c file_exe.c pe.h file_ext.c file_fcp.c file_fcs.c file_fh10.c file_fh5.c file_fits.c file_flac.c file_flv.c file_frm.c file_fs.c file_gho.c file_gif.c file_gpg.c file_gz.c file_ifo.c file_imb.c file_indd.c file_iso.c file_itu.c file_jpg.c file_jpg.h file_kdb.c file_lnk.c file_m2ts.c file_max.c file_mb.c file_mcd.c file_mdb.c file_mdf.c file_mfg.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_paf.c file_pap.c file_pct.c file_pcx.c file_pdf.c file_pfx.c file_png.c file_prc.c file_prt.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_res.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_sql.c file_stl.c file_stu.c file_swf.c file_tar.c file_tar.h file_tib.c file_tiff.c file_tph.c file_txt.c file_vmdk.c file_wpd.c file_wmf.c file_x3f.c file_xcf.c file_xm.c file_xsv.c file_veg.c file_wks.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_als.c b/src/file_als.c
new file mode 100644
index 0000000..20cb87c
--- /dev/null
+++ b/src/file_als.c
@@ -0,0 +1,66 @@
+/*
+
+ File: file_als.c
+
+ Copyright (C) 2008 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"
+
+static void register_header_check_als(file_stat_t *file_stat);
+static int header_check_als(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_als= {
+ .extension="als",
+ .description="Ableton Live Sets",
+ .min_header_distance=0,
+ .max_filesize=PHOTOREC_MAX_FILE_SIZE,
+ .recover=1,
+ .enable_by_default=1,
+ .register_header_check=&register_header_check_als
+};
+
+static const unsigned char als_header[24]= {
+ 0xab, 0x1e, 'V', 'x', 0x03, 'W', 0x00, 0x00,
+ 0x00, 0x00, 0x06, 0x0c, 'L', 'i', 'v', 'e',
+ 'D', 'o', 'c', 'u', 'm', 'e', 'n', 't'
+};
+
+static void register_header_check_als(file_stat_t *file_stat)
+{
+ register_header_check(0, als_header,sizeof(als_header), &header_check_als, file_stat);
+}
+
+static int header_check_als(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,als_header,sizeof(als_header))==0)
+ {
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_als.extension;
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/filegen.h b/src/filegen.h
index f751a04..7648a64 100644
--- a/src/filegen.h
+++ b/src/filegen.h
@@ -101,7 +101,7 @@ struct alloc_data_struct
void file_search_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length);
void file_search_lc_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length);
-alloc_data_t *del_search_space(alloc_data_t *list_search_space, uint64_t start, uint64_t end);
+alloc_data_t *del_search_space(alloc_data_t *list_search_space, const uint64_t start, const uint64_t end);
int data_check_size(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);
void file_check_size(file_recovery_t *file_recovery);
void reset_file_recovery(file_recovery_t *file_recovery);
diff --git a/src/photorec.c b/src/photorec.c
index a4003cd..772ce19 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -104,6 +104,7 @@ extern const file_hint_t file_hint_ace;
extern const file_hint_t file_hint_addressbook;
extern const file_hint_t file_hint_aif;
extern const file_hint_t file_hint_all;
+extern const file_hint_t file_hint_als;
extern const file_hint_t file_hint_amd;
extern const file_hint_t file_hint_amr;
extern const file_hint_t file_hint_arj;
@@ -335,12 +336,12 @@ static alloc_data_t *update_search_space(const file_recovery_t *file_recovery, a
return list_search_space;
}
-alloc_data_t *del_search_space(alloc_data_t *list_search_space, uint64_t start, uint64_t end)
+alloc_data_t *del_search_space(alloc_data_t *list_search_space, const uint64_t start, const uint64_t end)
{
return update_search_space_aux(list_search_space, start, end, NULL, NULL);
}
-static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, uint64_t start, uint64_t end, alloc_data_t **new_current_search_space, uint64_t *offset)
+static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, const uint64_t start, const uint64_t end, alloc_data_t **new_current_search_space, uint64_t *offset)
{
struct td_list_head *search_walker = NULL;
#ifdef DEBUG_UPDATE_SEARCH_SPACE
@@ -365,8 +366,9 @@ static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, ui
#endif
if(current_search_space->start==start)
{
- if(end<current_search_space->end)
- { /* current_search_space->start==start end<current_search_space->end */
+ const uint64_t pivot=current_search_space->end+1;
+ if(end+1<current_search_space->end)
+ { /* current_search_space->start==start end+1<current_search_space->end */
if(offset!=NULL && new_current_search_space!=NULL &&
current_search_space->start<=*offset && *offset<=end)
{
@@ -378,7 +380,6 @@ static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, ui
return list_search_space;
}
/* current_search_space->start==start current_search_space->end<=end */
- start=current_search_space->end+1;
if(list_search_space==current_search_space)
list_search_space=td_list_entry(current_search_space->list.next, alloc_data_t, list);
if(offset!=NULL && new_current_search_space!=NULL &&
@@ -389,14 +390,15 @@ static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, ui
}
td_list_del(search_walker);
free(current_search_space);
- return update_search_space_aux(list_search_space, start,end, new_current_search_space, offset);
+ return update_search_space_aux(list_search_space, pivot, end, new_current_search_space, offset);
}
if(current_search_space->end==end)
{
+ const uint64_t pivot=current_search_space->start-1;
#ifdef DEBUG_UPDATE_SEARCH_SPACE
log_trace("current_search_space->end==end\n");
#endif
- if(current_search_space->start<start)
+ if(current_search_space->start+1<start)
{ /* current_search_space->start<start current_search_space->end==end */
if(offset!=NULL && new_current_search_space!=NULL &&
start<=*offset && *offset<=current_search_space->end)
@@ -408,7 +410,6 @@ static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, ui
return list_search_space;
}
/* start<=current_search_space->start current_search_space->end==end */
- end=current_search_space->start-1;
if(list_search_space==current_search_space)
list_search_space=td_list_entry(current_search_space->list.next, alloc_data_t, list);
if(offset!=NULL && new_current_search_space!=NULL &&
@@ -419,18 +420,19 @@ static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, ui
}
td_list_del(search_walker);
free(current_search_space);
- return update_search_space_aux(list_search_space, start,end, new_current_search_space, offset);
+ return update_search_space_aux(list_search_space, start, pivot, new_current_search_space, offset);
}
if(start < current_search_space->start && current_search_space->start <= end)
{
- list_search_space=update_search_space_aux(list_search_space,
- start, current_search_space->start-1, new_current_search_space, offset);
- return update_search_space_aux(list_search_space, current_search_space->start, end, new_current_search_space, offset);
+ const uint64_t pivot=current_search_space->start;
+ list_search_space=update_search_space_aux(list_search_space, start, pivot-1, new_current_search_space, offset);
+ return update_search_space_aux(list_search_space, pivot, end, new_current_search_space, offset);
}
if(start <= current_search_space->end && current_search_space->end < end)
{
- list_search_space=update_search_space_aux(list_search_space, start, current_search_space->end, new_current_search_space, offset);
- return update_search_space_aux(list_search_space, current_search_space->end+1, end, new_current_search_space, offset);
+ const uint64_t pivot=current_search_space->end;
+ list_search_space=update_search_space_aux(list_search_space, start, pivot, new_current_search_space, offset);
+ return update_search_space_aux(list_search_space, pivot+1, end, new_current_search_space, offset);
}
if(current_search_space->start < start && end < current_search_space->end)
{
@@ -808,6 +810,7 @@ int main( int argc, char **argv )
{ .enable=0, .file_hint=&file_hint_addressbook},
{ .enable=0, .file_hint=&file_hint_aif },
{ .enable=0, .file_hint=&file_hint_all },
+ { .enable=0, .file_hint=&file_hint_als },
{ .enable=0, .file_hint=&file_hint_amd },
{ .enable=0, .file_hint=&file_hint_amr },
{ .enable=0, .file_hint=&file_hint_arj },