scripts: Reworked dbgtag.py, added -i/--input, included hex in output
This just gives dbgtag.py a few more bells and whistles that may be
useful:
- Can now parse multiple tags from hex:
$ ./scripts/dbgtag.py -x 71 01 01 01 12 02 02 02
71 01 01 01 altrgt 0x101 w1 -1
12 02 02 02 shrubdir w2 2
Note this _does_ skip attached data, which risks some confusion but
not skipping attached data will probably end up printing a bunch of
garbage for most use cases:
$ ./scripts/dbgtag.py -x 01 01 01 04 02 02 02 02 03 03 03 03
01 01 01 04 gdelta 0x01 w1 4
03 03 03 03 struct 0x03 w3 3
- Included hex in output. This is helpful for learning about the tag
encoding and also helps identify tags when parsing multiple tags.
I considered also included offsets, which might help with
understanding attached data, but decided it would be too noisy. At
some point you should probably jump to dbgrbyd.py anyways...
- Added -i/--input to read tags from a file. This is roughly the same as
-x/--hex, but allows piping from other scripts:
$ ./scripts/dbgcat.py disk -b4096 0 -n4,8 | ./scripts/dbgtag.py -i-
80 03 00 08 magic 8
Note this reads the entire file in before processing. We'd need to fit
everything into RAM anyways to figure out padding.
This commit is contained in:
+7
-3
@@ -46,14 +46,18 @@ def parity(x):
|
||||
return popc(x) & 1
|
||||
|
||||
|
||||
def main(paths, **args):
|
||||
def main(paths, *,
|
||||
hex=False,
|
||||
string=False):
|
||||
hex_ = hex; del hex
|
||||
|
||||
# interpret as sequence of hex bytes
|
||||
if args.get('hex'):
|
||||
if hex_:
|
||||
bytes_ = [b for path in paths for b in path.split()]
|
||||
print('%01x' % parity(crc32c(bytes(int(b, 16) for b in bytes_))))
|
||||
|
||||
# interpret as strings
|
||||
elif args.get('string'):
|
||||
elif string:
|
||||
for path in paths:
|
||||
print('%01x %s' % (parity(crc32c(path.encode('utf8'))), path))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user