android - open ANY SQLiteDatabase as su/root -


i know, can start process root user, how can create sqlitedatabase given path (any path, i.e. another's app database)? root user in root process...

i tried reading file directly, not work (it asks every time root access again) , prints empty result (because sqlite3 not found)

 string path = "/data/data/<app_package>/databases/<database_name>";  process p = runtime.getruntime().exec("su sqlite3 -csv " + path + " \"select * test\";");  stringbuilder res = new stringbuilder();  string line;  while ((line = bufferedreader.readline()) != null)      res.append(line + "\n"); 

actually, want read content of app's database, how can properly? content 1 of 2 following solutions:

  • get content of query csv or similar

  • getting sqlitedatabase object root, given database path (preferred, more flexible)

partially solution found:

see answer...

but: still 1 problem, asks su permissions every time, how can avoid this?

following works far, 1 problem: asks permissions everytime... because of new process...

try { string dbname = "<database_name>"; string packagesrc = "<package_source>"; string pathsource = "/data/data/" + packagesrc + "/databases/" + dbname; string pathtarget = "/data/data/" + mainapp.getappcontext().getpackagename() + "/databases/" + dbname;  // 1) delete old copied file // 2) copy file // 3/4) set permissions of copied file string commanddelete = "rm " + pathtarget + "\n"; string commandcopy = "cat " + pathsource + " > " + pathtarget + "\n"; string commandchown = "chown root.root " + pathtarget + "\n"; string commandchmod = "chmod 777 " + pathtarget + "\n";  process p = runtime.getruntime().exec("su");  outputstream os = p.getoutputstream();  os.write((commanddelete).getbytes("ascii")); os.flush(); os.write((commandcopy).getbytes("ascii")); os.flush(); os.write((commandchown).getbytes("ascii")); os.flush(); os.write((commandchmod).getbytes("ascii")); os.flush();  os.close();  try {     p.waitfor();     if (p.exitvalue() != 255)     {         sqlitedatabase db = sqlitedatabase.opendatabase(pathtarget, null, sqlitedatabase.open_readonly);         // happy , work database     } } catch (interruptedexception e) {     // error } } catch (ioexception e) { // error } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -