How to use hidden class in hook?

Search This thread

pyler

Senior Member
Jan 13, 2013
1,279
2,372
I have something like this..
Code:
XposedHelpers.findAndHookMethod(packageManagerService,
				"installPackage", Uri.class, IPackageInstallObserver.class, int.class, String.class, new XC_MethodHook()
bla bla...

But IPackageInstallObserver.class is not resolved (hidden, not in SDK). So, devs, how can I use it? Any workaround? I just need it to make hook working. For info, I am going to hook flags, not observer.
 
Last edited:

rovo89

Senior Recognized Developer
Jan 4, 2012
2,585
81,434
I have something like this..
Code:
XposedHelpers.findAndHookMethod(packageManagerService,
				"installPackage", Uri.class, IPackageInstallObserver.class, int.class, String.class, new XC_MethodHook()
bla bla...

But IPackageInstallObserver.class is not resolved (hidden, not in SDK). So, devs, how can I use it? Any workaround? I just need it to make hook working. For info, I am going to hook flags, not observer.

Simply use the string "android.content.pm.IPackageInstallObserver" instead of IPackageInstallObserver.class. You can do the same for the first class name:
Code:
XposedHelpers.findAndHookMethod("com.android.server.pm.PackageManagerService", null,
				"installPackage", Uri.class, "android.content.pm.IPackageInstallObserver", int.class, String.class, new XC_MethodHook()
bla bla...
(classloader is null here because the class is part of the BootClassLoader, usually you would use lpparam.classLoader instead)
 

pyler

Senior Member
Jan 13, 2013
1,279
2,372
Simply use the string "android.content.pm.IPackageInstallObserver" instead of IPackageInstallObserver.class. You can do the same for the first class name:
Code:
XposedHelpers.findAndHookMethod("com.android.server.pm.PackageManagerService", null,
				"installPackage", Uri.class, "android.content.pm.IPackageInstallObserver", int.class, String.class, new XC_MethodHook()
bla bla...
(classloader is null here because the class is part of the BootClassLoader, usually you would use lpparam.classLoader instead)

This is awesome. Thank you!
 

aoei

New member
Jun 20, 2014
4
0
Simply use the string "android.content.pm.IPackageInstallObserver" instead of IPackageInstallObserver.class. You can do the same for the first class name:
Code:
XposedHelpers.findAndHookMethod("com.android.server.pm.PackageManagerService", null,
				"installPackage", Uri.class, "android.content.pm.IPackageInstallObserver", int.class, String.class, new XC_MethodHook()
bla bla...
(classloader is null here because the class is part of the BootClassLoader, usually you would use lpparam.classLoader instead)

hello @rovo89

I know that I can use the string ... instead of .....class to use "findAndHookMethod",
but if I want to get the parameter in "beforeHookedMethod", like this:
Code:
XposedHelpers.findAndHookMethod("com.example.main", null,
	"a", "com.example.Details", int.class, String.class, new XC_MethodHook() {
	@Override
	protected void beforeHookedMethod(MethodHookParam param)
			throws Throwable {
			int i = (Integer)param.args[1];
			String s = (String)param.args[2];
			.........					
			}
});

I can get the parameters like this: int i = (Integer)param.args[1]; String s = (String)param.args[2];
but what about the first one?
how to define "(Details)param.args[0]"?

thanks.
 

rovo89

Senior Recognized Developer
Jan 4, 2012
2,585
81,434
I can get the parameters like this: int i = (Integer)param.args[1]; String s = (String)param.args[2];
but what about the first one?
how to define "(Details)param.args[0]"?

That's not possible. You have to assign it to an Object variable and then keep using reflection to get/set its fields and call methods. The methods in XposedHelpers make this very easy.
 

BytesReverser

Senior Member
Feb 10, 2017
86
32
127.0.0.1
That's not possible. You have to assign it to an Object variable and then keep using reflection to get/set its fields and call methods. The methods in XposedHelpers make this very easy.

what we don't know the parameter type ?
for example parameter type keep changing per class in update ,do we have something like keeping Object.class or unknown.class in paramtere type