天天看點

ios解析mobileprovision檔案内容

作者:洲遊曆累

1.在mac電腦上編寫以下腳本内容

#!/bin/sh

#讀取檔案過期時間
mobPath="$1"
if [ -z "$mobPath" ]; then
 echo "mobileprovision檔案路徑不為空"
fi
#mobileprovision過期時間
expried=`/usr/libexec/PlistBuddy -c 'Print :ExpirationDate' /dev/stdin <<< $(security cms -D -i "$mobPath")`
#mobileprovision檔案名
name=`/usr/libexec/PlistBuddy -c 'Print :Name' /dev/stdin <<< $(security cms -D -i "$mobPath")`
#teamId
teamId=`/usr/libexec/PlistBuddy -c 'Print :TeamIdentifier:0' /dev/stdin <<< $(security cms -D -i "$mobPath")`
#bundle id
appId=`/usr/libexec/PlistBuddy -c 'Print Entitlements:application-identifier' /dev/stdin <<< $(security cms -D -i "$mobPath")`
#字元串截取
appId=${appId#*.}
#mobileprovision真實檔案名
uuid=`/usr/libexec/PlistBuddy -c 'Print :UUID' /dev/stdin <<< $(security cms -D -i "$mobPath")`
#mobileprovision簽名
identity_str=`/usr/libexec/PlistBuddy -c 'Print DeveloperCertificates:0' /dev/stdin <<< $(security cms -D -u 11 -i "${mobPath}") | openssl x509 -subject -inform der | head -n 1`
codeSignIdentity=`echo "${identity_str}" | cut -d "/" -f3 | cut -d "=" -f2`
#證書過期時間
signExpriedDate=`/usr/libexec/PlistBuddy -c 'Print DeveloperCertificates:0' /dev/stdin <<< $(security cms -D -i "${mobPath}") | openssl x509 -inform DER -noout -enddate`
signExpriedDate=`echo "${signExpriedDate}" |  cut -d "=" -f2`
#證書類型判斷debug,ad-hoc,enterprise,appstore
provisionedDevices=`/usr/libexec/PlistBuddy -c 'Print :ProvisionedDevices' /dev/stdin <<< $(security cms -D -i "${mobPath}") 2>/dev/null`
fileType=""
if [ -n "$provisionedDevices" ]; then
   taskAllow=`/usr/libexec/PlistBuddy -c 'Print :Entitlements:get-task-allow' /dev/stdin <<< $(security cms -D -i "${mobPath}") 2>/dev/null`
   if [ "${taskAllow}" == "true" ]; then
       fileType="development"
   else
      fileType="ad-hoc"
   fi
else
   provisionsAllDevices=`/usr/libexec/PlistBuddy -c 'Print :ProvisionsAllDevices' /dev/stdin <<< $(security cms -D -i "${mobPath}") 2>/dev/null`
   if [ "${provisionsAllDevices}" == "true" ]; then
       fileType="enterprise"
   else
       fileType="app-store"
   fi
fi

echo ""
echo "過期時間:${expried}"
echo "檔案名:${name}"
echo "teamId:${teamId}"
echo "appId:${appId}"
echo "真實檔案名:${uuid}"
echo "簽名:${codeSignIdentity}"
echo "簽名過期時間:${signExpriedDate}"
echo "檔案類型:${fileType}"
echo ""
           

2.将腳本另存為read.sh,并添加檔案執行權限

chmod +x read.sh           

3.執行腳本

./read.sh    /xxx/xxx/xxx.mobileprovision           

執行結果:

過期時間:2023-10-29T10:23:00
檔案名: xxx
teamId: xxx
appId: com.ax.sz
真實檔案名: xxx
簽名: xxx
簽名過期時間: 2023-10-29T10:23:00
檔案類型: debug (證書類型debug,ad-hoc,enterprise,appstore)           

繼續閱讀