From 134cd71fa0087c4705cee41c32e0ea28dccb4683 Mon Sep 17 00:00:00 2001 From: Nullptr Date: Mon, 4 Sep 2023 01:18:48 +0800 Subject: [PATCH] Wrap whole onTransact (#2740) --- .../lsposed/lspd/service/BridgeService.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java b/magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java index 5e292450..f40e7962 100644 --- a/magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java +++ b/magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java @@ -100,39 +100,43 @@ public class BridgeService { public static boolean onTransact(@NonNull Parcel data, @Nullable Parcel reply, int flags) { if (!ParcelUtils.safeEnforceInterface(data, DESCRIPTOR)) return false; - ACTION action = ACTION.values()[data.readInt()]; + try { + ACTION action = ACTION.values()[data.readInt()]; - Log.d(TAG, "onTransact: action=" + action + ", callingUid=" + Binder.getCallingUid() + ", callingPid=" + Binder.getCallingPid()); + Log.d(TAG, "onTransact: action=" + action + ", callingUid=" + Binder.getCallingUid() + ", callingPid=" + Binder.getCallingPid()); - switch (action) { - case ACTION_SEND_BINDER: { - if (Binder.getCallingUid() == 0) { - receiveFromBridge(data.readStrongBinder()); - if (reply != null) { - reply.writeNoException(); + switch (action) { + case ACTION_SEND_BINDER: { + if (Binder.getCallingUid() == 0) { + receiveFromBridge(data.readStrongBinder()); + if (reply != null) { + reply.writeNoException(); + } + return true; } - return true; + break; + } + case ACTION_GET_BINDER: { + IBinder binder = null; + try { + String processName = data.readString(); + IBinder heartBeat = data.readStrongBinder(); + var applicationService = service == null ? null : service.requestApplicationService(Binder.getCallingUid(), Binder.getCallingPid(), processName, heartBeat); + if (applicationService != null) binder = applicationService.asBinder(); + } catch (RemoteException e) { + Log.e(TAG, Log.getStackTraceString(e)); + } + if (binder != null && reply != null) { + reply.writeNoException(); + Log.d(TAG, "got binder is " + binder); + reply.writeStrongBinder(binder); + return true; + } + return false; } - break; - } - case ACTION_GET_BINDER: { - IBinder binder = null; - try { - String processName = data.readString(); - IBinder heartBeat = data.readStrongBinder(); - var applicationService = service == null ? null : service.requestApplicationService(Binder.getCallingUid(), Binder.getCallingPid(), processName, heartBeat); - if (applicationService != null) binder = applicationService.asBinder(); - } catch (RemoteException e) { - Log.e(TAG, Log.getStackTraceString(e)); - } - if (binder != null && reply != null) { - reply.writeNoException(); - Log.d(TAG, "got binder is " + binder); - reply.writeStrongBinder(binder); - return true; - } - return false; } + } catch (Throwable e) { + Log.e(TAG, "onTransact", e); } return false; }