Xposed module with sqlite (without context

Search This thread

shnapsi

Senior Member
Aug 14, 2014
54
0
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
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
If you can't get a context from the method you're hooking, you could try the AndroidAppHelper.currentApplication method.
 

pyler

Senior Member
Jan 13, 2013
1,279
2,372
Code:
Context ctx = AndroidAppHelper.currentApplication();
Context myCtx = ctx.createPackageContext("com.developer.app");
 

elesbb

Senior Member
Jun 20, 2010
7,883
5,324
HI Guys,

I tried the AndroidAppHelper.currentApplication() option, but it returns NULL in my case...

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 :)
 

shnapsi

Senior Member
Aug 14, 2014
54
0
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 :)


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.
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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.
You probably don't have the required permissions to read/write to that location.
 

shnapsi

Senior Member
Aug 14, 2014
54
0
You probably don't have the required permissions to read/write to that location.

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!
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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!
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.
 

shnapsi

Senior Member
Aug 14, 2014
54
0
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.

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?
 

jmarques00

Member
Oct 11, 2015
13
0
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
 

Attachments

  • identityspoofing.zip
    4 KB · Views: 58