The OnePlus 2 & The Year of Smartphone Compromises

We are very close to entering the last third of 2015, and we have now seen many of … more

OnePlus 2 Teardown, Major Android Vulnerability – XDA TV

The OnePlus 2 has been officially released. That and much more news is … more

What Do You Think About Fingerprint Scanners?

More and more phones are featuring fingerprint scanners, and with many promising … more

What’s Next for Samsung and Its Flagships?

If we were to say that the Galaxy S6 was a leap of faith made by Samsung, we … more

Xposed module with sqlite (without context

53 posts
Thanks Meter: 0
 
By shnapsi, Member on 4th September 2014, 03:38 PM
Post Reply Subscribe to Thread Email Thread
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
 
 
5th September 2014, 02:38 AM |#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,327
 
More
If you can't get a context from the method you're hooking, you could try the AndroidAppHelper.currentApplication method.
5th September 2014, 05:24 PM |#3  
Senior Member
Thanks Meter: 1,101
 
More
Code:
Context ctx = AndroidAppHelper.currentApplication();
Context myCtx = ctx.createPackageContext("com.developer.app");
7th September 2014, 06:26 AM |#4  
OP Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by pyler

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...
7th September 2014, 06:45 AM |#5  
elesbb's Avatar
Senior Member
Thanks Meter: 4,696
 
Donate to Me
More
Quote:
Originally Posted by shnapsi

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
7th September 2014, 03:45 PM |#6  
OP Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by elesbb

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.
7th September 2014, 07:58 PM |#7  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,327
 
More
Quote:
Originally Posted by shnapsi

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.
9th September 2014, 06:40 AM |#8  
OP Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by GermainZ

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!
9th September 2014, 07:03 AM |#9  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,327
 
More
Quote:
Originally Posted by shnapsi

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.
9th September 2014, 07:49 AM |#10  
OP Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by GermainZ

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?
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes