Shoot Troubles, Not Users w/ Alex Boag-Munroe – XDA:DevCon 2014

In presenting the various sessions from XDA:DevCon 2014, weve mainly … more

Oppo Releases ColorOS for the Find 5… Poorly

Almost every OEM has taken the liberty of creating its own incarnation of the Android OS. … more

XDA LG Development Challenge Winners

Almost 3months ago, we set out with LGto findtwo amazing apps that developers could put together … more

Wearable Apps w/ Andreas Göransson – XDA:DevCon 2014

XDA:DevCon 2014 in Manchester, UK featured quite a few interesting topics as … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP shnapsi

17th August 2014, 05:24 PM   |  #1  
OP Member
Thanks Meter: 0
 
50 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, 04:15 PM   |  #2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,365
 
5,918 posts
Join Date:Joined: Aug 2012
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, 04:51 PM   |  #3  
OP Member
Thanks Meter: 0
 
50 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, 05:10 PM   |  #4  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,365
 
5,918 posts
Join Date:Joined: Aug 2012
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