最近在逆向App,重签的时候有时候不知到证书里有没有新加的UDID,所以出现了这篇文章
先上图
ShowCode
import zipfile
import re
import plistlib
import subprocess
import os
import shutil
# 解压ipa获取并信息
def unzip_ipa(path):
ipa_file = zipfile.ZipFile(path)
plist_path = find_path(ipa_file, 'Payload/[^/]*.app/Info.plist')
# 读取plist内容
plist_data = ipa_file.read(plist_path)
# 解析plist内容
plist_detail_info = plistlib.loads(plist_data)
# 获取plist信息
get_ipa_info(plist_detail_info)
# 获取mobileprovision文件路径
provision_path = find_path(ipa_file, 'Payload/[^/]*.app/embedded.mobileprovision')
# 临时解压
ipa_file.extract(provision_path, './')
# 获取当前路径
current_path = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + os.path.sep + ".")
# 获取mobileprovision路径并保存为plist
string_mobileprovision = string_subprocessPopen('security cms -D -i %s > ./temp.plist' % (current_path + '/' + provision_path),
None, False)
temp_plist = './temp.plist'
#加载plist并获取信息
with open(temp_plist,'rb') as fb:
plist_info = plistlib.load(fb)
print('过期时间:',plist_info['ExpirationDate'])
print('UDID:' + str(len(plist_info['ProvisionedDevices'])) + '个')
for i in plist_info['ProvisionedDevices']:
print(i)
# 删除临时解压文件
shutil.rmtree('./Payload')
os.remove(temp_plist)
# 获取plist路径
def find_path(zip_file, pattern_str):
name_list = zip_file.namelist()
pattern = re.compile(pattern_str)
for path in name_list:
m = pattern.match(path)
if m is not None:
return m.group()
# 获取ipa信息
def get_ipa_info(plist_info):
print('软件名称: %s' % str(plist_info['CFBundleDisplayName']))
print('软件标识: %s' % str(plist_info['CFBundleIdentifier']))
print('软件版本: %s' % str(plist_info['CFBundleShortVersionString']))
print('支持版本: %s' % str(plist_info['MinimumOSVersion']))
def string_subprocessPopen(command, cwd_patch, cancel_newline):
command_file = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
cwd=cwd_patch)
command_file.wait()
command_string = command_file.stdout.read().decode()
if cancel_newline == True:
command_string = command_string.replace("\n", '')
return command_string
if __name__ == '__main__':
flag = False
for filename in os.listdir(os.getcwd()):
hou = os.path.splitext(filename)[-1][1:]
if hou == 'ipa':
flag = True
unzip_ipa('./' + filename)
break
if not flag :
print('请将ipa放在当前目录')
解释
先获取当前目录下的文件,然后截取后缀名,判断是否有ipa文件
if __name__ == '__main__':
flag = False
for filename in os.listdir(os.getcwd()):
hou = os.path.splitext(filename)[-1][1:]
if hou == 'ipa':
flag = True
unzip_ipa('./' + filename)
break
if not flag :
print('请将ipa放在当前目录')
这里通过zipfile
库来读取ipa信息(ipa其实就是zip),然后用正则把plist文件匹配出来,通过plistlib
库来加载plist文件,然后打印其中内容.
通过同样的方法匹配出mobileprovision
文件的路径,因为需要执行security
命令,需要绝对路径,所以临时将mobileprovision
文件解压在当前目录,然后使用subprocess
执行security
命令将mobileprovision
文件保存为temp.plist
文件,再将其用plistlib
加载,读取UDID等信息,最后删除临时解压的文件.
# 解压ipa获取并信息
def unzip_ipa(path):
ipa_file = zipfile.ZipFile(path)
plist_path = find_path(ipa_file, 'Payload/[^/]*.app/Info.plist')
# 读取plist内容
plist_data = ipa_file.read(plist_path)
# 解析plist内容
plist_detail_info = plistlib.loads(plist_data)
# 获取plist信息
get_ipa_info(plist_detail_info)
# 获取mobileprovision文件路径
provision_path = find_path(ipa_file, 'Payload/[^/]*.app/embedded.mobileprovision')
# 临时解压
ipa_file.extract(provision_path, './')
# 获取当前路径
current_path = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + os.path.sep + ".")
# 获取mobileprovision路径并保存为plist
string_mobileprovision = string_subprocessPopen('security cms -D -i %s > ./temp.plist' % (current_path + '/' + provision_path),
None, False)
temp_plist = './temp.plist'
#加载plist并获取信息
with open(temp_plist,'rb') as fb:
plist_info = plistlib.load(fb)
print('过期时间:',plist_info['ExpirationDate'])
print('UDID:' + str(len(plist_info['ProvisionedDevices'])) + '个')
for i in plist_info['ProvisionedDevices']:
print(i)
# 删除临时解压文件
shutil.rmtree('./Payload')
os.remove(temp_plist)
打包
使用pyinstaller -F ipa.py
命令来打包成可执行文件.
打包成功后再dist目录下有个可执行文件,完成
脚本地址,包括打包后的可执行文件:点击下载