Reduce unnecessary interactivity in scripted run

This commit is contained in:
Christophe Grenier 2012-12-23 17:17:57 +01:00
parent 8a8d64e8e9
commit 62a39b9b45
12 changed files with 95 additions and 38 deletions

View file

@ -13,14 +13,14 @@ endif
bin_PROGRAMS = testdisk photorec fidentify $(QPHOTOREC)
EXTRA_PROGRAMS = photorecf
base_C = autoset.c common.c crc.c ewf.c fnctdsk.c hdaccess.c hdcache.c hdwin32.c hidden.c hpa_dco.c intrf.c iso.c list.c list_sort.c log.c log_part.c misc.c msdos.c parti386.c partgpt.c parthumax.c partmac.c partsun.c partnone.c partxbox.c io_redir.c ntfs_io.c ntfs_utl.c partauto.c sudo.c unicode.c win32.c
base_C = autoset.c common.c crc.c ewf.c fnctdsk.c hdaccess.c hdcache.c hdwin32.c hidden.c hpa_dco.c intrf.c iso.c list_sort.c log.c log_part.c misc.c msdos.c parti386.c partgpt.c parthumax.c partmac.c partsun.c partnone.c partxbox.c io_redir.c ntfs_io.c ntfs_utl.c partauto.c sudo.c unicode.c win32.c
base_H = alignio.h autoset.h common.h crc.h ewf.h fnctdsk.h hdaccess.h hdwin32.h hidden.h guid_cmp.h guid_cpy.h hdcache.h hpa_dco.h intrf.h iso.h iso9660.h lang.h list.h list_sort.h log.h log_part.h misc.h types.h io_redir.h msdos.h ntfs_utl.h parti386.h partgpt.h parthumax.h partmac.h partsun.h partxbox.h partauto.h sudo.h unicode.h win32.h
fs_C = analyse.c bfs.c bsd.c btrfs.c cramfs.c exfat.c fat.c fatx.c ext2.c jfs.c gfs2.c hfs.c hfsp.c hpfs.c luks.c lvm.c md.c netware.c ntfs.c rfs.c savehdr.c sun.c swap.c sysv.c ufs.c vmfs.c wbfs.c xfs.c zfs.c
fs_H = analyse.h bfs.h bsd.h btrfs.h cramfs.h exfat.h fat.h fatx.h ext2.h jfs_superblock.h jfs.h gfs2.h hfs.h hfsp.h hpfs.h luks.h lvm.h md.h netware.h ntfs.h rfs.h savehdr.h sun.h swap.h sysv.h ufs.h vmfs.h wbfs.h xfs.h zfs.h
testdisk_ncurses_C = addpart.c adv.c askloc.c chgtype.c chgtypen.c dimage.c dirn.c dirpart.c diskacc.c diskcapa.c edit.c ext2_sb.c ext2_sbn.c fat1x.c fat32.c fat_adv.c fat_cluster.c fatn.c geometry.c godmode.c hiddenn.c intrface.c intrfn.c nodisk.c ntfs_adv.c ntfs_fix.c ntfs_udl.c parti386n.c partgptn.c partmacn.c partsunn.c partxboxn.c tanalyse.c tbanner.c tdelete.c tdiskop.c tdisksel.c testdisk.c texfat.c thfs.c tload.c tlog.c tmbrcode.c tntfs.c toptions.c tpartwr.c
testdisk_ncurses_H = addpart.h adv.h askloc.h chgtype.h chgtypen.h dimage.h dirn.h dirpart.h diskacc.h diskcapa.h edit.h ext2_sb.h ext2_sbn.h fat1x.h fat32.h fat_adv.h fat_cluster.h fatn.h geometry.h godmode.h hiddenn.h intrface.h intrfn.h nodisk.h ntfs_udl.h partgptn.h parti386n.h partmacn.h partsunn.h partxboxn.h tanalyse.h tdelete.h tdiskop.h tdisksel.h texfat.h thfs.h tload.h tlog.h tmbrcode.h tntfs.h toptions.h tpartwr.h
testdisk_ncurses_H = addpart.h adv.h askloc.h chgtype.h chgtypen.h dimage.h dirn.h dirpart.h diskacc.h diskcapa.h edit.h ext2_sb.h ext2_sbn.h fat1x.h fat32.h fat_adv.h fat_cluster.h fatn.h geometry.h godmode.h hiddenn.h intrface.h intrfn.h nodisk.h ntfs_fix.h ntfs_udl.h partgptn.h parti386n.h partmacn.h partsunn.h partxboxn.h tanalyse.h tdelete.h tdiskop.h tdisksel.h texfat.h thfs.h tload.h tlog.h tmbrcode.h tntfs.h toptions.h tpartwr.h
testdisk_SOURCES = $(base_C) $(base_H) $(fs_C) $(fs_H) $(testdisk_ncurses_C) $(testdisk_ncurses_H) dir.c dir.h exfat_dir.c exfat_dir.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h ntfs_dir.c ntfs_dir.h ntfs_inc.h partgptw.c rfs_dir.c rfs_dir.h setdate.c setdate.h $(ICON_TESTDISK) next.c next.h
@ -287,7 +287,7 @@ file_C = filegen.c \
file_H = ext2.h filegen.h file_jpg.h file_sp3.h file_tar.h file_tiff.h file_txt.h ole.h pe.h suspend.h
photorec_C = photorec.c phcfg.c dir.c exfatp.c ext2grp.c ext2_dir.c ext2p.c fat_dir.c fatp.c file_found.c ntfs_dir.c ntfsp.c sessionp.c setdate.c dfxml.c
photorec_C = photorec.c phcfg.c dir.c exfatp.c ext2grp.c ext2_dir.c ext2p.c fat_dir.c fatp.c file_found.c ntfs_dir.c ntfsp.c sessionp.c setdate.c dfxml.c list.c
photorec_H = photorec.h phcfg.h dir.h exfatp.h ext2grp.h ext2p.h ext2_dir.h ext2_inc.h fat_dir.h fatp.h file_found.h memmem.h ntfs_dir.h ntfsp.h ntfs_inc.h sessionp.h setdate.h dfxml.h

