Exploit database

GH-14fb583d3d1bd2da10251bb1a37b93d6

gitchw/ghostlock-cve-2026-43499

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

170 sources

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

Repository files19

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

workspace/decomp/HeyOTA/sources/com/heytap/accessory/discovery/PeripheralManager.java

Java · 21,251 bytes
package com.heytap.accessory.discovery;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import com.heytap.accessory.api.IDiscoveryNativeService;
import com.heytap.accessory.api.IPeripheralCallback;
import com.heytap.accessory.api.IPeripheralService;
import com.heytap.accessory.api.ManagerConfig;
import com.heytap.accessory.bean.AdvertiseSetting;
import com.heytap.accessory.bean.AuthenticateMessage;
import com.heytap.accessory.bean.ConnectMessage;
import com.heytap.accessory.bean.DeviceInfo;
import com.heytap.accessory.bean.DiscoveryException;
import com.heytap.accessory.bean.Message;
import com.heytap.accessory.bean.SdkUnsupportedException;
import com.heytap.accessory.constant.AFConstants;
import com.heytap.accessory.discovery.BaseManager;
import com.heytap.accessory.logging.SdkLog;
import com.heytap.accessory.utils.HexUtils;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/* loaded from: classes.dex */
public class PeripheralManager extends BaseManager {
    public static final int ADVERTISE_FAILED_ALREADY_STARTED = 3;
    public static final int ADVERTISE_FAILED_DATA_TOO_LARGE = 1;
    public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 5;
    public static final int ADVERTISE_FAILED_INTERNAL_ERROR = 4;
    public static final int ADVERTISE_FAILED_SETUP_SERVER = 100;
    public static final int ADVERTISE_FAILED_TOO_MANY_ADVERTISERS = 2;
    public static final int CONNECT_RESULT_AGREE = 1;
    public static final int CONNECT_RESULT_AUTH_CUSTOMIZE = 4;
    public static final int CONNECT_RESULT_AUTH_PIN = 3;
    public static final int CONNECT_RESULT_REJECT = 2;
    public static final int ERROR_AUTHENTICATION_FAILED = 1;
    public static final int ERROR_DEVICE = 2;
    public static final int ERROR_NONE = 0;
    public static final int ERROR_PAIR_CONNECT_FAILED = 3;
    private static final String PREFIX = "ppl_";
    private static final String TAG = "PeripheralManager";
    private static volatile PeripheralManager sInstance;
    private Context mContext;
    private final Set<BaseManager.b> mManagerCallbackSet = new HashSet();
    private String mPackageName;
    private byte[] mPreRdi;
    private volatile IPeripheralService mService;

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public class PeripheralCallbackNative extends IPeripheralCallback.Stub {

        /* renamed from: a, reason: collision with root package name */
        private final IPeplCallback f72a;

        PeripheralCallbackNative(IPeplCallback iPeplCallback) {
            this.f72a = iPeplCallback;
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onAdvertiseFailure(int i) {
            Bundle bundle = new Bundle();
            bundle.putInt(Message.KEY_MSG_SCAN_TYPE, 1);
            bundle.putInt(Message.KEY_MSG_ERROR_CODE, i);
            onAdvertiseFailureV2(new Message(bundle));
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onAdvertiseFailureV2(Message message) {
            int i = message.getBundle().getInt(Message.KEY_MSG_ERROR_CODE);
            SdkLog.i(PeripheralManager.TAG, "onAdvertiseFailureV2 scanType : " + message.getBundle().getInt(Message.KEY_MSG_SCAN_TYPE) + ", err: " + i);
            try {
                this.f72a.onAdvertiseFailure(message);
            } catch (Exception e) {
                SdkLog.e(PeripheralManager.TAG, e);
            }
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onAdvertiseStopped() {
            Bundle bundle = new Bundle();
            bundle.putInt(Message.KEY_MSG_SCAN_TYPE, 1);
            onAdvertiseStoppedV2(new Message(bundle));
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onAdvertiseStoppedV2(Message message) {
            SdkLog.i(PeripheralManager.TAG, "onAdvertiseStoppedV2 scanType : " + message.getBundle().getInt(Message.KEY_MSG_SCAN_TYPE));
            try {
                this.f72a.onAdvertiseStopped(message);
            } catch (Exception e) {
                SdkLog.e(PeripheralManager.TAG, e);
            }
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onAdvertiseSuccess() {
            SdkLog.d(PeripheralManager.TAG, "onAdvertiseSuccess scanType : 1");
            Bundle bundle = new Bundle();
            bundle.putInt(Message.KEY_MSG_SCAN_TYPE, 1);
            try {
                this.f72a.onAdvertiseSuccess(new Message(bundle));
            } catch (Exception e) {
                SdkLog.e(PeripheralManager.TAG, e);
            }
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onAdvertiseSuccessV2(Message message) {
            PeripheralManager.this.mPreRdi = message.getBundle().getByteArray(Message.KEY_MSG_RDI);
            if (PeripheralManager.this.getFpCoreVersion() < 30003) {
                StringBuilder sb = new StringBuilder();
                sb.append("onAdvertiseSuccess preRdi : ");
                sb.append(PeripheralManager.this.mPreRdi != null ? HexUtils.byteArrayToHexStr(PeripheralManager.this.mPreRdi) : null);
                SdkLog.d(PeripheralManager.TAG, sb.toString());
                return;
            }
            int i = message.getBundle().getInt(Message.KEY_MSG_SCAN_TYPE);
            StringBuilder sb2 = new StringBuilder();
            sb2.append("onAdvertiseSuccessV2 scanType : ");
            sb2.append(i);
            sb2.append(", preRdi : ");
            sb2.append(PeripheralManager.this.mPreRdi != null ? HexUtils.byteArrayToHexStr(PeripheralManager.this.mPreRdi) : null);
            SdkLog.d(PeripheralManager.TAG, sb2.toString());
            try {
                this.f72a.onAdvertiseSuccess(message);
            } catch (Exception e) {
                SdkLog.e(PeripheralManager.TAG, e);
            }
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onPairFailure(DeviceInfo deviceInfo, Message message) {
            Bundle bundle = message.getBundle();
            if (bundle == null) {
                SdkLog.e(PeripheralManager.TAG, "onPairFailure failed, bundle is null");
                return;
            }
            try {
                this.f72a.onPairFailure(deviceInfo, bundle.getInt(Message.KEY_MSG_ERROR_CODE));
            } catch (Exception e) {
                SdkLog.e(PeripheralManager.TAG, e);
            }
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onPairSuccess(DeviceInfo deviceInfo) {
            try {
                this.f72a.onPairSuccess(deviceInfo);
            } catch (Exception e) {
                SdkLog.e(PeripheralManager.TAG, e);
            }
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onRequestAuthenticate(DeviceInfo deviceInfo, Message message) {
            Bundle bundle = message.getBundle();
            if (bundle == null) {
                SdkLog.e(PeripheralManager.TAG, "onRequestAuthenticate failed, bundle is null");
                return;
            }
            try {
                this.f72a.onRequestAuthenticate(deviceInfo, new AuthenticateMessage(bundle.getByteArray(Message.KEY_MSG_AUTH_DATA)));
            } catch (Exception e) {
                SdkLog.e(PeripheralManager.TAG, e);
            }
        }

        @Override // com.heytap.accessory.api.IPeripheralCallback
        public void onRequestConnect(DeviceInfo deviceInfo, Message message) {
            Bundle bundle = message.getBundle();
            if (bundle == null) {
                SdkLog.e(PeripheralManager.TAG, "onRequestConnect failed, bundle is null");
                return;
            }
            try {
                this.f72a.onRequestConnect(deviceInfo, new ConnectMessage(bundle.getByteArray(Message.KEY_MSG_CONNECT_DATA)));
            } catch (Exception e) {
                SdkLog.e(PeripheralManager.TAG, e);
            }
        }
    }

    /* loaded from: classes.dex */
    class a implements com.heytap.accessory.discovery.a {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ AdvertiseSetting f74a;

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ IPeplCallback f75b;

        a(AdvertiseSetting advertiseSetting, IPeplCallback iPeplCallback) {
            this.f74a = advertiseSetting;
            this.f75b = iPeplCallback;
        }

        @Override // com.heytap.accessory.discovery.a
        public void run() {
            PeripheralManager.this.startAdvertisingInternal(this.f74a, this.f75b);
        }
    }

    /* loaded from: classes.dex */
    class b implements com.heytap.accessory.discovery.a {
        b() {
        }

        @Override // com.heytap.accessory.discovery.a
        public void run() {
            PeripheralManager.this.stopAdvertisingInternal();
        }
    }

    private PeripheralManager() {
    }

    private boolean bindService(Context context) {
        if (this.mService != null) {
            SdkLog.i(TAG, "already bind service");
            return true;
        }
        Intent intent = new Intent(AFConstants.SCAN_SERVICE_INTENT);
        intent.setPackage(ManagerConfig.ACCESSORY_FRAMEWORK_PACKAGE);
        intent.putExtra(AFConstants.KEY_SUB_SERVICE, 2);
        return context.bindService(intent, this, 1);
    }

    /* JADX WARN: Multi-variable type inference failed */
    private synchronized boolean bindServiceSync(Context context) {
        long currentTimeMillis = System.currentTimeMillis();
        if (!bindService(context)) {
            SdkLog.e(TAG, "bindServiceSync failed");
            return false;
        }
        try {
            try {
                wait(9000L);
            } finally {
                SdkLog.i(TAG, "bind service cost: " + (System.currentTimeMillis() - currentTimeMillis));
            }
        } catch (InterruptedException e) {
            SdkLog.e(TAG, "bindServiceSync failed, InterruptedException: " + e.getMessage());
            e.printStackTrace();
        }
        return true;
    }

    public static PeripheralManager getInstance() {
        if (sInstance == null) {
            synchronized (PeripheralManager.class) {
                if (sInstance == null) {
                    sInstance = new PeripheralManager();
                }
            }
        }
        return sInstance;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static /* synthetic */ boolean lambda$onSubServiceConnected$0(BaseManager.b bVar) {
        boolean z = !bVar.f47a;
        bVar.f47a = true;
        return z;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void startAdvertisingInternal(AdvertiseSetting advertiseSetting, IPeplCallback iPeplCallback) {
        SdkLog.i(TAG, "startAdvertisingInternal, scanType:" + advertiseSetting.getScanType());
        if (this.mService == null) {
            SdkLog.e(TAG, "service is null");
            return;
        }
        try {
            advertiseSetting.setFpCoreVersion(getFpCoreVersion());
            if (this.mPreRdi != null) {
                byte[] bArr = {0, 0, 0, 0, 0, 0};
                if (advertiseSetting.getRdi() == null || Arrays.equals(advertiseSetting.getRdi(), bArr)) {
                    advertiseSetting.resetRdi(this.mPreRdi);
                }
            }
            this.mService.startAdvertising(advertiseSetting, new PeripheralCallbackNative(iPeplCallback));
        } catch (Exception e) {
            SdkLog.e(TAG, e);
            Bundle bundle = new Bundle();
            bundle.putInt(Message.KEY_MSG_ERROR_CODE, 100);
            bundle.putInt(Message.KEY_MSG_SCAN_TYPE, advertiseSetting.getScanType());
            iPeplCallback.onAdvertiseFailure(new Message());
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void stopAdvertisingInternal() {
        if (this.mService == null) {
            SdkLog.e(TAG, "service is null");
            return;
        }
        try {
            this.mService.stopAdvertising();
        } catch (Exception e) {
            SdkLog.e(TAG, e);
        }
    }

    public void createGroup(IPeplCallback iPeplCallback) throws DiscoveryException {
        SdkLog.i(TAG, "disable createGroup without debug");
    }

    @Override // com.heytap.accessory.discovery.BaseManager
    public /* bridge */ /* synthetic */ int getFpCoreVersion() {
        return super.getFpCoreVersion();
    }

    @Override // com.heytap.accessory.discovery.BaseManager
    protected String getPackageName() {
        return PREFIX + this.mPackageName;
    }

    @Override // com.heytap.accessory.discovery.BaseManager
    public /* bridge */ /* synthetic */ int getServiceVersion() {
        return super.getServiceVersion();
    }

    public synchronized boolean init(Context context) throws SdkUnsupportedException {
        SdkLog.i(TAG, "init");
        if (this.mService != null) {
            return true;
        }
        Context applicationContext = context.getApplicationContext();
        this.mContext = applicationContext;
        BaseManager.initAFMAccessory(applicationContext);
        this.mPackageName = this.mContext.getPackageName();
        if (bindServiceSync(this.mContext)) {
            return this.mService != null;
        }
        return false;
    }

    public void initAsync(Context context, IManagerCallback iManagerCallback) throws SdkUnsupportedException {
        SdkLog.i(TAG, "initAsync");
        if (this.mService != null) {
            iManagerCallback.onInited();
            return;
        }
        Context applicationContext = context.getApplicationContext();
        this.mContext = applicationContext;
        BaseManager.initAFMAccessory(applicationContext);
        this.mPackageName = this.mContext.getPackageName();
        synchronized (this.mManagerCallbackSet) {
            this.mManagerCallbackSet.add(new BaseManager.b(false, iManagerCallback));
        }
        if (bindService(this.mContext)) {
            return;
        }
        SdkLog.e(TAG, "initAsync, bind ScanService failed");
        onSubServiceDisconnected();
    }

    @Override // com.heytap.accessory.discovery.BaseManager, android.content.ServiceConnection
    public /* bridge */ /* synthetic */ void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        super.onServiceConnected(componentName, iBinder);
    }

    @Override // com.heytap.accessory.discovery.BaseManager, android.content.ServiceConnection
    public /* bridge */ /* synthetic */ void onServiceDisconnected(ComponentName componentName) {
        super.onServiceDisconnected(componentName);
    }

    @Override // com.heytap.accessory.discovery.BaseManager
    protected void onSubBindService(Context context) {
        bindServiceSync(context);
    }

    @Override // com.heytap.accessory.discovery.BaseManager
    protected void onSubServiceConnected(IDiscoveryNativeService iDiscoveryNativeService) {
        List list;
        SdkLog.i(TAG, "onSubServiceConnected");
        synchronized (this) {
            try {
                this.mService = iDiscoveryNativeService.getAdvertiseService();
                notifyAll();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
        List.of();
        synchronized (this.mManagerCallbackSet) {
            list = (List) this.mManagerCallbackSet.stream().filter(new Predicate() { // from class: com.heytap.accessory.discovery.-$$Lambda$PeripheralManager$6KqmJtTDpQlANPIWyIIZ3wwHK8c
                @Override // java.util.function.Predicate
                public final boolean test(Object obj) {
                    return PeripheralManager.lambda$onSubServiceConnected$0((BaseManager.b) obj);
                }
            }).map(new Function() { // from class: com.heytap.accessory.discovery.-$$Lambda$PeripheralManager$LuMqnkcTiphQa9SfjbjeFebA44Y
                @Override // java.util.function.Function
                public final Object apply(Object obj) {
                    IManagerCallback iManagerCallback;
                    iManagerCallback = ((BaseManager.b) obj).f48b;
                    return iManagerCallback;
                }
            }).collect(Collectors.toList());
        }
        list.forEach($$Lambda$jao6ooJJhKIvmFGirPbP16Y1xA.INSTANCE);
    }

    @Override // com.heytap.accessory.discovery.BaseManager
    protected void onSubServiceDisconnected() {
        List list;
        SdkLog.i(TAG, "onSubServiceDisconnected");
        this.mService = null;
        List.of();
        synchronized (this.mManagerCallbackSet) {
            list = (List) this.mManagerCallbackSet.stream().map(new Function() { // from class: com.heytap.accessory.discovery.-$$Lambda$PeripheralManager$akJGCDkIiAV4nsYEFjJrMkxUojQ
                @Override // java.util.function.Function
                public final Object apply(Object obj) {
                    IManagerCallback iManagerCallback;
                    iManagerCallback = ((BaseManager.b) obj).f48b;
                    return iManagerCallback;
                }
            }).collect(Collectors.toList());
            this.mManagerCallbackSet.clear();
        }
        list.forEach($$Lambda$x6LUMI97ky_K7TrH0qnHNFk4Ol8.INSTANCE);
    }

    public synchronized void release(Context context) {
        release();
    }

    public boolean responseAuthenticate(DeviceInfo deviceInfo, boolean z) throws DiscoveryException {
        SdkLog.i(TAG, "responseAuthenticate, deviceInfo: " + deviceInfo + ", agree: " + z);
        if (this.mService != null) {
            try {
                this.mService.responseAuthenticate(deviceInfo, z);
                return true;
            } catch (Exception e) {
                SdkLog.e(TAG, e);
                throw DiscoveryException.create(1, e.getMessage());
            }
        }
        throw DiscoveryException.create(2, "responseAuthenticate failed, service is null");
    }

    public boolean responseConnect(DeviceInfo deviceInfo, int i) throws DiscoveryException {
        SdkLog.i(TAG, "responseConnect, deviceInfo: " + deviceInfo + ", result: " + i);
        if (deviceInfo == null) {
            throw DiscoveryException.create(3, "deviceInfo shouldn't be null");
        }
        if (i >= 1 && i <= 4) {
            if (this.mService != null) {
                try {
                    this.mService.responseConnect(deviceInfo, i);
                    return true;
                } catch (Exception e) {
                    SdkLog.e(TAG, e);
                    throw DiscoveryException.create(1, e.getMessage());
                }
            }
            throw DiscoveryException.create(2, "responseConnect failed, service is null");
        }
        throw DiscoveryException.create(3, "unknown connect result: " + i);
    }

    public void saveModelId(byte[] bArr, byte[] bArr2) {
        try {
            SdkLog.i(TAG, "save modelId and remoteDeviceId");
            Bundle bundle = new Bundle();
            bundle.putInt(AFConstants.KEY_BUSINESS_TYPE, 3);
            bundle.putByteArray("model_id", bArr2);
            bundle.putByteArray(AFConstants.KEY_REMOTE_DEVICE_ID, bArr);
            this.mService.saveParameters(bundle);
        } catch (RemoteException e) {
            SdkLog.e(TAG, e.toString());
            e.printStackTrace();
        }
    }

    public int startAdvertise(AdvertiseSetting advertiseSetting, IPeplCallback iPeplCallback) throws DiscoveryException {
        if (this.mService != null) {
            startAdvertisingInternal(advertiseSetting, iPeplCallback);
            return 0;
        }
        Context context = this.mContext;
        if (context != null) {
            runOnBackGround(context, new a(advertiseSetting, iPeplCallback));
            return 0;
        }
        throw DiscoveryException.create(2, "startAdvertise failed, service and context is null");
    }

    public void stopAdvertise() throws DiscoveryException {
        if (this.mService != null) {
            stopAdvertisingInternal();
            return;
        }
        Context context = this.mContext;
        if (context != null) {
            runOnBackGround(context, new b());
            return;
        }
        throw DiscoveryException.create(2, "stopAdvertise failed, service and context is null");
    }

    public synchronized void release() {
        SdkLog.i(TAG, "release");
        Context context = this.mContext;
        if (context != null) {
            context.unbindService(this);
        }
        this.mService = null;
        this.mContext = null;
        synchronized (this.mManagerCallbackSet) {
            this.mManagerCallbackSet.clear();
        }
    }
}