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);
        }
Example #2
0
        static string GetSavePath(string recordName)
        {
            string path = PathTool.GetCurrentPath() + "\\" + c_directoryName + "\\" + recordName + ".json";

            return(path);
        }
Example #3
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("创建临时目录");
        }