[Q] R/W access to sharedPreferences w/Xposed - Xposed General

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.

Related

Xposed module with sqlite (without context

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

[MODULE HELP] Can I replace a system APK file conditionally per API Level?

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

Magisk Module development help

This is my first attempt at a Magisk Module (to fix a issue with a few poorly coded legacy apps and not trip safety net) inject or replace a font and set proper permission on the file
My super simple experiment is here (based on the template from Git)
https://drive.google.com/file/d/1PHdRjzefpSMg51KUOffo4FtqlfoxshOM
Magisk gives me a error when I try to install
I probably did something wrong, hopefully someone can point me in the correct direction (error one, not a valid Magisk Module, error two Magisk is not activated)
I appreciate any insight - please move this post to the correct location if needed
If you want someone to look at the module you'll have to enable sharing for the file first...
But, your errors are usually:
1 - the zip has been packaged wrongly (not the proper file/directory structure
2 - using an old template
Take a look in the official docs on how to work with the current module and module installation setup:
https://topjohnwu.github.io/Magisk/guides.html
Let's try this link:
https://drive.google.com/file/d/1PHdRjzefpSMg51KUOffo4FtqlfoxshOM/view?usp=sharing
I started on Git, but I may have inadvertently been in the wrong place / pulled the wrong file -- I will go back through that link you provided tomorrow and see if something jumps out at me
Yeah, you have a whole host of mixed issues there...
First, all the module files have to be in the root of the module zip, not in the magisk-module-DroidSansFallback you have them in now (this is the "not a Magisk module").
Second, your update-binary is a webpage... That ain't gonna work very well. When you download the module_installer.sh script, save it from the raw view (there's a button above the code when you open the file on GitHub).
Last (but this is only cosmetical really, since it won't affect anything) you found some really old module to base your work on, because the config.sh file hasn't been used for ages, and the readme file is ancient.
Fix the above and follow the instructions in the docs and you should be good to go.
Is there a current template on Git for the blank files?
I am here:
https://topjohnwu.github.io/Magisk/guides.html
Made the updates, going to try it now - but I would like to get a proper template setup
There is no longer an official template provided.
The current module installation setup is so simple that it really doesn't need it. Put whatever files you want to mount in /system, whatever boot script or prop files (as described in the docs) you want to run in the root of the zip, create the module.prop (again, described in the docs) so that you'll have some info about the module in the Manager, zip it up and flash it.
If you want to customise things more you do that with the customize.sh script (described in the docs).
If you really need a template there's always @Zackptg5's MMT-Ext...
So I downloaded a current module and looked through the files / structure and then the docs -- and now I have this
https://drive.google.com/file/d/1z4tlH6wGDpq0UnkxPF0f6i-DohcKnux-/view?usp=sharing
When I go to /system/fonts I now see DroidSansFallback.ttf (it was not present before installing the module)
and no error messages!!
I think I need to read a little more, on Android 5-8 adding this font into /system/fonts (manually) fixed my problem - now I am on Android 9 (OnePlus 6t TMO variant) and I do not see any changes from adding the file (fonts.xml issue?)
I really wanted to try this as a learning experience, and because the old method trips CTSProfile to false
I appreciate your patience - at least now I have a better starting point
All you need for the font file to be mounted is the /system/fonts/DroidSansFallback.ttf file in the module society directory. The REPLACE variable you've set in customize.sh is only for replacing directories with empty ones, not files (so you can remove it since it might be causing a conflict). Details in the docs:
https://topjohnwu.github.io/Magisk/guides.html#remove-folders
updated (linked file updated as well) no change.. .. ..
I did double check that the module places the file in the correct location, and when the module is disabled the file is removed
I found this on a random Google search (ASE) from a unrelated topic (Chinese character support)
On Android 9 it's Noto CJK, e. g. "Noto Sans CJK JP" font family (located in /system/fonts/NotoSansCJK-Regular.ttc). There is no DroidSansFallback.ttf anymore.
Could that explain why adding the file did not work?
Very possible. As you say, the module looks fine and works as intended (places the file where you want it), so the issue likely lies elsewhere.
I will take a stab at injecting a modified fonts.xml and see if that changes anything - thanks!
I experimented with adding a line into the fallback section of the fonts.xml (to reference the new font), and replacing the fonts.xml with a older version from Android 8 --- neither had any effect that I could discern

Get read/write permission for Android 11 in EdXposed Module

In my module, I want to compare my string with string in a list of strings, which is stored as a .txt file in the SD card of Android 11. If my string is found in that list, the module should return the "true" value. But I cannot access this .txt file, I met "Permission Denied". So, Is there any possible way to read that type of file in the EdXposed Module?
nthp999 said:
In my module, I want to compare my string with string in a list of strings, which is stored as a .txt file in the SD card of Android 11. If my string is found in that list, the module should return the "true" value. But I cannot access this .txt file, I met "Permission Denied". So, Is there any possible way to read that type of file in the EdXposed Module?
Click to expand...
Click to collapse
you can use objectinputsteam for read that file and after read that file you can check anything which you want and make sure make takget sdk 27 for bypass any aditional read or write security.
AndroidX said:
you can use objectinputsteam for read that file and after read that file you can check anything which you want and make sure make takget sdk 27 for bypass any aditional read or write security.
Click to expand...
Click to collapse
I tried in sdk27 and it doesn't work, so I used a broadcast receiver and send myString to MainActivity.java, this class will read the file which I stored in the SD card.

[REQUEST] Module to replace a file in vendor/etc

I have an LG V60 phone and I would like to put the phone in "high impedance mode" all the the time for more power to the earphones even if they are less than 50 ohm impedance.
In LG V40/50, it was very simple by rooting the phone and making some modifications in the one of the files that was in the "vendor/etc" directory. The problem with LG V60 is it does not allow any write access to the vendor folder at all.
So the only feasible option that I can think of is to create a Magisk module that replaces the original file with the modified one. My biggest disadvantage is not knowing anything about writing codes including Magisk module ones. So I was wondering if anyone could create a Magisk module that would replace the original file through Magisk?
ADDTIONAL INOFRMATION:
I am running Magisk 25 on a fully rooted LG V60.
The file that needs to be changed is mixer_paths.xml and it resides in the "vendor/etc" folder. I have created the modified file.
So if someone is able to develop a module to accomplish this, I will place the modified file in the "system/vendor/etc" folder of the Magisk module, as I understand it.
Many thanks for your support!
You can use this template system in future as its super easy
The template itself is here
GitHub - Zackptg5/MMT-Extended: Magisk Module Template Extended
Magisk Module Template Extended. Contribute to Zackptg5/MMT-Extended development by creating an account on GitHub.
github.com
click the Code button, then download zip
then extract the zip into a folder and rename the folder "MMT-Extended-master" to the something more meaningful, like the name of your module
Read the wiki and docs here to go step by step to create your first module:
Home
Magisk Module Template Extended. Contribute to Zackptg5/MMT-Extended development by creating an account on GitHub.
github.com
Notably the heading:
How do I make a MMT Extended mod?​
The steps for a simple file addition/replacement module, which are simple, should be steps 1-4, then 8. Then zip up the modules (as a zip) and test.
For you, if you read along (in Step 3) you will need to create a folder vendor, under the existing system one, and then a further etc folder under vendor, and put the necessary file (mixer_paths.xml in there.
If you try and fail, post back and someone will assist. But we prefer people to at least read the documentation and try first, ideally...this is the way the great didgeridoohan mentored myself and many others, he was not big on spoonfeeding
Imagine the satisfaction you might get finding out youre capable of such feats...i promise its not rocket surgery
Feel free to PM even, if you get stuck and think you have a silly question - of course knowing me, and i do, you'll probably get an even sillier, and off topic answer as well...
hint: you can knock out this basic module in far far less time than it took me to write all this
Thank you!
So my changes look like this:
1. Put the modified file in the system/vendor/etc folder of the Magisk module.
2. Made the needed changes to the customize.sh as attached.
Royaltiger said:
Thank you!
So my changes look like this:
1. Put the modified file in the system/vendor/etc folder of the Magisk module.
2. Made the needed changes to the customize.sh as attached.
Click to expand...
Click to collapse
Yes, though you'll need to uncomment (remove the leading #) from the set_perm lines to make them active, also you only really need the 2nd one
Royaltiger said:
Thank you
73sydney said:
Yes, though you'll need to uncomment (remove the leading #) from the set_perm lines to make them active, also you only really need the 2nd one
Click to expand...
Click to collapse
Click to expand...
Click to collapse
So I made the module with the suggested changes in customize.sh and put the modified mixer_path.xml file in the system/vendor/etc folder of the module. Module installs fine with Magisk but when it reboots, the device hangs on the initial LG screen and does not go anywhere from there.
I am attaching the customize.sh snapshot. Also, attached is the module file.
See here under "Disabling/uninstalling modules manually" if youre not able to boot
Module Issues:Magisk and MagiskHide Installation and Troubleshooting guide
www.didgeridoohan.com
I am assuming that it is not possible to accomplish what I wanted to achieve.
Royaltiger said:
I am assuming that it is not possible to accomplish what I wanted to achieve.
Click to expand...
Click to collapse
mixer_paths files have been replaced for years, long before magisk even...i did it back as far as the Galaxy S2 from memory, so im not sure why this didnt work for you, was the mxer_paths file specifically for your device? i have no clear idea why it hasnt worked for you
this thread has a guide to making /system RW, so you could manually copy the file and overwrite it, but id really consider how much you want to replace mixer_paths before i set out to do that
V60 Bootloader Unlock and Magisk Root
Earlier today I was alerted to https://www.cnblogs.com/yanhua-tj/p/15525593.html which has the actual firehose and steps to unlock! However it seems to be in Simplified Chinese so I'll translate it here for you. The firehose is attached below...
forum.xda-developers.com
73sydney said:
mixer_paths files have been replaced for years, long before magisk even...i did it back as far as the Galaxy S2 from memory, so im not sure why this didnt work for you, was the mxer_paths file specifically for your device? i have no clear idea why it hasnt worked for you
this thread has a guide to making /system RW, so you could manually copy the file and overwrite it, but id really consider how much you want to replace mixer_paths before i set out to do that
V60 Bootloader Unlock and Magisk Root
Earlier today I was alerted to https://www.cnblogs.com/yanhua-tj/p/15525593.html which has the actual firehose and steps to unlock! However it seems to be in Simplified Chinese so I'll translate it here for you. The firehose is attached below...
forum.xda-developers.com
Click to expand...
Click to collapse
Actually I had no problem in editing the mixer_tavil.xml file in LG V40/50. But when it comes to LG V60, the file is read-only. There is no way to edit it due to dynamic partition. Hence, I was seeking the only option available i.e., via Magisk module.
Royaltiger said:
Actually I had no problem in editing the mixer_tavil.xml file in LG V40/50. But when it comes to LG V60, the file is read-only. There is no way to edit it due to dynamic partition. Hence, I was seeking the only option available i.e., via Magisk module.
Click to expand...
Click to collapse
So, I encountered the same problem and found what you did wrong. I was able to write my own Magisk module and it works wonderfully. It took so much time to understand how to do it because there is no proper tutorial.
If you are still active and trying to know how to do it the right way, here comes the explanation:
The Replace = " /system/vendor/etc/ " must not be written as it completely wipes the actual folder from your phone. This is why you were not able to turn the phone on. It should be like this:
Replace = " " (That part must be blank)
The rest of the code is good. If you try it like this now, you will see it will work, just like mine did.
Cheers
Does not work. May I see your module? Please upload it here as attachment.
I even put my edited file under /data/adb/modules/<my directory>/system/vendor/etc. It shows up in Magisk as a module and the file loads (as it is not visible in file explorer) but there is no change in volume. So the thing is not working.

Categories

Resources