@Test public void parseIpa() { URL fileUrl = this.getClass().getClassLoader().getResource("back_test/test.ipa"); if (fileUrl == null) { return; } String filePath = fileUrl.getPath(); File file = new File(filePath); IpaParseRes res = IpaUtil.parseIpa(file); if (res != null) { System.out.println("get valid param as follows"); System.out.println(res.getBundleId()); System.out.println(res.getBundleVersion()); System.out.println(res.getDisplayName()); System.out.println(res.getVersionNameOnAppStore()); System.out.println(res.getBundleName()); System.out.println(res.getMinIOSVersion()); System.out.println(res.getTeamName()); for (String eachIconName : res.getIconNameList()) { System.out.println(eachIconName); } String storePath = "C:" + File.separator + "Users" + File.separator + "Administrator" + File.separator + "Desktop" + File.separator + "test_img_store"; IpaUtil.parseAndStoreFile(file, res.getIconNameList(), storePath); } }
public static IpaParseRes parseIpa(File file) { if (!file.exists()) { logger.warn("parseIpa, file not exist, param file path is: [{}]", file.getPath()); } else { try (InputStream in = new FileInputStream(file); ZipInputStream zipIns = new ZipInputStream(in)) { IpaParseRes res = new IpaParseRes(); ZipEntry zipEntry; while ((zipEntry = zipIns.getNextEntry()) != null) { if (!zipEntry.isDirectory()) { String entryName = zipEntry.getName(); if (entryName != null) { String entryNameLower = entryName.toLowerCase(); if (entryNameLower.contains(".app/info.plist")) { int chunk; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunk = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunk); } NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : rootDict.allKeys()) { logger.debug(key + ":" + rootDict.get(key)); } res.setBundleId(rootDict.get("CFBundleIdentifier").toString()); res.setBundleVersion(rootDict.get("CFBundleVersion").toString()); res.setDisplayName(rootDict.objectForKey("CFBundleDisplayName").toString()); res.setVersionNameOnAppStore(rootDict.objectForKey("CFBundleShortVersionString").toString()); res.setBundleName(rootDict.objectForKey("CFBundleName").toString()); res.setMinIOSVersion(rootDict.objectForKey("MinimumOSVersion").toString()); NSDictionary iconDict = (NSDictionary) rootDict.get("CFBundleIcons"); if (iconDict != null && iconDict.containsKey("CFBundlePrimaryIcon")) { NSDictionary cfBundlePrimaryIcon = (NSDictionary) iconDict.get("CFBundlePrimaryIcon"); if (cfBundlePrimaryIcon.containsKey("CFBundleIconFiles")) { NSArray cfBundleIconFiles = (NSArray) cfBundlePrimaryIcon.get("CFBundleIconFiles"); List<String> iconNameList = new ArrayList<>(); for (NSObject icon : cfBundleIconFiles.getArray()) { String iconName = icon.toString(); if (iconName.contains(".png")) { iconName = iconName.replace(".png", ""); } iconNameList.add(iconName); } res.setIconNameList(iconNameList); } } } else if (entryNameLower.contains(".mobileprovision")) { int chunkLength; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunkLength = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunkLength); } Map<String, Object> map = parseMobileProvisionToMap(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : map.keySet()) { logger.debug(key + ":" + map.get(key)); } res.setTeamName(map.get("TeamName").toString()); } } } } return res; } catch (Exception e) { logger.error("parseIpa, Exception: [{}]", e); } } return null; }
IpaUtil { public static IpaParseRes parseIpa(File file) { if (!file.exists()) { logger.warn("parseIpa, file not exist, param file path is: [{}]", file.getPath()); } else { try (InputStream in = new FileInputStream(file); ZipInputStream zipIns = new ZipInputStream(in)) { IpaParseRes res = new IpaParseRes(); ZipEntry zipEntry; while ((zipEntry = zipIns.getNextEntry()) != null) { if (!zipEntry.isDirectory()) { String entryName = zipEntry.getName(); if (entryName != null) { String entryNameLower = entryName.toLowerCase(); if (entryNameLower.contains(".app/info.plist")) { int chunk; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunk = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunk); } NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : rootDict.allKeys()) { logger.debug(key + ":" + rootDict.get(key)); } res.setBundleId(rootDict.get("CFBundleIdentifier").toString()); res.setBundleVersion(rootDict.get("CFBundleVersion").toString()); res.setDisplayName(rootDict.objectForKey("CFBundleDisplayName").toString()); res.setVersionNameOnAppStore(rootDict.objectForKey("CFBundleShortVersionString").toString()); res.setBundleName(rootDict.objectForKey("CFBundleName").toString()); res.setMinIOSVersion(rootDict.objectForKey("MinimumOSVersion").toString()); NSDictionary iconDict = (NSDictionary) rootDict.get("CFBundleIcons"); if (iconDict != null && iconDict.containsKey("CFBundlePrimaryIcon")) { NSDictionary cfBundlePrimaryIcon = (NSDictionary) iconDict.get("CFBundlePrimaryIcon"); if (cfBundlePrimaryIcon.containsKey("CFBundleIconFiles")) { NSArray cfBundleIconFiles = (NSArray) cfBundlePrimaryIcon.get("CFBundleIconFiles"); List<String> iconNameList = new ArrayList<>(); for (NSObject icon : cfBundleIconFiles.getArray()) { String iconName = icon.toString(); if (iconName.contains(".png")) { iconName = iconName.replace(".png", ""); } iconNameList.add(iconName); } res.setIconNameList(iconNameList); } } } else if (entryNameLower.contains(".mobileprovision")) { int chunkLength; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunkLength = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunkLength); } Map<String, Object> map = parseMobileProvisionToMap(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : map.keySet()) { logger.debug(key + ":" + map.get(key)); } res.setTeamName(map.get("TeamName").toString()); } } } } return res; } catch (Exception e) { logger.error("parseIpa, Exception: [{}]", e); } } return null; } }
IpaUtil { public static IpaParseRes parseIpa(File file) { if (!file.exists()) { logger.warn("parseIpa, file not exist, param file path is: [{}]", file.getPath()); } else { try (InputStream in = new FileInputStream(file); ZipInputStream zipIns = new ZipInputStream(in)) { IpaParseRes res = new IpaParseRes(); ZipEntry zipEntry; while ((zipEntry = zipIns.getNextEntry()) != null) { if (!zipEntry.isDirectory()) { String entryName = zipEntry.getName(); if (entryName != null) { String entryNameLower = entryName.toLowerCase(); if (entryNameLower.contains(".app/info.plist")) { int chunk; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunk = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunk); } NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : rootDict.allKeys()) { logger.debug(key + ":" + rootDict.get(key)); } res.setBundleId(rootDict.get("CFBundleIdentifier").toString()); res.setBundleVersion(rootDict.get("CFBundleVersion").toString()); res.setDisplayName(rootDict.objectForKey("CFBundleDisplayName").toString()); res.setVersionNameOnAppStore(rootDict.objectForKey("CFBundleShortVersionString").toString()); res.setBundleName(rootDict.objectForKey("CFBundleName").toString()); res.setMinIOSVersion(rootDict.objectForKey("MinimumOSVersion").toString()); NSDictionary iconDict = (NSDictionary) rootDict.get("CFBundleIcons"); if (iconDict != null && iconDict.containsKey("CFBundlePrimaryIcon")) { NSDictionary cfBundlePrimaryIcon = (NSDictionary) iconDict.get("CFBundlePrimaryIcon"); if (cfBundlePrimaryIcon.containsKey("CFBundleIconFiles")) { NSArray cfBundleIconFiles = (NSArray) cfBundlePrimaryIcon.get("CFBundleIconFiles"); List<String> iconNameList = new ArrayList<>(); for (NSObject icon : cfBundleIconFiles.getArray()) { String iconName = icon.toString(); if (iconName.contains(".png")) { iconName = iconName.replace(".png", ""); } iconNameList.add(iconName); } res.setIconNameList(iconNameList); } } } else if (entryNameLower.contains(".mobileprovision")) { int chunkLength; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunkLength = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunkLength); } Map<String, Object> map = parseMobileProvisionToMap(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : map.keySet()) { logger.debug(key + ":" + map.get(key)); } res.setTeamName(map.get("TeamName").toString()); } } } } return res; } catch (Exception e) { logger.error("parseIpa, Exception: [{}]", e); } } return null; }  }
IpaUtil { public static IpaParseRes parseIpa(File file) { if (!file.exists()) { logger.warn("parseIpa, file not exist, param file path is: [{}]", file.getPath()); } else { try (InputStream in = new FileInputStream(file); ZipInputStream zipIns = new ZipInputStream(in)) { IpaParseRes res = new IpaParseRes(); ZipEntry zipEntry; while ((zipEntry = zipIns.getNextEntry()) != null) { if (!zipEntry.isDirectory()) { String entryName = zipEntry.getName(); if (entryName != null) { String entryNameLower = entryName.toLowerCase(); if (entryNameLower.contains(".app/info.plist")) { int chunk; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunk = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunk); } NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : rootDict.allKeys()) { logger.debug(key + ":" + rootDict.get(key)); } res.setBundleId(rootDict.get("CFBundleIdentifier").toString()); res.setBundleVersion(rootDict.get("CFBundleVersion").toString()); res.setDisplayName(rootDict.objectForKey("CFBundleDisplayName").toString()); res.setVersionNameOnAppStore(rootDict.objectForKey("CFBundleShortVersionString").toString()); res.setBundleName(rootDict.objectForKey("CFBundleName").toString()); res.setMinIOSVersion(rootDict.objectForKey("MinimumOSVersion").toString()); NSDictionary iconDict = (NSDictionary) rootDict.get("CFBundleIcons"); if (iconDict != null && iconDict.containsKey("CFBundlePrimaryIcon")) { NSDictionary cfBundlePrimaryIcon = (NSDictionary) iconDict.get("CFBundlePrimaryIcon"); if (cfBundlePrimaryIcon.containsKey("CFBundleIconFiles")) { NSArray cfBundleIconFiles = (NSArray) cfBundlePrimaryIcon.get("CFBundleIconFiles"); List<String> iconNameList = new ArrayList<>(); for (NSObject icon : cfBundleIconFiles.getArray()) { String iconName = icon.toString(); if (iconName.contains(".png")) { iconName = iconName.replace(".png", ""); } iconNameList.add(iconName); } res.setIconNameList(iconNameList); } } } else if (entryNameLower.contains(".mobileprovision")) { int chunkLength; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunkLength = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunkLength); } Map<String, Object> map = parseMobileProvisionToMap(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : map.keySet()) { logger.debug(key + ":" + map.get(key)); } res.setTeamName(map.get("TeamName").toString()); } } } } return res; } catch (Exception e) { logger.error("parseIpa, Exception: [{}]", e); } } return null; }  @SuppressWarnings("unchecked") static Map<String, Object> parsePListToMap(InputStream in); @SuppressWarnings("unchecked") static Map<String, Object> parseMobileProvisionToMap(InputStream in); static String getFileContentByExecuteShell(String fileName); static IpaParseRes parseIpa(File file); static void parseAndStoreFile(File file, List<String> iconList, String path); static synchronized boolean changePlistContent(File originFile, File aimFile, String softwarePackageUrl, String displayImageUrl, String fullSizeImageUrl,
                                                          String bundleIdentifierValue, String bundleVersionValue, String titleValue); static Map<String, Object> generateDirByIpa(File ipaOriginFile, String ipaOriginFileName, String domain, String name); static ByteArrayOutputStream cloneInputStream(InputStream inputStream); }
