-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
79 lines (58 loc) · 1.92 KB
/
run.py
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
__author__ = "Matthew Tuusberg"
import os
import json
import glob
import biplist
from pprint import pprint
class Account(object):
def __init__(self, **kwargs):
if 'AppleID' not in kwargs:
raise ValueError('AppleID key is missing')
self.__dict__.update(kwargs)
def __repr__(self):
attibutes = [k for k in self.__dict__ if not k.startswith('_')]
return os.linesep.join('{}: {}'.format(attr, self.__dict__[attr]) for attr in attibutes)
def __hash__(self):
return hash(self.AppleID)
def __eq__(lh, rh):
return isinstance(rh, lh.__class__) and lh.AppleID == rh.AppleID
def grab_plists():
"""
Looks for iTunesMetadata files inside /var/mobile/Containers/Bundle/Application/ directory.
:returns: list of filenames
"""
return glob.glob('/var/mobile/Containers/Bundle/Application/*/iTunesMetadata.plist')
def read_plists(plists):
"""
Reads plist files and looks for App Store credentials.
:param plists: list of filenames
:returns: list of credentials found
"""
accounts = set()
for f in plists:
try:
data = biplist.readPlist(f)
except Exception as e:
print '{} is not readable.\nReason: {}'.format(f, e)
continue
account_info = data.get('com.apple.iTunesStore.downloadInfo', {}).get('accountInfo')
if not account_info:
continue
try:
account = Account(**account_info)
except ValueError as e:
print e
continue
accounts.add(account)
return list(accounts)
def main():
plists = grab_plists()
accounts = read_plists(plists)
if not any(accounts):
print 'Credentials were not found. Try to install an application from the App Store and relaunch this script.'
return
for account in accounts:
print account
print
if __name__ == '__main__':
main()