[工具-003]如何从ipa中提取info.plist并提取相应信息

  最近公司的产品要进行一次批量的升级,产品中的一些配置存放在info.plist,为了保证产品的信息无误,我们必须要对产品的发布信息进行验证。例如:广告ID,umeng,talkingdata等等。那么手动的核对,对于批量升级是又不保险,又费力气。然后我们聪明睿智的蔡主管安排我去做一个解压ipa,然后提取info.plist,最后提取产品信息进行比对的产品。

  我用的开发语言是C#,根据以上的描述,我们在开发中比较重要的就只有2步骤。

  1.解压ipa

  我引用的包是ICSharpCode.SharpZipLib.dll,为了提高速度,我只解压info.plist就结束了,其他都不做文件写入。

     private void unzipFileIOS(String filePath)

     {

            // 判断文件是否是ipa文件

            if (Path.GetExtension(filePath).Equals(".ipa"))

            {

                // 获取文件名

                String appName = Path.GetFileNameWithoutExtension(filePath);

                // 设置加压的文件夹目录

                String outPath = PATH_TEMP_IOS + "\\" + appName;

                // 获取输入流(ipa文件)

                ZipInputStream s = new ZipInputStream(File.OpenRead(filePath));

                // zip实体

                ZipEntry theEntry;

                String infoPlistName = "Info.plist";

                bool found = false;

                while ((theEntry = s.GetNextEntry()) != null)

                {

                    Console.WriteLine(theEntry.Name);

                    // 文件名称

                    string fileName = Path.GetFileName(theEntry.Name);

                    // 寻找Info.plist文件

                    if (infoPlistName != null)

                    {

                        if (fileName.Equals(infoPlistName))

                        {

                            found = true;

                            // 创建输出目录

                            if (outPath.Length > 0)

                            {

                                Directory.CreateDirectory(outPath);

                            }

                            // 文件写入操作

                            using (FileStream streamWriter = File.Create(outPath + "\\Info.plist"))

                            {



                                int size = 2048;

                                byte[] data = new byte[2048];

                                while (true)

                                {

                                    size = s.Read(data, 0, data.Length);

                                    if (size > 0)

                                    {

                                        streamWriter.Write(data, 0, size);

                                    }

                                    else

                                    {

                                        break;

                                    }

                                }

                            }

                            break;

                        }

                    }

                }

                // 一定要关闭流,不然下次会被占用

                s.Close();

                if (found == false)

                {

                    logAppend(appName + "------- 无效", false, false);

                    logAppend(Environment.NewLine, false, false);

                }

           }

    }

  2.读取info.plist

  通过以上的操作我们已经把ipa中的info.plist解压出来,那么我们接下来的操作就是读取plist中的内容

  我们引用的是CE.iPhone.PList.dll

  String pathInfo = subDirectory + "\\Info.plist";

  if (File.Exists(pathInfo))

  {

    count++;

     // 获取根

    PListRoot root = PListRoot.Load(pathInfo);

     // 获取主节点

    PListDict dic = (PListDict)root.Root;

    // 获取PList的树形(根据名称获取数据)

     PListString appKey   = (PListString)dic["CFBundleIdentifier"];

    PListString umengKey = (PListString)dic["UmengKey"];

    PListString adKey    = (PListString)dic["ADKey"];

     // 因为tostring -》 string:+content 所以过滤

    string appKeystring   = appKey.ToString().Substring(7).Trim();

    string umengKeystring = umengKey.ToString().Substring(7).Trim();

    string adKeystring = adKey.ToString().Substring(7).Trim();

  }

  通过以上的2个步骤我们就可以轻松的拿到我们的产品信息了,希望这篇文章对你们会有帮助。

 

 结语

  • 受益,学会了提取ipa中的info.plist中的信息

 

 

[工具-003]如何从ipa中提取info.plist并提取相应信息

本站文章为 宝宝巴士 SD.Team 原创,转载务必在明显处注明:(作者官方网站: 宝宝巴士 

转载自【宝宝巴士SuperDo团队】 原文链接: http://www.cnblogs.com/superdo/p/4527451.html

你可能感兴趣的:(plist)