[SOLVED][Help] Using the hooked app's resources in beforeHookedmethod - Xposed Framework Development

Hello, I am trying to hook a method and use the hooked app's resources in it, but I keep getting an error. Can you please have a look?
Code:
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && (lpparam.packageName.contains("android.keyguard") || lpparam.packageName.contains("com.android.systemui"))) {
Class<?> KeyguardHostView = XposedHelpers.findClass("com.android.keyguard.KeyguardSecurityContainer",lpparam.classLoader);
findAndHookMethod(KeyguardHostView, "showSecurityScreen", "com.android.keyguard.KeyguardSecurityModel$SecurityMode", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Context ctx = ((FrameLayout) param.thisObject).getContext();
mStartTranslation = ctx.getResources().getDimensionPixelOffset(R.dimen.appear_y_translation_start) * translationScaleFactor;
}); }}
The relevant source for the hooked method is here https://github.com/temasek/android_...droid/keyguard/KeyguardSecurityContainer.java
Thank you for your time.

Rijul.A said:
Hello, I am trying to hook a method and use the hooked app's resources in it, but I keep getting an error. Can you please have a look?
Code:
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && (lpparam.packageName.contains("android.keyguard") || lpparam.packageName.contains("com.android.systemui"))) {
Class<?> KeyguardHostView = XposedHelpers.findClass("com.android.keyguard.KeyguardSecurityContainer",lpparam.classLoader);
findAndHookMethod(KeyguardHostView, "showSecurityScreen", "com.android.keyguard.KeyguardSecurityModel$SecurityMode", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Context ctx = ((FrameLayout) param.thisObject).getContext();
mStartTranslation = ctx.getResources().getDimensionPixelOffset(R.dimen.appear_y_translation_start) * translationScaleFactor;
}); }}
The relevant source for the hooked method is here https://github.com/temasek/android_...droid/keyguard/KeyguardSecurityContainer.java
Thank you for your time.
Click to expand...
Click to collapse
Depends on whether R.dimen.appear_y_translation_start is part of your module, or part of hooked package.
If it is part of hooked package resources you need to get it within hooked package context using proper identifier;
you cannot use identifier of resource you put in your module resources because it's completely different resource with different ID.
Example:
Code:
int resId = ctx.getResources().getIdentifier("appear_y_translation_start", "dimen", lpparam.packageName);
mStartTranslation = ctx.getResources().getDimensionPixelOffset(resId) * translationScaleFactor;
If this resource is part of your xposed module package, then you have to create package context using original context so you can get your module resources
which inherit proper display metrics from original package resources.
Code:
Context moduleContext = ctx.createPackageContext(myModulePackageName, Context.CONTEXT_IGNORE_SECURITY);
mStartTranslation = moduleContext.getResources().getDimensionPixelOffset(R.dimen.appear_y_translation_start) * translationScaleFactor;

C3C076 said:
Depends on whether R.dimen.appear_y_translation_start is part of your module, or part of hooked package.
If it is part of hooked package resources you need to get it within hooked package context using proper identifier;
you cannot use identifier of resource you put in your module resources because it's completely different resource with different ID.
Example:
Code:
int resId = ctx.getResources().getIdentifier("appear_y_translation_start", "dimen", lpparam.packageName);
mStartTranslation = ctx.getResources().getDimensionPixelOffset(resId) * translationScaleFactor;
If this resource is part of your xposed module package, then you have to create package context using original context so you can get your module resources
which inherit proper display metrics from original package resources.
Code:
Context moduleContext = ctx.createPackageContext(myModulePackageName, Context.CONTEXT_IGNORE_SECURITY);
mStartTranslation = moduleContext.getResources().getDimensionPixelOffset(R.dimen.appear_y_translation_start) * translationScaleFactor;
Click to expand...
Click to collapse
Thanks, that works very well. Can you please also explain to me how I can retrieve value of attribute resources (I think that's what they are called) from the hooked package resources?
Code:
android:textColor="?android:attr/textColorSecondary"
I want to get this colour (as used in XML) so that I can do it in code
Code:
mEmergencyButton.setTextColor(color)

In case someone is looking for a solution to this
Code:
TypedValue outValue = new TypedValue();
mContext.getTheme().resolveAttribute(android.R.attr.textColorSecondary, outValue, true);
int[] textSizeAttr = new int[] {android.R.attr.textColorSecondary};
TypedArray a = context.obtainStyledAttributes(outValue.data, textSizeAttr);
int textColor = a.getColor(0, -1);
a.recycle();
mEmergencyButton.setTextColor(textColor);
mContext.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
mEmergencyButton.setBackgroundResource(outValue.resourceId);

Related

[Help] Loading image to replace camera buffer

So I've created module to hijack an app's onPictureTaken callback method to manipulate the image-data that is returned from the Camera (android.hardware.Camera.PictureCallback).
I have succeeded to manipulate the image to return a Grayscale of it which was my first goal.
Now I want to replace the entire image with an image loaded from the filesystem which I'm unsuccessful in doing. I've tried different methods, paths etc. but haven't managed to do it. I've never been able to find the file which I want to load.
The full path of the image file I want to load is according to Solid Explorer
Code:
/storage/emulated/0/input.png
What code should I use to load the filesystem image into a Bitmap?
Do I need to take any extra Camera parameters into account that says stuff about the image?
Do I need take file permissions into account?
I'm running an OPO on Lollipop 5.0.2 / Cyanogen OS 12.0 / Xposed 67
This is the code I've used to create the Grayscale example:
Code:
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.os.Environment;
import java.io.ByteArrayOutputStream;
import java.io.File;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
public class CamHook implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
XposedBridge.log("Loaded app: " + lpparam.packageName);
if (!lpparam.packageName.equals("somepackage.somewhere.app"))
return;
XposedBridge.log("CamHook: We're here!");
findAndHookMethod("somepackage.somewhere.app.NewPhotoFragment$3$1", lpparam.classLoader, "onPictureTaken", "byte[]", "android.hardware.Camera", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("CamHook: before picture taken");
XposedBridge.log("CamHook: byteLength " + ((byte[]) (param.args)[0]).length);
byte[] bitmapdata = ((byte[]) (param.args)[0]);
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length);
XposedBridge.log("CamHook: StorageState: " + Environment.getExternalStorageState());
XposedBridge.log("CamHook: StoragePath: " + Environment.getExternalStorageDirectory().getAbsolutePath());
XposedBridge.log("CamHook: StoragePathEnv: " + System.getenv("EXTERNAL_STORAGE"));
//Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/input.jpg");
XposedBridge.log("CamHook: Bitmap is null: " + (bitmap == null));
bitmap = toGrayscale(bitmap);
ByteArrayOutputStream blob = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 0, blob);
param.args[0] = blob.toByteArray();
}
/*@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// this will be called after the clock was updated by the original method
}*/
});
}
public Bitmap toGrayscale(Bitmap bmpOriginal)
{
int width, height;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmpOriginal, 0, 0, paint);
return bmpGrayscale;
}
}
Does this mean it's working? App settings and YouTube adaway seem to work. But I know app settings can work without xposed
Did you get this to work?
Hi,
I found your thread. Did you ever get this to work?
Kind regards!
Hello did it work out for you? I am also looking into similar thing.
سلام

Help Xposed Connection

Hi, I'm new to the subject of modules for Xposed, I hope you can help.
1) I have managed to make a change in the status bar of android, with a few lines.
Code:
String methodeStatusBar = "com.android.systemui.statusbar.phone.PhoneStatusBar";
XposedHelpers.findAndHookMethod(methodeStatusBar, lpparam.classLoader, "makeStatusBarView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("Hola Mundo-> Xposed: " + param);
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
LinearLayout mStatusBarContents = (LinearLayout)XposedHelpers.getObjectField(param.thisObject, "mStatusBarContents");
mStatusBarContents.setBackgroundColor(Color.rgb(100, 100, 255));
XposedBridge.log("findAndHookMethod-> Xposed: " + mContext);
XposedBridge.log("findAndHookMethod-> Xposed: " + mStatusBarContents);
}
});
2) I manage to identify activity that has focus.
Code:
XposedHelpers.findAndHookMethod(Activity.class, "onWindowFocusChanged", boolean.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Activity activity = (Activity) param.thisObject;
}
});
3) but I can not connect "StatusBar" with "Activity", to extract the color of the "activity" and then set the "setBackgroundColor" the statusbar.
my question is: How can I connect "StatusBar" with "Activity"?
you can help me !!!!
translation "translate.google.com.do/".

Boolean Replacement

Hey Guys..
I have a problem with my xposed module.
I will a class to boolean false not true if rooted device..
Code:
public static boolean isRooted()
This to return false if rooted device..
Code:
XposedHelpers.findAndHockMethod("com.example.utils.RootCheck", lpparam.classLoader, "isRooted", boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.args[0] = false;
}
});
Xposed say me nosuchmethoderror com.example.utils.RootCheck#isRooted(boolean)..
Can help me..
Thanks
Sorry for my bad English i m a german.
what class is it, is it your own?
are you filtering by package name?
Is not my own class..
From another Application..
This is the class. i have decoded.
I want replace "public static final String" , public static boolean isRooted() to ever false and private static boolean a(String str) to ever false..
can help me?
Code:
public final class RootCheck {
public static final String VALUE_DEVICE_FLAG_SU = "su";
public static final String VALUE_DEVICE_FLAG_SUPER_USER_APK = "superuser.apk";
public static final String VALUE_DEVICE_FLAG_TEST_KEYS = "testkeys";
private RootCheck() {
}
public static boolean isRooted() {
BuildConfig.IS_PROD.booleanValue();
return false;
}
public static Object[] getFlags() {
int i;
int i2;
List arrayList;
Object[] objArr;
int i3 = 1;
String str = Build.TAGS;
if (str == null || !str.contains("test-keys")) {
i = 0;
} else {
i = 1;
}
try {
if (new File("/system/app/Superuser.apk").exists()) {
i2 = 1;
if (!(a("/system/xbin/which su") || a("/system/bin/which su") || a("which su"))) {
i3 = 0;
}
arrayList = new ArrayList();
if (i3 != 0) {
arrayList.add(VALUE_DEVICE_FLAG_SU);
}
if (i2 != 0) {
arrayList.add(VALUE_DEVICE_FLAG_SUPER_USER_APK);
}
if (i != 0) {
arrayList.add(VALUE_DEVICE_FLAG_TEST_KEYS);
}
objArr = new Object[0];
if (arrayList.isEmpty()) {
return arrayList.toArray(objArr);
}
return objArr;
}
} catch (Exception e) {
}
i2 = 0;
i3 = 0;
arrayList = new ArrayList();
if (i3 != 0) {
arrayList.add(VALUE_DEVICE_FLAG_SU);
}
if (i2 != 0) {
arrayList.add(VALUE_DEVICE_FLAG_SUPER_USER_APK);
}
if (i != 0) {
arrayList.add(VALUE_DEVICE_FLAG_TEST_KEYS);
}
objArr = new Object[0];
if (arrayList.isEmpty()) {
return objArr;
}
return arrayList.toArray(objArr);
}
private static boolean a(String str) {
try {
Runtime.getRuntime().exec(str);
return true;
} catch (Exception e) {
return false;
}
}
}
oh wait, isRooted doesn't take any arguments and you're trying to hook isRooted with a boolean argument, which would be a different method
return values are called result here (getResult, setResult.) args is only for arguments
Oh thx
Code:
06-17 22:21:05.373: E/Xposed(30470): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
06-17 22:21:05.373: E/Xposed(30470): at de.bozja.hrh.Hidder$1.beforeHookedMethod(Hidder.java:22)
Error why?
class
Code:
findAndHookMethod("com.example.RootCheck", lpparam.classLoader, "isRooted", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
boolean isRoot = (Boolean) param.getResult(); //Error on this line
if(isRoot == true)
isRoot = false;
param.setResult(isRoot);
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
boolean isRoot = (Boolean) param.getResult();
if(isRoot == true)
isRoot = false;
param.setResult(isRoot);
}
});
beforeHookedMethod is called before the method is executed, so there can't be any result. so it's null
Just setresult to false in beforehooked dont add extra junk
And dont hook method afterhook no need before will do what u need
gitfib said:
oh wait, isRooted doesn't take any arguments and you're trying to hook isRooted with a boolean argument, which would be a different method
return values are called result here (getResult, setResult.) args is only for arguments
Click to expand...
Click to collapse
i am also facing the same issue today when trying to hook some certain method that doesnt take in any argument. And i really didnt get the answer you gave. Could you be more elaborate please?
that was a long time. necrobumping from Google?
I think I meant to use param.setResult instead of param.args[0] to set the return value
gitfib said:
that was a long time. necrobumping from Google?
I think I meant to use param.setResult instead of param.args[0] to set the return value
Click to expand...
Click to collapse
thanks. Will try this too. Couldn't find it on Google
gitfib said:
that was a long time. necrobumping from Google?
I think I meant to use param.setResult instead of param.args[0] to set the return value
Click to expand...
Click to collapse
this is the method i want to hook. I want it to return false
public boolean vpn() {
try {
Iterator it = Collections.list(NetworkInterface.getNetworkInterfaces()).iterator();
String str = "";
do {
if (!it.hasNext()) {
return false;
}
NetworkInterface networkInterface = (NetworkInterface) it.next();
if (networkInterface.isUp()) {
str = networkInterface.getName();
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("IFACE NAME: ");
stringBuilder.append(str);
Log.d("DEBUG", stringBuilder.toString());
if (str.contains("tun") || str.contains("ppp")) {
Toast.makeText(getContext(), "Hello vpn detected", 1).show();
}
} while (!str.contains("pptp"));
Toast.makeText(getContext(), "Hello vpn detected", 1).show();
return true;
} catch (SocketException e) {
e.printStackTrace();
}
}
and this is my kotlin class
package app.devzeus.yesvpn.hook
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage
class hook: IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam?) {
val pakage = "com.eclipse.gamonyapp"
val className = "com.eclipse.gamonyapp.Fragments.OffersFragment"
val method = "vpn"
if (lpparam?.packageName == pakage){
XposedHelpers.findAndHookMethod(className, lpparam.classLoader, method, object: XC_MethodHook(){
override fun beforeHookedMethod(param: MethodHookParam?) {
super.beforeHookedMethod(param)
param?.result = false
}
})
}
}
}
am i doing it wrong? it still doesnt work. The class and method locations are correct
devzeus_ke said:
XposedHelpers.findAndHookMethod(className, lpparam.classLoader, method, object: XC_MethodHook(){
override fun beforeHookedMethod(param: MethodHookParam?) {
super.beforeHookedMethod(param)
param?.result = false
}
Click to expand...
Click to collapse
this should be a separate thread imo
XC_MethodHook | Xposed Framework API
api.xposed.info
in Java there would be no need for the super call and the syntax is .setResult, but I'm not sure in Kotlin
gitfib said:
this should be a separate thread imo
XC_MethodHook | Xposed Framework API
api.xposed.info
in Java there would be no need for the super call and the syntax is .setResult, but I'm not sure in Kotlin
Click to expand...
Click to collapse
about the .setResult(false) the compiler suggests .result = false

Xposed access variables in methods

Hello,
Iam working on a XposedModule and I need to get a variable from an other class. I have access to this class and I can access the global variables from this class but I can not access a variable which is only available in a method.
using:
Code:
Class<?> ProfileInfoClass = XposedHelpers.findClass("com.hi",lpparam.classLoader);
XposedBridge.hookAllMethods(ProfileInfoClass,"hie",new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
String s = (String)XposedHelpers.getObjectField(param.thisObject,"hello2"); //not found
}
});
with this class:
Code:
public class hi(){
String hello = "hello"; //This variable I can get
public void hie(){
String hello2 = "hi"; //This Variable I can not get using XposedHelpers.getObjectField(param.thisObject,"hello2");
}
}
Is there an other way to access variables inner Mehtods?
Thanks. Jojii
Nope, you can't.

How to access byte[] array from hooked method?

I'm a noob when it comes to both java and xposed, although I can more or less "read" java. I'm trying to create my first xposed plugin.
This is in the source (via jadx) from my original apk:
Code:
private void onHandle(byte[] data, int start, int length) {
byte b = data[start];
I wrote in my plugin:
Code:
findAndHookMethod("com.syu.ms.dev.ReceiverMcu", lpparam.classLoader, "onHandle", byte[].class, int.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
[B]byte[] data = assetAsByteArray(param.thisObject, "byte[].class");[/B]
int start = getIntField(param.thisObject, "start");
int length = getIntField(param.thisObject, "length");
byte b = data[start];
....... etcetera .................
The bold part is what I need. I know that this line of code is wrong, but I'm already trying (monkey like) all kinds of constructions, but I always get an error.
How can I access that "byte[] data" from my original apk in my plugin?
The arguments are in 'param.args'. Since you want to access the first one, what you need is 'byte[] data = (byte[]) param.args[0];'
JoseRebelo said:
The arguments are in 'param.args'. Since you want to access the first one, what you need is 'byte[] data = (byte[]) param.args[0];'
Click to expand...
Click to collapse
Thanks a lot. It compiles fine now.
Now see if it really works

Categories

Resources