예제 #1
0
        public void Rebuild_R_Table(string aimPath)
        {
            OutPut("创建临时目录");
            String R_Path = PathTool.GetCurrentPath() + "/R_path/";

            FileTool.CreatPath(R_Path);
            //OutPut("生成R文件");
            //OutPut("生成的R文件的jar");
            //OutPut("生成 dex文件");
            //OutPut("生成smali文件");
            //OutPut("替换smali文件");

            //String androidPath = @"D:\AndroidSDK\platforms\android-28\android.jar";
            string manifest = aimPath + "/AndroidManifest.xml";
            string resPath  = aimPath + "/res";

            CmdService cmd = new CmdService(OutPut, errorCallBack);

            OutPut("生成R.java文件");

            OutPut("R_Path " + R_Path + " resPath " + resPath + " manifest " + manifest);

            //生成R文件
            cmd.Execute("aapt package -f -I android.jar -m -J " + R_Path + " -S " + resPath + " -M " + manifest + "");

            if (FindRPath(R_Path) != null)
            {
                //GBK转码
                //string java = FileTool.ReadStringByFile(FindRPath(R_Path));
                //java = compileTool.RemoveSpecialCode(java);
                //FileTool.WriteStringByFile(FindRPath(R_Path),java);

                //编译R.java文件
                cmd.Execute("javac -encoding UTF-8 -source 1.6 -target 1.6 " + FindRPath(R_Path), true, true);

                //生成的R文件的jar
                cmd.Execute("jar cvf ./R.jar ./com", path: R_Path);

                //Jar to dex
                cmd.Execute("java -jar dx.jar --dex --output=./R_path/classes.dex ./R_path/R.jar ", true, true);

                //dex to smali
                cmd.Execute("java -jar baksmali-2.1.3.jar --o=" + aimPath + "/smali ./R_path/classes.dex");
            }
            else
            {
                throw new Exception("R文件生成失败! 请检查清单文件是否正确!");
            }


            FileTool.SafeDeleteDirectory(R_Path);
            Directory.Delete(R_Path);

            //cmd.Execute("java -jar baksmali-2.1.3.jar classes.dex");
        }
예제 #2
0
        public void ConfusionDLL(string filePath)
        {
            string dllPath = filePath + @"\assets\bin\Data\Managed\Assembly-CSharp.dll";
            string outPath = filePath + @"\assets\bin\Data\Managed\Assembly-CSharp_Secure\Assembly-CSharp.dll";
            string outDir  = filePath + @"\assets\bin\Data\Managed\Assembly-CSharp_Secure";

            CmdService cmd = new CmdService(OutPut, errorCallBack);

            //混淆
            cmd.Execute(@"DotNETReactor\dotNET_Reactor.exe -file " + dllPath);

            //覆盖
            File.Copy(outPath, dllPath, true);

            //删除旧文件
            File.Delete(outPath);
            Directory.Delete(outDir);
        }
        public void Jar2Smali(string jarPath, string filePath)
        {
            string smaliPath    = filePath + "\\smali";
            string JavaTempPath = PathTool.GetCurrentPath() + "\\JavaTempPath";
            string jarName      = FileTool.GetFileNameByPath(jarPath);
            string tempPath     = JavaTempPath + "\\" + jarName;

            FileTool.CreatPath(JavaTempPath);

            CmdService cmd = new CmdService(OutPut, errorCallBack);

            //Jar to dex
            cmd.Execute("java -jar dx.jar --dex --output=" + tempPath + " " + jarPath);

            //dex to smali
            cmd.Execute("java -jar baksmali-2.1.3.jar --o=" + smaliPath + " " + tempPath);

            //删除临时目录
            FileTool.DeleteDirectory(JavaTempPath);
            Directory.Delete(JavaTempPath);
        }
예제 #4
0
            public void Repackage()
            {
                try
                {
                    for (int i = 0; i < channelList.Count; i++)
                    {
                        ChannelInfo channelInfo = channelList[i];

                        if (string.IsNullOrEmpty(EditorData.AndroidSdkPath))
                        {
                            throw new Exception("AndroidSdkPath 不能为空!");
                        }

                        if (string.IsNullOrEmpty(EditorData.SdkLibPath))
                        {
                            throw new Exception("SdkLibPath 不能为空!");
                        }

                        if (string.IsNullOrEmpty(EditorData.BuildToolVersion))
                        {
                            throw new Exception("BuildToolVersion 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.keyStorePath))
                        {
                            throw new Exception("keyStore 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStorePassWord))
                        {
                            throw new Exception("KeyStore PassWord 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStoreAlias))
                        {
                            throw new Exception("Alias 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStoreAliasPassWord))
                        {
                            throw new Exception("Alias PassWord 不能为空!");
                        }

                        string fileName  = FileTool.GetFileNameByPath(repackageInfo.apkPath);
                        string aimPath   = outPath + "\\" + FileTool.RemoveExpandName(fileName);
                        string apkPath   = aimPath + "\\dist\\" + fileName;
                        string finalPath = repackageInfo.exportPath + "\\" + FileTool.RemoveExpandName(fileName) + ".apk";

                        if (!string.IsNullOrEmpty(channelInfo.suffix))
                        {
                            finalPath = repackageInfo.exportPath + "\\" + FileTool.RemoveExpandName(fileName) + "_" + channelInfo.suffix + ".apk";
                        }

                        CmdService  cmd         = new CmdService(OutPutCallBack, ErrorCallBack);
                        ChannelTool channelTool = new ChannelTool(OutPutCallBack, ErrorCallBack);

                        string apktool_version = "apktool";

                        //反编译APK
                        MakeProgress("反编译APK ", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("java -jar " + apktool_version + ".jar d -f " + repackageInfo.apkPath + " -o " + aimPath);

                        //执行对应的文件操作
                        MakeProgress("执行对应的文件操作", i, channelList.Count, channelInfo.Name);
                        channelTool.ChannelLogic(aimPath, channelInfo);

                        //移除过长的YML
                        MakeProgress("移除过长的YML", i, channelList.Count, channelInfo.Name);
                        channelTool.YMLLogic(aimPath);

                        //分包
                        MakeProgress("分包", i, channelList.Count, channelInfo.Name);
                        channelTool.SplitDex(aimPath);

                        ////混淆DLL
                        //MakeProgress("混淆DLL", i, channelList.Count, channelInfo.Name);
                        //channelTool.ConfusionDLL(aimPath);

                        //重新生成R表
                        MakeProgress("重新生成R表", i, channelList.Count, channelInfo.Name);
                        channelTool.Rebuild_R_Table(aimPath);

                        //重打包
                        MakeProgress("重打包", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("java -jar " + apktool_version + ".jar b " + aimPath, true, true);

                        //进行签名
                        MakeProgress("进行签名", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("jarsigner" // -verbose
                                                //+ " -tsa https://timestamp.geotrust.com/tsa"
                                    + " -digestalg SHA1 -sigalg MD5withRSA"
                                    + " -storepass " + channelInfo.KeyStorePassWord
                                    + " -keystore " + channelInfo.KeyStorePath
                                    + " -sigFile CERT" //强制将RSA文件更名为CERT
                                    + " " + apkPath
                                    + " " + channelInfo.KeyStoreAlias
                                    );

                        //进行字节对齐并导出到最终目录
                        MakeProgress("进行字节对齐并导出到最终目录", i, channelList.Count, channelInfo.Name);
                        cmd.Execute(EditorData.GetZipalignPath() + " -f  4 " + apkPath + " " + finalPath);

                        if (EditorData.IsAutoInstall)
                        {
                            //自动安装
                            MakeProgress("自动安装", i, channelList.Count, channelInfo.Name);
                            cmd.Execute("adb install -r " + finalPath, true, true);
                        }

                        if (channelInfo.IsDeleteTempPath)
                        {
                            //删除临时目录
                            MakeProgress("删除临时目录", i, channelList.Count, channelInfo.Name);
                            FileTool.SafeDeleteDirectory(aimPath);
                        }
                        else
                        {
                            //删除临时目录
                            MakeProgress("跳过删除临时目录", i, channelList.Count, channelInfo.Name);
                        }


                        MakeProgress("完成", i, channelList.Count, channelInfo.Name);
                    }
                }
                catch (Exception e)
                {
                    ErrorCallBack(e.ToString());
                }
            }
            public void Repackage()
            {
                try
                {
                    for (int i = 0; i < channelList.Count; i++)
                    {
                        ChannelInfo channelInfo = channelList[i];

                        if (string.IsNullOrEmpty(channelInfo.keyStorePath))
                        {
                            throw new Exception("keyStore 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStorePassWord))
                        {
                            throw new Exception("KeyStore PassWord 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStoreAlias))
                        {
                            throw new Exception("Alias 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStoreAliasPassWord))
                        {
                            throw new Exception("Alias PassWord 不能为空!");
                        }

                        string fileName  = FileTool.GetFileNameByPath(repackageInfo.apkPath);
                        string aimPath   = outPath + "\\" + FileTool.RemoveExpandName(fileName);
                        string apkPath   = aimPath + "\\dist\\" + fileName;
                        string finalPath = repackageInfo.exportPath + "\\" + FileTool.RemoveExpandName(fileName) + ".apk";

                        if (!string.IsNullOrEmpty(channelInfo.suffix))
                        {
                            finalPath = repackageInfo.exportPath + "\\" + FileTool.RemoveExpandName(fileName) + "_" + channelInfo.suffix + ".apk";
                        }

                        CmdService  cmd         = new CmdService(OutPutCallBack, ErrorCallBack);
                        ChannelTool channelTool = new ChannelTool(OutPutCallBack, ErrorCallBack);

                        string apktool_version = "apktool";

                        //MakeProgress("移除过长的YML", i, channelList.Count, channelInfo.Name);
                        //channelTool.YMLLogic(aimPath);

                        //反编译APK
                        MakeProgress("反编译APK ", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("java -jar " + apktool_version + ".jar d -f " + repackageInfo.apkPath + " -o " + aimPath);

                        //执行对应的文件操作
                        MakeProgress("执行对应的文件操作", i, channelList.Count, channelInfo.Name);
                        channelTool.ChannelLogic(aimPath, channelInfo);

                        //移除过长的YML
                        MakeProgress("移除过长的YML", i, channelList.Count, channelInfo.Name);
                        channelTool.YMLLogic(aimPath);

                        ////混淆DLL
                        //MakeProgress("混淆DLL", i, channelList.Count, channelInfo.Name);
                        //channelTool.ConfusionDLL(aimPath);

                        //重打包
                        MakeProgress("重打包", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("java -jar " + apktool_version + ".jar b " + aimPath);

                        //进行签名
                        MakeProgress("进行签名", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("jarsigner" // -verbose
                                                //+ " -tsa https://timestamp.geotrust.com/tsa"
                                    + " -digestalg SHA1 -sigalg MD5withRSA"
                                    + " -storepass " + channelInfo.KeyStorePassWord
                                    + " -keystore " + channelInfo.KeyStorePath
                                    + " " + apkPath
                                    + " " + channelInfo.KeyStoreAlias
                                    );

                        //进行字节对齐并导出到最终目录
                        MakeProgress("进行字节对齐并导出到最终目录", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("zipalign -f  4 " + apkPath + " " + finalPath);

                        //删除临时目录
                        MakeProgress("删除临时目录", i, channelList.Count, channelInfo.Name);

                        FileTool.SafeDeleteDirectory(aimPath);
                        Directory.Delete(aimPath);

                        MakeProgress("完成", i, channelList.Count, channelInfo.Name);
                    }
                }
                catch (Exception e)
                {
                    ErrorCallBack(e.ToString());
                }
            }
예제 #6
0
        public string BuildRTable(string aimPath, string name, string sdkPath)
        {
            string result = "";

            String R_Path = aimPath + "/R_path/";

            FileTool.CreatPath(R_Path);

            //String androidPath = @"D:\AndroidSDK\platforms\android-28\android.jar";
            string manifest = aimPath + "/AndroidManifest.xml";
            string resPath  = aimPath + "/res";

            CmdService cmd = new CmdService(OutPut, errorCallBack);

            //生成R文件
            cmd.Execute(EditorData.GetAAPTPath() + " package -f -I " + EditorData.GetAndroidJarPath(29) + " -m -J " + R_Path + " -S " + resPath + " -M " + manifest + "");

            //aapt2
            //cmd.Execute(EditorData.GetAAPT2Path() + " link -I " + EditorData.GetAndroidJarPath(29) + " --java " + R_Path + " -A " + resPath + " --manifest " + manifest + " -v");

            if (FindRPath(R_Path) != null)
            {
                string javaPath = FindRPath(R_Path);
                string jarPath  = R_Path + "/" + name + "_R.jar";
                string rPath    = aimPath + "/R.txt";

                ////替换ID
                ////有时不同aar包的R.id 会冲突,这里使用aar自带的R.id,进行替换,如果还不行再改
                //result += RTableUtil.AnalysisRJava(javaPath);

                //编译R.java文件
                cmd.Execute("javac -encoding UTF-8 -source 1.7 -target 1.7 " + javaPath, true, true);

                //删除掉java文件
                FileTool.DeleteFile(javaPath);

                cmd.Execute("cd " + R_Path);

                //取第一个文件夹名作为命令开头
                string fileName = FileTool.GetDirectoryName(Directory.GetDirectories(R_Path)[0]);

                //生成的R文件的jar
                cmd.Execute("jar cvf ./" + name + "_R.jar ./" + fileName, path: R_Path);

                if (File.Exists(jarPath))
                {
                    //复制R文件到库
                    File.Copy(jarPath, sdkPath + "/" + name + "_R.jar", true);

                    result += "R文件生成完成! ";
                }
            }
            else
            {
                result += "R文件生成失败! 请检查清单文件是否正确!";
            }

            //FileTool.SafeDeleteDirectory(R_Path);
            //Directory.Delete(R_Path);

            return(result);
        }
예제 #7
0
        public void Rebuild_R_Table(string aimPath)
        {
            OutPut("创建临时目录");
            String R_Path = PathTool.GetCurrentPath() + "/R_path/";

            FileTool.CreatPath(R_Path);
            //OutPut("生成R文件");
            //OutPut("生成的R文件的jar");
            //OutPut("生成 dex文件");
            //OutPut("生成smali文件");
            //OutPut("替换smali文件");

            //String androidPath = @"D:\AndroidSDK\platforms\android-28\android.jar";
            string manifest  = aimPath + "/AndroidManifest.xml";
            string resPath   = aimPath + "/res";
            string smaliPath = aimPath + "/smali";

            CmdService cmd = new CmdService(OutPut, errorCallBack);

            OutPut("生成R.java文件");

            //OutPut("R_Path " + R_Path + " resPath " + resPath + " manifest " + manifest);

            //生成R文件
            cmd.Execute(EditorData.GetAAPTPath() + " package -f -I " + EditorData.GetAndroidJarPath(29) + " -m -J " + R_Path + " -S " + resPath + " -M " + manifest + " --debug-mode");

            //aapt2
            //cmd.Execute(EditorData.GetAAPT2Path() + " link -I " + EditorData.GetAndroidJarPath(29) + " -java " + R_Path + " -A " + resPath + " --manifest " + manifest + " -v");

            if (FindRPath(R_Path) != null)
            {
                //GBK转码
                //string java = FileTool.ReadStringByFile(FindRPath(R_Path));
                //java = compileTool.RemoveSpecialCode(java);
                //FileTool.WriteStringByFile(FindRPath(R_Path),java);

                //转换smli文件
                RTableUtil rt = new RTableUtil();
                rt.callBack      += OutPut;
                rt.errorCallBack += ErrorOutPut;
                rt.GenerateRKV(FindRPath(R_Path));

                rt.ReplaceRTable(smaliPath);

                OutPut("编译R.java文件");
                //编译R.java文件
                cmd.Execute("javac -encoding UTF-8 -source 1.7 -target 1.7 " + FindRPath(R_Path), true, true);

                //取第一个文件夹名作为命令开头
                string fileName = FileTool.GetDirectoryName(Directory.GetDirectories(R_Path)[0]);

                OutPut("生成的R文件的jar");
                //生成的R文件的jar
                cmd.Execute("jar cvf ./R.jar ./" + fileName, path: R_Path);

                OutPut("Jar to dex");
                //Jar to dex
                cmd.Execute("java -jar " + EditorData.GetDxPath() + " --dex --output=./R_path/classes.dex ./R_path/R.jar ", true, true);

                OutPut("dex to smali");
                //dex to smali
                cmd.Execute("java -jar baksmali-2.1.3.jar --o=" + aimPath + "/smali ./R_path/classes.dex");
            }
            else
            {
                throw new Exception("R文件生成失败! 请检查清单文件是否正确!");
            }

            FileTool.SafeDeleteDirectory(R_Path);

            //cmd.Execute("java -jar baksmali-2.1.3.jar classes.dex");

            OutPut("创建临时目录");
        }