예제 #1
0
    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.CreatePath(JavaTempPath);

        CmdService cmd = new CmdService(OutPut, errorCallBack);

        OutPut("放入Jar :" + jarName);

        //Jar to dex
        cmd.Execute("java -jar " + EditorData.GetDxPath() + " --dex --output=" + tempPath + " " + jarPath, true, true);

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

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

        //删除临时目录
        FileTool.DeleteDirectory(JavaTempPath);
        Directory.Delete(JavaTempPath);
    }
예제 #2
0
    public void Compile(SDKConfig sdkConfig, ChannelInfo channelInfo, string filePath)
    {
        string smaliPath           = filePath + "\\smali";
        string JavaCompileTempPath = PathTool.GetCurrentPath() + "\\JavaCompileTempPath";
        string JavaCompileSrcPath  = PathTool.GetCurrentPath() + "\\JavaCompileTempPath\\Src";
        string JavaCompileLibPath  = PathTool.GetCurrentPath() + "\\JavaCompileTempPath\\Lib";
        string JavaFilePath        = JavaCompileTempPath + "\\smali.java";
        string classFilePath       = JavaCompileTempPath + "\\Class";
        string dexFilePath         = JavaCompileTempPath + "\\smali.dex";

        CmdService cmd = new CmdService(OutPut, errorCallBack);

        //构造编译环境
        //创建Java类(替换关键字)
        for (int i = 0; i < sdkConfig.customJavaClass.Count; i++)
        {
            string javaName = JavaCompileSrcPath + "\\" + sdkConfig.customJavaClass[i].key + ".java";
            string s        = ReplaceKeyWord(sdkConfig.customJavaClass[i].value, channelInfo);
            FileTool.WriteStringByFile(javaName, s);
        }

        //复制Java库
        string libs = "";

        for (int i = 0; i < sdkConfig.customJavaLibrary.Count; i++)
        {
            string p = JavaCompileLibPath + "\\" + FileTool.GetFileNameByPath(sdkConfig.customJavaLibrary[i]);
            libs += p + ";";
            FileTool.CreateFilePath(p);

            string libPath = EditorData.SdkLibPath + sdkConfig.customJavaLibrary[i];
            File.Copy(libPath, p, true);
        }

        //创建导出目录
        FileTool.CreatePath(classFilePath);

        //Java to class
        cmd.Execute("javac  -classpath " + libs + " " + JavaCompileSrcPath + "\\*.java -d " + classFilePath);

        //class to dex
        cmd.Execute("java -jar " + EditorData.GetDxPath() + " --verbose --dex --output=" + dexFilePath + " " + classFilePath);

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

        //删除临时目录
        FileTool.DeleteDirectory(JavaCompileTempPath);
        Directory.Delete(JavaCompileTempPath);
    }