PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/dbstealer/dbstealer.php

https://github.com/gopinathdanda/AFE
PHP | 149 lines | 129 code | 2 blank | 18 comment | 41 complexity | d0a0a2896515843c518b593217602f3c MD5 | raw file
  1. <?php
  2. //////////////////////////////////////////////////
  3. // Android file browser and .db file extractor //
  4. // Author: Subho Halder //
  5. // Blog: http://subho.me/ //
  6. // Web: http://subhohalder.com/ //
  7. // License: GNU GPlv2 //
  8. // Donot remove this header ! //
  9. //////////////////////////////////////////////////
  10. echo "Welcome to .db file extractor !!\n\n\n";
  11. //////////se base path --->> //////////////////////////////////
  12. $base = "/data/data/";
  13. //////////////////////////////////////////////////////////////
  14. /////// Getting which OS ////////////////////////////////////
  15. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  16. $platform = 'windows';
  17. } else if (strtoupper(substr(PHP_OS, 0, 3)) === 'DAR') {
  18. $platform = 'mac';
  19. } else {
  20. $platform = 'linux';
  21. }
  22. //////////////////////////////////////////////////////////////////////////////////
  23. ////////getting the list of devices attached ////////////////////////////////////
  24. @exec('adb devices');
  25. exec('adb devices', $d);
  26. $extend = "";
  27. device:
  28. $dev = 0;
  29. /////////// Menu of devices!! ////////////////////////////////////
  30. foreach($d as $devices) {
  31. if($dev==0) {
  32. echo $devices."\n\n";
  33. $dev++;
  34. continue;
  35. }
  36. if (empty($devices)) {
  37. $dev++;
  38. continue;
  39. }
  40. $slc = preg_split("/\s+/", $devices, -1, PREG_SPLIT_NO_EMPTY);
  41. echo $dev.' '.$slc[0]."\n";
  42. $dev++;
  43. }
  44. /////////////////Menu choice ////////////////////////////////////
  45. echo "\nChoose Which device you want to work with? (Enter 1,2,3....)\n";
  46. $inp = strtolower(trim(fgets(STDIN)));
  47. $default = '';
  48. if(empty($inp) || $inp=="\r" || $inp>=$dev-1 || $inp<=0 || !is_numeric($inp)) {
  49. goto device;
  50. } else {
  51. $tsel = $d[$inp];
  52. $t2sel = preg_split("/\s+/", $tsel, -1, PREG_SPLIT_NO_EMPTY);
  53. $device = $t2sel[0];
  54. $device = trim($device);
  55. }
  56. //////////////////////Devices menu End ////////////////////////////////////
  57. exec('adb -s '.$device.' root');
  58. exec('adb -s '.$device.' shell ls -l '.$base, $m);
  59. ///////////////File list menu ////////////////////////////////////////////
  60. menu:
  61. echo "\nFound Files in the ".$base.$extend." Folder! \n\n";
  62. $n=1;
  63. foreach ($m as $line) {
  64. $slice = preg_split("/\s+/", $line, -1, PREG_SPLIT_NO_EMPTY);
  65. $end=7;
  66. if(stristr($slice[0],'d')) {
  67. $end=6;
  68. }
  69. echo $n." ".$slice[$end-1]."\n";
  70. $n++;
  71. }
  72. echo "\nChoose Which file you want to get? (Enter 1,2,3....)\nEnter R to go back to default directory\nEnter e to exit\nEnter A to get all .db files from this directory\n\n";
  73. $input = strtolower(trim(fgets(STDIN)));
  74. $default = '';
  75. $final_p = "../../Output/dbstealer/".$device."/";
  76. if($input == 'e' || $input == 'E') {
  77. goto end;
  78. }
  79. if($input == 'a' || $input == 'A') {
  80. goto findall;
  81. }
  82. if($input == 'r' || $input == 'R') {
  83. $extend = "";
  84. $m = "";
  85. exec('adb -s '.$device.' shell ls -l '.$base, $m);
  86. goto menu;
  87. }
  88. if(empty($input) || $input=="\r" || $input>=$n || $input<=0 || !is_numeric($input)) {
  89. goto menu;
  90. } else {
  91. $tmp1 = $m[$input-1];
  92. $files = preg_split("/\s+/", $tmp1, -1, PREG_SPLIT_NO_EMPTY);
  93. if(stristr($files[0],'d')) {
  94. $extend = $extend.$files[5]."/";
  95. $m = "";
  96. exec('adb -s '.$device.' shell ls -l '.$base.$extend, $m);
  97. goto menu;
  98. }
  99. $file = $files[6];
  100. }
  101. if(!is_dir($final_p)) {
  102. @mkdir($final_p);
  103. }
  104. if(file_exists($final_p."/".$file)) {
  105. echo "Remove the db file from the folder to copy !";
  106. } else {
  107. exec('adb -s '.$device.' pull '.$base.$extend.$file.' '.$final_p);
  108. }
  109. goto menu;
  110. findall:
  111. echo "getting all .db files from ".$base.$extend." directory and beneath it too \n\n...";
  112. @mkdir($final_p);
  113. exec('adb -s '.$device.' shell ls -l '.$base.$extend, $ma);
  114. foreach ($ma as $line) {
  115. $slice = preg_split("/\s+/", $line, -1, PREG_SPLIT_NO_EMPTY);
  116. $end=7;
  117. if(stristr($slice[0],'d')) {
  118. $end=6;
  119. scaneer($base.$extend.$slice[$end-1],$device);
  120. }
  121. if($end==7) {
  122. if(stristr($slice[$end-1],'.db')) {
  123. exec('adb -s '.$device.' pull '.$base.$extend.$slice[$end-1].' '.$final_p);
  124. }
  125. }
  126. }
  127. goto menu;
  128. /////////////////////// function to get all .db files inside a specific path ////////////////////////
  129. function scaneer($path,$device) {
  130. $fp = "../../Output/dbstealer/".$device;
  131. exec('adb -s '.$device.' shell ls -l '.$path, $mf);
  132. foreach ($mf as $line) {
  133. $slice = preg_split("/\s+/", $line, -1, PREG_SPLIT_NO_EMPTY);
  134. $end=7;
  135. if(stristr($slice[0],'d')) {
  136. $end=6;
  137. scaneer($path.'/'.$slice[$end-1],$device);
  138. }
  139. if($end==7) {
  140. if(stristr($slice[$end-1],'.db')) {
  141. exec('adb -s '.$device.' pull '.$path.'/'.$slice[$end-1].' '.$fp);
  142. }
  143. }
  144. }
  145. }
  146. end:
  147. ?>