Hi,
I want to use sqlite in my xposed module but i don't have any activity or context to send the database constructor.
Is it possible to overcome this?
I tried to send null as a context, but i'm getting nullPointerException when i try to open the database.
Thanks,
Gidi
If you can't get a context from the method you're hooking, you could try the AndroidAppHelper.currentApplication method.
Code:
Context ctx = AndroidAppHelper.currentApplication();
Context myCtx = ctx.createPackageContext("com.developer.app");
pyler said:
Code:
Context ctx = AndroidAppHelper.currentApplication();
Context myCtx = ctx.createPackageContext("com.developer.app");
Click to expand...
Click to collapse
HI Guys,
I tried the AndroidAppHelper.currentApplication() option, but it returns NULL in my case...
shnapsi said:
HI Guys,
I tried the AndroidAppHelper.currentApplication() option, but it returns NULL in my case...
Click to expand...
Click to collapse
If you are editing a database using sqlite and the current process you are hooking as no context reference, you can use root to set the database file to readable, then have your own service running in the background with a file observer tracking changes to a file on the device. Inside xposed module you will write to the file with a command instructing the file observer what to do. Then your service will "hear" the command and execute the changes needed.
I plan on writing up a guide for this. Tomorrow
elesbb said:
If you are editing a database using sqlite and the current process you are hooking as no context reference, you can use root to set the database file to readable, then have your own service running in the background with a file observer tracking changes to a file on the device. Inside xposed module you will write to the file with a command instructing the file observer what to do. Then your service will "hear" the command and execute the changes needed.
I plan on writing up a guide for this. Tomorrow
Click to expand...
Click to collapse
Thanks, I'll be happy to read your guide and learn new stuff
Anyway, I read that it's possible to use Sqlite DB without using SQLiteOpenHelper, this way, i don't need context.
the problem is that when i do it i get exception:
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
this is my code:
database = SQLiteDatabase.openOrCreateDatabase(DB_NAME,null);
database.execSQL(CREATE_TABLE);
Thanks.
shnapsi said:
Thanks, I'll be happy to read your guide and learn new stuff
Anyway, I read that it's possible to use Sqlite DB without using SQLiteOpenHelper, this way, i don't need context.
the problem is that when i do it i get exception:
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
this is my code:
database = SQLiteDatabase.openOrCreateDatabase(DB_NAME,null);
database.execSQL(CREATE_TABLE);
Thanks.
Click to expand...
Click to collapse
You probably don't have the required permissions to read/write to that location.
GermainZ said:
You probably don't have the required permissions to read/write to that location.
Click to expand...
Click to collapse
Thanks GermainZ,
which permissions do i need?
I tried to do it this way too:
Code:
File db = new File("/data/data/com.example.mytest/databases/" + DB_NAME);
db.setReadable(true);
db.setWritable(true);
File path = new File("/data/data/com.example.mytest/databases/");
path.setReadable(true);
path.setWritable(true);
path.mkdirs();
database = SQLiteDatabase.openOrCreateDatabase(db,null);
Still same result...
Thanks!
shnapsi said:
Thanks GermainZ,
which permissions do i need?
I tried to do it this way too:
Code:
File db = new File("/data/data/com.example.mytest/databases/" + DB_NAME);
db.setReadable(true);
db.setWritable(true);
File path = new File("/data/data/com.example.mytest/databases/");
path.setReadable(true);
path.setWritable(true);
path.mkdirs();
database = SQLiteDatabase.openOrCreateDatabase(db,null);
Still same result...
Thanks!
Click to expand...
Click to collapse
Let's differentiate between two things: your module (normal code) and the hooked process (the Xposed code).
Remember that hooked code runs as the hooked process (that is, the app you're hooking — *not* your module), so you won't be able to write to your module's data directory.
I don't know if you can change that. Maybe you could create the database and use Context.MODE_WORLD_WRITABLE (from your module, when it firsts open), but I don't think you'll have any luck creating it from the hooked process directly.
GermainZ said:
Let's differentiate between two things: your module (normal code) and the hooked process (the Xposed code).
Remember that hooked code runs as the hooked process (that is, the app you're hooking — *not* your module), so you won't be able to write to your module's data directory.
I don't know if you can change that. Maybe you could create the database and use Context.MODE_WORLD_WRITABLE (from your module, when it firsts open), but I don't think you'll have any luck creating it from the hooked process directly.
Click to expand...
Click to collapse
So where is the best place to use AndroidAppHelper.currentApplication(); so it won't return null and i will be able to use it in my hooked method?
Hello gays, i read all post's . I've the same problem. I start develop a module for xposed for my thesis the goal of application is return fake data when some aplications want access features that they don't need. I all ready can save in sqlite database the restrictions that the user want to restrict, the package name of application and uid. Now i want to access to the database methods by the main class (with implements IXposedHookLoadPackage) and i allways getting nullPointerException when i try connect to database. Anyone can solve this problem?? I will attach my main class IdentitySpoofing and my DatabaseHelper Best Regards Joao Marques
So I'm writing my first Xposed module and I've hit another snag.
My module has a UI that can be opened from the launcher. My UI is simple and it just allows the user to increment/decrement the counter. The value of the counter is saved to the SharedPreferences file found at \data\data\com.appname\shared_prefs.
The Xposed portion of the module will read the value out of the shared_prefs file, decrement the counter, and save the decremented value back to the file...
How can this be done? I know that I shouldn't be reading/writing to the shared_prefs file from the Xposed activity... so if there is a better (read correct) way of doing what I need to do, can you point me in the right direction? The only part of the module I don't have working is this last part... My UI is already able to Read/Write to the shared_prefs file, so hopefully that helps... or at least shows that I'm not wasting anyone's time.
In xposed module send intent to your app to modify prefs.
Could you be a little more specific? I'm more of an embedded/C programmer... Android/Java is still a little new to me.
Define own intent sction in manifest - e.g. mymodule.intent.action.DESCREASE_COUNTER
Then in hook you have to get context (getObjectField("mContext") - in android, AndroidAppHelper.currentApplication - for other apps)
Then just run intent:
mContext.sendBroadcast(new Intent("mymodule.intent.action.DESCREASE_COUNTER"));
I use such way in my module - https://github.com/pylerSM/XInstaller/. Check it
I try to read a shared preferences file in the Xposed Bridge module and I cannot get anything. Can you please, provide some information on how to read the file. I would prefer to use shared preferences instead of a binder.
How to get access to resources in own res/strings.xml file (witch contain my xposed project)?
My xposed project does not have any activity. If I try to get string from res/strings.xml
Code:
hookedctivity.getString(R.string.my_id)
I got value from hooked module not mine.
How I can get value from res/string.xml in my project?
Use Context.createPackageContext
I trying to use Gstreamer on Android via Xamarin.Android(in the Visual Studio), so I built this sample project(github.com/jaroslavas/Gstreamer-Android-example) on the Ubuntu, took the compiled libtutorial-5.so and libgstreamer_android.so libraries and added them into the Xamarin.Android project as AndroidNativeLibrary's. When I try to use libgstreamer_android.so using DllImport, then all going ok, but when I try to use libtutorial-5.so (of course using DllImport), then I get:
DllImport unable to load library 'dlopen failed: could not load library "build/obj/local/armeabi-v7a/libgstreamer_android.so" needed by "libtutorial-5.so"; caused by library "build/obj/local/armeabi-v7a/libgstreamer_android.so" not found'.
Click to expand...
Click to collapse
This error occurs because libtutorial-5.so depends on the libgstreamer_android.so. libtutorial-5.so trying to find libgstreamer_android.so library in build/obj/local/armeabi-v7a/libgstreamer_android.so location.
But of course these two libraries are located in the lib/armeabi-v7a directory and even if I replace all two libraries or just libgstreamer_android.so in this location, then I still have this error.
So how can I change path of the library on which my first library will depend in the Android Studio or just in the .mk files(on the .so building stage)?
Hi, lib not found may cause by:
1. Lib is not exist.
2. Lib that declare in Build.gradle that is different that that you load in java class
3. Function name is not follow the form (the dot. in package name of java class is replaced by "_" in c++ function and class.
4. Clean project and rebuilt it. If you not clean, old lib .so will not be deleted.
5. Check if you declare create in android.productFlavors{}
I'm trying to create a module where I need to replace a /system/priv-app/<filename>.apk with another one but it depends on the running Android version (API Level). Can this be scripted somehow with Magisk or would I need to create a module for each API Level I need/want to support?
You're on a roll today, aren't you?
What you're asking for is quite easy with a Magisk module. It's already implemented in the template:
https://github.com/topjohnwu/magisk...META-INF/com/google/android/update-binary#L62
You can place the different versions of the apk you want to use in the /common folder, name them accordingly, and then use the $API to install the correct one. Example:
Code:
cp $INSTALLER/common/apkname-$API.apk $MODPATH/system/priv-app/apknamefolder/apkname.apk
I just want to make sure I do this module correctly and don't break anything when sharing the module with everyone.
Should I just place the copy command directly in the "update-binary" file or create a "custom function" inside my config.sh and and call that inside "update-binary"? What's the recommended approach here?
I'd create a function in config.sh and call that inside update-binary. That way it'll be a lot easier for you to update to a new template further on.
Thank you