-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresignIPA.py
More file actions
86 lines (71 loc) · 2.79 KB
/
resignIPA.py
File metadata and controls
86 lines (71 loc) · 2.79 KB
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
#!/usr/bin/env python
import optparse
import os
import sys
import subprocess
import zipfile
import tempfile
import glob
import shutil
def Resign(ipa, identity, provision, output, verbose):
'''Resign the ipa with new identity and provision.
'''
# xcrun will save the output ipa to its working dir if ipa is a
# relative path.
if not os.path.isabs(ipa):
ipa = os.path.join(os.getcwd(), ipa)
# Fallback to default ipa name.
if not output:
output = os.path.splitext(ipa)[0] + '.%s.resigned.ipa' \
% os.path.splitext(os.path.basename(provision))[0]
working_dir = tempfile.gettempdir()
working_dir = os.path.join(os.getcwd(), "package")
# Unzip the IPA
zfile = zipfile.ZipFile(ipa,'r')
zfile.extractall(working_dir)
# Got app dir.
app_dir = glob.glob(working_dir + '/Payload/*')[0]
# Replace embedded mobile provisioning profile
shutil.copy(provision, os.path.join(app_dir, 'embedded.mobileprovision'))
# Re-sign, Removed the Entitlement part (see alleys comment, thanks)
# codesign -f -s "$CODE_SIGN_IDENTITY" --resource-rules "$APP/ResourceRules.plist" "$APP"
if verbose:
subprocess.call([
'codesign', '-f', '-v', '-s', identity,
'--resource-rules', os.path.join(app_dir, 'ResourceRules.plist'),
app_dir])
else:
subprocess.call([
'codesign', '-f', '-s', identity,
'--resource-rules', os.path.join(app_dir, 'ResourceRules.plist'),
app_dir])
# Zip the payload.
f = zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(working_dir):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
f.write(filepath, os.path.relpath(filepath, working_dir))
f.close()
print 'Resigned to', output
def main(argv=None):
parser = optparse.OptionParser(usage=__doc__)
print("\npython resign-ipa.py -s reCer.p12 demo.ipa -p embedded.mobileprovision -o ./newdemp.ipa\n")
parser.add_option('-s', '--sign',
metavar='IDENTITY', default='', dest='identity',
help="Write the generated .ipa to IPA.")
parser.add_option('-p', '--provision',
metavar='PROVISION_FILE', default='', dest='provision',
help="Write the generated .ipa to IPA.")
parser.add_option('-o', '--output',
metavar='IPA', default='', dest='output',
help="Write the generated .ipa to IPA.")
parser.add_option('-v', '--verbose',
action='store_true', default=False, dest='verbose')
opts, args = parser.parse_args()
print opts
if not args or not opts.identity or not opts.provision:
parser.print_help()
sys.exit(1)
Resign(args[0], opts.identity, opts.provision, opts.output, opts.verbose)
if __name__ == '__main__':
main()