IpaUtil { public static IpaParseRes parseIpa(File file) { if (!file.exists()) { logger.warn("parseIpa, file not exist, param file path is: [{}]", file.getPath()); } else { try (InputStream in = new FileInputStream(file); ZipInputStream zipIns = new ZipInputStream(in)) { IpaParseRes res = new IpaParseRes(); ZipEntry zipEntry; while ((zipEntry = zipIns.getNextEntry()) != null) { if (!zipEntry.isDirectory()) { String entryName = zipEntry.getName(); if (entryName != null) { String entryNameLower = entryName.toLowerCase(); if (entryNameLower.contains(".app/info.plist")) { int chunk; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunk = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunk); } NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : rootDict.allKeys()) { logger.debug(key + ":" + rootDict.get(key)); } res.setBundleId(rootDict.get("CFBundleIdentifier").toString()); res.setBundleVersion(rootDict.get("CFBundleVersion").toString()); res.setDisplayName(rootDict.objectForKey("CFBundleDisplayName").toString()); res.setVersionNameOnAppStore(rootDict.objectForKey("CFBundleShortVersionString").toString()); res.setBundleName(rootDict.objectForKey("CFBundleName").toString()); res.setMinIOSVersion(rootDict.objectForKey("MinimumOSVersion").toString()); NSDictionary iconDict = (NSDictionary) rootDict.get("CFBundleIcons"); if (iconDict != null && iconDict.containsKey("CFBundlePrimaryIcon")) { NSDictionary cfBundlePrimaryIcon = (NSDictionary) iconDict.get("CFBundlePrimaryIcon"); if (cfBundlePrimaryIcon.containsKey("CFBundleIconFiles")) { NSArray cfBundleIconFiles = (NSArray) cfBundlePrimaryIcon.get("CFBundleIconFiles"); List<String> iconNameList = new ArrayList<>(); for (NSObject icon : cfBundleIconFiles.getArray()) { String iconName = icon.toString(); if (iconName.contains(".png")) { iconName = iconName.replace(".png", ""); } iconNameList.add(iconName); } res.setIconNameList(iconNameList); } } } else if (entryNameLower.contains(".mobileprovision")) { int chunkLength; byte[] tempStoreData = new byte[preSetByteSize]; ByteArrayOutputStream tempByteOuts = new ByteArrayOutputStream(); while ((chunkLength = zipIns.read(tempStoreData)) != -1) { tempByteOuts.write(tempStoreData, 0, chunkLength); } Map<String, Object> map = parseMobileProvisionToMap(new ByteArrayInputStream(tempByteOuts.toByteArray())); for (String key : map.keySet()) { logger.debug(key + ":" + map.get(key)); } res.setTeamName(map.get("TeamName").toString()); } } } } return res; } catch (Exception e) { logger.error("parseIpa, Exception: [{}]", e); } } return null; }  @SuppressWarnings("unchecked") static Map<String, Object> parsePListToMap(InputStream in); @SuppressWarnings("unchecked") static Map<String, Object> parseMobileProvisionToMap(InputStream in); static String getFileContentByExecuteShell(String fileName); static IpaParseRes parseIpa(File file); static void parseAndStoreFile(File file, List<String> iconList, String path); static synchronized boolean changePlistContent(File originFile, File aimFile, String softwarePackageUrl, String displayImageUrl, String fullSizeImageUrl,
                                                          String bundleIdentifierValue, String bundleVersionValue, String titleValue); static Map<String, Object> generateDirByIpa(File ipaOriginFile, String ipaOriginFileName, String domain, String name); static ByteArrayOutputStream cloneInputStream(InputStream inputStream);  }