View file

@ -62,13 +62,16 @@ static void dump_fat1x_ncurses(disk_t *disk_car, partition_t *partition, const u
}
#endif
static void dump_fat1x(disk_t *disk_car, partition_t *partition, const unsigned char *buffer_bs)
static void dump_fat1x(disk_t *disk_car, partition_t *partition, const unsigned char *buffer_bs, char **current_cmd)
{
log_info("Boot sector\n");
dump_log(buffer_bs, FAT1x_BOOT_SECTOR_SIZE);
if(*current_cmd==NULL)
{
#ifdef HAVE_NCURSES
dump_fat1x_ncurses(disk_car, partition, buffer_bs);
dump_fat1x_ncurses(disk_car, partition, buffer_bs);
#endif
}
}
int fat1x_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind, const unsigned int expert, char **current_cmd)
@ -153,9 +156,9 @@ int fat1x_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
if(strchr(options,'L')!=NULL)
command='L';
}
else if(strncmp(*current_cmd,"repairfat",8)==0)
else if(strncmp(*current_cmd,"repairfat",9)==0)
{
(*current_cmd)+=8;
(*current_cmd)+=9;
if(strchr(options,'C')!=NULL)
command='C';
}
@ -184,13 +187,13 @@ int fat1x_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
rebuild_FAT_BS(disk_car,partition,verbose,dump_ind,1,expert,current_cmd);
break;
case 'D':
dump_fat1x(disk_car, partition, buffer_bs);
dump_fat1x(disk_car, partition, buffer_bs, current_cmd);
break;
case 'C':
repair_FAT_table(disk_car,partition,verbose);
repair_FAT_table(disk_car, partition, verbose, current_cmd);
break;
case 'I':
FAT_init_rootdir(disk_car,partition,verbose);
FAT_init_rootdir(disk_car, partition, verbose, current_cmd);
break;
case 'L':
dir_partition(disk_car, partition, 0,current_cmd);

View file

@ -64,14 +64,17 @@ static void dump_fat32_ncurses(disk_t *disk_car, const partition_t *partition, c
}
#endif
static void dump_fat32(disk_t *disk_car, const partition_t *partition, const unsigned char *buffer_bs, const unsigned char *buffer_backup_bs)
static void dump_fat32(disk_t *disk_car, const partition_t *partition, const unsigned char *buffer_bs, const unsigned char *buffer_backup_bs, char **current_cmd)
{
log_info("Boot sector Backup boot sector\n");
dump2_log(buffer_bs, buffer_backup_bs, 3*disk_car->sector_size);
log_fat2_info((const struct fat_boot_sector*)buffer_bs,(const struct fat_boot_sector*)buffer_backup_bs,UP_FAT32,disk_car->sector_size);
if(*current_cmd==NULL)
{
#ifdef HAVE_NCURSES
dump_fat32_ncurses(disk_car, partition, buffer_bs, buffer_backup_bs);
dump_fat32_ncurses(disk_car, partition, buffer_bs, buffer_backup_bs);
#endif
}
}
int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind, const unsigned int expert, char **current_cmd)
@ -227,9 +230,9 @@ int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
if(strchr(options,'L')!=NULL)
command='L';
}
else if(strncmp(*current_cmd,"repairfat",8)==0)
else if(strncmp(*current_cmd,"repairfat",9)==0)
{
(*current_cmd)+=8;
(*current_cmd)+=9;
if(strchr(options,'C')!=NULL)
command='C';
}
@ -290,10 +293,10 @@ int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
#endif
break;
case 'C':
repair_FAT_table(disk_car,partition,verbose);
repair_FAT_table(disk_car, partition, verbose, current_cmd);
break;
case 'D':
dump_fat32(disk_car, partition, buffer_bs, buffer_backup_bs);
dump_fat32(disk_car, partition, buffer_bs, buffer_backup_bs, current_cmd);
break;
case 'L':
if(strchr(options,'O')==NULL && strchr(options,'B')!=NULL)

View file

@ -903,13 +903,16 @@ static void fat32_dump_ncurses(disk_t *disk_car, const partition_t *partition, c
}
#endif
static void fat32_dump(disk_t *disk_car, const partition_t *partition, const upart_type_t upart_type, const unsigned char *orgboot, const unsigned char *newboot)
static void fat32_dump(disk_t *disk_car, const partition_t *partition, const upart_type_t upart_type, const unsigned char *orgboot, const unsigned char *newboot, char **current_cmd)
{
log_info(" Rebuild Boot sector Boot sector\n");
dump2_log(newboot,orgboot, (unsigned int)(upart_type==UP_FAT32?3*disk_car->sector_size:DEFAULT_SECTOR_SIZE));
if(*current_cmd==NULL)
{
#ifdef HAVE_NCURSES
fat32_dump_ncurses(disk_car, partition, upart_type, orgboot, newboot);
fat32_dump_ncurses(disk_car, partition, upart_type, orgboot, newboot);
#endif
}
}
static void menu_write_fat_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose, const upart_type_t upart_type, const unsigned char *orgboot, const unsigned char*newboot, const int error, char **current_cmd)
@ -1007,7 +1010,7 @@ static void menu_write_fat_boot_sector(disk_t *disk_car, partition_t *partition,
case 'd':
case 'D':
if(strchr(options,'D')!=NULL)
fat32_dump(disk_car, partition, upart_type, orgboot, newboot);
fat32_dump(disk_car, partition, upart_type, orgboot, newboot, current_cmd);
break;
case 'l':
case 'L':
@ -2207,7 +2210,7 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
return 0;
}
int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose)
int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose, char **current_cmd)
{
unsigned long int fat_length,sector;
uint64_t start_rootdir,start_data;
@ -2253,7 +2256,10 @@ int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose
}
if(error==0)
{
display_message("TestDisk doesn't seem needed to reset the root directory.\n");
if(*current_cmd!=NULL)
log_info("TestDisk doesn't seem needed to reset the root directory.\n");
else
display_message("TestDisk doesn't seem needed to reset the root directory.\n");
free(buffer);
return 0;
}
@ -2286,7 +2292,7 @@ int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose
enum fat_status_type { FAT_UNREADABLE=0, FAT_CORRUPTED=1, FAT_OK=2 };
enum fat_ask_repair { FAT_REPAIR_ASK=0, FAT_REPAIR_YES=1, FAT_REPAIR_NO=2 };
int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose)
int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose, char **current_cmd)
{
if(check_FAT(disk_car,partition,verbose)!=0)
{
@ -2800,7 +2806,10 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
}
if(fat_damaged==0)
{
display_message("FATs seems Ok, nothing to do.\n");
if(current_cmd!=NULL)
log_info("FATs seems Ok, nothing to do.\n");
else
display_message("FATs seems Ok, nothing to do.\n");
}
else
{

View file

@ -26,8 +26,8 @@ extern "C" {
#endif
int rebuild_FAT_BS(disk_t *disk_car,partition_t *partition, const int verbose, const int dump_ind,const int interface, const unsigned int expert, char**current_cmd);
int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose);
int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose);
int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose, char **current_cmd);
int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose, char **current_cmd);
#ifdef __cplusplus
} /* closing brace for extern "C" */

