Guest User

Untitled

a guest
Mar 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. type=1400 audit(0.0:6364): avc: denied { open } for name="database.db" dev="mmcblk0p28" ino=171293 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=file permissive=0
  2. os_unix.c:31278: (13) open(/data/user/0/com.testapp/databases/database.db)
  3.  
  4. // Define in and out filepaths
  5. String DB_INPUT = "/data/data/com.package.name/databases/database.db";
  6. String DB_OUTPUT = activity.getDatabasePath("database.db").getPath();
  7.  
  8. try {
  9. // Request superuser permissions
  10. Process suProcess = Runtime.getRuntime().exec("su");
  11. DataOutputStream suOutputStream = new DataOutputStream(suProcess.getOutputStream());
  12.  
  13. // Copy database
  14. suOutputStream.writeBytes("cat " + DB_INPUT + " > " + DB_OUTPUT + "n");
  15.  
  16. // Fix permissions
  17. int appUID = getApplication().getApplicationInfo().uid;
  18. suOutputStream.writeBytes("chmod 600 " + DB_OUTPUT + "n"); // rw- --- ---
  19. suOutputStream.writeBytes("chown " + appUID + "." + appUID + " " + DB_OUTPUT + "n");
  20. suOutputStream.writeBytes("exitn");
  21. suProcess.waitFor();
  22. suOutputStream.close();
  23.  
  24. // Test
  25. SQLiteDatabase.openDatabase(DB_OUTPUT, null, SQLiteDatabase.OPEN_READWRITE);
  26. } catch(Exception e) {
  27. Log.e(LOGTAG, "Something went terrible wrong: " + e.getMessage());
  28. }
  29.  
  30. // Define in and out filepaths
  31. String DB_INPUT = "/data/data/com.package.name/databases/database.db";
  32. String DB_OUTPUT = activity.getDatabasePath("database.db").getPath();
  33.  
  34. // Create empty database to grant permissions
  35. SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_OUTPUT, null);
  36. db.close();
  37.  
  38. try {
  39. // Request superuser permissions
  40. Process suProcess = Runtime.getRuntime().exec("su");
  41. DataOutputStream suOutputStream = new DataOutputStream(suProcess.getOutputStream());
  42.  
  43. // Copy database
  44. suOutputStream.writeBytes("cat " + DB_INPUT + " > " + DB_OUTPUT + "n");
  45.  
  46. // Close terminal
  47. suOutputStream.writeBytes("exitn");
  48. suProcess.waitFor();
  49. suOutputStream.close();
  50. } catch(Exception e) {
  51. Log.e(LOGTAG, "Something went terrible wrong: " + e.getMessage());
  52. }
Add Comment
Please, Sign In to add comment