From 4c62ddc0ffff67bf18d8a10812aad679a6231f9f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 22 Aug 2017 10:25:21 +0200 Subject: [PATCH] print list of header candidates --- deltatar/crypto.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 47 insertions(+), 1 deletions(-) diff --git a/deltatar/crypto.py b/deltatar/crypto.py index bef3ced..c0896bb 100755 --- a/deltatar/crypto.py +++ b/deltatar/crypto.py @@ -1307,6 +1307,7 @@ PDTCRYPT_SCRYPT_FORMAT = \ { "i2n" : PDTCRYPT_SCRYPT_INTRANATOR , "params" : PDTCRYPT_SCRYPT_PARAMETERS } +PDTCRYPT_TT_COLUMNS = 80 # assume standard terminal class PDTDecryptionError (Exception): """Decryption failed.""" @@ -1602,6 +1603,50 @@ def mode_scrypt (pw, ins=None, nacl=None, fmt=PDTCRYPT_SCRYPT_INTRANATOR): print (out) +def noise_output_candidates (cands, indent=8, cols=PDTCRYPT_TT_COLUMNS): + """ + Print a list of offsets without garbling the terminal too much. + + The indent is counted from column zero; if it is wide enough, the “PDT: ” + marker will be prepended, considered part of the indentation. + """ + wd = cols - 1 + nc = len (cands) + idt = " " * indent if indent < 5 else "PDT: " + " " * (indent - 5) + line = idt + lpos = indent + sep = "," + lsep = len (sep) + init = True # prevent leading separator + + if indent >= wd: + raise ValueError ("the requested indentation exceeds the line " + "width by %d" % (indent - wd)) + + for n in cands: + ns = "%d" % n + lns = len (ns) + if init is False: + line += sep + lpos += lsep + + lpos += lns + if lpos > wd: # line break + noise (line) + line = idt + lpos = indent + lns + elif init is True: + init = False + else: # space + line += ' ' + lpos += 1 + + line += ns + + if lpos != indent: + noise (line) + + def mode_scan (pw, fname, nacl=None): """ Dissect a binary file, looking for PDTCRYPT headers and objects. @@ -1622,7 +1667,8 @@ def mode_scan (pw, fname, nacl=None): "headers; giving up.") return -1 if PDTCRYPT_VERBOSE is True: - noise ("PDT: scan complete: found %d candidates" % len (cands)) + noise ("PDT: scan complete: found %d candidates:" % len (cands)) + noise_output_candidates (cands) finally: os.close (fd) -- 1.7.1