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

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

Tip us?
 
shnapsi
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 23
Join Date: Aug 2014
Default [Q] Xposed - How to get the package name of a process

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
 
GermainZ
Old
#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,380
Posts: 5,467
Join Date: Aug 2012
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;
    }
}
 
shnapsi
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 23
Join Date: Aug 2014
Quote:
Originally Posted by GermainZ View Post
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?
 
GermainZ
Old
#4  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,380
Posts: 5,467
Join Date: Aug 2012
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: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes