V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
estk
V2EX  ›  生活

AntiDefraudAppManager. Java

  •  
  •   estk · 2022-11-30 00:34:35 +08:00 · 2139 次点击
    这是一个创建于 725 天前的主题,其中的信息可能已经有所发展或是发生改变。
    package com.miui.guardprovider.engine.mi.antidefraud;
    
    import android.content.Context;
    import android.content.pm.PackageInfo;
    import android.content.pm.PackageManager;
    import android.content.pm.Signature;
    import android.os.Build;
    import android.text.TextUtils;
    import android.util.Log;
    import com.miui.guardprovider.GuardApplication;
    import com.miui.guardprovider.d.b;
    import com.miui.guardprovider.engine.mi.antivirus.NetworkApiHelper;
    import com.xiaomi.onetrack.OneTrack;
    import java.net.URLEncoder;
    import java.security.MessageDigest;
    import java.util.ArrayList;
    import java.util.List;
    import org.json.JSONArray;
    import org.json.JSONObject;
    
    public class AntiDefraudAppManager {
        private static final boolean DEBUG = GuardApplication.c;
        private static final String DETECT_APPS_URL = "https://flash.sec.miui.com/detect/app";
        private static final String MIUI_VERSION = ("MIUI-" + Build.VERSION.INCREMENTAL);
        private static final String SALT_FLASH = "6988567a-4220-4b51-bc2d-ccdec27a74a1";
        private static final String TAG = "AntiDefraudAppManager";
    
        private AntiDefraudAppManager() {
        }
    
        public static String[] getAllDetectUnsafeApps() {
            try {
                String allUnSystemAppsStatus = getAllUnSystemAppsStatus(getUnSystemAppList(GuardApplication.d));
                if (TextUtils.isEmpty(allUnSystemAppsStatus)) {
                    return new String[0];
                }
                MiDetectAppsManager.getInstance(GuardApplication.d).saveDetectApps(allUnSystemAppsStatus);
                JSONObject jSONObject = new JSONObject(allUnSystemAppsStatus);
                if (jSONObject.has("error_code")) {
                    if (DEBUG) {
                        Log.d("TAG", "error_code: " + jSONObject.getInt("error_code"));
                    }
                    return new String[0];
                }
                JSONArray optJSONArray = jSONObject.optJSONArray("data");
                ArrayList arrayList = new ArrayList();
                if (optJSONArray != null) {
                    for (int i = 0; i < optJSONArray.length(); i++) {
                        JSONObject optJSONObject = optJSONArray.optJSONObject(i);
                        if (optJSONObject != null) {
                            if (optJSONObject.optInt("basisOf") == 2) {
                                arrayList.add(optJSONObject.optString(OneTrack.Param.PKG));
                            }
                        }
                    }
                }
                String[] strArr = new String[arrayList.size()];
                for (int i2 = 0; i2 < arrayList.size(); i2++) {
                    strArr[i2] = (String) arrayList.get(i2);
                }
                return strArr;
            } catch (Exception e) {
                Log.e(TAG, "getAllDetectUnsafeApps error, ", e);
                return new String[0];
            }
        }
    
        public static String getAllUnSystemAppsStatus(List<AntiDefraudAppInfo> list) {
            try {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
                jSONObject.put("os", MIUI_VERSION);
                jSONObject.put("biz_id", "virus_scan");
                jSONObject.put("uuid", b.a());
                JSONArray jSONArray = new JSONArray();
                for (int i = 0; i < list.size(); i++) {
                    JSONObject jSONObject2 = new JSONObject();
                    AntiDefraudAppInfo antiDefraudAppInfo = list.get(i);
                    jSONObject2.put(OneTrack.Param.PKG, antiDefraudAppInfo.getPkgName());
                    jSONObject2.put("version", antiDefraudAppInfo.getVersion());
                    jSONObject2.put("signature", antiDefraudAppInfo.getSign());
                    jSONObject2.put("appname", antiDefraudAppInfo.getAppName());
                    jSONArray.put(jSONObject2);
                }
                jSONObject.put("content", jSONArray);
                String doPost = NetworkApiHelper.doPost(GuardApplication.d, DETECT_APPS_URL, jSONObject, SALT_FLASH);
                if (DEBUG) {
                    Log.w("TAG", "responseDetectApp get: " + doPost);
                }
                return doPost;
            } catch (Exception e) {
                Log.e(TAG, "getAllUnSystemAppsStatus error, ", e);
                return null;
            }
        }
    
        public static String getDetectUnsafeAppStatus(String str) {
            if (MiDetectAppsManager.getInstance(GuardApplication.d).virusInMiEngineRiskList(str)) {
                return str;
            }
            return null;
        }
    
        public static String getMessageDigest(byte[] bArr) {
            char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
            try {
                MessageDigest instance = MessageDigest.getInstance("MD5");
                instance.update(bArr);
                byte[] digest = instance.digest();
                int length = digest.length;
                char[] cArr2 = new char[(length * 2)];
                int i = 0;
                for (byte b2 : digest) {
                    int i2 = i + 1;
                    cArr2[i] = cArr[(b2 >>> 4) & 15];
                    i = i2 + 1;
                    cArr2[i2] = cArr[b2 & 15];
                }
                return new String(cArr2);
            } catch (Exception e) {
                Log.e(TAG, "getMessageDigest error, ", e);
                return null;
            }
        }
    
        private static Signature[] getRawSignature(Context context, String str) {
            if (!(str == null || str.length() == 0)) {
                try {
                    PackageInfo packageInfo = context.getPackageManager().getPackageInfo(str, 64);
                    if (packageInfo == null) {
                        return null;
                    }
                    return packageInfo.signatures;
                } catch (PackageManager.NameNotFoundException e) {
                    Log.e(TAG, "getRawSignature error, ", e);
                }
            }
            return null;
        }
    
        public static String getSign(Context context, String str) {
            Signature[] rawSignature = getRawSignature(context, str);
            if (rawSignature == null || rawSignature.length == 0) {
                return null;
            }
            return getMessageDigest(rawSignature[0].toByteArray());
        }
    
        public static List<AntiDefraudAppInfo> getUnSystemAppList(Context context) {
            PackageManager packageManager = context.getPackageManager();
            List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);
            ArrayList arrayList = new ArrayList();
            for (PackageInfo packageInfo : installedPackages) {
                if ((packageInfo.applicationInfo.flags & 1) != 1) {
                    String str = packageInfo.packageName;
                    AntiDefraudAppInfo antiDefraudAppInfo = new AntiDefraudAppInfo();
                    antiDefraudAppInfo.setPkgName(str);
                    antiDefraudAppInfo.setVersion(String.valueOf(packageInfo.versionCode));
                    antiDefraudAppInfo.setSign(getSign(context, str));
                    try {
                        antiDefraudAppInfo.setAppName(URLEncoder.encode(packageInfo.applicationInfo.loadLabel(packageManager).toString(), "UTF-8"));
                    } catch (Exception e) {
                        Log.e(TAG, "getUnSystemAppList error, ", e);
                    }
                    arrayList.add(antiDefraudAppInfo);
                }
            }
            return arrayList;
        }
    
        public static void updateAllDetectApps(Context context) {
            try {
                String allUnSystemAppsStatus = getAllUnSystemAppsStatus(getUnSystemAppList(GuardApplication.d));
                if (!TextUtils.isEmpty(allUnSystemAppsStatus)) {
                    MiDetectAppsManager.getInstance(context).saveDetectApps(allUnSystemAppsStatus);
                }
            } catch (Exception e) {
                Log.e(TAG, "updateAllDetectApps error, ", e);
            }
        }
    }
    
    3 条回复    2022-12-15 13:46:55 +08:00
    abvatous
        1
    abvatous  
       2022-12-02 13:48:15 +08:00
    这个怎么用?用在那个版本的手机?什么版本的代码?
    estk
        2
    estk  
    OP
       2022-12-02 15:42:13 +08:00
    @abvatous #1
    这位师爷真的是装糊涂的高手?
    jackOff
        3
    jackOff  
       2022-12-15 13:46:55 +08:00 via Android
    ssr ssr:
    华为 DNS 大军如下,可能不全
    ||grs.dbankcloud.com11^$important
    ||openapi-drcn.cloud.dbankcloud.cn^$important
    ||business-drcn.cloud.dbankcloud.cn^$important
    ||userk-drcn.cloud.dbankcloud.cn^$important
    ||extensions-drcn.cloud.dbankcloud.cn^$important
    ||syncdrive-drcn.cloud.dbankcloud.cn^$important
    ||conf-drcn.cloud.dbankcloud.cn^$important
    ||imlong-sa-p03-drcn.platform.dbankcloud.cn^$important
    ||im-drcn.platform.dbankcloud.cn^$important
    ||recommend-drcn.hms.dbankcloud.cn^$important
    ||logservice1.dbankcloud.cn^$important
    ||connectivitycheck.cbg-app.huawei.com^$important
    ||nsp-logservice-hiview-p43-drcn.obs.cn-north-2.myhuaweicloud.com^$important
    ||query.hicloud.com^$important
    ||cqs-drcn.emui.hicloud.com^$important
    ||dnkeeper.hicloud.com^$important
    ||terms1.hicloud.com^$important
    ||h5hosting.dbankcdn.com.c.cdnhwc1.com^$important
    ||appdl6-drcn.dbankcdn.80800000.globalsign.c.cdnhwc1.cn^$important
    ||cloudres-drcn.dbankcdn.cn^$important
    ||h5hosting.dbankcdn.com^$important
    ||h5hosting.dbankcdn.com.cdn.dnsv1.com^$important
    ||aop-pic-drcn.dbankcdn.com^$important
    ||appdlc-drcn.hispace.dbankcloud.cn^$important
    ||appoptimize-drcn.dbankcdn.cn^$important
    ||uc-drcn.hispace.dbankcloud.cn^$important
    ||store-drcn.hispace.dbankcloud.cn^$important
    ||appdl-drcn.dbankcdn.com^$important
    ||appimg.dbankcdn.com^$important
    ||appdl-2-drcn.dbankcdn.com^$important
    ||gs-drcn.game.dbankcloud.com^$important
    ||browserr-drcn.dbankcdn.cn^$important
    ||gs-drcn.game.dbankcloud.cn^$important
    ||gps-drcn.game.dbankcloud.cn^$important
    ||trs-drcn.push.hihonorcloud.com^$important
    ||configserver.hicloud.com^$important
    ||logservice-drcn.dt.hihonorcloud.com^$important
    ||selfservice-cn.hihonor.com^$important
    ||assetscdn.c.hihonor.com^$important
    ||connectivitycheck.platform.hihonorcloud.com^$important
    ||connect-api.cloud.huawei.com^$important
    ||apm.yun.hihonor.com^$important
    ||apppromotion-drcn.dbankcdn.cn^$important
    ||events-drcn.op.dbankcloud.com^$important
    ||ai-drcn.op.hihonorcloud.com^$important
    ||seccloud.ipd.hihonor.com^$important
    ||connect-drcn.dbankcloud.cn^$important
    ||contentcenter-drcn.dbankcdn.cn^$important
    ||feeds-drcn.cloud.huawei.com.cn^$important
    ||browseraps-drcn.dbankcdn.cn^$important
    ||cs02-pps-drcn.dbankcdn.com.c.cdnhwc1.com^$important
    ||cs02-pps-drcn.dbankcdn.com.cdn.dnsv1.com^$important
    ||appimg.dbankcdn.com.c.cdnhwc1.com^$important
    ||appimg.dbankcdn.com.cdn.dnsv1.com^$important
    ||browseraps-drcn.dbankcdn.80800000.globalsign.c.cdnhwc1.cn^$important
    ||browseraps-drcn.dbankcdn.cn.cdn.dnsv1.com^$important
    ||cs02-pps-drcn.dbankcdn.cn.cdn.dnsv1.com^$important
    ||cs02-pps-drcn.dbankcdn.globalsign.c.cdnhwc1.cn^$important
    ||feeds-drcn.dbankcdn.cn.cdn.dnsv1.com^$important
    ||feeds-drcn.dbankcdn.globalsign.c.cdnhwc1.cn^$important
    ||contentcenter-drcn.dbankcdn.globalsign.c.cdnhwc1.cn^$important
    ||browserr-drcn.dbankcdn.globalsign.c.cdnhwc1.cn^$important
    ||browserr-drcn.dbankcdn.cn.cdn.dnsv1.com^$important
    ||api.cloud.huawei.com^$important
    ||browsercfg-drcn.cloud.dbankcloud.cn^$important
    ||upfile-drcn.platform.hicloud.com^$important
    ||cs02-pps-drcn.dbankcdn.cn^$important
    ||contentcenter-videovali-drcn.dbankcdn.cn^$important
    ||feeds-drcn.dbankcdn.cn^$important
    ||connectivitycheck.platform.hicloud.com^$important
    ||grs.platform.dbankcloud.ru^$important
    ||grs.dbankcloud.asia^$important
    ||hivision-drcn.emui.dbankcloud.com^$important
    ||api-drcn.theme.dbankcloud.cn^$important
    ||musicorder.hicloud.com^$important
    ||terms-drcn.platform.dbankcloud.cn^$important
    ||service-cn.hwccpc.com^$important
    ||httpdns.huaweicloud.com^$important
    ||metrics1-drcn.dt.dbankcloud.cn^$important
    ||oauth-login-drcn.platform.dbankcloud.com^$important
    ||grs.dbankcloud.asia11^$important
    ||grs.dbankcloud.eu11^$important
    ||grs.dbankcloud.cn11^$important
    ||grs.hihonorcloud.com^$important
    ||grs.dbankcloud.com^$important
    ||dnkeeper.platform.dbankcloud.cn^$important

    ||events-drcn.op.dbankcloud.cn^$important
    ||httpdns.c.cdnhwc2.com^$important
    ||hwid-drcn.platform.hicloud.com^$important
    ||sdkserver-drcn.op.dbankcloud.cn^$important
    ||hwid.platform.hicloud.com^$important
    ||hw-sdk.open.talk.getui.cn^$important
    ||msch.f.360.cn^$important
    ||ubacollect-drcn.cloud.dbankcloud.cn^$important
    ||openlocation-drcn.platform.dbankcloud.com^$important
    grs.dbankcloud.eu.home
    grs.dbankcloud.eu
    grs.dbankcloud.com
    cloudres-dra.dbankcdn.com
    grs.dbankcloud.cn
    openapi5.dbank.com
    appoptimize-dra.dbankcdn.com.home
    appdl2.dbankcdn.com
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   929 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:31 · PVG 06:31 · LAX 14:31 · JFK 17:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.