Android自检工具

来源:互联网 发布:linux 脚本 sleep 编辑:程序博客网 时间:2024/06/18 06:23

前一段时间在做发包任务时, 由于疏忽, 尽管自检了, 但是还是漏掉了关键项的检查, 所以对此深恶痛觉, 便有了这个自检工具。


先使用Apktool进行APK的反编,然后对AndroidManifest.xml进行解析和比较来确定参数的正确性。

AndroidManifest.xml文件的解析:

public void checkUpOn_manifest(string xmlPath){string localMsID = "", localServerID = "", localEgameID = "",localPackageName = "";ZXml xml = new ZXml(xmlPath);var root = xml._data.SelectSingleNode("manifest").SelectSingleNode("application");localPackageName = ((XmlElement)xml._data.SelectSingleNode("manifest")).GetAttribute("package").ToString();AddNewLineMsg("-----------------------------------");AddNewLineMsg("应用包名:" + localPackageName);AddNewLineMsg("指定包名:" + this.packgeName);AddNewLineMsg("-----------------------------------");var metas = root.ChildNodes;foreach(var item in metas){XmlElement metaEle = (XmlElement)item;string data = metaEle.GetAttribute("android:name").ToString();switch(data){case "EGAME_CHANNEL":localEgameID = metaEle.GetAttribute("android:value");AddNewLineMsg("电信ID:" + localEgameID);AddNewLineMsg("指定ID:" + this.egameID);AddNewLineMsg("-----------------------------------");break;case "ServerChannelId":localServerID = metaEle.GetAttribute("android:value");AddNewLineMsg("后台ID:" + localServerID);AddNewLineMsg("指定ID:" + this.serverID);AddNewLineMsg("-----------------------------------");break;case "MSDK_CHANNELID":localMsID = metaEle.GetAttribute("android:value");AddNewLineMsg("火星ID:" + localMsID);AddNewLineMsg("指定ID:" + this.msID);AddNewLineMsg("-----------------------------------");break;default: break;}}AddNewLineMsg("Manifest对比结果:");if(!string.IsNullOrEmpty(this.packgeName)){if(localPackageName != this.packgeName) AddNewLineMsg("包名不同!"); else AddNewLineMsg("包名相同!");}if(!string.IsNullOrEmpty(this.msID)){if(localMsID != this.msID) AddNewLineMsg("火星ID不同!"); else AddNewLineMsg("火星ID相同!");}if(!string.IsNullOrEmpty(this.serverID)){if(localServerID != this.serverID) AddNewLineMsg("后台不同!"); else AddNewLineMsg("后台相同!");}if(!string.IsNullOrEmpty(this.egameID)){if(localEgameID != this.egameID) AddNewLineMsg("电信ID不同!"); else AddNewLineMsg("电信ID相同!");}AddNewLineMsg("-----------------------------------");}
使用Apktool进行Apk的反编译:

public void useApkToolToDecompile(string strInFilePath, string strOutDirectoryPath){if(Directory.Exists(strOutDirectoryPath)){AddNewLineMsg("输出路径已存在,开始清除目录...");Directory.Delete(strOutDirectoryPath, true);}AddNewLineMsg("开始反编译apk");Process process = new Process();process.StartInfo.FileName = this._apkToolPath;process.StartInfo.Arguments = " d " + strInFilePath + " -o " + strOutDirectoryPath;//隐藏DOS窗口  process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;process.Start();process.WaitForExit();process.Close();AddNewLineMsg("反编译完成!开始比对manifest文件:");checkUpOn_manifest(strOutDirectoryPath + "/AndroidManifest.xml");}


本工具全由C#编写,因为公司主营的是单机游戏,所以功能上也是贴合自己的需求而做的,项目我已经上传网盘,需要的看官自取。

链接:http://pan.baidu.com/s/1qYlwtvY 密码:trh3



原创粉丝点击