Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
hook native methods instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tehcneko committed May 28, 2024
1 parent ad92151 commit 622283d
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ private void hookWindowState(ClassLoader classLoader) throws ClassNotFoundExcept
hook(isSecureLockedMethod, SecureLockedHooker.class);
}

private static Class<?> captureArgsClazz;
private static Field captureSecureLayersField;
private static Field allowProtectedField;

Expand All @@ -214,15 +213,15 @@ private void hookScreenCapture(ClassLoader classLoader) throws ClassNotFoundExce
var screenCaptureClazz = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ?
classLoader.loadClass("android.window.ScreenCapture") :
SurfaceControl.class;
captureArgsClazz = classLoader.loadClass(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ?
var captureArgsClazz = classLoader.loadClass(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ?
"android.window.ScreenCapture$CaptureArgs" :
"android.view.SurfaceControl$CaptureArgs");
captureSecureLayersField = captureArgsClazz.getDeclaredField("mCaptureSecureLayers");
captureSecureLayersField.setAccessible(true);
allowProtectedField = captureArgsClazz.getDeclaredField("mAllowProtected");
allowProtectedField.setAccessible(true);
hookMethods(screenCaptureClazz, ScreenCaptureHooker.class, "captureDisplay");
hookMethods(screenCaptureClazz, ScreenCaptureHooker.class, "captureLayers");
hookMethods(screenCaptureClazz, ScreenCaptureHooker.class, "nativeCaptureDisplay");
hookMethods(screenCaptureClazz, ScreenCaptureHooker.class, "nativeCaptureLayers");
}

@TargetApi(Build.VERSION_CODES.S)
Expand Down Expand Up @@ -327,9 +326,6 @@ private static class ScreenCaptureHooker implements Hooker {
@BeforeInvocation
public static void before(@NonNull BeforeHookCallback callback) {
var captureArgs = callback.getArgs()[0];
if (!captureArgsClazz.isInstance(captureArgs)) {
return;
}
try {
captureSecureLayersField.set(captureArgs, true);
allowProtectedField.set(captureArgs, true);
Expand Down

0 comments on commit 622283d

Please sign in to comment.