1、查询当前电脑所有可用的签名证书
security find-identity -v -p codesigning
2、签名
def codesign():
global entitlements_file_path
sign = "xxxxx" #iPhone Distribution:xxxxx.
cmd = "codesign -f -s %s"%sign
for path,ds,fs in os.walk(app_path):
for d in ds:
if(re.search(r".*.framework",d,0) != None):
cmd1 = cmd + " "+ os.path.join(path,d)
os.system(cmd1)
for f in fs:
if(re.search(r".*.dylib",f,0) != None):
cmd1 = cmd + " "+ os.path.join(path,f)
os.system(cmd1)
cmd = "codesign -f -s %s --entitlements %s %s"%(sign,entitlements_file_path,app_path)
os.system(cmd)
3、验证签名
codesign --verify "xxx.app"
4、查看签名
codesign -vv -d "xxx.app"
5、查看授权
codesign -d --entitlements - "xxx.app"
python3的完整重签名脚本
# !/usr/bin/python3
import os;
import sys;
import shutil
import re
import subprocess
# ['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__',
# '_get_sep', '_joinrealpath', '_varprog', '_varprogb', 'abspath', 'altsep', 'basename', 'commonpath', 'commonprefix',
# 'curdir', 'defpath', 'devnull', 'dirname', 'exists', 'expanduser', 'expandvars', 'extsep', 'genericpath', 'getatime',
# 'getctime', 'getmtime', 'getsize', 'isabs', 'isdir', 'isfile', 'islink', 'ismount', 'join', 'lexists', 'normcase',
# 'normpath', 'os', 'pardir', 'pathsep', 'realpath', 'relpath', 'samefile', 'sameopenfile', 'samestat', 'sep', 'split',
# 'splitdrive', 'splitext', 'stat', 'supports_unicode_filenames', 'sys']
app_path = None
script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(script_path)
if(len(sys.argv)>1):
app_path = sys.argv[1]
# print("script_dir:",script_dir)
payload_path = None
ppfile_name = "embedded.mobileprovision"
entitlements_file = "entitlements.entitlements"
entitlements_file_path = None
info_plist = "Info.plist"
info_plist_path = None
origin_bundleid = None
new_team_id = None
app_name = None
def copy_pp_file():
src_path = os.path.join(script_dir,ppfile_name)
dest_path = os.path.join(app_path,ppfile_name)
shutil.copy(src_path,dest_path)
def init_payload_path():
global payload_path
global app_path
global info_plist
global info_plist_path
global origin_bundleid
global app_name
for path,ds,fs in os.walk(script_dir):
if(None != payload_path):
break;
for d in ds:
path = os.path.join(path,d)
if(d == "Payload"):
payload_path = path
break;
if(None == payload_path):
print("not find 'Payload' directory")
exit(0)
for fs in os.listdir(payload_path):
if(re.search(r".?.app",fs,0) != None):
app_path = os.path.join(payload_path,fs)
app_name = fs
break;
if(None == app_path):
print("not find '*.app' directory")
exit(0)
def init_argvs():
global entitlements_file_path
entitlements_file_path = os.path.join(script_dir,entitlements_file)
info_plist_path = os.path.join(app_path,info_plist)
print(entitlements_file_path,info_plist_path)
cmd = "/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' %s"%info_plist_path
origin_bundleid = os.popen(cmd).read().strip()
ppfile_path = os.path.join(script_dir,ppfile_name)
cmd = '/usr/libexec/PlistBuddy -c "Print :TeamIdentifier:0" /dev/stdin <<< $(/usr/bin/security cms -D -i "%s")' % (ppfile_path)
new_team_id = subprocess.check_output(cmd,shell = True).strip()
app_id = "%s.%s"%(new_team_id,origin_bundleid)
cmd = "/usr/libexec/PlistBuddy -c 'Set :application-identifier %s' %s"%(app_id,entitlements_file_path)
os.system(cmd)
def codesign():
global entitlements_file_path
sign = "xxx" #需要替换成自己的证书ID或者证书名字(使用security find-identity -v -p codesigning 查找)
cmd = "codesign -f -s %s"%sign
for path,ds,fs in os.walk(app_path):
for d in ds:
if(re.search(r".*.framework",d,0) != None):
cmd1 = cmd + " "+ os.path.join(path,d)
os.system(cmd1)
for f in fs:
if(re.search(r".*.dylib",f,0) != None):
cmd1 = cmd + " "+ os.path.join(path,f)
os.system(cmd1)
cmd = "codesign -f -s %s --entitlements %s %s"%(sign,entitlements_file_path,app_path)
os.system(cmd)
def zip():
global app_name
folder = os.path.dirname(payload_path)
ipa_name = os.path.splitext(app_name)[0]
ipa_path = os.path.join(script_dir,ipa_name)+".ipa"
paths = ""
for fs in os.listdir(folder):
if(re.search(fs,".DS_Store",0) == None):
paths = paths + fs + " "
os.chdir(folder)
cmd = "zip -r %s %s"%(ipa_path,paths)
print(cmd)
os.system(cmd)
if __name__ == '__main__':
init_payload_path()
init_argvs()
copy_pp_file()
codesign()
zip()
pass
990

被折叠的 条评论
为什么被折叠?



