Unity技术分享Unity教程合集

gson多版本兼容问题

2016-08-27  本文已影响868人  2b75747cf703

搞别人的app,必备神器gson,打印内存数据。
对方app如果已经包含gson,可能版本跟你的不兼容,那么就蛋疼了。。。

Paste_Image.png

ProcessHelper http://www.jianshu.com/p/d58925a50137

破解工具代码如下:

using Babybus.Framework.Extension;
using System.IO;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            PatchJar(@"C:\Users\Lin\Desktop\gson-2.6.1.jar");
        }

        static void DeleteDirectory(string path)
        {
            if (!Directory.Exists(path))
                return;

            foreach (var directory in Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly))
            {
                DeleteDirectory(directory);
            }

            foreach (var file in Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly))
            {
                File.Delete(file);
            }

            Directory.Delete(path);
        }

        static void Jar2Smali(string jarPath)
        {
            ProcessHelper.StartProcess("jar2dex.bat", jarPath + " --force");

            DeleteDirectory("out");

            var dex = Path.GetFileNameWithoutExtension(jarPath) + "-jar2dex.dex";

            ProcessHelper.StartProcess("baksmali.bat", dex);

            File.Delete(dex);
        }

        static void PatchJar(string sdkJar)
        {
            Directory.SetCurrentDirectory("C:/dex2jar-2.0");

            Jar2Smali(sdkJar);

            var files = Directory.GetFiles("out", "*", SearchOption.AllDirectories);
            foreach (var path in files)
            {
                var text = File.ReadAllText(path);

                text = Regex.Replace(text, @"Lcom/google/gson", "Lcom/qiang/gson");

                File.WriteAllText(path, text);
            }

            ProcessHelper.StartProcess("smali.bat", "out");

            ProcessHelper.StartProcess("dex2jar.bat", "out.dex --force");

            File.Delete("out.dex");

            var patchJar = Path.GetDirectoryName(sdkJar) + "/" + Path.GetFileNameWithoutExtension(sdkJar) + "-patch.jar";

            File.Copy("out-dex2jar.jar", patchJar, true);

            File.Delete("out-dex2jar.jar");

            Jar2Smali(patchJar);
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读