Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,805,734 Members 42,807 Now Online
XDA Developers Android and Mobile Development Forum

Replace method. Need help. PLease

Tip us?
S0bes's Avatar
Senior Member - OP
Thanks Meter 247
Posts: 263
Join Date: Jan 2012
Location: Tomsk

Default Replace method. Need help. PLease

Hi everyone. I ask for help. I literally beg for it..
You can see it here
I only want to replace method . Any of them.
For example I want this method returns FALSE every time it's called.
   public boolean isValidDialpadAlphabeticChar(char ch) {
       return (ch >= 'a' && ch <= 'z');
Here is my code
public class Fm implements IXposedHookLoadPackage {      
    public void handleLoadPackage(final LoadPackageParam loadpkg) throws Throwable { 
        if (loadpkg.packageName.equals("")) { 
            ClassLoader classLoader = loadpkg.classLoader; 
            XC_MethodReplacement methodreplacer = new XC_MethodReplacement() {  
                protected Object replaceHookedMethod( 
                        XC_MethodHook.MethodHookParam paramAnonymousMethodHookParam)
                        throws Throwable {
                	 XposedBridge.log("ALLLLL RIGHTTTT . NOW We ARE IN. AND MADE IT FALSe"); 
                    return false;  
            XposedHelpers.findAndHookMethod("", loadpkg.classLoader,
                    "isValidDialpadAlphabeticChar", Character.class, methodreplacer);
But this doesn't work
Here what I see in xposed log file:
java.lang.NoSuchMethodError: idDialpadAlphabeticChar(java.lang.Character)#exact
at ct(
at thod(
at thod(
at com.s0bes.fmspeaker.Fm.handleLoadPackage( 0)

BUUUT. If I will try to replace other method. For example
matchesCombination in (
Here the part of code which was changed:
XposedHelpers.findAndHookMethod("", loadpkg.classLoader,
                    "matchesCombination", String.class, String.class, ArrayList.class, methodreplacer);
Now everything work...
So, it works with one thing and doesnt work with method I need
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,365
Posts: 5,459
Join Date: Aug 2012
If you want to replace a method to return a consatnt, you can use the XC_MethodReplacement.returnConstant(…) shortcut. For example:
Select Code
XposedHelpers.findAndHookMethod("", loadpkg.classLoader,
                    "matchesCombination", String.class, String.class, ArrayList.class, XC_MethodReplacement.returnConstant(false));
As for your problem, you're trying to hook isValidDialpadAlphabeticChar(Character.class), but you should be hooking isValidDialpadAlphabeticChar(char.class). Just replace "Character.class" by "char.class" in your findAndHookMethod call.
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes