折腾:
【未解决】Win中VMWare中macOS中调试抓包项目
期间,对于支持检测已安装app,第一行,除了之前的total,还有CBF的可能:
src/common/DevicesMethods.py
1 2 3 4 5 6 7 8 9 10 | def get_iOS_installedAppList( self ): ... # Total: 9 apps # CFBundleIdentifier, CFBundleVersion, CFBundleDisplayName isTotalStr = eachAppStr.startswith( "Total:" ) isNotTotal = not isTotalStr isCbfStr = eachAppStr.startswith( "CFBundleIdentifier" ) isNotCfb = not isCbfStr if eachAppStr and isNotTotal and isNotCfb: logging.error( "not match installed app item: %s" , eachAppStr) |
但是后续发现:
每个app输出的结构,略有变化,导致之前代码不支持了:

去看看返回的原始字符串
1 | 'CFBundleIdentifier, CFBundleVersion, CFBundleDisplayName\ncom.tencent.xin, "7.0.12.33", "微信"\ncom.qschou.easyhealth, "86", "轻松互助"\ncn.kags.kagsapp, "413009", "康爱公社"\ncom.fenbi.ape.zebstrika, "221", "斑马AI课"\ncom.wuyouchou.RaiseFunds, "1.0.1", "无忧筹"\ncom.pocketkobo.bodhisattva, "1.0.0", "善友筹"\ncom.dianping.dpscope, "10.28.10.46", "大众点评"\ncn.com.cnpc.yilutongxing, "61004", "益路同行"\ncom.jd.jinrong, "618", "京东金融"\ncom.taobao.taobao4iphone, "20000682", "手机淘宝"\ncom.puhui.hyd, "20200331", "恒易贷"\ncom.Qting.QTTour, "8.6.6.15", "蜻蜓FM"\ncom.biyao.fu, "5.30.1.5", "必要"\ncn.gov.tax.its, "20200603185859", "个人所得税"\ncom.tmri.12123, "345", "交管12123"\ncom.ss.iphone.ugc.Aweme, "113015", "抖音短视频"\ncom.tencent.QQMusic, "20021", "QQ音乐"\ncom.tencent.meeting, "404", "腾讯会议"\ncom.tencent.microvision, "175", "微视"\ncom.laiwang.DingTalk, "13207758", "钉钉"\ncom.tencent.ww, "48464", "企业微信"\ncom.hxak.LGBProducts, "1.0.287", "链工宝"\ntuhu.cn.main, "1892", "途虎养车"\ncom.baidu.BaiduMobile, "11.23.5.16", "百度"\ncom.taobao.special, "13212820", "淘宝特价版"\ncom.netease.mhxywyb, "100005", "梦幻西游网页版"\ncom.kugou.kugou1002, "10.1.5.3", "酷狗音乐"\ncom.yaymedialabs.putong, "4.0.7.2", "探探"\ncom.hpbr.bosszhipin, "8.050", "BOSS直聘"\ncom.xiaomi.mihome, "4.30.2.0", "米家"\ncom.baidu.netdisk, "10.1.20.7", "百度网盘"\ncom.sina.weibo, "42867", "微博"\ncom.kingsoft.www.office.wpsoffice, "10.11.076659", "WPS Office"\ncom.playrix.gardenscapes-m3-ios, "4.4.2", "梦幻花园"\ncom.netease.cloudmusic, "1664", "网易云音乐"\ncom.crifan.WebDriverAgentRunner.xctrunner, "1", "WebDriverAgentRunner-Runner"\nrn.notes.best, "11122019", "爱思极速版"\n' |
都是逗号分隔了。
所以要去优化逻辑
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 | def get_iOS_installedAppList( self ): installedAppList = [] listAppCmd = 'ideviceinstaller -l' appListStr = CommonUtils.get_cmd_lines(listAppCmd, text = True ) logging.debug( "appListStr=%s" , appListStr) if appListStr: appRawList = appListStr.split( "\n" ) curP = None isTotalStyle = appListStr.startswith( "Total:" ) isCbfStyle = appListStr.startswith( "CFBundleIdentifier" ) if isTotalStyle: """ Total: 9 apps com.dianping.dpscope - 大众点评 10.27.10.21 com.tencent.xin - 微信 7.0.12.33 com.tencent.tiantianptu - 天天P图 603040 com.didapinche.taxi - 嘀嗒出行 3 com.luojilab.LuoJiFM-IOS - 得到 7.10.361 com.suiyi.foodshop1 - 食行生鲜 49267 com.alipay.iphoneclient - 支付宝 10.1.90.8000 com.crifan.WebDriverAgentRunner.xctrunner - WebDriverAgentRunner-Runner 1 com.xiaojukeji.didi - 滴滴出行 5.4.10.904142127 """ # curP = "(?P<bundleId>com\.\S+)\s+-\s+(?P<name>\S+)\s+(?P<version>[\d\.]+)" # rn.notes.best - 爱思极速版 11122019 # curP = "(?P<bundleId>[\w\.]+)\s+-\s+(?P<name>\S+)\s+(?P<version>[\d\.]+)" # 'com.kingsoft.www.office.wpsoffice - WPS Office 10.11.076659' curP = "(?P<bundleId>[\w\.]+)\s+-\s+(?P<name>[\S ]+)\s+(?P<version>[\d\.]+)" elif isCbfStyle: """ CFBundleIdentifier, CFBundleVersion, CFBundleDisplayName com.tencent.xin, "7.0.12.33", "微信" com.qschou.easyhealth, "86", "轻松互助" com.laiwang.DingTalk, "13207758", "钉钉" com.tencent.ww, "48464", "企业微信" com.hxak.LGBProducts, "1.0.287", "链工宝" tuhu.cn.main, "1892", "途虎养车" com.baidu.BaiduMobile, "11.23.5.16", "百度" ... com.crifan.WebDriverAgentRunner.xctrunner, "1", "WebDriverAgentRunner-Runner" rn.notes.best, "11122019", "爱思极速版" """ curP = '(?P<bundleId>[\w\.]+),\s+"(?P<version>[\d\.]+",\s+"(?P<name>\S+)"' else : logging.error( "Not supported app info style for %s" , appListStr) if curP: for eachAppStr in appRawList: eachAppStr = eachAppStr.strip() foundApp = re.search(curP, eachAppStr) if foundApp: bundleId = foundApp.group( "bundleId" ) # 'com.dianping.dpscope' name = foundApp.group( "name" ) # '大众点评' version = foundApp.group( "version" ) # '10.27.10.21' curAppInfo = { "bundleId" : bundleId, "name" : name, "version" : version, } installedAppList.append(curAppInfo) else : # Total: 9 apps # CFBundleIdentifier, CFBundleVersion, CFBundleDisplayName isTotalStr = eachAppStr.startswith( "Total:" ) isNotTotal = not isTotalStr isCbfStr = eachAppStr.startswith( "CFBundleIdentifier" ) isNotCfb = not isCbfStr if eachAppStr and isNotTotal and isNotCfb: logging.error( "not match installed app item: %s" , eachAppStr) logging.debug( "installedAppList=%s" , installedAppList) return installedAppList |
去调试看看
语法写错了,少个右括号,加上:
1 | curP = '(?P< bundleId >[\w\.]+),\s+"(?P< version >[\d\.]+)",\s+"(?P< name >\S+)"' |
继续
遇到新情况:
1 | 'com.kingsoft.www.office.wpsoffice, "10.11.076659", "WPS Office"' |
再去修改
以及顺带优化,为:
1 2 3 4 5 6 7 8 9 10 11 | bundleIdP = "(?P< bundleId >[\w\.]+)" nameP = "(?P< name >[\S ]+)" versionP = "(?P< version >[\d\.]+)" # curP = "(?P< bundleId >[\w\.]+)\s+-\s+(?P< name >[\S ]+)\s+(?P< version >[\d\.]+)" curP = "%s\s+-\s+%s\s+%s" % (bundleIdP, nameP, versionP) # curP = '(?P< bundleId >[\w\.]+),\s+"(?P< version >[\d\.]+)",\s+"(?P< name >[\S ]+)"' curP = '%s,\s+"%s",\s+"%s"' % (bundleIdP, versionP, nameP) |
继续调试,

都可以完美解析出来了。
【总结】
最终代码:
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 87 | def get_iOS_installedAppList( self ): installedAppList = [] listAppCmd = 'ideviceinstaller -l' appListStr = CommonUtils.get_cmd_lines(listAppCmd, text = True ) logging.debug( "appListStr=%s" , appListStr) if appListStr: appRawList = appListStr.split( "\n" ) curP = None isTotalStyle = appListStr.startswith( "Total:" ) isCbfStyle = appListStr.startswith( "CFBundleIdentifier" ) bundleIdP = "(?P<bundleId>[\w\.]+)" nameP = "(?P<name>[\S ]+)" versionP = "(?P<version>[\d\.]+)" if isTotalStyle: """ Total: 9 apps com.dianping.dpscope - 大众点评 10.27.10.21 com.tencent.xin - 微信 7.0.12.33 com.tencent.tiantianptu - 天天P图 603040 com.didapinche.taxi - 嘀嗒出行 3 com.luojilab.LuoJiFM-IOS - 得到 7.10.361 com.suiyi.foodshop1 - 食行生鲜 49267 com.alipay.iphoneclient - 支付宝 10.1.90.8000 com.crifan.WebDriverAgentRunner.xctrunner - WebDriverAgentRunner-Runner 1 com.xiaojukeji.didi - 滴滴出行 5.4.10.904142127 """ # curP = "(?P<bundleId>com\.\S+)\s+-\s+(?P<name>\S+)\s+(?P<version>[\d\.]+)" # rn.notes.best - 爱思极速版 11122019 # curP = "(?P<bundleId>[\w\.]+)\s+-\s+(?P<name>\S+)\s+(?P<version>[\d\.]+)" # 'com.kingsoft.www.office.wpsoffice - WPS Office 10.11.076659' # curP = "(?P<bundleId>[\w\.]+)\s+-\s+(?P<name>[\S ]+)\s+(?P<version>[\d\.]+)" curP = "%s\s+-\s+%s\s+%s" % (bundleIdP, nameP, versionP) elif isCbfStyle: """ CFBundleIdentifier, CFBundleVersion, CFBundleDisplayName com.tencent.xin, "7.0.12.33", "微信" com.qschou.easyhealth, "86", "轻松互助" com.laiwang.DingTalk, "13207758", "钉钉" com.tencent.ww, "48464", "企业微信" com.hxak.LGBProducts, "1.0.287", "链工宝" tuhu.cn.main, "1892", "途虎养车" com.baidu.BaiduMobile, "11.23.5.16", "百度" ... com.kingsoft.www.office.wpsoffice, "10.11.076659", "WPS Office" com.crifan.WebDriverAgentRunner.xctrunner, "1", "WebDriverAgentRunner-Runner" rn.notes.best, "11122019", "爱思极速版" """ # curP = '(?P<bundleId>[\w\.]+),\s+"(?P<version>[\d\.]+)",\s+"(?P<name>[\S ]+)"' curP = '%s,\s+"%s",\s+"%s"' % (bundleIdP, versionP, nameP) else : logging.error( "Not supported app info style for %s" , appListStr) if curP: for eachAppStr in appRawList: eachAppStr = eachAppStr.strip() if not eachAppStr: # omit empty string continue foundApp = re.search(curP, eachAppStr) if foundApp: bundleId = foundApp.group( "bundleId" ) # 'com.dianping.dpscope' name = foundApp.group( "name" ) # '大众点评' version = foundApp.group( "version" ) # '10.27.10.21' curAppInfo = { "bundleId" : bundleId, "name" : name, "version" : version, } installedAppList.append(curAppInfo) else : # Total: 9 apps # CFBundleIdentifier, CFBundleVersion, CFBundleDisplayName isTotalStr = eachAppStr.startswith( "Total:" ) isNotTotal = not isTotalStr isCbfStr = eachAppStr.startswith( "CFBundleIdentifier" ) isNotCfb = not isCbfStr if isNotTotal and isNotCfb: logging.error( "not match installed app item: %s" , eachAppStr) logging.debug( "installedAppList=%s" , installedAppList) return installedAppList |
即可支持2种输出格式的app信息的解析。
转载请注明:在路上 » 【已解决】更新检测iPhone中已安装app信息的代码逻辑