1 /*
2
3 File: phnc.c
4
5 Copyright (C) 1998-2009 Christophe GRENIER <grenier@cgsecurity.org>
6
7 This software is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write the Free Software Foundation, Inc., 51
19 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #ifdef HAVE_NCURSES
28 #include <stdio.h>
29 #ifdef HAVE_STDLIB_H
30 #include <stdlib.h>
31 #endif
32 #ifdef HAVE_STRING_H
33 #include <string.h>
34 #endif
35 #include "types.h"
36 #include "common.h"
37 #include "intrf.h"
38 #include "intrfn.h"
39 #include "filegen.h"
40 #include "photorec.h"
41 #include "phnc.h"
42
photorec_info(WINDOW * window,const file_stat_t * file_stats)43 void photorec_info(WINDOW *window, const file_stat_t *file_stats)
44 {
45 unsigned int i;
46 unsigned int nbr;
47 unsigned int others=0;
48 file_stat_t *new_file_stats;
49 for(i=0;file_stats[i].file_hint!=NULL;i++);
50 nbr=i;
51 if(nbr==0)
52 return ;
53 new_file_stats=(file_stat_t*)MALLOC(nbr*sizeof(file_stat_t));
54 memcpy(new_file_stats, file_stats, nbr*sizeof(file_stat_t));
55 qsort(new_file_stats, nbr, sizeof(file_stat_t), sorfile_stat_ts);
56 for(i=0; i<9 && i<nbr && new_file_stats[i].recovered>0; i++)
57 {
58 wmove(window,12+i,0);
59 wclrtoeol(window);
60 wprintw(window, "%s: %u recovered\n",
61 (new_file_stats[i].file_hint->extension!=NULL?
62 new_file_stats[i].file_hint->extension:""),
63 new_file_stats[i].recovered);
64 }
65 for(;i<nbr && new_file_stats[i].recovered>0;i++)
66 others+=new_file_stats[i].recovered;
67 if(others>0)
68 {
69 wmove(window,12+9,0);
70 wclrtoeol(window);
71 wprintw(window, "others: %u recovered\n", others);
72 }
73 free(new_file_stats);
74 }
75
photorec_progressbar(WINDOW * window,const unsigned int pass,const struct ph_param * params,const uint64_t offset,const time_t current_time)76 pstatus_t photorec_progressbar(WINDOW *window, const unsigned int pass, const struct ph_param *params, const uint64_t offset, const time_t current_time)
77 {
78 const partition_t *partition=params->partition;
79 const unsigned int sector_size=params->disk->sector_size;
80 if(params->status!=STATUS_FIND_OFFSET)
81 {
82 wmove(window,8,0);
83 wclrtoeol(window);
84 wprintw(window,"Destination %s", params->recup_dir);
85 }
86 wmove(window,10,0);
87 wclrtoeol(window);
88 if(params->status==STATUS_EXT2_ON_BF || params->status==STATUS_EXT2_OFF_BF)
89 {
90 wprintw(window,"Bruteforce %10lu sectors remaining (test %u), ",
91 (unsigned long)((offset-partition->part_offset)/sector_size),
92 pass);
93 }
94 else
95 {
96 wprintw(window,"Pass %u - Reading sector %10llu/%llu, ",
97 pass,
98 (unsigned long long)((offset-partition->part_offset)/sector_size),
99 (unsigned long long)(partition->part_size/sector_size));
100 }
101 if(params->status==STATUS_FIND_OFFSET)
102 wprintw(window,"%u/10 headers found\n", params->file_nbr);
103 else
104 wprintw(window,"%u files found\n", params->file_nbr);
105 wmove(window,11,0);
106 wclrtoeol(window);
107 if(current_time > params->real_start_time)
108 {
109 const time_t elapsed_time=current_time - params->real_start_time;
110 wprintw(window,"Elapsed time %uh%02um%02us",
111 (unsigned)(elapsed_time/60/60),
112 (unsigned)(elapsed_time/60%60),
113 (unsigned)(elapsed_time%60));
114 if(offset > partition->part_offset && params->status!=STATUS_EXT2_ON_BF && params->status!=STATUS_EXT2_OFF_BF)
115 {
116 const time_t eta=(partition->part_offset+partition->part_size-1-offset)*elapsed_time/(offset-partition->part_offset);
117 wprintw(window," - Estimated time to completion %uh%02um%02u\n",
118 (unsigned)(eta/3600),
119 (unsigned)((eta/60)%60),
120 (unsigned)(eta%60));
121 }
122 }
123 photorec_info(window, params->file_stats);
124 wrefresh(window);
125 return(check_enter_key_or_s(window)==0?PSTATUS_OK:PSTATUS_STOP);
126 }
127 #endif
128