Exploit database

GH-14fb583d3d1bd2da10251bb1a37b93d6

gitchw/ghostlock-cve-2026-43499

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

166 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files11

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

workspace/decomp/HeyOTA/sources/com/heytap/wearable/ota/util/CommonUtil.java

Java · 18,447 bytes
package com.heytap.wearable.ota.util;

import android.app.ActivityManager;
import android.content.ContentProviderClient;
import android.content.Context;
import android.icu.text.MeasureFormat;
import android.icu.util.Measure;
import android.icu.util.MeasureUnit;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import com.heytap.wearable.ota.activity.DetailEntry;
import com.heytap.wearable.ota.activity.EntryActivity;
import com.heytap.wearable.ota.db.DbHelper;
import com.heytap.wearable.ota.db.SharedPrefManager;
import com.oplus.stdid.sdk.StdIDSDK;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Locale;

/* loaded from: classes.dex */
public class CommonUtil {
    private static final Long DEFAULT_OTA_TIME = 540000L;
    private static final Long MAX_OTA_TIME = 1800000L;

    public static String getOperator() {
        return "";
    }

    public static boolean isOTADebug() {
        return 1 == SystemProperties.getInt("oppo.ota.debug.mode", 0);
    }

    public static boolean isUseTestServer() {
        return SystemProperties.getBoolean("persist.ota.testserver", false);
    }

    public static boolean isPreVersion() {
        return SystemProperties.getBoolean("persist.sys.special.version", false) && SystemProperties.get("ro.build.version.ota", "").contains("PRE");
    }

    public static int getNetworkType(Context context) {
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
        if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) {
            return 0;
        }
        int type = activeNetworkInfo.getType();
        if (type != 0) {
            if (type == 1) {
                return 1;
            }
            if (type != 2 && type != 3 && type != 4 && type != 5) {
                if (type != 7 && type != 17) {
                    return 8;
                }
                int i = Settings.Global.getInt(context.getContentResolver(), "bluetooth_proxy_network_type", 1);
                if (i == 1) {
                    return 7;
                }
                if (i == 0) {
                    return 6;
                }
                if (i != -1) {
                    return 8;
                }
                OppoLog.e("CommonUtil", "bluetooth_net_proxy_on=1 && bluetooth_proxy_network_type=-1, network is disabled");
                return 0;
            }
        }
        return 2;
    }

    public static String getOtaVersion() {
        String str = SystemProperties.get("debug.ota.otaversion", "");
        return !TextUtils.isEmpty(str) ? str : SystemProperties.get("ro.build.version.ota", "");
    }

    public static String getOtaVersionForDecription() {
        String otaVersion = getOtaVersion();
        if (otaVersion == null) {
            return "";
        }
        String[] split = otaVersion.replace("_INT", "").split("_");
        int[] iArr = {4, 12, 14};
        char[] charArray = otaVersion.toCharArray();
        if (split.length != iArr[0] || split[3].length() != iArr[1] || split[2].length() != iArr[0]) {
            return otaVersion;
        }
        charArray[otaVersion.length() - iArr[2]] = '0';
        return String.valueOf(charArray);
    }

    public static String getColorOSVersion() {
        String str = SystemProperties.get("ro.build.version.opporom");
        if (str == null || str.length() == 0) {
            str = "V1.0.0";
        }
        String lowerCase = str.toLowerCase(Locale.getDefault());
        String str2 = "alpha";
        if (!lowerCase.endsWith("alpha")) {
            str2 = lowerCase.endsWith("beta") ? "beta" : "";
        }
        int indexOf = str.indexOf("V") + 1;
        if (-1 == indexOf) {
            indexOf = 0;
        }
        int indexOf2 = str.indexOf("_");
        if (-1 == indexOf2) {
            indexOf2 = str.length();
        }
        return "ColorOS" + str.substring(indexOf, indexOf2).replaceAll("\n", " ") + str2;
    }

    public static String getAndroidVerison() {
        return "Android" + Build.VERSION.RELEASE;
    }

    public static String getRomVersion() {
        String str = SystemProperties.get("ro.build.display.id");
        if (str == null || str.length() == 0) {
            str = "V1.0.0";
        }
        return str.replaceAll("\n", " ");
    }

    public static String getDeviceId(Context context) {
        StdIDSDK.init(context);
        for (int i = 0; i < 5; i++) {
            String guid = StdIDSDK.getGUID(context);
            if (!TextUtils.isEmpty(guid)) {
                return guid;
            }
            OppoLog.e("CommonUtil", "getId fail, try " + i);
            try {
                Thread.sleep(500L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "0000000000000000000000000000000000000000000000000000000000000000";
    }

    public static String getNewVersionShowName(Context context) {
        return DbHelper.getOTAUpdateInfo(context).romVersion;
    }

    public static int getVersionForRus(Context context) {
        return new SharedPrefManager(context, 4).readInt("version_for_rus", 20200822);
    }

    public static void updateVersionForRus(Context context, int i) {
        new SharedPrefManager(context, 4).writePref("version_for_rus", i);
    }

    public static String getLocale() {
        StringBuilder sb = new StringBuilder();
        Locale locale = Locale.getDefault();
        String language = locale.getLanguage();
        String country = locale.getCountry();
        if (!TextUtils.isEmpty(language)) {
            sb.append(language);
            if (!TextUtils.isEmpty(country)) {
                sb.append("-");
                sb.append(country);
            }
        } else {
            sb.append("zh-CN");
        }
        return sb.toString();
    }

    public static int getTestMode() {
        String str = SystemProperties.get("sys.ota.test", "0");
        return (str == null || str.equals("") || !str.equals("1")) ? 0 : 1;
    }

    public static boolean getTestPolicy() {
        return SystemProperties.getBoolean("sys.ota.policy.test", false);
    }

    public static String getMobile() {
        String[] split;
        String otaVersion = getOtaVersion();
        return (otaVersion == null || (split = otaVersion.split("_")) == null || split.length < 1) ? "" : split[0];
    }

    public static boolean checkOtaIDValid(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        String[] split = str.split("_");
        int[] iArr = {4, 12, 3};
        return split.length == iArr[0] && split[3].length() == iArr[1] && (split[2].length() == iArr[0] || split[2].length() == iArr[2]);
    }

    public static boolean isScreenOn(Context context) {
        return ((PowerManager) context.getSystemService("power")).isScreenOn();
    }

    public static boolean isOTADetailActivityInFront(Context context) {
        String topActivity = ((ActivityManager) context.getSystemService("activity")).getTopActivity();
        return topActivity.equals(DetailEntry.class.getName()) || topActivity.contains("com.oppo.engineermode");
    }

    public static boolean isOTAEntryActivityInFront(Context context) {
        return ((ActivityManager) context.getSystemService("activity")).getTopActivity().equals(EntryActivity.class.getName());
    }

    public static boolean isOTAInFront(Context context) {
        String topActivity = ((ActivityManager) context.getSystemService("activity")).getTopActivity();
        return topActivity.contains("com.heytap.wearable.ota") || topActivity.contains("com.oppo.engineermode");
    }

    public static void removeSharePreData(Context context) {
        OppoLog.d("CommonUtil", "removeSharePreData");
        SharedPrefManager sharedPrefManager = new SharedPrefManager(context, 1);
        sharedPrefManager.remove("record_install_or_root_result");
        sharedPrefManager.remove("install_failed_type");
        sharedPrefManager.remove("install_failed_key");
        sharedPrefManager.remove("last_start_install_time");
        sharedPrefManager.remove("last_finish_install_time");
        sharedPrefManager.remove("download_state_key_and_value");
        sharedPrefManager.remove("ota_user_agree_download_in_watch_mobile_flag");
        sharedPrefManager.remove("ota_user_agree_download_in_watch_phone_flag");
        sharedPrefManager.remove("install_later_flag");
        sharedPrefManager.remove("later_install_power_flag");
        sharedPrefManager.remove("download_delayed_by_power_flag");
        sharedPrefManager.remove("is_manual_create_download_flag");
        sharedPrefManager.remove("last_proc_download_finish_notification_time");
        sharedPrefManager.remove("install_by_manual");
        setNewFlag(context, false);
    }

    public static Message createAutoUpdateStateMsg(Handler handler, int i, boolean z) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("is_auto_update", z);
        Message obtainMessage = handler.obtainMessage(i);
        obtainMessage.setData(bundle);
        return obtainMessage;
    }

    public static boolean getAutoUpdateStateFormMsg(Message message) {
        Bundle data = message.getData();
        if (data == null) {
            return false;
        }
        return data.getBoolean("is_auto_update", false);
    }

    public static CharSequence formatDuration(Context context, long j) {
        int i;
        int i2;
        int i3;
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        int floor = (int) Math.floor(j / 1000);
        int i4 = 0;
        if (floor >= 86400) {
            i2 = floor / 86400;
            floor -= 86400 * i2;
            i = 1;
        } else {
            i = 0;
            i2 = 0;
        }
        if (floor >= 3600) {
            i3 = floor / 3600;
            floor -= i3 * 3600;
            i++;
        } else {
            i3 = 0;
        }
        if (floor >= 60) {
            if (i < 2) {
                i4 = floor / 60;
                floor -= i4 * 60;
            } else {
                i3++;
            }
        }
        ArrayList arrayList = new ArrayList(4);
        if (i2 > 0) {
            arrayList.add(new Measure(Integer.valueOf(i2), MeasureUnit.DAY));
        }
        if (i3 > 0) {
            arrayList.add(new Measure(Integer.valueOf(i3), MeasureUnit.HOUR));
        }
        if (i4 > 0) {
            arrayList.add(new Measure(Integer.valueOf(i4), MeasureUnit.MINUTE));
        }
        if (arrayList.size() == 0) {
            arrayList.add(new Measure(Integer.valueOf(floor), MeasureUnit.SECOND));
        }
        spannableStringBuilder.append((CharSequence) MeasureFormat.getInstance(context.getResources().getConfiguration().locale, MeasureFormat.FormatWidth.NARROW).formatMeasures((Measure[]) arrayList.toArray(new Measure[arrayList.size()])));
        return spannableStringBuilder;
    }

    public static void setMonitorNetworkState(Context context, int i) {
        if (Settings.Global.getInt(context.getContentResolver(), "monitor_ota_private_network", 0) != i) {
            Settings.Global.putInt(context.getContentResolver(), "monitor_ota_private_network", i);
        }
    }

    public static void setNewFlag(Context context, boolean z) {
        if ((Settings.System.getInt(context.getContentResolver(), "has_new_ota_edition", 0) == 1) != z) {
            Settings.System.putInt(context.getContentResolver(), "has_new_ota_edition", z ? 1 : 0);
        }
    }

    public static boolean isAutoUpdateEnabled(Context context) {
        return isPreVersion() || new SharedPrefManager(context, 4).readInt("auto_update_switch_enabled", context.getPackageManager().hasSystemFeature("oppo.specialversion.exp.sellmode") ? 1 : 0) == 1;
    }

    public static void setAutoUpdateEnabled(Context context, boolean z) {
        new SharedPrefManager(context, 4).writePref("auto_update_switch_enabled", z ? 1 : 0);
    }

    public static boolean isSchoolModeEnabled(Context context) {
        return Settings.Global.getInt(context.getContentResolver(), "school_mode_status", 0) == 1;
    }

    public static String getPrintOtaVer(String str) {
        if (!checkOtaIDValid(str)) {
            return "unknown";
        }
        String[] split = str.split("_");
        String[] split2 = split[1].split("\\.");
        return split2[1] + "." + split2[2] + "_" + split[2] + split[3].replaceAll("\\d{8}(\\d{4})", "****$1");
    }

    public static String getPrintRomVer(String str) {
        String[] split = str.split("_");
        return split.length != 3 ? "unknown" : split[2];
    }

    public static String getPrintIMEI(Context context) {
        String deviceId = getDeviceId(context);
        if (deviceId.length() <= 10) {
            return "error id";
        }
        return deviceId.replaceAll("(.{5}).{" + (deviceId.length() - 10) + "}(.{5})", "$1*****$2");
    }

    public static String getFormattedSizeString(long j) {
        double d = j;
        return j < 1000 ? String.format("%.0f B", Double.valueOf(d)) : j < 1024 ? "1.0 KB" : j < 1024000 ? String.format("%.0f KB", Double.valueOf(d / 1024.0d)) : j < 1048576 ? "1.0 MB" : j < 104857600 ? String.format("%.1f MB", Double.valueOf(d / 1048576.0d)) : j < 1048576000 ? String.format("%.0f MB", Double.valueOf(d / 1048576.0d)) : j < 1073741824 ? "0.98 GB" : j < 10737418240L ? String.format("%.2f GB", Double.valueOf(d / 1.073741824E9d)) : String.format("%.1f GB", Double.valueOf(d / 1.073741824E9d));
    }

    public static String getFormattedDownloadSpeedString(long j) {
        double d = j;
        return j < 1000 ? String.format("%.0f B/s", Double.valueOf(d)) : j < 1024 ? "1.0 KB/S" : j < 1024000 ? String.format("%.0f KB/s", Double.valueOf(d / 1024.0d)) : j < 1048576 ? "1.0 MB/S" : j < 104857600 ? String.format("%.1f MB/s", Double.valueOf(d / 1048576.0d)) : j < 1048576000 ? String.format("%.0f MB/s", Double.valueOf(d / 1048576.0d)) : j < 1073741824 ? "0.98 GB/S" : j < 10737418240L ? String.format("%.2f GB/s", Double.valueOf(d / 1.073741824E9d)) : String.format("%.1f GB/s", Double.valueOf(d / 1.073741824E9d));
    }

    public static double calcuOtaPower(Context context, long j, long j2) {
        return ((context.getPackageManager().hasSystemFeature("oplus.wear.screen.round.small") ? 138.0d : 95.0d) * j2) / 3600000.0d;
    }

    public static long calcuOtaTime(Context context, long j) {
        long readLong = j - new SharedPrefManager(context, 1).readLong("last_start_install_time", j);
        return (readLong <= 0 || readLong > MAX_OTA_TIME.longValue()) ? DEFAULT_OTA_TIME.longValue() : readLong;
    }

    public static boolean isSporting(Context context) {
        ContentProviderClient contentProviderClient = null;
        boolean z = false;
        try {
            try {
                ContentProviderClient acquireUnstableContentProviderClient = context.getContentResolver().acquireUnstableContentProviderClient(Uri.parse("content://com.heytap.wearable.health.provider"));
                if (acquireUnstableContentProviderClient != null) {
                    try {
                        z = acquireUnstableContentProviderClient.call("isInSport", null, null).getBoolean("is_in_sport");
                    } catch (Exception e) {
                        e = e;
                        contentProviderClient = acquireUnstableContentProviderClient;
                        OppoLog.e("CommonUtil", "isInSport  " + e.getMessage());
                        if (contentProviderClient != null) {
                            contentProviderClient.close();
                        }
                        return z;
                    } catch (Throwable th) {
                        th = th;
                        contentProviderClient = acquireUnstableContentProviderClient;
                        if (contentProviderClient != null) {
                            contentProviderClient.close();
                        }
                        throw th;
                    }
                }
                if (acquireUnstableContentProviderClient != null) {
                    acquireUnstableContentProviderClient.close();
                }
            } catch (Exception e2) {
                e = e2;
            }
            return z;
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public static String[] parsePolicy(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        for (String str2 : str.split(";")) {
            if (str2.contains(OTAConstants.PROJECT_VERSION)) {
                return str2.split(",");
            }
        }
        return null;
    }

    public static boolean isHostAvailable(String str) {
        return isHostAvailable(str, 10000L);
    }

    public static boolean isHostAvailable(String str, long j) {
        try {
            DNSResolver dNSResolver = new DNSResolver(str);
            Thread thread = new Thread(dNSResolver);
            thread.start();
            thread.join(j);
            return dNSResolver.get() != null;
        } catch (Exception unused) {
            return false;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class DNSResolver implements Runnable {
        private String domain;
        private InetAddress inetAddr;

        public DNSResolver(String str) {
            this.domain = str;
        }

        @Override // java.lang.Runnable
        public void run() {
            try {
                set(InetAddress.getByName(this.domain));
            } catch (UnknownHostException e) {
                OppoLog.d("CommonUtil", "UnknownHostException:" + e.toString());
            }
        }

        public synchronized void set(InetAddress inetAddress) {
            this.inetAddr = inetAddress;
        }

        public synchronized InetAddress get() {
            return this.inetAddr;
        }
    }
}