Skip to content

Commit 169211e

Browse files
committed
sbxdec: added continue on errors. seqbox: start with an invalid blockn.
1 parent 74a1e71 commit 169211e

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

sbxdec.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import seqbox
3434

35-
PROGRAM_VER = "0.8.2b"
35+
PROGRAM_VER = "0.8.3b"
3636

3737

3838
def banner():
@@ -56,6 +56,8 @@ def get_cmdline():
5656
help="test container integrity")
5757
parser.add_argument("-i", "--info", action="store_true", default=False,
5858
help="show informations/metadata")
59+
parser.add_argument("-c", "--continue", action="store_true", default=False,
60+
help="continue on errors", dest="cont")
5961
parser.add_argument("-o", "--overwrite", action="store_true", default=False,
6062
help="overwrite existing file")
6163
res = parser.parse_args()
@@ -110,7 +112,7 @@ def main():
110112
hashcheck = False
111113

112114
buffer = fin.read(sbx.blocksize)
113-
if not sbx.decode(buffer):
115+
if not sbx.decode(buffer) and cmdline.cont == False:
114116
errexit(errlev=1, mess="invalid block at offset 0x0")
115117
if sbx.blocknum > 1:
116118
errexit(errlev=1, mess="blocks missing or out of order at offset 0x0")
@@ -178,18 +180,27 @@ def main():
178180
lastblocknum = 0
179181

180182
filesize = 0
183+
blockmiss = 0
181184
updatetime = time()
182185
while True:
183186
buffer = fin.read(sbx.blocksize)
184187
if len(buffer) < sbx.blocksize:
185188
break
186189
if not sbx.decode(buffer):
187-
errexit(errlev=1, mess="invalid block at offset %s" %
188-
(hex(fin.tell()-sbx.blocksize)))
190+
if cmdline.cont:
191+
blockmiss += 1
192+
lastblocknum += 1
193+
else:
194+
errexit(errlev=1, mess="invalid block at offset %s" %
195+
(hex(fin.tell()-sbx.blocksize)))
189196
else:
190197
if sbx.blocknum > lastblocknum+1:
191-
errexit(errlev=1, mess="block %i out of order or missing"
192-
% (lastblocknum+1))
198+
if cmdline.cont:
199+
blockmiss += 1
200+
lastblocknum += 1
201+
else:
202+
errexit(errlev=1, mess="block %i out of order or missing"
203+
% (lastblocknum+1))
193204
lastblocknum += 1
194205
if trimfilesize:
195206
filesize += sbx.datasize
@@ -211,6 +222,9 @@ def main():
211222
fout.close()
212223

213224
print("SBX decoding complete")
225+
if blockmiss:
226+
errexit(1, "missing blocks: %i" % blockmiss)
227+
214228
if hashcheck:
215229
if hashtype == 0x12:
216230
print("SHA256", d.hexdigest())

seqbox.py

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def encode(self):
9090
return (self.magic + crc + buffer)
9191

9292
def decode(self, buffer):
93+
#start setting an invalid block number
94+
self.blocknum = -1
9395
#check the basics
9496
if len(buffer) != self.blocksize:
9597
return False

0 commit comments

Comments
 (0)