ProcessHelper
PatchJar(asProjectTemplateLibs + "/PluginAppUpdate.jar", delegate (string text)
{
return Regex.Replace(text, "com/baidu/autoupdatesdk/", "");
});
static void PatchJar(string jarPath, Func<string, string> replaceFunc)
{
if (!Path.IsPathRooted(jarPath))
jarPath = BabySystem.workspace + jarPath;
var currentDirectory = "dex2jar-2.0";
if (!Directory.Exists(currentDirectory))
{
var path = BabySystem.babyFrameWorkPath + "AndroidBuilder/Tools/dex2jar-2.0.zip";
if(Application.platform == RuntimePlatform.OSXEditor)
{
ProcessHelper.StartProcess("unzip", path);
}
else
{
using (ZipFile zip = ZipFile.Read(path))
{
zip.ExtractAll("");
}
}
}
if (Application.platform != RuntimePlatform.WindowsEditor)
ProcessHelper.StartProcess("/bin/chmod", "+x ./d2j_invoke.sh", true, currentDirectory);
var dexPath = jarPath + ".dex";
var smaliPath = jarPath + "-out";
ProcessHelper.StartProcess("d2j-jar2dex.bat", jarPath + " --force -o " + dexPath, true, currentDirectory);
ProcessHelper.StartProcess("d2j-dex2smali.bat", dexPath + " --force -o " + smaliPath, true, currentDirectory);
var files = Directory.GetFiles(smaliPath, "*", SearchOption.AllDirectories);
foreach (var path in files)
{
var text = File.ReadAllText(path);
File.WriteAllText(path, replaceFunc(text));
}
ProcessHelper.StartProcess("d2j-smali.bat", smaliPath + " -o " + dexPath, true, currentDirectory);
FileTools.DeleteFileOrDirectory(smaliPath);
ProcessHelper.StartProcess("d2j-dex2jar.bat", dexPath + " --force -o " + jarPath, true, currentDirectory);
FileTools.DeleteFileOrDirectory(dexPath);
}
网友评论