各大平台自更新SDK破解

作者: 2b75747cf703 | 来源:发表于2016-08-12 18:12 被阅读870次

    如果你的产品需要做互推,而你没有自己的服务器,或者你的服务器不够稳定,或者想省下一大笔服务器流量费。。。

    天下没有破解不了的自更新SDK,因为自更新SDK所需要的数据(包名、版本号、是否已经安装等)都是可以伪造的。

    以下C#代码是SDK破解工具

    ProcessHelper

    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\xiaomi_sdk.jar");
                PatchJar(@"C:\Users\Lin\Desktop\BDAutoUpdateSDK_20150605_V1.2.0.jar");
                PatchJar(@"C:\Users\Lin\Desktop\UpdateLib_2.0.8.jar");
            }
    
            static void PatchJar(string sdkJar)
            {
                Directory.SetCurrentDirectory("C:/dex2jar-2.0");
    
                ProcessHelper.StartProcess("jar2dex.bat", sdkJar + " --force");
    
                var dex = Path.GetFileNameWithoutExtension(sdkJar) + "-jar2dex.dex";
    
                ProcessHelper.StartProcess("baksmali.bat", dex);
    
                File.Delete(dex);
    
                var files = Directory.GetFiles("out", "*", SearchOption.AllDirectories);
                foreach (var path in files)
                {
                    var text = File.ReadAllText(path);
    
                    //替换getPackageInfo
                    text = Regex.Replace(text, @"invoke-virtual {([pv][0-9]+, [pv][0-9]+, [pv][0-9]+)}, Landroid/content/pm/PackageManager;->getPackageInfo\(Ljava/lang/String;I\)Landroid/content/pm/PackageInfo;", (match) =>
                    {
                        return "invoke-static {" + match.Groups[1].Value + "}, Lcom/sinyee/babybus/plugins/PluginAppUpdate;->getPackageInfo(Landroid/content/pm/PackageManager;Ljava/lang/String;I)Landroid/content/pm/PackageInfo;";
                    });
    
                    //替换getApplicationInfo
                    text = Regex.Replace(text, @"invoke-virtual {([pv][0-9]+, [pv][0-9]+, [pv][0-9]+)}, Landroid/content/pm/PackageManager;->getApplicationInfo\(Ljava/lang/String;I\)Landroid/content/pm/ApplicationInfo;", (match) =>
                    {
                        return "invoke-static {" + match.Groups[1].Value + "}, Lcom/sinyee/babybus/plugins/PluginAppUpdate;->getApplicationInfo(Landroid/content/pm/PackageManager;Ljava/lang/String;I)Landroid/content/pm/ApplicationInfo;";
                    });
    
                    //替换包名
                    text = Regex.Replace(text, @"invoke-virtual {[pv][0-9]+}, Landroid/content/Context;->getPackageName\(\)Ljava/lang/String;", "invoke-static {}, Lcom/sinyee/babybus/plugins/PluginAppUpdate;->getPackageName()Ljava/lang/String;");
    
                    //替换版本名
                    text = Regex.Replace(text, "iget-object ([pv][0-9]+), [pv][0-9]+, Landroid/content/pm/PackageInfo;->versionName:Ljava/lang/String;", (match) =>
                    {
                        return "invoke-static {}, Lcom/sinyee/babybus/plugins/PluginAppUpdate;->getVersionName()Ljava/lang/String;\n    move-result-object " + match.Groups[1].Value;
                    });
    
                    //替换版本号
                    text = Regex.Replace(text, "iget ([pv][0-9]+), [pv][0-9]+, Landroid/content/pm/PackageInfo;->versionCode:I", (match) =>
                    {
                        return "invoke-static {}, Lcom/sinyee/babybus/plugins/PluginAppUpdate;->getVersionCode()I\n    move-result " + match.Groups[1].Value;
                    });
    
                    File.WriteAllText(path, text);
                }
    
                ProcessHelper.StartProcess("smali.bat", "out");
    
                Directory.Delete("out", true);
    
                ProcessHelper.StartProcess("dex2jar.bat", "out.dex --force");
    
                File.Delete("out.dex");
    
                File.Copy("out-dex2jar.jar", Path.GetDirectoryName(sdkJar) + "/" + Path.GetFileNameWithoutExtension(sdkJar) + "-patch.jar", true);
    
                File.Delete("out-dex2jar.jar");
            }
        }
    }
    

    以下为Java调用代码

    package com.sinyee.babybus.plugins;
    
    import android.app.Activity;
    import android.app.Application;
    import android.content.pm.ApplicationInfo;
    import android.content.pm.PackageInfo;
    import android.content.pm.PackageManager;
    import android.os.Bundle;
    
    import com.baidu.autoupdatesdk.AppUpdateInfo;
    import com.baidu.autoupdatesdk.AppUpdateInfoForInstall;
    import com.baidu.autoupdatesdk.BDAutoUpdateSDK;
    import com.baidu.autoupdatesdk.CPCheckUpdateCallback;
    import com.qihoo.appstore.updatelib.AppInfo;
    import com.qihoo.appstore.updatelib.UpdateManager;
    import com.sinyee.babybus.listeners.AppUpdateListener;
    import com.xiaomi.market.sdk.UpdateResponse;
    import com.xiaomi.market.sdk.UpdateStatus;
    import com.xiaomi.market.sdk.XiaomiUpdateAgent;
    import com.xiaomi.market.sdk.XiaomiUpdateListener;
    
    import java.lang.reflect.Method;
    
    public class PluginAppUpdate
    {
        public class Platform
        {
            public static final int Baidu = 0;
            public static final int Qihoo = 1;
            public static final int Tencent = 2;
            public static final int Xiaomi = 3;
        }
    
        private static String packageName = "";
        private static String versionName = "1.0";
        private static int versionCode = 1;
    
        private static Application application;
    
        static
        {
            final Class<?> activityThreadClass;
            try
            {
                activityThreadClass = Class.forName("android.app.ActivityThread");
                final Method method = activityThreadClass.getMethod("currentApplication");
                application = (Application) method.invoke(null, (Object[]) null);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    
        public static String getPackageName()
        {
            return packageName;
        }
    
        public static String getVersionName()
        {
            return versionName;
        }
    
        public static int getVersionCode()
        {
            return versionCode;
        }
    
        public static PackageInfo getPackageInfo(PackageManager packageManager, String packageName, int flags) throws PackageManager.NameNotFoundException {
            if(packageName.equals(PluginAppUpdate.packageName))
                packageName = application.getPackageName();
    
            return packageManager.getPackageInfo(packageName, flags);
        }
    
        public static ApplicationInfo getApplicationInfo(PackageManager packageManager, String packageName, int flags) throws PackageManager.NameNotFoundException {
            if(packageName.equals(PluginAppUpdate.packageName))
                packageName = application.getPackageName();
    
            return packageManager.getApplicationInfo(packageName, flags);
        }
    
        public static void getUpdateInfo(Activity currentActivity, String packageName, int platform, final AppUpdateListener appUpdateListener)
        {
            PluginAppUpdate.packageName = packageName;
    
            switch (platform) {
                case Platform.Baidu:
                    BDAutoUpdateSDK.cpUpdateCheck(currentActivity, new CPCheckUpdateCallback() {
                        public void onCheckUpdateCallback(AppUpdateInfo info, AppUpdateInfoForInstall infoForInstall) {
                            if (info != null)
                                appUpdateListener.onCheckComplete(info.getAppUrl(), info.getAppVersionName(), info.getAppVersionCode(), info.getAppChangeLog());
                            else
                                appUpdateListener.onCheckComplete("", "", 0, "");
                        }
                    });
                    break;
    
                case Platform.Qihoo:
                    UpdateManager.checkUpdate(currentActivity, false, false, packageName, new UpdateManager.CheckUpdateListener() {
                        public void onResult(boolean status, Bundle data) {
                            if(status == false)
                                return;
    
                            AppInfo updateInfo = (AppInfo) data.getParcelable(UpdateManager.KEY_UPDATE_INFO);
                            if(updateInfo != null)
                                appUpdateListener.onCheckComplete(updateInfo.downloadUrl, updateInfo.versioName, (int)updateInfo.versionCode, updateInfo.updateComment);
                            else
                                appUpdateListener.onCheckComplete("", "", 0, "");
                        }
                    });
                    break;
    
                case Platform.Tencent:
                    break;
    
                case Platform.Xiaomi:
                    XiaomiUpdateAgent.setUpdateListener(new XiaomiUpdateListener() {
                        @Override
                        public void onUpdateReturned(int updateStatus, UpdateResponse updateInfo) {
                            if (updateStatus == UpdateStatus.STATUS_UPDATE)
                                appUpdateListener.onCheckComplete(updateInfo.path, updateInfo.versionName, updateInfo.versionCode, updateInfo.updateLog);
                            else
                                appUpdateListener.onCheckComplete("", "", 0, "");
                        }
                    });
    
                    XiaomiUpdateAgent.setUpdateAutoPopup(false);
    
                    XiaomiUpdateAgent.update(currentActivity);
                    break;
            }
        }
    }
    
    package com.sinyee.babybus.listeners;
    
    public interface AppUpdateListener
    {
        void onCheckComplete(String url, String versionName, int versionCode, String updateLog);
    }
    

    相关文章

      网友评论

        本文标题:各大平台自更新SDK破解

        本文链接:https://www.haomeiwen.com/subject/wuresttx.html