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

Get App version before hooking.

OP slvrbllt

27th June 2014, 12:09 PM   |  #1  
slvrbllt's Avatar
OP Senior Member
Flag Rome
Thanks Meter: 46
 
218 posts
Join Date:Joined: Feb 2005
More
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.
27th June 2014, 02:23 PM   |  #2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,333
 
5,910 posts
Join Date:Joined: Aug 2012
More
From memory, I believe you can use the appInfo field in LoadPackageParam: lpparam.appInfo.
Otherwise you can get a context with AndroidAppHelper.currentApplication()
27th June 2014, 04:52 PM   |  #3  
slvrbllt's Avatar
OP Senior Member
Flag Rome
Thanks Meter: 46
 
218 posts
Join Date:Joined: Feb 2005
More
Quote:
Originally Posted by GermainZ

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?
27th June 2014, 05:03 PM   |  #4  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,333
 
5,910 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by slvrbllt

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.
27th June 2014, 05:12 PM   |  #5  
slvrbllt's Avatar
OP Senior Member
Flag Rome
Thanks Meter: 46
 
218 posts
Join Date:Joined: Feb 2005
More
Quote:
Originally Posted by GermainZ

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...
27th June 2014, 07:23 PM   |  #6  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter: 15,323
 
2,386 posts
Join Date:Joined: Jan 2012
More
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.
28th June 2014, 10:49 AM   |  #7  
slvrbllt's Avatar
OP Senior Member
Flag Rome
Thanks Meter: 46
 
218 posts
Join Date:Joined: Feb 2005
More
Quote:
Originally Posted by rovo89

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.
28th June 2014, 03:42 PM   |  #8  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter: 15,323
 
2,386 posts
Join Date:Joined: Jan 2012
More
Quote:
Originally Posted by slvrbllt

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.
30th June 2014, 10:03 AM   |  #9  
slvrbllt's Avatar
OP Senior Member
Flag Rome
Thanks Meter: 46
 
218 posts
Join Date:Joined: Feb 2005
More
Quote:
Originally Posted by rovo89

[...] 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!

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes