Chris Pomeroy
2017-12-01 562346bb6189aef7634d76930d2979e68c2b3106
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python
 
import os
import subprocess
 
def filechecksum(aaxfile):
    ret = subprocess.Popen(["ffprobe", "-v", "info", "-hide_banner", os.path.abspath(aaxfile)], stderr=subprocess.PIPE)
    grep = subprocess.Popen(["grep", "checksum"], stdin=ret.stderr, stdout=subprocess.PIPE)
    awk = subprocess.Popen(["awk", " { print $8 } "], stdin=grep.stdout, stdout=subprocess.PIPE)
    hashsum,out = awk.communicate()
    hashsum = hashsum.strip('\n')
    return hashsum
 
 
def writeauthcode(hashsum):
    try:
        file = open(".authcode", "a")
        file.write(hashsum + os.linesep)
    except (IOError, OSError) as e:
        print "Can't write to .authcode"
        return 1
    finally:
        file.close()
        return 0
 
 
def readauthcode():
    try:
      if not os.path.isfile(".authcode"):
          open (".authcode", "w").close()
      with open(".authcode") as f:
          hashes = f.read().split()
    except (IOError, OSError) as e:
        print "Can't read in .authcode"
        return 1
    finally:
        f.close()
        return hashes
 
 
def newauthcode(checksum):
    rcwd = os.path.dirname(os.path.realpath(__file__))
    command = "./rcrack *.rtc -h "
    command += checksum
    cmd = subprocess.Popen(command, cwd=rcwd, stdout=subprocess.PIPE, shell=True)
    grep = subprocess.Popen(["grep","-a", "hex"], stdin=cmd.stdout,stdout=subprocess.PIPE)
    key,stderr = grep.communicate()
    key = key.split()
    return key[2].split(':')[1]
 
def checkagainstexisting(abytes,aaxfile):
    ret = subprocess.Popen(["ffprobe","-activation_bytes", abytes ,"-hide_banner" , os.path.abspath(aaxfile)], stderr=subprocess.PIPE)
    grep = subprocess.Popen(["grep", "mismatch", "-c"], stdin=ret.stderr, stdout=subprocess.PIPE)
    works,out = grep.communicate()
    return works.strip('\n')
 
 
def getcorrectkey(aaxfile):
    authcodes = readauthcode()
    abyte = ''
    for x in authcodes:
        if (checkagainstexisting(x,aaxfile) == '0'):
            abyte = x
            return abyte
    if (abyte == ''):
        csum = filechecksum(aaxfile)
        abyte = newauthcode(csum)
        writeauthcode(abyte)
        return abyte
 
 
if __name__ == "__main__":
    import sys
    if len(sys.argv) >= 2:
        args = sys.argv[1]
    else:
        print "I need an file name to lookup"
        sys.exit(1)
    checksum = filechecksum(args)
    out = newauthcode(checksum.strip())
    if out is not None:
        print sys.argv[1], "Auth code is:", out
    else:
        print sys.argv[1], "no Authcode found"