Beispiel #1
0
        /// <summary>
        /// 签名
        /// </summary>
        /// <param name="config"></param>
        /// <param name="logView"></param>
        /// <returns></returns>
        public static bool SignApk(KeystoreConfig config, ILog logView)
        {
            string tempApkPath = PathUtils.GetPath(Constants.PATH_TEMPAPK);

            if (!File.Exists(tempApkPath))
            {
                logView.Log(">>>>>>签名失败: " + tempApkPath + "未生成!");
                return(false);
            }

            string jarsignerPath = PathUtils.GetPath(Constants.PATH_JARSIGNER);

            if (!File.Exists(jarsignerPath))
            {
                logView.Log(">>>>>>签名失败: " + jarsignerPath + "不存在!");
                return(false);
            }

            logView.Log("↓↓↓↓↓↓ 签名-开始 ↓↓↓↓↓↓");

            string args = jarsignerPath + " -digestalg SHA1 -sigalg SHA1withRSA -keystore " + config.KeystoreFilePath + " -storepass " + config.Password + " -keypass " + config.Aliaspwd + " " + tempApkPath + " " + config.Aliaskey;

            string[] ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>签名失败: 执行CMD失败");
                return(false);
            }

            logView.Log("↑↑↑↑↑↑ 签名-结束 ↑↑↑↑↑↑");
            logView.BlankLine();

            return(true);
        }
Beispiel #2
0
        public void Initialize()
        {
            var keystoreConfig = new KeystoreConfig();
            var networkConfig  = new NetworkConfig();
            var jsonRpcConfig  = new JsonRpcConfig();

            _configProvider = new JsonConfigProvider();
        }
Beispiel #3
0
        /// <summary>
        /// 读取输入的签名信息
        /// </summary>
        /// <returns></returns>
        private KeystoreConfig GetKeystoreConfig()
        {
            KeystoreConfig config = new KeystoreConfig();

            config.KeystoreFilePath = txtKeystoreFile.Text.Trim();
            config.Password         = txtPassword.Text.Trim();
            config.Aliaskey         = txtAliaskey.Text.Trim();
            config.Aliaspwd         = txtAliaspwd.Text.Trim();

            return(config);
        }
Beispiel #4
0
        public MergeJarForm()
        {
            InitializeComponent();

            //从配置上读取上次保存的签名信息
            KeystoreConfig config = ConfigUtils.ReadKeystoreConfig();

            if (config != null)
            {
                txtKeystoreFile.Text = config.KeystoreFilePath;
                txtPassword.Text     = config.Password;
                txtAliaskey.Text     = config.Aliaskey;
                txtAliaspwd.Text     = config.Aliaspwd;
            }
        }
Beispiel #5
0
        /// <summary>
        /// 打入Jar文件
        /// </summary>
        private void MergeJar()
        {
            ThreadStart threadStart = new ThreadStart(delegate()
            {
                BlankLine();
                Log("================== 打入Jar文件-开始 ==================");
                BlankLine();

                KeystoreConfig config = GetKeystoreConfig();
                // 将签名信息保存到配置
                ConfigUtils.SaveKeystoreConfig(config);

                string jarPath    = txtJarFilePath.Text.Trim();
                string newFileDir = txtNewFileDir.Text.Trim();
                if (!Directory.Exists(newFileDir))
                {
                    Directory.CreateDirectory(newFileDir);
                }
                string newApkPath = PathUtils.JoinPath(newFileDir, txtNewFileName.Text.Trim());


                bool b;
                string s;

                // 1.反编译
                string decompileDir = MergeJarBLL.DecompileApk(ApkFilePath, this);
                if (decompileDir == null)
                {
                    return;
                }

                // 2.Jar文件转换成Dex文件
                s = MergeJarBLL.Jar2Dex(jarPath, this);
                if (s == null)
                {
                    return;
                }

                // 3.将Dex文件转换为Smali文件
                b = MergeJarBLL.Dex2Smali(decompileDir, this);
                if (b == false)
                {
                    return;
                }

                // 4.回编译
                b = MergeJarBLL.RecompileApk(decompileDir, this);
                if (b == false)
                {
                    return;
                }


                // 5.签名
                b = MergeJarBLL.SignApk(config, this);
                if (b == false)
                {
                    return;
                }

                // 6.对齐优化
                b = MergeJarBLL.AlignApk(newApkPath, this);
                if (b == false)
                {
                    return;
                }


                BlankLine();
                Log("================== 打入Jar文件-结束 ==================");
                BlankLine();
                BlankLine();

                // 更新UI
                UpdateUI();
            });
            Thread thread = new Thread(threadStart);

            thread.Start();
        }
Beispiel #6
0
 public void ReadSetting()
 {
     setting     = EditorTool.LoadObjectFromJsonFile <Setting>(SettingPath);
     keystoreCnf = EditorTool.LoadObjectFromJsonFile <KeystoreConfig>(KeystorePath);
 }
Beispiel #7
0
        /// <summary>
        /// 重签名
        /// </summary>
        /// <param name="apkFilePath"></param>
        /// <param name="newApkPath"></param>
        /// <param name="config"></param>
        /// <param name="logView"></param>
        /// <returns></returns>
        public static bool ResignApk(string apkFilePath, string newApkPath, KeystoreConfig config, ILog logView)
        {
            if (string.IsNullOrEmpty(apkFilePath) || !File.Exists(apkFilePath))
            {
                logView.Log(">>>>>>重新签名失败: " + apkFilePath + "不存在!");
                return(false);
            }

            string tempDir = PathUtils.GetPath(Constants.DIR_TEMP_RESIGNAPK);

            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }
            FileUtils.ClearDir(tempDir);
            string tempApkFilePath = PathUtils.JoinPath(tempDir, "temp.apk");

            // 拷贝一份APK作为临时文件,在该临时文件上操作
            FileInfo fi = new FileInfo(apkFilePath);

            if (fi.Exists)
            {
                fi.CopyTo(tempApkFilePath, true);
            }

            logView.BlankLine();
            logView.Log("删除APK文件中META-INF目录下的签名文件");
            ZipUtils.RemoveApkCertFile(tempApkFilePath, logView);

            logView.BlankLine();
            logView.Log("↓↓↓↓↓↓ 重签名-开始 ↓↓↓↓↓↓");

            string jarsignerPath = PathUtils.GetPath(Constants.PATH_JARSIGNER);
            string args          = jarsignerPath + " -digestalg SHA1 -sigalg SHA1withRSA -keystore " + config.KeystoreFilePath + " -storepass " + config.Password + " -keypass " + config.Aliaspwd + " " + tempApkFilePath + " " + config.Aliaskey;

            string[] ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>重新签名失败: 执行CMD失败");
                return(false);
            }
            logView.Log("↑↑↑↑↑↑ 重签名-结束 ↑↑↑↑↑↑");


            logView.BlankLine();
            logView.Log("↓↓↓↓↓↓ 对齐优化-开始 ↓↓↓↓↓↓");
            string zipalignPath = PathUtils.GetPath(Constants.PATH_ZIPALIGN);

            args = zipalignPath + " -f 4 " + tempApkFilePath + " " + newApkPath;

            ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>对齐优化失败: 执行CMD失败");
                return(false);
            }
            logView.Log("↑↑↑↑↑↑ 对齐优化-结束 ↑↑↑↑↑↑");
            logView.BlankLine();


            if (!File.Exists(newApkPath))
            {
                logView.Log(">>>>>>重新签名失败: " + newApkPath + "导出的新apk文件不存在!");
                return(false);
            }

            logView.Log("导出apk为: " + newApkPath);

            return(true);
        }