aboutsummaryrefslogtreecommitdiffstats
path: root/print_dep.py
blob: 803b5e99d153a30d862753a7cd229cca4a294645 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3

# quick and dirty utility to make the binary mess, produced by my redo program
# into something more friendly to the human eye
# requires termcolor (pip install termcolor)

import struct
import sys
import hashlib
from binascii import hexlify
from os.path import basename
from termcolor import colored

def convert_back(s):
    return s.replace('!', '/')

if (len(sys.argv) < 2):
    print("Need an argument.")
    exit(1)

hasher = hashlib.sha1()
file = open(sys.argv[1], 'rb')
magic = file.read(4)
hash = file.read(20)
subdeps = file.read()
org_file = convert_back(basename(sys.argv[1]))

hash_str = str(hexlify(hash), 'ascii')

with open(org_file, 'rb') as f:
    buf = f.read()
    hasher.update(buf)

print("Target: " + org_file)
print("Hash: " + hash_str + " ", end="")
if hasher.hexdigest() == hash_str:
    print(colored(u"\u2714", "green", attrs=['bold']))
else:
    print(colored(u"\u2718", "red", attrs=['bold']))

print("Magic number: " + str(struct.unpack('i', magic)[0]))
print("Dependencies:")
start = True
thing = ""
for byte in subdeps:
    if start:
        print("    " + chr(byte) + "-", end="")
        start = False
    elif byte == 0:
        start = True
        print(thing)
        thing = ""
    else:
        thing += chr(byte)
        continue