⽤python输出mac上安装的所有mobileprovision信息
.mobileprovision是iOS开发中的设备描述⽂件,⾥⾯有证书信息、调试设备的UUID信息、bundle identifier等,此⽂件是⼆进制格式,如何查看其中信息呢
.mobileprovision 在mac上的安装⽬录: /Users/XXX/Library/MobileDevice/Provisioning Profiles
可以⽤python脚本来搞定,脚本如下:
# print_mp.py
import os
import re
def_exc_cmd(cmd):
pf = os.popen(cmd)
res = pf.read()
pf.close()
return res
def parse_mobileprovision(file_name):
f =open(file_name,"rb")
ctx = f.read()
f.close()
r_cer = repile("<key>DeveloperCertificates</key>[\s\r\n]*<array>[\s\r\n]*<data>(.*)</data>[\s\r\n]*</array>", re.M|re.S)
cer_ls = r_cer.findall(ctx)
cer = cer_ls[0]
r_uuid = repile(r"<key>UUID</key>[\s\r\n]*<string>([0-9a-f-]+)</string>",re.M|re.S)
uuid_ls = r_uuid.findall(ctx)
uuid = uuid_ls[0]
r_name = repile("<key>Name</key>[\s\r\n]*<string>(.*?)</string>",re.M|re.S)
name_ls = r_name.findall(ctx)
name = name_ls[0]
r_id = repile(r"<key>application-identifier</key>[\s\r\n]*<string>([^\.]+)\.(.*?)</string>")做网站的供应商
id_ls = r_id.findall(ctx)
group_id, id_ = id_ls[0]
v_type =""
if ctx.find("ProvisionsAllDevices")>=0:
v_type ="enterprise"
elif ctx.find("ProvisionedDevices")>=0:
if ctx.find("Entitlements")>=0:
if ctx.find("get-task-allow")>=0:
v_type ="development"
else:
v_type ="ad-hoc"
oracle取交集的函数else:
v_type ="app-store"
info ={
"type":v_type,
"uuid":uuid,
"team":group_id,
"id":id_,
"name":name,
"cer":cer,
}
del ctx
return info
def find_local_usr_mobileprovision_info_l():
home = os.environ['HOME']
p_d = os.path.join(home,"Library/MobileDevice/Provisioning Profiles")
ls =[]
ls =[]
for f in os.listdir(p_d):
dswith(".mobileprovision"):
info = parse_mobileprovision(os.path.join(p_d,f))
ls.append(info)
return ls
def find_sec_id():
cmd ="security find-identity -v"
res = _exc_cmd(cmd)
r1 = repile( r"\d+\)\s+([0-9A-Fa-f]+)\s+\"(.+?)\"")
return r1.findall(res)
def find_sec_cert():
cmd ="security find-certificate -apZ"
res = _exc_cmd(cmd)
r2 = repile(r"SHA-1 hash:\s+([0-9A-Fa-f]+)[\s\r\n]+-----BEGIN CERTIFICATE-----[\s\r\n]+(.+?)[\s\r\n]+-----END CERTIFICATE-----", re.M|re.S) return r2.findall(res)
def get_cert_info():
id_ls = find_sec_id()
cr_ls = find_sec_cert()
tab ={}
for hash_id, name in id_ls:
tab[hash_id]={"hash":hash_id,"name":name}
for hash_id, cer in cr_ls:
if tab.has_key(hash_id):
tab[hash_id]["cert"]= place("\n","").replace("\r","")
margin属性与paddingreturn tab
def find_local_usr_mobileprovision_info():mysql的存储过程流程
ls = find_local_usr_mobileprovision_info_l()
cer_t = get_cert_info()
cer_t2 ={}
for k in cer_t:
v = cer_t[k]
cer_t2[v['cert']]=v
for info in ls:
c = info['cer']
v = (c)
if v:
info["cer_hash"]= v["hash"]
info["cer_name"]= v["name"]
return ls
def_test_find_mp_info():
python安装教程macls= find_local_usr_mobileprovision_info()
for v in ls:
print("-------")
print(" name:", v["name"])
print(" id:", v["id"])
print(" team:", v["team"])
print(" uuid:", v["uuid"])
print(" type:", v["type"])
if v.has_key("cer_name"):用数组求100以内的素数
print(" cer:",v["cer_name"])
print("finish")
if __name__ =='__main__':
_test_find_mp_info()
运⾏
补充
在终端输⼊命令 security cms -D -bileprovision
可以查看签名信息,证书,创建时间,TeamName,证书过期时间,是否是企业证书(ProvisionsAllDevices这个参数是true),UUID,Version等,⽅便开发者查看打包的信息
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论