[Q] Access to project resources res/strings.xml - Xposed General

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

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

[Q] Getting the execution path information by Xposed

Hi folks,
I'm trying to extract execution path information using Xposed. All I need is to record the invocation of methods in logCat. I found this Xposed-Method-Finder module (github.com/MohammadAG/Xposed-Method-Finder) on repository that can inspect all the methods in a package. However, it needs the name of classes in the package as an input (private static final String[] CLASSES_TO_HOOK). Is there any way to automatically generate the list of classes inside a package instead of provide it manually? Or, is there any other way to inspect and hook all the methods in a package without providing the exact names?
I appreciate your helps

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

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.

[Q] can androidmanifest.xml properties be altered by an xposed module?

Hello.
I know you can overwrite layouts, resources and other properties using an xposed module.
My question is - is it possible to write a module to alter an APK's manifest properties once it loads? (kinda like post-inflate hooks)?
Thanks
Theoretically yes, check PackageParser class or so..

Theming mediatek-res.apk

I have been interested in theming an MTK 6592 mediatek phone (Infinix Hot Note x551) I have owned for quite a while. Its currently running Stock Android 5.1 Lollipop.
I reached a point where I needed to decompile and recompile the mediatek-res.apk framework resource app.
I was using apktool version 2.1.1 and later on 2.2.0-a4270d-SNAPSHOT
I wanted to get rid of this notification item, every time you opened the Dialer, Contacts or Mms application. I found it annoying - asking every time to choose a default simcard, when I clearly wanted and is able to choose a line on calls, or outgoing SMSs.
Sorry, cant post image links yet!!
Click to expand...
Click to collapse
After a few weeks of on-of/trial and error research, I realized that these could be accomplished by editing the mediatek-res.apk located in /system/framework/mediatek-res.
It decompiled ok, but could not compile after editing(again, trial-error).
These were the compilation errors I was getting: A tonne of errors concerning all the resources and their Id's:
HTML:
W: /home/*****/Desktop/mtk/mediatek-res/res/layout/account_five.xml:6: error: Error: No resource found that matches the given name (at 'id' with value '@id/account_five_img').
I read up on this error and one post here on XDA (didnt save the link, sorry) and also over at github, said to edit the apktool.yml file and include the framework ID for the mediatek-res.apk (already installed via 'apktool if mediatek-res.apk'). Its framework ID was 8. So I added it.
HTML:
usesFramework:
ids:
- 1
to
HTML:
usesFramework:
ids:
- 1
- 8
On compilation, a ton of these new errors came up:
HTML:
W: /home/*****/Desktop/mtk/mediatek-res/res/values/styles.xml:3: error: Resource entry style/ImageSwitch is already defined in package com.mediatek.
Looked around furrther for quite sometime couldnt get a solution to this new errors. I continued on my trial and error ways and discovered that If edited the apktoo.yml file
HTML:
sharedLibrary: false
to
HTML:
sharedLibrary: true
and removed the mediatek-res framework ID from apktool.yml file, the errors were reduced to TWO!!
HTML:
W: /home/*****/Desktop/mtk/mediatek-res/res/values/public.xml:914: error: Public symbol ^attr-private/factor declared here is not defined.
HTML:
W: /home/*****/Desktop/mtk/mediatek-res/res/values/public.xml:915: error: Public symbol ^attr-private/scale declared here is not defined.
On investigating the error, I found out that indeed the two resources( ^attr-private/scale & ^attr-private/factor) were not defined in Ids.xml located in /res/values. I added the two to the bottom of the file,
HTML:
<item type="^attr-private" name="factor">false</item>
<item type="^attr-private" name="scale">false</item>
Also I renamed the file ^attr-privates.xml to ^attr-private.xml
On compilation, NO ERRORS!! and the app but pushed to system the phone ends up in endless bootloop.
I finally resolved the bootloop by replacing the resources.arsc in the compiled apk by the one from the original resources.arsc. They differ in size by a few kilobytes.
STEP BY STEP
1. Using APK Multi-Tools, use option
1. Extract APK
Click to expand...
Click to collapse
. Go to Projects folder and copy the resources.arsc file. This is the original file you shall place in the compiled app.
2. Compile as usual the modified mediatek-res app.
3. Go to '/Build/apk' folder and replace the resources.arsc therein with the one from setp 1.
4. Compile a second time.
5. Your apk will be able to boot and run ok now.
Because I am not very well versed with apktool and its inner workings, I don't know why this errors came up. I know this is a work-around, but for now it will have to do.
If this post saves you a few hours/days/weeks of research, hit thanks!!

Categories

Resources