FORUMS
Remove All Ads from XDA

[TUTORIAL]Xposed module devlopment

1,658 posts
Thanks Meter: 2,002
 
Post Reply Email Thread
21st August 2016, 09:24 PM |#181  
P1nGu1n_'s Avatar
Senior Member
Thanks Meter: 2,552
 
Donate to Me
More
Quote:
Originally Posted by samkpo

How and where would you do it? I've been trying without success...

Enviado desde mi Moto G mediante Tapatalk

I'd do it like this. I've added comments to explain it. Please let me know if it works for you

Code:
Select Code
public class XposedMod implements IXposedHookLoadPackage {

 @override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if (!lpparam.packageName.equals("com.replace.with.your.app")) {
            return;
        }

        XposedHelpers.findAndHookMethod("android.graphics.Typeface", lpparam.classLoader, "create", String.class, int.class, new XC_MethodHook() {
            // 'beforeHookedMethod' so we can replace the argument before the actual method is executed
 @override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                // 'param.args' are the arguments passed to the method, we get the first one and compare it
                String name = (String) param.args[0];
                if ("sans-serif-medium".equals(name)) {
                    // let's replace it
                    param.args[0] = "NEW NAME";
                }
            }
        });
    }
}
Note: I've not tested this.
 
 
22nd August 2016, 02:46 PM |#182  
Member
Thanks Meter: 17
 
More
Quote:
Originally Posted by P1nGu1n_

I'd do it like this. I've added comments to explain it. Please let me know if it works for you

Code:
Select Code
public class XposedMod implements IXposedHookLoadPackage {

 @override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if (!lpparam.packageName.equals("com.replace.with.your.app")) {
            return;
        }

        XposedHelpers.findAndHookMethod("android.graphics.Typeface", lpparam.classLoader, "create", String.class, int.class, new XC_MethodHook() {
            // 'beforeHookedMethod' so we can replace the argument before the actual method is executed
 @override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                // 'param.args' are the arguments passed to the method, we get the first one and compare it
                String name = (String) param.args[0];
                if ("sans-serif-medium".equals(name)) {
                    // let's replace it
                    param.args[0] = "NEW NAME";
                }
            }
        });
    }
}
Note: I've not tested this.

It worked! But there's a bug. It replaces all the coincidences, not just the one from the method I quoted. But it worked

Enviado desde mi Moto G mediante Tapatalk
26th August 2016, 07:32 PM |#183  
adlx.xda's Avatar
Recognized Developer
Flag Madrid
Thanks Meter: 1,767
 
Donate to Me
More
Quote:
Originally Posted by samkpo

It worked! But there's a bug. It replaces all the coincidences, not just the one from the method I quoted. But it worked

Enviado desde mi Moto G mediante Tapatalk

You can add more filtering to only alter parameters when you need, using these:

Name of the method calling the hooked method: param.method.getName()

Name of the class of the method calling the hooked method: param.thisObject.getClass().getName(),
The Following User Says Thank You to adlx.xda For This Useful Post: [ View ]
27th August 2016, 01:05 AM |#184  
Member
Thanks Meter: 17
 
More
Quote:
Originally Posted by adlx.xda

You can add more filtering to only alter parameters when you need, using these:

Name of the method calling the hooked method: param.method.getName()

Name of the class of the method calling the hooked method: param.thisObject.getClass().getName(),

Hi, thanks for the suggestions. I tried what you said but it didn't throw anything good.
This is the code:
Code:
Select Code
try{
    XposedBridge.log("Declaring class: " + param.method.getDeclaringClass().getSimpleName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}

try{
    XposedBridge.log("Method name: " + param.method.getName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}

try{
    XposedBridge.log("Class name: " + param.thisObject.getClass().getName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}

try{
    XposedBridge.log("Declaring class name: " + param.thisObject.getClass().getDeclaringClass().getName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}

try{
    XposedBridge.log("Class canonical name: " + param.thisObject.getClass().getCanonicalName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}
And this is the result, for every call it's the same:

Quote:

08-26 19:48:24.813 I/Xposed ( 4106): Declaring class: Typeface
08-26 19:48:24.814 I/Xposed ( 4106): Method name: create
08-26 19:48:24.832 I/Xposed ( 4106): Error: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
08-26 19:48:24.832 I/Xposed ( 4106): Error: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
08-26 19:48:24.832 I/Xposed ( 4106): Error: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference

The first two work, but they yield what I already know. The other three throw an exception..
The Following User Says Thank You to samkpo For This Useful Post: [ View ] Gift samkpo Ad-Free
27th August 2016, 01:27 AM |#185  
adlx.xda's Avatar
Recognized Developer
Flag Madrid
Thanks Meter: 1,767
 
Donate to Me
More
Quote:
Originally Posted by samkpo

Hi, thanks for the suggestions. I tried what you said but it didn't throw anything good.
This is the code:

Code:
Select Code
try{
    XposedBridge.log("Declaring class: " + param.method.getDeclaringClass().getSimpleName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}

try{
    XposedBridge.log("Method name: " + param.method.getName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}

try{
    XposedBridge.log("Class name: " + param.thisObject.getClass().getName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}

try{
    XposedBridge.log("Declaring class name: " + param.thisObject.getClass().getDeclaringClass().getName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}

try{
    XposedBridge.log("Class canonical name: " + param.thisObject.getClass().getCanonicalName() );
} catch (Exception e) {
    XposedBridge.log("Error: " + e.getMessage());
}
And this is the result, for every call it's the same:



The first two work, but they yield what I already know. The other three throw an exception..

Damn you're right, my mistake sorry I was wrong.

I think you need something like this:

Code:
Select Code
StackTraceElement[] trace = Thread.currentThread().getStackTrace();

for (int i=6; i < trace.length; i++)

{

Log.i(TAG, trace[i].getClassName() + " " + trace[i].getMethodName());

}
Experiment with these and you might find the value of I that gives the values you expect.
The Following User Says Thank You to adlx.xda For This Useful Post: [ View ]
28th August 2016, 12:41 AM |#186  
Member
Thanks Meter: 17
 
More
Quote:
Originally Posted by adlx.xda

Damn you're right, my mistake sorry I was wrong.

I think you need something like this:

Code:
Select Code
StackTraceElement[] trace = Thread.currentThread().getStackTrace();

for (int i=6; i < trace.length; i++)

{

Log.i(TAG, trace[i].getClassName() + " " + trace[i].getMethodName());

}
Experiment with these and you might find the value of I that gives the values you expect.

I'm gonna try it

Enviado desde mi Moto G mediante Tapatalk
17th September 2016, 11:28 AM |#187  
adlx.xda's Avatar
Recognized Developer
Flag Madrid
Thanks Meter: 1,767
 
Donate to Me
More
Quote:
Originally Posted by samkpo

I'm gonna try it

Enviado desde mi Moto G mediante Tapatalk

Any luck?
28th September 2016, 09:42 PM |#188  
Member
Thanks Meter: 3
 
More
Been asking everywhere.. Cant get the clock example to work on my Samsung S7 Edge, howcome?

My guess is different classname or something since the hooking function does not run.
If so, what to do?

Full explanation about my problem: http://stackoverflow.com/questions/3...stem-processes

Edit, sorry! Was because of other modules.
Can you write an updated guide for Android Studio? I'd be willing to donate for that, seriously. So hard to find information about xposed development.
29th September 2016, 05:57 PM |#189  
hamzahrmalik's Avatar
OP Senior Member
Thanks Meter: 2,002
 
Donate to Me
More
Quote:
Originally Posted by Kewkpad

Been asking everywhere.. Cant get the clock example to work on my Samsung S7 Edge, howcome?

My guess is different classname or something since the hooking function does not run.
If so, what to do?

Full explanation about my problem: http://stackoverflow.com/questions/3...stem-processes

Edit, sorry! Was because of other modules.
Can you write an updated guide for Android Studio? I'd be willing to donate for that, seriously. So hard to find information about xposed development.

Been meaning to do so for so long. Its been like a year. Maybe over this weekend I'll just add the setup for Studio, since the actual programming is of course the same

Sent from my A0001 using Tapatalk
The Following User Says Thank You to hamzahrmalik For This Useful Post: [ View ] Gift hamzahrmalik Ad-Free
3rd October 2016, 07:30 PM |#190  
hamzahrmalik's Avatar
OP Senior Member
Thanks Meter: 2,002
 
Donate to Me
More
Update:
I'm adding a tutorial for Android Studio now
EDIT: done
The Following 2 Users Say Thank You to hamzahrmalik For This Useful Post: [ View ] Gift hamzahrmalik Ad-Free
8th October 2016, 04:25 AM |#191  
Member
Thanks Meter: 3
 
More
Quote:
Originally Posted by hamzahrmalik

Update:
I'm adding a tutorial for Android Studio now
EDIT: done

Thank you very much!
Post Reply Subscribe to Thread

Tags
beginner, development, mod, tutorial, xposed

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes