Beispiel #1
0
        /// <summary>
        /// 获取路径path下的所有apk文件,或apk解包根目录信息
        /// </summary>
        public static Dictionary <string, string> getApk_FileOrDir(String path)
        {
            Dictionary <string, string> FileDir = new Dictionary <string, string>();

            // 若载入的为apk文件
            if (Apktool.isApkDir(path) || Apktool.isApkFile(path))
            {
                string name = System.IO.Path.GetFileName(path);
                FileDir.Add(name, path);
            }
            else
            {
                Dictionary <string, string> apks    = getFileNameByExt(path, ".apk");     // 获取所有apk文件信息
                Dictionary <string, string> apkDirs = getApkDir(path);                    // 获取所有apk解包路径信息

                // 优先添加apk文件的解包目录
                foreach (string dir in apkDirs.Keys)
                {
                    FileDir.Add(dir, apkDirs[dir]);
                }

                // 再添加没有解包目录的apk文件
                foreach (string apk in apks.Keys)
                {
                    String dir = apk.Replace(".apk", "").TrimEnd('.');
                    if (!apkDirs.Keys.Contains(dir))
                    {
                        FileDir.Add(apk, apks[apk]);
                    }
                }
            }

            return(FileDir);
        }
Beispiel #2
0
        private void UnPack_Logic()
        {
            OutPut("【I】");

            if (Apktool.isApkFile(file.Text))       // 解包
            {
                OutPut("【I】apk解包开始...");
                String result = Apktool.unPackage(file.Text, OutPut, false, false);   // 使用apktool进行apk的解包
                if (result.Contains("【E】"))
                {
                    return;
                }
                OutPut("【I】apk解包结束!\r\n");
            }
            else if (Apktool.isApkDir(file.Text))   // 打包
            {
                OutPut("【I】apk打包开始...");
                String result = Apktool.package(file.Text, OutPut);     // 使用apktool进行打包
                if (result.Contains("【E】"))
                {
                    return;
                }
                OutPut("【I】apk未签名文件已生成!\r\n");

                // 若有签名文件,则进行签名
                if (!comboBox_sign.Text.Equals(""))
                {
                    OutPut("【I】apk签名中...");
                    String apkName = file.Text + "..apk";
                    String pem     = SinPath() + "\\" + comboBox_sign.Text + ".x509.pem";
                    String pk8     = SinPath() + "\\" + comboBox_sign.Text + ".pk8";
                    String psw     = "letang123";
                    result = Apktool.Sign(apkName, pem, pk8, psw, OutPut);
                    if (result.Contains("【E】"))
                    {
                        return;
                    }
                    OutPut("【I】apk签名、对齐 完成!\r\n");

                    // 删除打包生成的未签名文件
                    if (System.IO.File.Exists(apkName))
                    {
                        System.IO.File.Delete(apkName);
                    }
                }

                OutPut("【I】apk打包结束!\r\n");
            }
            else
            {
                Cmd.Run(file.Text, OutPut); // 执行cmd命令
            }
        }
Beispiel #3
0
        private bool isApkDir(String paths)
        {
            String[] A = paths.Split(';');
            foreach (String path in A)
            {
                if (Apktool.isApkDir(path) || Apktool.isApkFile(path))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        //==========================
        // apk解包打包逻辑封装

        /// <summary>
        /// 若为apk文件,则先行解包
        /// </summary>
        public static String apkUnpack(String apkFile, Cmd.Callback call, bool deletPublicXML = false)
        {
            // 若输入的为apk文件,则自动进行解包
            if (Apktool.isApkFile(apkFile))
            {
                if (call != null)
                {
                    call("【I】" + Path.GetFileName(apkFile));
                }
                if (call != null)
                {
                    call("【I】apk解包开始...");
                }

                string dir = Apktool.unPackage(apkFile, call, deletPublicXML);   // 使用apktool进行apk的解包
                if (dir.Contains("【E】"))
                {
                    return(dir);
                }

                if (call != null)
                {
                    call("【I】apk解包结束!\r\n");
                }

                // 拷贝apk目录下的配置文件到解包文件所在目录
                String configTxt  = apkFile.Replace(".apk", ".txt");
                String configTxt2 = apkFile.Replace(".apk", "-" + Settings.gameId + ".txt");    // 可按游戏获取游戏id对应的配置文件
                if (File.Exists(configTxt2) && !File.Exists(dir + ".txt"))
                {
                    File.Copy(configTxt2, dir + ".txt", false);
                }
                else if (File.Exists(configTxt) && !File.Exists(dir + ".txt"))
                {
                    File.Copy(configTxt, dir + ".txt", false);
                }

                if (File.Exists(dir + ".txt"))
                {
                    // 添加游戏附加配置信息到渠道包,打包配置中
                    String gameAttachConfig = ToolSetting.Instance().serverRoot + "游戏附加配置\\" + Settings.gameId + ".txt";
                    Settings.AppendSettingsTo(gameAttachConfig, dir + ".txt");
                }

                return(dir);
            }
            else
            {
                return(apkFile);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 判定执行对应逻辑
        /// </summary>
        private void file_TextChanged(object sender, EventArgs e)
        {
            if (Apktool.isApkFile(file.Text))
            {
                unPack.Text = "apk解包";                                   // 若为apk文件则,可解包
            }
            else if (Apktool.isApkDir(file.Text))
            {
                unPack.Text = "apk打包";                                   // 若为apk解包文件夹,则可打包
            }
            else
            {
                unPack.Text = "执行cmd";
            }

            comboBox_sign.Visible = Apktool.isApkDir(file.Text);           // 若为打包操作,可选择签名
        }