forked from ios-driver/ios-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim_access.py
26 lines (23 loc) · 969 Bytes
/
sim_access.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
import re
import shutil
import tempfile
import difflib
# read the contents of /etc/authorization
with open('/etc/authorization','r') as file:
content = file.read()
match = re.search('<key>system.privilege.taskport</key>\s*\n\s*<dict>\n\s*<key>allow-root</key>\n\s*(<[^>]+>)',content)
if match is None:
raise Exception('Could not find the system.privilege.taskport key in /etc/authorization')
elif re.search('<false/>', match.group(0)) is None:
print '/etc/authorization has already been modified'
exit(0)
new_text = match.group(0).replace(match.group(1), '<true/>')
new_content = content.replace(match.group(0), new_text)
# backup /etc/authorization
backupFile = tempfile.mkstemp('.backup','authorization')[1]
shutil.copy('/etc/authorization', backupFile)
print 'backed up /etc/authorization to %s...' % backupFile
# write back the modified permissions
with open('/etc/authorization','w') as file:
file.write(new_content)
print 'wrote new /etc/authorization'