Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,810,466 Members 50,576 Now Online
XDA Developers Android and Mobile Development Forum

Get App version before hooking.

Tip us?
 
slvrbllt
Old
#1  
slvrbllt's Avatar
Senior Member - OP
Thanks Meter 46
Posts: 218
Join Date: Feb 2005
Location: Rome
Default Get App version before hooking.

Hi all,

My Xposed module deals with different versions of an app. Different versions means different hooks, so my question is: how can I get the application version during the handleLoadPackage execution? I mean... getPackageManager requires a context which I do not have *or* I don't know how to find out...

Any clues, guys?
Thanks.
Silver Bullet
________________________________
Nexus 7 (2013) 32Gb
HTC One (M7) 32Gb
Samsung Galaxy Note 10.1 2014 Edition LTE (SM-P605)
Samsung Galaxy Tab 4 8.0 LTE (SM-T335)
 
GermainZ
Old
#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,401
Posts: 5,478
Join Date: Aug 2012
From memory, I believe you can use the appInfo field in LoadPackageParam: lpparam.appInfo.
Otherwise you can get a context with AndroidAppHelper.currentApplication()
 
slvrbllt
Old
#3  
slvrbllt's Avatar
Senior Member - OP
Thanks Meter 46
Posts: 218
Join Date: Feb 2005
Location: Rome
Quote:
Originally Posted by GermainZ View Post
From memory, I believe you can use the appInfo field in LoadPackageParam: lpparam.appInfo.
Otherwise you can get a context with AndroidAppHelper.currentApplication()
No luck!
AndroidAppHelper.currentApplication() returns null and lpparam.appInfo does not appear to be a Context object...
Any other idea?
Silver Bullet
________________________________
Nexus 7 (2013) 32Gb
HTC One (M7) 32Gb
Samsung Galaxy Note 10.1 2014 Edition LTE (SM-P605)
Samsung Galaxy Tab 4 8.0 LTE (SM-T335)
 
GermainZ
Old
#4  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,401
Posts: 5,478
Join Date: Aug 2012
Quote:
Originally Posted by slvrbllt View Post
No luck!
AndroidAppHelper.currentApplication() returns null and lpparam.appInfo does not appear to be a Context object...
Any other idea?
lpparam.appInfo = ApplicationInfo, not Context. It might have the version, but I can't recall if it does or check it right now.
 
slvrbllt
Old
#5  
slvrbllt's Avatar
Senior Member - OP
Thanks Meter 46
Posts: 218
Join Date: Feb 2005
Location: Rome
Quote:
Originally Posted by GermainZ View Post
lpparam.appInfo = ApplicationInfo, not Context. It might have the version...
I couldn't see anything in the ApplicationInfo object that could be related to the version number of the package...
Silver Bullet
________________________________
Nexus 7 (2013) 32Gb
HTC One (M7) 32Gb
Samsung Galaxy Note 10.1 2014 Edition LTE (SM-P605)
Samsung Galaxy Tab 4 8.0 LTE (SM-T335)
 
rovo89
Old
#6  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter 14,104
Posts: 2,367
Join Date: Jan 2012
I assume you're placing your hooks in handleLoadPackage(). The Context/Application isn't created yet at that time. I think some modules managed to get a system context via reflection, but I don't know which ones. Maybe you can find something via the search function.

Just another idea: Instead of comparing versions, you might be able to achieve the same by checking whether certain classes/methods exist.
Tired of updating your mod for every new ROM release?
You want give users the possibility to combine different mods without creating tons of different files for all possible combinations?
Then have a look at my Xposed framework - modifications without APK changes!
 
slvrbllt
Old
#7  
slvrbllt's Avatar
Senior Member - OP
Thanks Meter 46
Posts: 218
Join Date: Feb 2005
Location: Rome
Quote:
Originally Posted by rovo89 View Post
I assume you're placing your hooks in handleLoadPackage(). The Context/Application isn't created yet at that time. I think some modules managed to get a system context via reflection, but I don't know which ones. Maybe you can find something via the search function.

Just another idea: Instead of comparing versions, you might be able to achieve the same by checking whether certain classes/methods exist.
Thanks for your reply, mate.
You are correct! handleLoadPackage is where I placed my hooks.

As per your suggestion, I will try to find any other existing module that does what I'm looking for.

Unfortunately I need to identify the package version in any reliable way but classes/methods existence check.
The app is obfuscated... method a.a.b could be a.b.c in another version while method a.a.b could still exist but with different implementation.

Is there any other way to retrieve the installed version of a package, given it's package name?
Thanks.
Silver Bullet
________________________________
Nexus 7 (2013) 32Gb
HTC One (M7) 32Gb
Samsung Galaxy Note 10.1 2014 Edition LTE (SM-P605)
Samsung Galaxy Tab 4 8.0 LTE (SM-T335)
 
rovo89
Old
#8  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter 14,104
Posts: 2,367
Join Date: Jan 2012
Quote:
Originally Posted by slvrbllt View Post
Is there any other way to retrieve the installed version of a package, given it's package name?
Apart from using the system context to access the package manager, you could try to parse the package yourself. There is a PackageParser class which is hidden from the SDK, but if you manage to call parsePackage() via reflection (or by referencing a JAR which includes the hidden APIs as well, like XposedBridge does), then you can use it with ApplicationInfo.sourceDir and get the version numbers from the result. Not sure how expensive that operation is, but if you execute it just once, it should be ok.
Tired of updating your mod for every new ROM release?
You want give users the possibility to combine different mods without creating tons of different files for all possible combinations?
Then have a look at my Xposed framework - modifications without APK changes!
 
slvrbllt
Old
#9  
slvrbllt's Avatar
Senior Member - OP
Thanks Meter 46
Posts: 218
Join Date: Feb 2005
Location: Rome
Quote:
Originally Posted by rovo89 View Post
[...] if you manage to call parsePackage() via reflection (or by referencing a JAR which includes the hidden APIs as well, like XposedBridge does), then you can use it with ApplicationInfo.sourceDir and get the version numbers from the result.[...]
I will definitely give it a try.
Thanks!
Silver Bullet
________________________________
Nexus 7 (2013) 32Gb
HTC One (M7) 32Gb
Samsung Galaxy Note 10.1 2014 Edition LTE (SM-P605)
Samsung Galaxy Tab 4 8.0 LTE (SM-T335)

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes