Apple iOS (ipa)文件解析

Apple iOS (ipa)文件解析

  •  6个月前
  •  207
  •  Java iOS 

代码不够严谨,仅供参考

public static void analyze(File file) {
    try (ZipFile zipFile = new ZipFile(file)) {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        ZipEntry zipEntry;
        while (entries.hasMoreElements()) {
            zipEntry = entries.nextElement();
            String entryName = zipEntry.getName();

            if (entryName.endsWith(".app/Info.plist")) {
                System.out.println();
                logger.info("plist:{}", entryName);
                String path = file.getParent() + File.separator + "Info.plist";
                logger.info("path:{}", path);
                InputStream is = zipFile.getInputStream(zipEntry);
                NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is);
                // 应用包名
                NSString pac = (NSString) rootDict.get("CFBundleIdentifier");
                logger.info("package:{}", pac.toString());
                // 应用版本号
                NSString version = (NSString) rootDict.objectForKey("CFBundleVersion");
                logger.info("version:{}", version.toString());
                //应用名称
                NSString name = (NSString) rootDict.objectForKey("CFBundleDisplayName");
                logger.info("name:{}", name.toString());

                NSDictionary cfBundleIcons = (NSDictionary) rootDict.objectForKey("CFBundleIcons");
                NSDictionary cfBundlePrimaryIcon = (NSDictionary) cfBundleIcons.objectForKey("CFBundlePrimaryIcon");
                NSObject[] iconArrys = ((NSArray) cfBundlePrimaryIcon.objectForKey("CFBundleIconFiles")).getArray();
                logger.info("icon:{}", iconArrys[iconArrys.length - 1]);

            } else if (entryName.endsWith(".app/embedded.mobileprovision")) {
                System.out.println();
                logger.info("mobileprovision:{}", entryName);
                InputStream is = zipFile.getInputStream(zipEntry);
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader reader = new BufferedReader(isr);

                String line;
                boolean flag = false;
                String company = null;
                while ((line = reader.readLine()) != null) {
                    if (flag) {
                        company = line.trim().replace("<string>", "").replace("</string>", "");
                        break;
                    }
                    flag = line.contains("<key>TeamName</key>");
                }
                logger.info("company:{}", company);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}


扫一扫分享到微信

已有 条评论
写评论