View file

@ -87,7 +87,6 @@ int test_NTFS(const disk_t *disk_car,const struct ntfs_boot_sector*ntfs_header,
#define NTFS_GETU64(p) (le64(*(const uint64_t*)(p)))
unsigned int ntfs_sector_size(const struct ntfs_boot_sector *ntfs_header);
int rebuild_NTFS_BS(disk_t *disk_car,partition_t *partition, const int verbose, const int interface, const unsigned int expert, char**current_cmd);
int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, const unsigned int expert);
#ifdef __cplusplus
} /* closing brace for extern "C" */

View file

@ -85,13 +85,16 @@ static void ntfs_dump_ncurses(disk_t *disk_car, const partition_t *partition, co
}
#endif
static void ntfs_dump(disk_t *disk_car, const partition_t *partition, const unsigned char *orgboot, const unsigned char *newboot)
static void ntfs_dump(disk_t *disk_car, const partition_t *partition, const unsigned char *orgboot, const unsigned char *newboot, char **current_cmd)
{
log_info(" Rebuild Boot sector Boot sector\n");
dump2_log(newboot, orgboot, NTFS_SECTOR_SIZE);
if(*current_cmd==NULL)
{
#ifdef HAVE_NCURSES
ntfs_dump_ncurses(disk_car, partition, orgboot, newboot);
ntfs_dump_ncurses(disk_car, partition, orgboot, newboot);
#endif
}
}
static void menu_write_ntfs_boot_sector_cli(disk_t *disk_car, partition_t *partition, const unsigned char *orgboot, const unsigned char *newboot, const int error, char **current_cmd)
@ -123,7 +126,7 @@ static void menu_write_ntfs_boot_sector_cli(disk_t *disk_car, partition_t *parti
else if(strncmp(*current_cmd,"dump",4)==0)
{
(*current_cmd)+=4;
ntfs_dump(disk_car, partition, orgboot, newboot);
ntfs_dump(disk_car, partition, orgboot, newboot, current_cmd);
}
else if(strncmp(*current_cmd,"noconfirm,",10)==0)
{

View file

@ -40,6 +40,7 @@
#include "ntfs.h"
#include "dir.h"
#include "ntfs_dir.h"
#include "ntfs_fix.h"
#include "io_redir.h"
#include "log.h"
#include "intrfn.h"
@ -49,7 +50,7 @@
#define INTER_MFT_X 0
#define INTER_MFT_Y 18
int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, const unsigned int expert)
int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, const unsigned int expert, char **current_cmd)
{
struct ntfs_boot_sector *ntfs_header;
unsigned char *buffer_mft;
@ -124,7 +125,8 @@ int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, cons
if(memcmp(buffer_mft, buffer_mftmirr, mftmirr_size_bytes)==0)
{
log_info("MFT and MFT mirror matches perfectly.\n");
display_message("MFT and MFT mirror matches perfectly.\n");
if(*current_cmd==NULL)
display_message("MFT and MFT mirror matches perfectly.\n");
free(buffer_mftmirr);
free(buffer_mft);
free(ntfs_header);

30
src/ntfs_fix.h Normal file
View file

@ -0,0 +1,30 @@
/*
File: ntfs_fix.h
Copyright (C) 2012 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 __cplusplus
extern "C" {
#endif
int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, const unsigned int expert, char **current_cmd);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif

View file

@ -61,13 +61,16 @@ static void exFAT_dump_ncurses(disk_t *disk, const partition_t *partition, const
}
#endif
static void exFAT_dump(disk_t *disk, const partition_t *partition, const unsigned char *buffer_bs, const unsigned char *buffer_backup_bs)
static void exFAT_dump(disk_t *disk, const partition_t *partition, const unsigned char *buffer_bs, const unsigned char *buffer_backup_bs, char **current_cmd)
{
log_info("Superblock Backup superblock\n");
dump2_log(buffer_bs, buffer_backup_bs, 12 * disk->sector_size);
if(*current_cmd==NULL)
{
#ifdef HAVE_NCURSES
exFAT_dump_ncurses(disk, partition, buffer_bs, buffer_backup_bs);
exFAT_dump_ncurses(disk, partition, buffer_bs, buffer_backup_bs);
#endif
}
}
int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, char **current_cmd)
@ -233,7 +236,7 @@ int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, c
#endif
break;
case 'D':
exFAT_dump(disk, partition, buffer_bs, buffer_backup_bs);
exFAT_dump(disk, partition, buffer_bs, buffer_backup_bs, current_cmd);
break;
}
}

View file

@ -62,13 +62,16 @@ static void hfs_dump_ncurses(disk_t *disk_car, const partition_t *partition, con
}
#endif
static void hfs_dump(disk_t *disk_car, const partition_t *partition, const unsigned char *buffer_bs, const unsigned char *buffer_backup_bs)
static void hfs_dump(disk_t *disk_car, const partition_t *partition, const unsigned char *buffer_bs, const unsigned char *buffer_backup_bs, char **current_cmd)
{
log_info("Superblock Backup superblock\n");
dump2_log(buffer_bs, buffer_backup_bs, HFSP_BOOT_SECTOR_SIZE);
if(*current_cmd==NULL)
{
#ifdef HAVE_NCURSES
hfs_dump_ncurses(disk_car, partition, buffer_bs, buffer_backup_bs);
hfs_dump_ncurses(disk_car, partition, buffer_bs, buffer_backup_bs);
#endif
}
}
int HFS_HFSP_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose, char **current_cmd)
@ -204,6 +207,7 @@ int HFS_HFSP_boot_sector(disk_t *disk_car, partition_t *partition, const int ver
{
log_flush();
#ifdef HAVE_NCURSES
wredrawln(stdscr,0,getmaxy(stdscr));
command=screen_buffer_display_ext(stdscr, options, menu_hfsp, &menu);
#else
command=0;
@ -246,7 +250,7 @@ int HFS_HFSP_boot_sector(disk_t *disk_car, partition_t *partition, const int ver
#endif
break;
case 'D':
hfs_dump(disk_car, partition, buffer_bs, buffer_backup_bs);
hfs_dump(disk_car, partition, buffer_bs, buffer_backup_bs, current_cmd);
break;
}
}

View file

@ -37,6 +37,7 @@
#include "intrfn.h"
#include "dirpart.h"
#include "ntfs.h"
#include "ntfs_fix.h"
#include "io_redir.h"
#include "log.h"
#include "log_part.h"
@ -276,7 +277,7 @@ int ntfs_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose
dir_partition(disk_car, partition, 0,current_cmd);
break;
case 'M':
repair_MFT(disk_car, partition, verbose, expert);
repair_MFT(disk_car, partition, verbose, expert, current_cmd);
break;
case 'R': /* R : rebuild boot sector */
rebuild_NTFS_BS(disk_car, partition, verbose, 1, expert, current_cmd);