Skip to content

Commit 314e340

Browse files
committed
BHLReco: added variable step option.
1 parent c730f1b commit 314e340

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

bhlreco.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import argparse
3030
import time
3131

32-
PROGRAM_VER = "0.5.3a"
32+
PROGRAM_VER = "0.5.5a"
3333
BHL_VER = 1
3434
BHL_MAGIC = b"BlockHashLoc\x1a"
3535

@@ -50,6 +50,8 @@ def get_cmdline():
5050
help="target/to recover file")
5151
parser.add_argument("-o", "--overwrite", action="store_true", default=False,
5252
help="overwrite existing file")
53+
parser.add_argument("-st", "--step", type=int, default=0,
54+
help=("scan step"), metavar="n")
5355
res = parser.parse_args()
5456
return res
5557

@@ -76,7 +78,6 @@ def metadataDecode(data):
7678
metadata["filename"] = metabb.decode('utf-8')
7779
elif metaid == b'FDT':
7880
metadata["filedatetime"] = int.from_bytes(metabb, byteorder='big')
79-
8081
return metadata
8182

8283

@@ -141,6 +142,10 @@ def main():
141142
if globalhash.digest() != digest:
142143
errexit(1, "hash block corrupt!")
143144

145+
scanstep = cmdline.step
146+
if scanstep == 0:
147+
scanstep = blocksize
148+
144149
#start scanning and recovering process...
145150
print("scanning file '%s'..." % imgfilename)
146151
fin = open(imgfilename, "rb", buffering=1024*1024)
@@ -152,7 +157,8 @@ def main():
152157
starttime = time.time()
153158
wrotelist = {}
154159
blocksfound = 0
155-
while True:
160+
for pos in range(0, imgfilesize, scanstep):
161+
fin.seek(pos, 0)
156162
buffer = fin.read(blocksize)
157163
if len(buffer) > 0:
158164
blockhash = hashlib.sha256()
@@ -178,20 +184,20 @@ def main():
178184
blocksfound += 1
179185

180186
#status update
181-
pos = fin.tell()
182187
if ((time.time() > updatetime) or (totblocksnum == blocksfound) or
183-
(pos == imgfilesize)):
188+
(imgfilesize-pos-len(buffer) == 0) ):
184189
etime = (time.time()-starttime)
185190
if etime == 0:
186-
etime = .1
191+
etime = .001
187192
print(" %.1f%% - tot: %i - found: %i - %.2fMB/s" %
188-
(pos*100/imgfilesize, totblocksnum, blocksfound,
189-
pos/(1024*1024)/etime), end = "\r", flush=True)
193+
((pos+len(buffer)-1)*100/imgfilesize,
194+
totblocksnum, blocksfound, pos/(1024*1024)/etime),
195+
end = "\r", flush=True)
190196
updatetime = time.time() + .2
197+
#break early if all the work is done
198+
if totblocksnum == blocksfound:
199+
break
191200

192-
else:
193-
break
194-
195201
fout.close()
196202
fin.close()
197203
if "filedatetime" in metadata:

0 commit comments

Comments
 (0)