[Q] findClass vs. static class specification - Xposed General

In all Xposed examples/mods that I've seen so far, the following pattern is used (Environment class used as example):
Code:
findAndHookMethod("android.os.Environment", lpparam.classLoader, <method>, <params>, <hook>);
or something like
Code:
Class<?> cls = findClass("android.os.Environment", lpparam.classLoader); findAndHookMethod(cls, <method>, <params>, <hook>);
But it seems that a direct static specification of the class works as well:
Code:
findAndHookMethod(Environment.class, <method>, <params>, <hook>);
Are there any cons to this approach?

You usually use Environment.class when you can, and "android.os.Environment" when the class is not in the SDK.

Related

[Q] Changing a returned object's property

Hello,
Please consider the following scenario
Code:
public class Document {
...
protected boolean dirty;
...
void setDirty(boolean value) {...}
public boolean getDirty() {...}
}
public class DocumentManager {
...
public Document getDocument(String Id) {...}
...
}
Now I'm hooking getDocument method just fine, but I need to change the returned object's 'dirty' property.
How can I accomplish this?
Thanks in advance for your help.
Call XposedHelpers.setBooleanField(…) on a Document object for "dirty" or hook getDirty() and use param.setResult(…) (or the XC_MethodReplacement.returnConstant(…) shortcut) to set the result you want.
GermainZ said:
Call XposedHelpers.setBooleanField(…) on a Document object for "dirty" or hook getDirty() and use param.setResult(…) (or the XC_MethodReplacement.returnConstant(…) shortcut) to set the result you want.
Click to expand...
Click to collapse
XposedHelpers.setBooleanField did the trick. The class sometimes access the 'dirty' member without going through the getter. That's why I needed to change the field instead of hooking getDirty.
Thanks mate.
Cheers.

[Q] Hooking overriden methods in extended classes

So I'm (attempting) to write my first Xposed module. I'm a little hung up so I'm looking for some help.
I'm trying to hook into the onStartCommand method of the AlarmKlaxon class in com.android.deskclock (link). The AlarmKlaxon class extends "Service" and onStartCommand (the method I want to hook) has the @override identifier.
I would think, I would be able to do something like this:
public class AlarmHandler implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {​
if (!lpparam.packageName.equals("com.android.deskclock"))​return;​
XposedBridge.log("Found Package!");​
findAndHookMethod("com.android.deskclock.AlarmKlaxon", lpparam.classLoader, "onStartCommand", new XC_MethodHook() {​@override​protected void beforeHookedMethod(MethodHookParam param) throws Throwable {​XposedBridge.log("Found Method!");​}​});​}​}
Click to expand...
Click to collapse
When I test out the application, I get "ClassNotFound" exceptions when I hit findAndHookMethod. What seems very strange is that if I try to hook a method in a class that does not extend another class, it seems to work... For example, if I hook AlarmAlertWakeLock class (link), I don't see the exceptions....
Is there something special with the extended classes? When defining the class string, do I need to state that AlarmKlaxon extends another (e.g. "com.android.deskclock.Service.AlarmKlaxon")
Figured it out. Apparently the Cyanogenmod source code I was looking at wasn't the correct version or something. I needed to call the class "com.android.deskclock.alarm.AlarmKlax on"
This thread can be marked as solved.

Help needed with a View class.

Hi, this is my first post here so please forgive me if I have put this in the wrong section, it was a bit confusing.
I have an application that takes the touch coordinates from onTouchEvent and and puts them in to an SQLite Database.
My three relevant classes:
Main class: TouchDetector.
Custom View class: TouchDetectorView.
Database class: TouchDatabaseHandler.
TouchDetectorView captures the touches and stores the x, y values in variables. I need to access the TouchDatabaseHandler class from this view class in order to send them to the database.
Constructor inside TouchDatabaseHandler class where data is sent to database:
Code:
public TouchDatabaseHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
View class constructor.
Code:
public TouchDetectorView(Context context, AttributeSet attrs) {
super(context, attrs);
dbHandler = new TouchDatabaseHandler([COLOR="Red"][U]this[/U][/COLOR], null, null, 1);
}
What do I replace the this with to make my code work? The tutorial I was following had the dbHandler inside the onCreate but since I am in a View class I do not have on. I apologise if this is very vague, I am a beginner and would appreciate any help and/or feedback.

Is there a way to access a class variable without knowing its name?

I'm trying to use getObjectField(Object obj, String fieldName) to get the value of a class variable,
However I cannot get the real fieldName of that variable after decompilation:
public final class fR
{
public final fT a;
public final CharSequence a;
public final Object a;
public final String a; //this is the variable I want to access
public final CharSequence b;
....
Is there a way to access a class variable without knowing its name?

; expected even though there allready is one

my java class in android studio is asking me to add ; but its already there. ive done the things youd usually do like delete the ; and put it in again and rebuild the project also restart my pc. nothing seems to work
package com.sudafly.charts;
import android.support.v7.app.AppCompatActivity;
/**
* Created by Dragos on 25/01/2017.
*/
public class HomeScreen extends AppCompatActivity home_screen{
}
Click to expand...
Click to collapse
dragos_popa said:
my java class in android studio is asking me to add ; but its already there. ive done the things youd usually do like delete the ; and put it in again and rebuild the project also restart my pc. nothing seems to work
Click to expand...
Click to collapse
Hi,
Android studio is right, there is something wrong in the code, the "home_screen" after AppCompatActivity should not be there.
Code:
public class HomeScreen extends AppCompatActivity {
}
If "home_screen" is an interface
Code:
public class HomeScreen extends AppCompatActivity implements home_screen {
}
Hope it helps, good luck

Categories

Resources