How to cast param.args[] Object to Class? - Xposed General

Hello,
i try to cast
Object test = param.args[1]; to
TestClass new = (TestClass) test;
But I get an error that the Class is not created?
What am i missing here?
Code:
Class<?> TestClass = Class.forName("com.android.internal.x");
Class<?> HookClass = Class.forName("com.android.systemui.z", false, lpparam.classLoader);
XposedHelpers.findAndHookMethod(HookClass, "someMethod", IBinder.class, TestClass, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
{
Object test = param.args[1];
TestClass testConverted = (TestClass) test;
}
});

Why are you trying to cast it? You probably don't need to and can keep it as an Object.
(Can't say much more without an exact error.)

GermainZ said:
Why are you trying to cast it? You probably don't need to and can keep it as an Object.
(Can't say much more without an exact error.)
Click to expand...
Click to collapse
Solved, i used XposedHelpers.getObjectField
to get the field i needed.
Xposed is awesoeme
Danke!

Related

I'd like to decrease dialer vibration and I need help with that..

I'm completely noob.
Here are the sources
http://grepcode.com/file/repository...cFeedback.java#HapticFeedback.0mHapticPattern
Code:
public void init(Context context, boolean enabled) {
mEnabled = enabled;
if (enabled)
{
mVibrator = new SystemVibrator(context);
mHapticPattern = new long[] {0, DURATION, 2 * DURATION, 3 * DURATION};
mSystemSettings = new Settings.System();
mContentResolver = context.getContentResolver();
}
}
I need to change mHapticPattern array to adjust vibration duration on dialpad.
So, I can use that
Code:
findAndHookMethod("com.android.phone.common.HapticFeedback", lpparam.classLoader, "init", new XC_MethodHook()
{
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// BUT I don't know what I have to write here to get it working :(
// I know that this method will be called after init method and I don't know how I can change mHapticPattern array :(
}
});
Or I think I can also change value of Duration
private static final long DURATION = 10;
Click to expand...
Click to collapse
But anyway I do not know how...
I will be glad if anyone will try to help me...
Changing DURATION directly will have no effect. This is because the compiler replaces final static variables with their values (so "10" will be directly used instead of "DURATION").
What you could do is replace the init(Context context, boolean enabled) method entirely. Check out the development tutorial (and other wiki pages) for some hints on where to get started.
GermainZ said:
Changing DURATION directly will have no effect. This is because the compiler replaces final static variables with their values (so "10" will be directly used instead of "DURATION").
What you could do is replace the init(Context context, boolean enabled) method entirely. Check out the development tutorial (and other wiki pages) for some hints on where to get started.
Click to expand...
Click to collapse
Thank you for your answer. But I did not see it till now. That's why my respond is so late.
I had one experience with replacing entire method. But it was just a boolean method. I used this example http://forum.xda-developers.com/showpost.php?p=34609860&postcount=4
And also I've tried to replace whole init method but I have a problem with that string:
Code:
mVibrator = new SystemVibrator(context);
I did
import android.os.SystemVibrator;
but this "android.os.SystemVibrator;" is highlighted with red in eclipse
It says "The import android.os.SystemVibrator cannot be resolved" but the file exists...
I have a code but because of that error I can't test it
S0bes said:
It says "The import android.os.SystemVibrator cannot be resolved" but the file exists...
Click to expand...
Click to collapse
It's possible it's not in the SDK. Use XposedHelpers.findClass(...) to get the SystemVibrator class, then XposedHelpers.newInstance(...) to create a new instance.
@GermainZ please help me. This is the last thing I want to implement. Dialpad vibration is heavy and I think it's not good for vibro inside my phone.
This is what I try but Vibration is gone after that:
PHP:
package com.s0bes.fmspeaker;
import android.content.Context;
import android.os.Vibrator;
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 static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.newInstance;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
import android.content.ContentResolver;
import android.provider.Settings;
//import android.os.SystemVibrator;
public class bool1 {
static Context context;
private static Vibrator mVibrator ;
private static Settings.System mSystemSettings;
private static ContentResolver mContentResolver;
private static long[] mHapticPattern;
public static void InitResources(final LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("com.android.dialer")) {
XposedHelpers.findAndHookMethod("com.android.phone.common.HapticFeedback", lpparam.classLoader,
"init", Context.class, boolean.class, new XC_MethodHook() {
@Override protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
XposedBridge.log("HOOOKED init" );
//context=(Context) param.args[0];
}
});
XposedHelpers.findAndHookMethod("com.android.phone.common.HapticFeedback", lpparam.classLoader, "init", Context.class, boolean.class, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
context=(Context) param.args[0];
XposedBridge.log("REPLACED init. Enabled="+param.args[1] );
Class Myclass = findClass("android.os.SystemVibrator", lpparam.classLoader);
Object mVibrator = newInstance(Myclass, context);
mHapticPattern = new long[] {0, 10, 2 * 10, 8 * 10};
mSystemSettings = new Settings.System();
mContentResolver = context.getContentResolver();
return true;
}
});
}
}
}
EDIT:
Yeehoooo. I got this working
Your post http://forum.xda-developers.com/showpost.php?p=54951841&postcount=8 very helped me.
Instead replace init method I replaced vibrate();
PHP:
XposedHelpers.findAndHookMethod("com.android.phone.common.HapticFeedback", lpparam.classLoader, "vibrate", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
Class Myclass = findClass("android.os.SystemVibrator", lpparam.classLoader);
Object mVibrator = newInstance(Myclass, context);
mHapticPattern = new long[] {0, 10, 1 * 10, 1 * 10};
((Vibrator) mVibrator).vibrate(mHapticPattern, -1);
return true;
}
});
}

[Q] Use System context

Is there a way to use System context from non system app?
I try to create xposed module that enable double-tap to sleep in my specific app (the app is for G3 smart case only, so I try to mimic LG's stock Quick Circle apps).
I tried to override PowerManager.gotoSleep that will do
[CODEjava] mService.gotoSleep(time, GO_TO_SLEEP_REASON_DEVICE_ADMIN)[/CODE]
but it seem that the GO_TO_SLEEP_REASON_USER isn't the problem.
can I save the context of a system app for later use? using this code, context somewhy is null...
Java:
public class XposedModule implements IXposedHookLoadPackage {
static Context context;
[user=439709]@override[/user]
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("com.yoavst.quickapps")) {
findAndHookMethod("com.yoavst.quickapps.DoubleTapper", lpparam.classLoader, "onDoubleTap", Context.class, MotionEvent.class, new XC_MethodHook() {
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("onDoubleTap After; context: " + (context == null ? "null" : "notNull"));
if (context != null) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
powerManager.goToSleep(((MotionEvent) param.args[1]).getEventTime());
}
}
});
} else if (lpparam.packageName.equals("com.android.systemui")) {
findAndHookMethod("com.android.systemui.SystemUIService", lpparam.classLoader, "onCreate", new XC_MethodHook() {
[user=439709]@override[/user]
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// this will be called before the clock was updated by the original method
}
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("hooking onCreate: " + (param.thisObject == null ? "null" :"not Null"));
context = (Service) param.thisObject;
XposedBridge.log("context: " + (context == null ? "null" :"not Null"));
}
});
}
}
}
You could call AndroidAppHelper.currentApplication() if you need any context — it doesn't look you need the system's context anyway..
GermainZ said:
You could call AndroidAppHelper.currentApplication() if you need any context — it doesn't look you need the system's context anyway..
Click to expand...
Click to collapse
I need the context of an app with DEVICE_POWER permission (level 2 permission).
Oh, wait — your code won't work at all the way you expect it to work. Keep in mind the hooked code is running in the hooked app's process, so even though you set "context" in com.android.systemui, the "context" variable is still null in the "com.yoavst.quickapps" process (and will *always* be null).
You probably want to send a broadcast from your app instead, and register a BroadcastReceiver somewhere in SystemUI to handle it.
@yoavst you need to use a Device Policy Manager that will allow you to turn off the display. Doesn't even require root or xposed.

[Q] How to replace onMeasure method? Can't call setMeasuredDimension

Hi there. I'm trying to write a module for an app that looks like this:
Code:
public class ThirdPartyAppView extends View {
// ...
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// ...
// do some stuff to calculate desired dimensions
// ...
setMeasuredDimension(desiredWidth, desiredHeight);
}
// ...
}
I want to change the calculated dimensions, so I'm replacing the onMeasure method of this class, like this:
Code:
XC_MethodReplacement onMeasure_replacement = new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
View v = (View) param.thisObject;
int paramInt1 = (Integer) param.args[0];
int paramInt2 = (Integer) param.args[1];
// ...
// do MY OWN stuff to calculate desired dimensions
// ...
setMeasuredDimension(myDesiredWidth, myDesiredHeight); // here is the problem call
return null;
}
};
findAndHookMethod("com.third.party.app.ThirdPartyAppView",
lpparam.classLoader,
"onMeasure", int.class, int.class,
onMeasure_replacement);
The roadblock I'm hitting is
Code:
The method setMeasuredDimension(int, int) is undefined for the type new XC_MethodReplacement(){}
Any pointers?
On closer look, that should be v.setMeasuredDimension:
Code:
View v = (View) param.thisObject;
// ...
v.setMeasuredDimension(myDesiredWidth, myDesiredHeight); // here is the problem call
return null;
But both onMeasure() and setMeasuredDimension() are protected methods on class ThirdPartyAppView. How could I call them from the module? I can't instance ThirdPartyAppView...
Found a solution thanks to http://forum.xda-developers.com/showpost.php?p=57190802&postcount=2
Ended up hooking on the superclass instead (android.view.View), doing things before calling setMeasuredDimension() there, and checking class name within the hook. This did the trick.
Code:
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(com.third.party.app))
return;
XC_MethodHook setMeasuredDimensionHook = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.thisObject.getClass().getName().equals(com.third.party.app.ThirdPartyAppView") {
View v = (View) param.thisObject;
int paramInt1 = (Integer) param.args[0];
int paramInt2 = (Integer) param.args[1];
// ...
// calculate my dimensions here
// ...
param.args[0] = desiredWidth;
param.args[1] = desiredHeight;
}
};
findAndHookMethod("android.view.View",
lpparam.classLoader,
"setMeasuredDimension", int.class, int.class,
setMeasuredDimensionHook);
}
Nephiel said:
Found a solution thanks to http://forum.xda-developers.com/showpost.php?p=57190802&postcount=2
Ended up hooking on the superclass instead (android.view.View), doing things before calling setMeasuredDimension() there, and checking class name within the hook. This did the trick.
Code:
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(com.third.party.app))
return;
XC_MethodHook setMeasuredDimensionHook = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.thisObject.getClass().getName().equals(com.third.party.app.ThirdPartyAppView") {
View v = (View) param.thisObject;
int paramInt1 = (Integer) param.args[0];
int paramInt2 = (Integer) param.args[1];
// ...
// calculate my dimensions here
// ...
param.args[0] = desiredWidth;
param.args[1] = desiredHeight;
}
};
findAndHookMethod("android.view.View",
lpparam.classLoader,
"setMeasuredDimension", int.class, int.class,
setMeasuredDimensionHook);
}
Click to expand...
Click to collapse
Another way is to "emulate" call to setMeasuredDimension directly from onMeasure hook.
Example: https://github.com/GravityBox/Gravi...kitkat/gravitybox/ModQuickSettings.java#L1358
"Emulating" means you basically execute the same code that the original method does.
Of course, attention should be paid to different android versions and potential differences in setMeasuredDimension implementation.

Having Trouble Changing a Color

I'm trying to change the color of text from black to white. Modding the app with smali, I have narrowed it down to this portion of code. Where this.b(-16777216); would be the color black.
Code:
@Override
public void t() {
super.t();
this.p.setVisibility(8);
this.q.setVisibility(8);
this.n.setVisibility(8);
this.o.setVisibility(8);
this.u.setVisibility(8);
this.t.setVisibility(8);
this.r.setVisibility(8);
this.w.setVisibility(8);
this.x.setVisibility(8);
this.z.setVisibility(8);
this.C.setVisibility(8);
this.B.setVisibility(8);
this.D.setVisibility(8);
this.i.setVisibility(8);
this.k.setVisibility(8);
this.b(-16777216);
this.B.setOnClickListener(null);
this.D.setOnClickListener(null);
this.I = false;
}
So far this is where I am at. Logs not throwing any errors.
Edit.. I've also placed param.thisObject in place of null with no luck as well.
Code:
public class ClassName implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("com.app.package"))
return;
findAndHookMethod("com.app.package.blah.blah.Class", lpparam.classLoader, "t", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedHelpers.setIntField(null, "b", Color.WHITE);
}
});
}
}
Try using Xposedhelpers.callMethod(param.thisObject, "b", Color.WHITE) instead of setIntField.
set***Field methods are for the purpose of setting values of field members of object.
"b" is not a field member. It's a method (function).
C3C076 said:
Try using Xposedhelpers.callMethod(param.thisObject, "b", Color.WHITE) instead of setIntField.
set***Field methods are for the purpose of setting values of field members of object.
"b" is not a field member. It's a method (function).
Click to expand...
Click to collapse
OMG THANK YOU! It worked perfectly. I've been trying everything since Monday. Since I know what works and re-reading the section on the wiki about the callMethod helper, it makes a lot more sense now. Thanks again .
C3C076 said:
Try using Xposedhelpers.callMethod(param.thisObject, "b", Color.WHITE) instead of setIntField.
set***Field methods are for the purpose of setting values of field members of object.
"b" is not a field member. It's a method (function).
Click to expand...
Click to collapse
One last thing.. before I spend days trying to figure it out again lol. I'm getting a cannot cast to android....TextView with the following:
Edit: I think it is because I forgot to add the following:
Code:
String text = tv.getText().toString();
tv.setText(text);
I'll test when I get home.
Code:
XposedHelpers.findAndHookMethod("com.app.package.blah.blah.Class", lpparam.classLoader, "a", "com.app.package.blah.blah.AnotherClass", TextView.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
TextView tv = (TextView) param.thisObject;
tv.setTextColor(Color.WHITE);
}
});
This is what the portion of code looks like for the text color I am trying to change: textView.setTextColor(-16777216);
Code:
@Trace
private void a(FeedItem feedItem, TextView textView) {
this.b(chatFeedItem, textView);
if (feedItem instanceof StatefulChatFeedItem && (feedItem.Y() || feedItem.Z())) {
textView.setTextColor(this.b.getResources().getColor(2131230734));
return;
}
textView.setTextColor(-16777216);
}
Nevermind.. didn't work
93Akkord said:
Nevermind.. didn't work
Click to expand...
Click to collapse
Arguments of a function you are hooking are accessed using param.args array, not param.thisObject.
param.thisObject refers to the instance of an object you are working with. In your case,
it's an instance of "com.app.package.blah.blah.Class" class.
So proper way of getting that TextView which is a second argument of a function you are hooking is:
TextView tv = (TextView) param.args[1];
C3C076 said:
Arguments of a function you are hooking are accessed using param.args array, not param.thisObject.
param.thisObject refers to the instance of an object you are working with. In your case,
it's an instance of "com.app.package.blah.blah.Class" class.
So proper way of getting that TextView which is a second argument of a function you are hooking is:
TextView tv = (TextView) param.args[1];
Click to expand...
Click to collapse
Oh wow.. thanks. That worked. I actually tried TextView tv = (TextView) param.args[0];, among numerous other combinations, and never thought to try [1]. It makes me feel happy and sad at the same time lol. I appreciate the help :highfive:
dupe
param.args array is zero based and TextView is a second argument of a function. so:
- param.args[0] is FeedItem argument
- param.args[1] is TextView argument

Xposed destroying object?

Sorry, I know this is in the wrong section, but my post count would not let me post this anywhere else.
edit: I guess the title is slightly misleading, when the method LH64SpKkS1auK7N8sA is called, it now acts like there is no data left in ByteBuffer Ebn0ng1tXXh6Wa0h4V5Z
Anyways, I'm trying to capture packets with XPosed, however when I do this the app hangs for about 2 minutes(however captured packets are being logged) then force quits. I believe getStaticObjectField(docs claim it sets it to accessible, this is a private ByteBuffer) is possibly causing conflicts with other classes using the same field name. I have tried using field.setAccessible(false) after the getStaticObjectField call to no avail.
Code:
findAndHookMethod("com.AmZcqxXhvYDc8ktpbnHM", lpparam.classLoader, "LH64SpKkS1auK7N8sA", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Class<?> clazz = XposedHelpers.findClass("com.AmZcqxXhvYDc8ktpbnHM",lpparam.classLoader);
Field f = XposedHelpers.findField(clazz,"wQgxcxe7fAn3LzYJ8Jj");
//f.setAccessible(true);
if(XposedHelpers.getStaticBooleanField(clazz,f.getName())) {
XposedBridge.log("wQ true");
f = XposedHelpers.findField(clazz, "Ebn0ng1tXXh6Wa0h4V5Z");
//f.setAccessible(true);
ByteBuffer b = (ByteBuffer)XposedHelpers.getStaticObjectField(clazz,"Ebn0ng1tXXh6Wa0h4V5Z");
//f.setAccessible(false);
XposedBridge.log(b.toString());
//b.flip();
byte[] bytes = new byte[b.remaining()];
b.get(bytes);
String packet = new String(bytes);
XposedBridge.log("packet: " + packet);
}
else
XposedBridge.log("wQ false");
}
});

Categories

Resources