summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2020-08-08 11:48:20 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2020-08-08 11:48:20 +0200
commit7fcac38ea35e013ce975400e6927799dde3505ba (patch)
tree9324b719817658f0e80611cdf4413435a7eb1011
parent4e9925e96d2a1a7f6d4eeb5024d71ffdbdd5cf89 (diff)
Update photorec_aux() in qpsearch.cpp to match the function from psearchn.c
See commit 9b0e8ff284301e4f9d07f5ccadb8c1756c6a9150
-rw-r--r--src/qpsearch.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/qpsearch.cpp b/src/qpsearch.cpp
index 86704ff..d7248e3 100644
--- a/src/qpsearch.cpp
+++ b/src/qpsearch.cpp
@@ -83,6 +83,7 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
const unsigned int read_size=(blocksize>65536?blocksize:65536);
uint64_t offset_before_back=0;
unsigned int back=0;
+ pfstatus_t file_recovered_old=PFSTATUS_BAD;
alloc_data_t *current_search_space;
file_recovery_t file_recovery;
memset(&file_recovery, 0, sizeof(file_recovery));
@@ -211,19 +212,37 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
{
if(data_check_status==DC_SCAN)
{
- get_next_sector(list_search_space, &current_search_space,&offset,blocksize);
- if(offset > offset_before_back)
- back=0;
+ if(file_recovered_old==PFSTATUS_OK)
+ {
+ offset_before_back=offset;
+ if(back < 5 &&
+ get_prev_file_header(list_search_space, &current_search_space, &offset)==0)
+ {
+ back++;
+ }
+ else
+ {
+ back=0;
+ get_prev_location_smart(list_search_space, &current_search_space, &offset, file_recovery.location.start);
+ }
+ }
+ else
+ {
+ get_next_sector(list_search_space, &current_search_space,&offset,blocksize);
+ if(offset > offset_before_back)
+ back=0;
+ }
}
}
- else if(file_recovered==PFSTATUS_OK_TRUNCATED ||
- (file_recovered==PFSTATUS_OK && file_recovery.file_stat==NULL))
+ else if(file_recovered==PFSTATUS_OK_TRUNCATED)
{
/* try to recover the previous file, otherwise stay at the current location */
offset_before_back=offset;
if(back < 5 &&
get_prev_file_header(list_search_space, &current_search_space, &offset)==0)
+ {
back++;
+ }
else
{
back=0;
@@ -284,6 +303,7 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
}
}
}
+ file_recovered_old=file_recovered;
} /* end while(current_search_space!=list_search_space) */
free(buffer_start);
return ind_stop;