]> FriiDump Source - friidump.git/blobdiff - libfriidump/xbox_ref/utils.c
FriiDump 0.5.3.10: add Redump evidence and optimize Xbox flow
[friidump.git] / libfriidump / xbox_ref / utils.c
index 2e24078c86395157d7bf360335635c808618ce8a..3cf28114b01b0df5f00cc14de1003f7e4e6a4cb1 100644 (file)
@@ -3,6 +3,7 @@
 #include "xbe_cert.h"
 #include "unlock.h"
 #include "xbox_ref_log.h"
 #include "xbe_cert.h"
 #include "unlock.h"
 #include "xbox_ref_log.h"
+#include "../xbox_ref_bridge.h"
 
 #include <time.h>
 #include <windows.h>
 
 #include <time.h>
 #include <windows.h>
@@ -2695,7 +2696,10 @@ static BOOL WriteXboxDvdSidecarFiles(const char *isoFilename,
     fprintf(json, "  ],\n");
 
     fprintf(json, "  \"auth\": {\n");
     fprintf(json, "  ],\n");
 
     fprintf(json, "  \"auth\": {\n");
-    fprintf(json, "    \"requires_media_transition\": true,\n");
+    fprintf(json, "    \"requires_media_transition\": false,\n");
+    fprintf(json, "    \"unlock_requires_media_transition\": false,\n");
+    fprintf(json, "    \"locked_video_view_restore_requires_media_transition\": true,\n");
+    fprintf(json, "    \"state_detection\": \"READ CAPACITY (10) visible-sector count\",\n");
     fprintf(json, "    \"mode_page\": \"0x3E\",\n");
     fprintf(json, "    \"challenge_table_source\": \"read_dvd_structure_xbox_control_block\",\n");
     fprintf(json, "    \"challenge_table_response_offset\": 774,\n");
     fprintf(json, "    \"mode_page\": \"0x3E\",\n");
     fprintf(json, "    \"challenge_table_source\": \"read_dvd_structure_xbox_control_block\",\n");
     fprintf(json, "    \"challenge_table_response_offset\": 774,\n");
@@ -2734,7 +2738,7 @@ static BOOL WriteXboxDvdSidecarFiles(const char *isoFilename,
     return ok;
 }
 
     return ok;
 }
 
-void DumpXboxGameDisc(HANDLE hDevice, const char *filename, char xisoFormat, uint32_t totalDiscSectors, bool isDualLayer, bool EjectOnSuccess)
+BOOL DumpXboxGameDisc(HANDLE hDevice, const char *filename, char xisoFormat, uint32_t totalDiscSectors, bool isDualLayer, bool EjectOnSuccess, xbox_ref_dump_result *result)
 {
     HCRYPTPROV hProv = 0;
     HCRYPTHASH hHash = 0;
 {
     HCRYPTPROV hProv = 0;
     HCRYPTHASH hHash = 0;
@@ -2760,6 +2764,15 @@ void DumpXboxGameDisc(HANDLE hDevice, const char *filename, char xisoFormat, uin
 
     memset(&sidecarCapture, 0, sizeof(sidecarCapture));
 
 
     memset(&sidecarCapture, 0, sizeof(sidecarCapture));
 
+    if (result) {
+        result->attempted = 1;
+        result->mode = xisoFormat;
+        if (filename && filename[0]) {
+            strncpy(result->output_path, filename, sizeof(result->output_path) - 1);
+            result->output_path[sizeof(result->output_path) - 1] = '\0';
+        }
+    }
+
     if (totalDiscSectors == 0)
         totalDiscSectors = GetTotalSectors(hDevice);
     if (totalDiscSectors == 0)
     if (totalDiscSectors == 0)
         totalDiscSectors = GetTotalSectors(hDevice);
     if (totalDiscSectors == 0)
@@ -2768,11 +2781,11 @@ void DumpXboxGameDisc(HANDLE hDevice, const char *filename, char xisoFormat, uin
     rawTargetSectors = NormalizeRawIsoTargetSectors(totalDiscSectors, isDualLayer);
 
     if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
     rawTargetSectors = NormalizeRawIsoTargetSectors(totalDiscSectors, isDualLayer);
 
     if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
-        return;
+        return FALSE;
     if (!CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash))
     {
         CryptReleaseContext(hProv, 0);
     if (!CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash))
     {
         CryptReleaseContext(hProv, 0);
-        return;
+        return FALSE;
     }
 
     EnsureDriveReady(hDevice, 30000);
     }
 
     EnsureDriveReady(hDevice, 30000);
@@ -2788,6 +2801,8 @@ void DumpXboxGameDisc(HANDLE hDevice, const char *filename, char xisoFormat, uin
 
         outputLabel = "RAW ISO";
         expectedOutputBytes = (unsigned long long)rawTargetSectors * 2048ULL;
 
         outputLabel = "RAW ISO";
         expectedOutputBytes = (unsigned long long)rawTargetSectors * 2048ULL;
+        if (result)
+            result->output_sectors = rawTargetSectors;
 
         if (rawTargetSectors != totalDiscSectors)
         {
 
         if (rawTargetSectors != totalDiscSectors)
         {
@@ -3061,6 +3076,8 @@ void DumpXboxGameDisc(HANDLE hDevice, const char *filename, char xisoFormat, uin
 
         outputLabel = "XISO";
         expectedOutputBytes = ((unsigned long long)sectorsToRead + 32ULL) * 2048ULL;
 
         outputLabel = "XISO";
         expectedOutputBytes = ((unsigned long long)sectorsToRead + 32ULL) * 2048ULL;
+        if (result)
+            result->output_sectors = sectorsToRead + 32U;
 
         printf("[SUCCESS] Final XISO target: %u sectors plus 32-sector lead-in (%llu bytes).\n",
                sectorsToRead,
 
         printf("[SUCCESS] Final XISO target: %u sectors plus 32-sector lead-in (%llu bytes).\n",
                sectorsToRead,
@@ -3150,6 +3167,19 @@ void DumpXboxGameDisc(HANDLE hDevice, const char *filename, char xisoFormat, uin
         printf("\n[WARN] Could not calculate CRC32/MD5/SHA-1/SHA-256 from finalized output file.\n");
     }
 
         printf("\n[WARN] Could not calculate CRC32/MD5/SHA-1/SHA-256 from finalized output file.\n");
     }
 
+    if (result) {
+        result->output_size = GetFileSizeBytes64(filename);
+        strncpy(result->crc32, crc32String, sizeof(result->crc32) - 1);
+        result->crc32[sizeof(result->crc32) - 1] = '\0';
+        strncpy(result->md5, md5String, sizeof(result->md5) - 1);
+        result->md5[sizeof(result->md5) - 1] = '\0';
+        strncpy(result->sha1, sha1String, sizeof(result->sha1) - 1);
+        result->sha1[sizeof(result->sha1) - 1] = '\0';
+        strncpy(result->sha256, fileSha256String, sizeof(result->sha256) - 1);
+        result->sha256[sizeof(result->sha256) - 1] = '\0';
+        result->hashes_complete = result->crc32[0] && result->md5[0] && result->sha1[0] && result->sha256[0];
+    }
+
     if (xisoFormat == '1')
     {
         printf("Final RAW ISO Sector Count: %u\n", rawTargetSectors);
     if (xisoFormat == '1')
     {
         printf("Final RAW ISO Sector Count: %u\n", rawTargetSectors);
@@ -3192,8 +3222,9 @@ void DumpXboxGameDisc(HANDLE hDevice, const char *filename, char xisoFormat, uin
     FormatElapsedTime(GetTickCount() - operationStartTick, operationTimeStr);
     printf("\nOperation Complete! Total elapsed: %s\n", operationTimeStr);
 
     FormatElapsedTime(GetTickCount() - operationStartTick, operationTimeStr);
     printf("\nOperation Complete! Total elapsed: %s\n", operationTimeStr);
 
-    StopDriveUnit(hDevice);
-
+    /* The caller owns final drive cleanup.  Embedded FriiDump runs issue one
+     * STOP UNIT after Redump verification; standalone bridge runs stop the
+     * drive in xbox_ref_gdr8050l_dump_core() before closing the handle. */
     if (EjectOnSuccess)
         ControlTray(hDevice, TRUE);
 
     if (EjectOnSuccess)
         ControlTray(hDevice, TRUE);
 
@@ -3204,4 +3235,11 @@ cleanup:
         CryptDestroyHash(hHash);
     if (hProv)
         CryptReleaseContext(hProv, 0);
         CryptDestroyHash(hHash);
     if (hProv)
         CryptReleaseContext(hProv, 0);
+    if (result) {
+        result->dump_success = dumpOk ? 1 : 0;
+        result->elapsed_seconds = (double)(GetTickCount() - operationStartTick) / 1000.0;
+        if (dumpOk && result->output_size == 0)
+            result->output_size = GetFileSizeBytes64(filename);
+    }
+    return dumpOk;
 }
 }