Need Help with Writing my First Xposed Module to Bypass Audio Recording API Restrictions #1187
-
Hello LSPosed Community, Although I have been an LSPosed user for about a year now, I have never tried digging in to building an LSPosed module. I recently became interested in building, however with the goal of bypassing the Android API's restrictions on what apps can and cannot have their audio captured. I started by looking at the Android Developer documentation for capturing video and audio playback at https://developer.android.com/guide/topics/media/av-capture, and from there, started digging through the Android source code to try identifying what functions need hooked in order to make this work. I decided that the first one I would try would be the function that I believe processes the Since I have no experience with building Xposed modules, I decided that instead of starting a new project from nothing, I would instead use the DisableFlagSecure project code as a starting point and modify it to hook the function. Here is what I came up with as my modified function hook. package com.test.universal_audio_capture_enabler;
import android.media.AudioAttributes;
import android.os.Build;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
public class AudioCaptureEnabler implements IXposedHookLoadPackage {
// Useful Reference: https://developer.android.com/guide/topics/media/av-capture
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) {
// Filter by package names with "android" in them and limit hooking to Android 11.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Bypass "allowAudioPlaybackCapture" in AndroidManifest.xml
/* https://cs.android.com/android/platform/superproject/+/master:frameworks/
base/core/java/android/content/pm/parsing/ParsingPackageImpl.java;l=2539 */
try {
Class<?> parsingPkgImpl = XposedHelpers.findClass(
"android.content.pm.parsing.ParsingPackageImpl",
loadPackageParam.classLoader);
XposedHelpers.findAndHookMethod(
parsingPkgImpl,
"setAllowAudioPlaybackCapture",
XC_MethodReplacement.returnConstant(true));
} catch (Throwable t) {
XposedBridge.log(t);
}
}
}
} After making this change, compiling the app, installing it on my phone, enabling "System Framework" as well as another app to test audio recording with in the LSPosed manager app, and rebooting, I tried testing to see if the hook was working properly and instead had the following error in the logs:
Does anyone have any idea what I am doing wrong? In an earlier version that I tried to compile, I had a conditional just like the one in the Disable FLAG_SECURE code hook that read I ran in to this same issue whenever I was trying to hook two other functions for this project, but have left them out of here for now since I think one example is enough. Apparently, I am also going to have to add a native hook for the C-based Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
As an update, I figured out how to fix the above error. It turns out that I forgot to include the function arguments as part of the hook. Adding that fixed the issue! |
Beta Was this translation helpful? Give feedback.
As an update, I figured out how to fix the above error. It turns out that I forgot to include the function arguments as part of the hook. Adding that fixed the issue!