Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,807,518 Members 50,804 Now Online
XDA Developers Android and Mobile Development Forum

Xposed module with sqlite (without context

Tip us?
 
shnapsi
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 23
Join Date: Aug 2014
Default 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
 
pyler
Old
#3  
Senior Member
Thanks Meter 439
Posts: 357
Join Date: Jan 2013
Code:
Context ctx = AndroidAppHelper.currentApplication();
Context myCtx = ctx.createPackageContext("com.developer.app");
 
shnapsi
Old
#4  
Junior Member - OP
Thanks Meter 0
Posts: 23
Join Date: Aug 2014
Quote:
Originally Posted by pyler View Post
Code:
Context ctx = AndroidAppHelper.currentApplication();
Context myCtx = ctx.createPackageContext("com.developer.app");
HI Guys,

I tried the AndroidAppHelper.currentApplication() option, but it returns NULL in my case...
 
elesbb
Old
#5  
elesbb's Avatar
Senior Member
Thanks Meter 4,367
Posts: 6,799
Join Date: Jun 2010

 
DONATE TO ME
Quote:
Originally Posted by shnapsi View Post
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
Old
#6  
Junior Member - OP
Thanks Meter 0
Posts: 23
Join Date: Aug 2014
Quote:
Originally Posted by elesbb View Post
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.SQLiteCantOpenDatabaseExce ption: unknown error (code 14): Could not open database

this is my code:

database = SQLiteDatabase.openOrCreateDatabase(DB_NAME,null);
database.execSQL(CREATE_TABLE);

Thanks.
 
GermainZ
Old
#7  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,378
Posts: 5,467
Join Date: Aug 2012
Quote:
Originally Posted by shnapsi View Post
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.SQLiteCantOpenDatabaseExce ption: 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
Old
#8  
Junior Member - OP
Thanks Meter 0
Posts: 23
Join Date: Aug 2014
Quote:
Originally Posted by GermainZ View Post
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
Old
#9  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,378
Posts: 5,467
Join Date: Aug 2012
Quote:
Originally Posted by shnapsi View Post
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
Old
#10  
Junior Member - OP
Thanks Meter 0
Posts: 23
Join Date: Aug 2014
Quote:
Originally Posted by GermainZ View Post
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?

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes