forked from iOSForensics/pymobiledevice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apps.py
executable file
·144 lines (127 loc) · 4.75 KB
/
apps.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
# -*- coding: utf8 -*-
#
# $Id$
#
# Copyright (c) 2012-2014 "dark[-at-]gotohack.org"
#
# This file is part of pymobiledevice
#
# pymobiledevice is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
from lockdown import LockdownClient
from pprint import pprint
from afc import AFCClient, AFCShell
from optparse import OptionParser
import os
import warnings
warnings.warn(
"""The libraries upon which this program depends will soon be deprecated in
favor of the house_arrest.py and installation_proxy.py libraries.
See those files for example program written using the new libraries."""
)
def house_arrest(lockdown, applicationId):
try:
mis = lockdown.startService("com.apple.mobile.house_arrest")
except:
lockdown = LockdownClient()
mis = lockdown.startService("com.apple.mobile.house_arrest")
if mis == None:
return
mis.sendPlist({"Command": "VendDocuments", "Identifier": applicationId})
res = mis.recvPlist()
if res.get("Error"):
print "Unable to Lookup the selected application: You probably trying to access to a system app..."
return None
return AFCClient(lockdown, service=mis)
def house_arrest_shell(lockdown, applicationId):
afc = house_arrest(lockdown, applicationId)
if afc: AFCShell(client=afc).cmdloop()
"""
"Install"
"Upgrade"
"Uninstall"
"Lookup"
"Browse"
"Archive"
"Restore"
"RemoveArchive"
"LookupArchives"
"CheckCapabilitiesMatch"
installd
if stat("/var/mobile/tdmtanf") => "TDMTANF Bypass" => SignerIdentity bypass
"""
def mobile_install(lockdown,ipaPath):
#Start afc service & upload ipa
afc = AFCClient(lockdown)
afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath,'rb').read())
mci = lockdown.startService("com.apple.mobile.installation_proxy")
#print mci.sendPlist({"Command":"Archive","ApplicationIdentifier": "com.joystickgenerals.STActionPig"})
mci.sendPlist({"Command":"Install",
#"ApplicationIdentifier": "com.gotohack.JBChecker",
"PackagePath": os.path.basename(ipaPath)})
while True:
z = mci.recvPlist()
if not z:
break
completion = z.get('PercentComplete')
if completion:
print 'Installing, %s: %s %% Complete' % (ipaPath, z['PercentComplete'])
if z.get('Status') == 'Complete':
print "Installation %s\n" % z['Status']
break
def list_apps(lockdown):
mci = lockdown.startService("com.apple.mobile.installation_proxy")
#print
mci.sendPlist({"Command":"Lookup"})
res = mci.recvPlist()
for app in res["LookupResult"].values():
if app.get("ApplicationType") != "System":
print app["CFBundleIdentifier"], "=>", app.get("Container")
else:
print app["CFBundleIdentifier"], "=> N/A"
def get_apps_BundleID(lockdown,appType="User"):
appList = []
mci = lockdown.startService("com.apple.mobile.installation_proxy")
mci.sendPlist({"Command":"Lookup"})
res = mci.recvPlist()
for app in res["LookupResult"].values():
if app.get("ApplicationType") == appType:
appList.append(app["CFBundleIdentifier"])
#else: #FIXME
# appList.append(app["CFBundleIdentifier"])
mci.close()
#pprint(appList)
return appList
if __name__ == "__main__":
parser = OptionParser(usage="%prog")
parser.add_option("-l", "--list", dest="list", action="store_true", default=False,
help="List installed applications (non system apps)")
parser.add_option("-a", "--app", dest="app", action="store", default=None,
metavar="APPID", help="Access application files with AFC")
parser.add_option("-i", "--install", dest="installapp", action="store", default=None,
metavar="FILE", help="Install an application package")
(options, args) = parser.parse_args()
if options.list:
lockdown = LockdownClient()
list_apps(lockdown)
elif options.app:
lockdown = LockdownClient()
house_arrest_shell(lockdown, options.app)
elif options.installapp:
lockdown = LockdownClient()
mobile_install(lockdown, options.installapp)
else:
parser.print_help()