Post Reply

[Q] Xposed - How to get the package name of a process

OP shnapsi

17th August 2014, 04:24 PM   |  #1  
OP Member
Thanks Meter: 0
 
47 posts
Join Date:Joined: Aug 2014
Hello,

I'm building an xposed module and i want to hook a method only if certain process (app) called this method. I can get the process pid and uid using Binder, but I can't find a way to get the package name.

How can I get it?

Thanks, Gidi
18th August 2014, 03:15 PM   |  #2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 6,746
 
5,698 posts
Join Date:Joined: Aug 2012
Donate to Me
More
You can get it the usual way if you have a context. It might be a better idea to do something like this, depending on what you're trying to do:
Code:
Select Code
public class XposedMod implements IXposedHookLoadPackage {
    private int mHookedAppUid; // You can use this field to directly compare the UID.

 @override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if (!lpparam.packageName.equals("package"))
            return;
        mHookedAppUid = lpparam.appInfo.uid;
    }
}
18th August 2014, 03:51 PM   |  #3  
OP Member
Thanks Meter: 0
 
47 posts
Join Date:Joined: Aug 2014
Quote:
Originally Posted by GermainZ

You can get it the usual way if you have a context. It might be a better idea to do something like this, depending on what you're trying to do:

Code:
Select Code
public class XposedMod implements IXposedHookLoadPackage {
    private int mHookedAppUid; // You can use this field to directly compare the UID.

 @override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if (!lpparam.packageName.equals("package"))
            return;
        mHookedAppUid = lpparam.appInfo.uid;
    }
}


Thanks, but i still can't find a good way to get it.
for my example, i'm trying to hook the method sendTextMessage from android.telephony.SmsManager
if i do it using handleLoadPackage, it doesn't seems to work, but if i do it using initZygote it does work (i'm able to hook the method)
and since i don't have a Context, i can't do it in the usual way, and it seems i'm doing something wrong, since i can't use the other way too...

any idea?
18th August 2014, 04:10 PM   |  #4  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 6,746
 
5,698 posts
Join Date:Joined: Aug 2012
Donate to Me
More
You should use handleLoadPackage for the app you want (e.g. AOSP SMS app), it's independent from the initZygote hook and only there to store the UID.

Otherwise, you can try AndroidAppHelper.currentApplication() to get a context. This may not always return a context, though.
The Following User Says Thank You to GermainZ For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Xposed General by ThreadRank