Using root to access and modify protected database on Android - android

I’m trying to create an app that is able to access and modify a protected database within /data/data/. This process obviously requires root privileges and I am testing this on a rooted device. The general code to access the SQLite database is complete and works against a test database that is located elsewhere (on /sdcard/).
However when I want the application to access the database within /data/data/, it obviously fails as I am trying to access it as a normal user. I have read on the topic of using the su binary on Android for a bit now, and as far as I understand it usually used to execute shell commands only.
So my initial idea of making this work was to simply change the permissions of the file when the application starts, and change it back when it quits. So before actually bothering with implementing that in the application itself, I used my file explorer to change the permission to rw-rw-rw-. However my application was still not able to open the database.
My next idea was to use the sqlite3 program directly from the shell, but I found out, that my ROM does not come with it, so I would have to distribute it myself (Titanium Backup seems to do that).
However there is something that makes me wonder if there might not be a better way: I am using Root Explorer as my file explorer and it has a built-in way to browse any SQLite database. Given that it does not seem to ship with a custom sqlite3 binary, and that my phone does not have one itself, the access seems to happen using the normal Java tools. But how does the app get root rights then?
Is there a way to make an Android application run as root? Or did I forget setting something for the permissions earlier which prevented me from accessing it? Or does anyone know how Root Explorer does it?

You cannot raise the permissions of an already running process as far as I know. The simplest answer would be to copy it somewhere using the root shell / command line edit it, then copy it back as root again. And yes, I did read your question, just didn't explain the answer fully. Hopefully it's clear now. Not sure if root explorer does that or something else, but it would work.

Related

On Rooted phone read /data/data/****/**.db

I'm making an app that read messages from Whatsapp, Viber, mails, etc. and groups it so you can read all that one person said to you in just one App.
To do this I'm trying to read the *.db files each App has on /data/data directory but have encountered two problems.
Since I'm new to programing for rooted phones I don't know how this works and have not found a good tutorial or any documentation. Do you have any that I could read to understand?
Once I know how to access /data/data with root, how can I read the *.db without making a copy. Many other topics say that I should copy the *.db file to a folder and read it there, but wouldn't it be a lot more simple to just read it from where it is?
Apps, regardless of whether the phone is rooted or not, can only ever read files that they themselves own, or that are public (e.g., on a SD card). This is because while the phone may be rooted, the apps themselves do not gain root access.
Instead, on your phone, you have an executable named su lets apps run root commands. However, by default, it refuses to let any app run any root commands. When you root your phone, you replace this executable by a new, modified version that lets approved apps run root commands. It is by using these root commands that you can gain indirect root access to the system.
Now, since you only have indirect root access for your app, you cannot just read any file from the file system. But if you run a root command to copy it to your own, private directory, where you do have permission to read it, your app can directly read it from there.
(Note: you can technically read files without copying them first, by using the su executable, but unless there's a real reason why you can't copy first, and you actually know what you're doing, you probably shouldn't even bother because it's rarely worth the trouble anyways, especially not for sqlite databases.)
For details about how to run root commands with su, see this link (which Gumbo posted in the comments above).

How can I display the folders that require root acess in android?

I am working on a android app and i want the user to be able to view the folders that require root access. I tried looking through the Cyanogenmod file manager code to try and trying the su command in java with the Runtime thing, but I had no luck.
You cannot do this without rooting the device (which simply means gaining required root access level). That's basically the reason for permission system - to keep you away from the places you should not be looking in.

How to modify AOSP to allow specific apps to get root access?

I'm working on AOSP. I've successfully added my apk to build. Now I want to give root access to my app. I don't want to provide root access to other apps or to install the Superuser app in my build. I just want to add my app to get root access. How can I achieve that?
I went through the su.c file in path system/extras/su but I'm unable to understand the whole code.
When I went through the code, I think my objective can be achieved if I could modify su.c to provide root access to my app,compile it and add the binary to the build. Am I right?
You're moving in the right direction. You need to check the sources for su.c The only problem that you can face is how to run your program as root. To do this you need to set SUID sticky bit for the executable of your application. To do this you need to modify system/core/include/private/android_filesystem_config.h file (structure android_files[]), for instance for su program you can see how this bit is set:
{ 06755, AID_ROOT, AID_ROOT, "system/xbin/su" },
ChainFire has written a a guide on su and how to use it for normal apps. If you're intending on working with anything other than your own phone I suggest this is the approach you follow.

Writing file manager for Android with root rights

I am writing web interfaced file manager for Android. It works really decent I can navigate over Android file system using web browser. However here is one problem, the manager can't step in certain directories, for example if I step into '/cache', method File("/cache").listFiles() return null. I can imagine that the problem leads to permissions. However I know that there is root file manager application, so certainly this problem can be addressed. Could somebody suggest a solution?
As per this answer, you need to start a subprocess with root permissions and then execute the shell commands via Java I\O.

Viewing an Android application database

Is there a way to view an application database on an Android device? The only solution I've found requires a developer device and I don't have one. I know I can root it and get the same result, but I'd rather not do that.
There is no way other than rooting the device.
If you just want to view/edit what is in the database you can follow the instructions near the end of this blog post:
http://www.screaming-penguin.com/node/7742
I used this method to make sure data was being written correctly and to add data as well.
For more on ADB: http://developer.android.com/guide/developing/tools/adb.html
Hope this helps
[Edit] I just re-read your question and I realize you may have been asking to view the database from your Android device - the method I suggested in the link allows you to view/edit from a computer with the ADB - NOT on the device.
If you create your .db on the SD Card, you can view it without root privileges. But, this is probably not what you want to do for your production app. Otherwise you need a dev phone or one with root access.
If you want a visual tool to open/display your .db files, MOTODEV Studio allows you to open an arbitrary .db file from your SD card. Look in the "MOTODEV Database" perspective for the ability to map a file to a database. developer.motorola.com

Categories

Resources