Get App version before hooking. - Xposed General

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.

From memory, I believe you can use the appInfo field in LoadPackageParam: lpparam.appInfo.
Otherwise you can get a context with AndroidAppHelper.currentApplication()

GermainZ said:
From memory, I believe you can use the appInfo field in LoadPackageParam: lpparam.appInfo.
Otherwise you can get a context with AndroidAppHelper.currentApplication()
Click to expand...
Click to collapse
No luck!
AndroidAppHelper.currentApplication() returns null and lpparam.appInfo does not appear to be a Context object...
Any other idea?

slvrbllt said:
No luck!
AndroidAppHelper.currentApplication() returns null and lpparam.appInfo does not appear to be a Context object...
Any other idea?
Click to expand...
Click to collapse
lpparam.appInfo = ApplicationInfo, not Context. It might have the version, but I can't recall if it does or check it right now.

GermainZ said:
lpparam.appInfo = ApplicationInfo, not Context. It might have the version...
Click to expand...
Click to collapse
I couldn't see anything in the ApplicationInfo object that could be related to the version number of the package...

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.

rovo89 said:
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.
Click to expand...
Click to collapse
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.

slvrbllt said:
Is there any other way to retrieve the installed version of a package, given it's package name?
Click to expand...
Click to collapse
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.

rovo89 said:
[...] 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.[...]
Click to expand...
Click to collapse
I will definitely give it a try.
Thanks!

For anyone wondering the snippet we used up until now is "deprecated" in Android 11 and totally gone in 12 (S). You can use the code below to get the version code for your app:
Java:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Class<?> pkgParserClass = XposedHelpers.findClass("android.content.pm.PackageParser", lpparam.classLoader);
Object packageLite = XposedHelpers.callStaticMethod(pkgParserClass, "parsePackageLite", apkPath, 0);
versionCode = XposedHelpers.getIntField(packageLite, "versionCode");
} else {
Class<?> parserCls = XposedHelpers.findClass("android.content.pm.PackageParser", lpparam.classLoader);
Object pkg = XposedHelpers.callMethod(parserCls.newInstance(), "parsePackage", apkPath, 0);
versionCode = XposedHelpers.getIntField(pkg, "mVersionCode");
}

Massi-X said:
For anyone wondering the snippet we used up until now is "deprecated" in Android 11 and totally gone in 12 (S). You can use the code below to get the version code for your app:
Java:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Class<?> pkgParserClass = XposedHelpers.findClass("android.content.pm.PackageParser", lpparam.classLoader);
Object packageLite = XposedHelpers.callStaticMethod(pkgParserClass, "parsePackageLite", apkPath, 0);
versionCode = XposedHelpers.getIntField(packageLite, "versionCode");
} else {
Class<?> parserCls = XposedHelpers.findClass("android.content.pm.PackageParser", lpparam.classLoader);
Object pkg = XposedHelpers.callMethod(parserCls.newInstance(), "parsePackage", apkPath, 0);
versionCode = XposedHelpers.getIntField(pkg, "mVersionCode");
}
Click to expand...
Click to collapse
Thank you so much broo

Related

Little help? (new developer, first app; BackApp, allows you to back up all your apps)

Okay so, after having my phone for a few months now, I've decided to start developing for it. I decided I wanted an application that backs up my applications for me. Yes, I know Astro does it, but it's going to become a paid app soon, and I don't need the file managing aspect of it either.
So, knowing the commands to do back my apps up through the terminal:
$su
#cp -r /data/app /sdcard/apps
(That backs up all my apps to my SDcard, in a folder called apps.)
I knew that openoverclocker sends commands to the phone, in order to set the cpu speed. So using the openoverclocker source (available from here: http://code.google.com/p/openoverclocker/ ) as a reference I created an application that sends the command to the phone. After successfully compiling the app and installing it, I'm getting a force close. I've uploaded my source for you guys to take a look at here: http://www.mediafire.com/?zdmjmydzk2x
Suggestions?
Cheers in advance- Thrash
The easiest way to debug is to make sure USB dev is enabled, then have a binary copy of 'adb' and run 'adb logcat' on your computer it will dump out system log from your phone including why apps crash, although it sounds like you don't have the proper permissions in your manifest file.
ThrashWolf said:
Okay so, after having my phone for a few months now, I've decided to start developing for it. I decided I wanted an application that backs up my applications for me. Yes, I know Astro does it, but it's going to become a paid app soon, and I don't need the file managing aspect of it either.
So, knowing the commands to do back my apps up through the terminal:
$su
#cp -r /data/app /sdcard/apps
(That backs up all my apps to my SDcard, in a folder called apps.)
I knew that openoverclocker sends commands to the phone, in order to set the cpu speed. So using the openoverclocker source (available from here: http://code.google.com/p/openoverclocker/ ) as a reference I created an application that sends the command to the phone. After successfully compiling the app and installing it, I'm getting a force close. I've uploaded my source for you guys to take a look at here: http://www.mediafire.com/?zdmjmydzk2x
Suggestions?
Cheers in advance- Thrash
Click to expand...
Click to collapse
how about i just add that script to the app that i will be releasing in a few days?? my app will have a free version and a donate version that will allow people to pay a dollar to danate to me if they so please but the versions will be no different other than nagging for donationg on the free version. would you mind if i implement your idea?
looks like what you did wrong that i saw right off the bat is CoreTask should be capitalized, but what about just using the "Runtime.getRuntime().exec("command");" instead? just input the command you want to execute in place of the word command in the quotes
oh and you have no xml layout in /res/layout
start a new project and just import the files you need from your source, the layout xml should create what it needs at the top on it's own. it shouldn't be empty
Thanks for all the help guys, tubaking182, if you want to do that, go ahead =)
I really want to complete this application myself though, as it's important to me (first app blah blah blah) and I'll feel I'll have accomplished something by seeing it through.
ThrashWolf said:
Thanks for all the help guys, tubaking182, if you want to do that, go ahead =)
I really want to complete this application myself though, as it's important to me (first app blah blah blah) and I'll feel I'll have accomplished something by seeing it through.
Click to expand...
Click to collapse
i completely understand that, the app i just released is my first app as well, i wanted something for myself and a few beta testers told me i should sell it so i made a donate version. i am mainly just happy that it works in one build, hopefully i can get it to work in all builds as it is supposed to
This would be awesome if you could give it su permissions & have it backup the protected apps as well so I don't have to manually do it through terminal everytime I wanna try a new ROM out
Beast84 said:
This would be awesome if you could give it su permissions & have it backup the protected apps as well so I don't have to manually do it through terminal everytime I wanna try a new ROM out
Click to expand...
Click to collapse
Use a Apps to SD build that way your apps etc won't get wiped if/when you upgrade with a build the wipes the data partition etc.
tubaking182 said:
i completely understand that, the app i just released is my first app as well, i wanted something for myself and a few beta testers told me i should sell it so i made a donate version. i am mainly just happy that it works in one build, hopefully i can get it to work in all builds as it is supposed to
Click to expand...
Click to collapse
Awesome, is it in the market just now?
Beast84 said:
This would be awesome if you could give it su permissions & have it backup the protected apps as well so I don't have to manually do it through terminal everytime I wanna try a new ROM out
Click to expand...
Click to collapse
Something along these lines?
CoreTask.runRootCommand("cd /data/app-private");
CoreTask.runRootCommand("cp -r /data/app-private /sdcard/apps");
CoreTask.runRootCommand("cd /data/app");
CoreTask.runRootCommand("cp -r /data/app /sdcard/apps");
ThrashWolf said:
CoreTask.runRootCommand("cd /data/app-private");
Click to expand...
Click to collapse
That's funcitonality from one of the tether apps, use this instead:
hasroot = true;
try
{
Runtime.getRuntime().exec("su");
} catch (Exception e) {
hasroot = false;
}
delta_foxtrot2 said:
That's funcitonality from one of the tether apps, use this instead:
hasroot = true;
try
{
Runtime.getRuntime().exec("su");
} catch (Exception e) {
hasroot = false;
}
Click to expand...
Click to collapse
getting a bit of an issue here, I'm being told "hasroot cannot be resolved"
Any suggestions?
thanks for all the help so far guys.
ThrashWolf said:
Awesome, is it in the market just now?
Click to expand...
Click to collapse
yes my app is in the market but i have not implemented you idea because i want you to have the joy of finishing an app before i decide to merge it with another app
tubaking182 said:
yes my app is in the market but i have not implemented you idea because i want you to have the joy of finishing an app before i decide to merge it with another app
Click to expand...
Click to collapse
Thanks man =D
ThrashWolf said:
getting a bit of an issue here, I'm being told "hasroot cannot be resolved"
Any suggestions?
thanks for all the help so far guys.
Click to expand...
Click to collapse
you just needed to put boolean in front of the first instance of gotroot, but that code doesn't work as I thought it would, you need to do this instead.
Code:
private boolean GotRoot()
{
boolean ihasroot = false;
Process process = null;
DataOutputStream os = null;
try
{
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("exit\n");
os.flush();
process.waitFor();
if(process.exitValue() == 0)
ihasroot = true;
} catch (Exception e) {
} finally {
try
{
if(os != null)
os.close();
os = null;
if(process != null)
process.destroy();
process = null;
} catch (Exception e) {}
}
return ihasroot;
}
You can use that code by doing something like this:
Code:
if(!GotRoot())
{
new AlertDialog.Builder(this)
.setTitle("Unable to get root.")
.setMessage("I was unable to get root access.")
.setNeutralButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
finish();
}
})
.show();
}
Still having a tiny bit of trouble with the app.
So far as I can see, it *should* work, but it isn't (opens and exits correctly, just isn't copying over .apks, or even looking for root access). If someone could have a look at the source and point me in the right direction I'd really appreciate it. Thanks for all the help so far:
http://www.mediafire.com/?sharekey=b26ee7e91e0cb0d7dd8b33b5aa27078d
Oh forgot to mention, the (rather stupid) icon's a WIP.
tubaking182 said:
yes my app is in the market but i have not implemented you idea because i want you to have the joy of finishing an app before i decide to merge it with another app
Click to expand...
Click to collapse
Whats your app called?
my app is Kingdroid Scripts, there is a free and donate version but for the time being it only works in dude builds(and i am not sure why) but i am looking into it and hopefully i can get some work done if my girl will let me near my computer long enough. been trying to downgrade my comp back to ubuntu 8.10 which is a pain in the arse especially when you are trying not to lose anything
tubaking182 said:
my app is Kingdroid Scripts, there is a free and donate version but for the time being it only works in dude builds(and i am not sure why) but i am looking into it and hopefully i can get some work done if my girl will let me near my computer long enough. been trying to downgrade my comp back to ubuntu 8.10 which is a pain in the arse especially when you are trying not to lose anything
Click to expand...
Click to collapse
Awesome, shame it doesn't work on the JF firmware =(

[DEV]We got some parts of drivers that will help us about CM7

e way we got a little help from Broadcom.
David has given us all we need to build CM7 ..
Thanks for the information whitexp.
Based on your feedback, we've noted the following issues with the current BCM21553 CM7 port, and will investigate to see if we can help resolve them:
1) Colors are swapped when using software rendering. There are fixes for this, which involve copying libraries from the stock firmware, but they introduce stability issues.
2) libGLES_hgl.so has many shared library dependencies and does not work with the stock surfaceflinger/libui.
I was able to build CM7, with a couple modifications to your device tree, and replicate the color swap issue seen with software rendering.
We're working on a solution to formally release our software, but in the meantime, we have a test patch to fix the color swap issue without using any additional prebuilt libraries.
To try this, please copy the gralloc folder from hardware/libhardware/modules/gralloc (http://madteam.co/forum/go.php?url=aHR0cHM6Ly9naXRodWIuY29tL0N5YW5vZ2VuTW9kL2FuZHJvaWRfaGFyZHdhcmVfbGliaGFyZHdhcmUvdHJlZS9nYi1yZWxlYXNlLTcuMi9tb2R1bGVzL2dyYWxsb2M) to your device tree and apply the attached patch to use the correct fbFormat for the hardware.
You will also need to modify the LOCAL_MODULE in Android.mk with the correct board name.
Thanks,
David
Patch inline:
diff --git a/modules/gralloc/framebuffer.cpp b/modules/gralloc/framebuffer.cpp
index fe57a8a..a46d46e 100644
--- a/modules/gralloc/framebuffer.cpp
+++ b/modules/gralloc/framebuffer.cpp
@@ -355,7 +355,7 @@ int fb_device_open(hw_module_t const* module, const char* name,
if (status >= 0) {
int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
int format = (m->info.bits_per_pixel == 32)
- ? HAL_PIXEL_FORMAT_RGBX_8888
+ ? HAL_PIXEL_FORMAT_BGRA_8888
: HAL_PIXEL_FORMAT_RGB_565;
#ifdef NO_32BPP
format = HAL_PIXEL_FORMAT_RGB_565;
Of course these are only temporary drivers ..
Click to expand...
Click to collapse
LINK FOR ORIGINAL POST: http://madteam.co/forum/general-77/%28dev%27s%29%28broadcom%29-open-dialogue-with-broadcom/60/
This is just a hacked up solution to the blue-red color switch problem that was haunting devs for a very long time...
I'm not sure if we even have a cm7 build that can even boot to that point!
What you highlighted in red is the difference between the 'before' and 'after' code. Basically the only thing changed is the order in which colors are read by the GPU. Before it was reading red-green-blue-(ignores alpha), now it's reading blue-green-red-alpha.
Now that it's reading alpha too I think it might fix some crashes with some games but i'm not sure
Ooops!!! Wrong section i guess
ZakooZ said:
This is just a hacked up solution to the blue-red color switch problem that was haunting devs for a very long time...
I'm not sure if we even have a cm7 build that can even boot to that point!
What you highlighted in red is the difference between the 'before' and 'after' code. Basically the only thing changed is the order in which colors are read by the GPU. Before it was reading red-green-blue-(ignores alpha), now it's reading blue-green-red-alpha.
Now that it's reading alpha too I think it might fix some crashes with some games but i'm not sure
Click to expand...
Click to collapse
Can't find the sense about change the RGBA order :silly:
Now colors not are swapped! Yeeeeaaaahh
Thats one small step for Cm7, One giant leap for Broadcomm.. (yes i am taking the ****)

[Q] Xposed use classes obfuscated with proguard

Hi,
I just started using Xposed Framework and I think it is really cool tool! For now I am just trying to learn the API and how to do the things. I am trying to change some values returned by functions by an app, but the decompiled code is obfuscated and all class names and methods are with one or two letters. For example :
Code:
if(!p.a().h() && ae1.c() > 500F){
com.bones.modes.cn.a(com.bones.modes.cl.a(b)).b().a("New message");
}
So what I need is a way to change return value of
Code:
p.a().h()
and
Code:
ae1.c()
which are located in different package than
Code:
com.bones.modes
.
Any idea how to achieve this?
Why decompile when you can compile from source or directly edit source
check repositories under this user : https://github.com/rovo89
if you find your changes could benifit others submit a change request.
anantshri said:
Why decompile when you can compile from source or directly edit source
check repositories under this user : rovo89
if you find your changes could benifit others submit a change request.
Click to expand...
Click to collapse
I decompiled application just to find class names and methods so I can inject code and make some changes, but don't know how to deal with obfuscated code and Xposed. I've tried to hook method found using dex2jar, but it's throwing an exception
Code:
NoSuchMethodError
.
hardartcore said:
Hi,
I just started using Xposed Framework and I think it is really cool tool! For now I am just trying to learn the API and how to do the things. I am trying to change some values returned by functions by an app, but the decompiled code is obfuscated and all class names and methods are with one or two letters. For example :
Code:
if(!p.a().h() && ae1.c() > 500F){
com.bones.modes.cn.a(com.bones.modes.cl.a(b)).b().a("New message");
}
So what I need is a way to change return value of
Code:
p.a().h()
and
Code:
ae1.c()
which are located in different package than
Code:
com.bones.modes
.
Any idea how to achieve this?
Click to expand...
Click to collapse
Hook the application's package (application package != Java package), then hook the class name you want using its full name (e.g. com.bones.modes.ClassName, or com.otherpackage.something.ClassName).
If that doesn't help, post the code you're trying with (and more information about the "different package").
anantshri said:
Why decompile when you can compile from source or directly edit source
check repositories under this user : https://github.com/rovo89
if you find your changes could benifit others submit a change request.
Click to expand...
Click to collapse
He's talking about something entirely different.
GermainZ said:
Hook the application's package (application package != Java package), then hook the class name you want using its full name (e.g. com.bones.modes.ClassName, or com.otherpackage.something.ClassName).
If that doesn't help, post the code you're trying with (and more information about the "different package").
He's talking about something entirely different.
Click to expand...
Click to collapse
I've already fixed it. I realise that the method which I was trying to override takes params and I wasn't pointing them in declaration of hook method.

Android 5.1.1 Update

What's new in Android 5.1.1 Lollipop Update ?
Code:
int main()
{
for (;;); // or while (1);
}
or, if you prefer:
Code:
10 PRINT "INFINITE LOOP"
20 GOTO 10
varxx said:
Code:
int main()
{
for (;;); // or while (1);
}
or, if you prefer:
Code:
10 PRINT "INFINITE LOOP"
20 GOTO 10
Click to expand...
Click to collapse
That's C++ and BASIC right?
ken1645 said:
That's C++ and BASIC right?
Click to expand...
Click to collapse
I need both of those on my phone! :silly:
Thats just C, although it probably applies to C++ too... And your kernel was written in it.
scryan said:
Thats just C, although it probably applies to C++ too... And your kernel was written in it.
Click to expand...
Click to collapse
What he said ...
(or she)

[Q] Replace method and framework.jar

Hi guys, i am learning how to build xposed modules, actually i already built a small module for a few personal things, but now i want to fix a bug i have on my cyanogen. I know cyanogen is open , and i could just download it and compile it , but i want to learn xposed, so it will be a challenge.
Well, i need to replace a method , but looking at the original method there is a line i will need to keep:
Final Set<String> ret = Sets.newHashSet()
where Sets is from 'import com.google.android.collect.Sets;'
Since i do not have this class, how can i make that line to compile ? I think com.google.android.collect.Sets is inside framework.jar, but it appears to be odexed, so eclipse does not recognize if i try to put on build path.
Sorry it the question is too simple, i am still learning =)
There are more alternatives:
1) check source code of Sets.newHashSet(). It most likely returns new HashSet<String>() in which case you simply use that instead. So:
final Set<String> ret = new HashSet<String>()
2) use xposed:
final Set<String> ret = XposedHelpers.callStaticMethod(XposedHelpers.findClass("com.google.android.collect.Sets", classLoader), "newHashSet"));

Categories

Resources