Skip to content

Bluray#360

Merged
superg merged 7 commits intomainfrom
bluray
Mar 2, 2026
Merged

Bluray#360
superg merged 7 commits intomainfrom
bluray

Conversation

@superg
Copy link
Owner

@superg superg commented Mar 1, 2026

Summary by CodeRabbit

  • New Features

    • Blu-ray support: raw BD reading with per-frame descrambling
    • New --bd-raw option to enable raw Blu-ray dumping
  • Improvements

    • Distinct raw dump flows and transfer sizes for DVD vs Blu-ray
    • Improved detection to choose DVD or BD extraction when auxiliary image files exist
    • Enhanced progress reporting, warnings and logging for BD/DVD raw operations
  • Chores

    • Build/module configuration updated to enable BD functionality

Deterous and others added 3 commits March 1, 2026 16:18
* Raw BD read

* code review

* fix

* fix build

* Fix bd scrambler

* currently only works with dump size 1

* OmniDrive bluray data frame is 2070 bytes

---------

Co-authored-by: Hennadiy Brych <gennadiy.brich@gmail.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

Warning

Rate limit exceeded

@superg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 72c96dc and 899df41.

📒 Files selected for processing (2)
  • dvd/bd_scrambler.ixx
  • dvd/dvd_split.ixx
📝 Walkthrough

Walkthrough

Adds Blu-ray raw-read and extraction support: new BD C++ modules (dvd/bd.ixx, dvd/bd_scrambler.ixx), BD-aware read/split flows and CLI flag, and file-existence checks for .sbram; integrates BD descrambling and per-disc raw handling into dump/split logic.

Changes

Cohort / File(s) Summary
Build Configuration
CMakeLists.txt
Added dvd/bd.ixx and dvd/bd_scrambler.ixx to the redumper target's C++ module FILE_SET.
BD Data & Types
dvd/bd.ixx
New module exporting BD constants (LBA_START, LBA_IZ, ECC_FRAMES), DataFrame and OmniDriveDataFrame types, plus DataFrame::valid/DataFrame::descramble runtime logic.
BD Scrambler
dvd/bd_scrambler.ixx
New module exporting gpsxre::bd::Scrambler singleton implementing an LFSR-based descramble algorithm and public descramble API.
DVD/BD Dumping & Read Path
dvd/dvd_dump.ixx
Extended read_dvd_sectors() signature and logic to support BD raw reads (.sbram), omnidrive BD frame mapping, per-disc transfer sizing, BD-specific validation/logging, and updated BOOK_TYPE entry.
Split / Extraction Flow
dvd/dvd_split.ixx
Refactored extraction into dvd_extract_iso(...) and new bd_extract_iso(...); dispatch now checks .sdram vs .sbram, adds per-LBA progress and BD extraction path.
Options / CLI
options.ixx
Added exported bool bd_raw with --bd-raw flag (default false) and help text for Blu-ray raw dumping.
File-existence / Dispatch Checks
cd/protection.ixx, redumper.ixx
Early-existence checks and redumper dispatch extended to consider .sbram alongside .iso and .sdram.
Minor DVD change
dvd/dvd.ixx
DataFrame::descramble now calls Scrambler::get().descramble(...) via the new BD scrambler namespace reference.

Sequence Diagram

sequenceDiagram
    participant Caller as redumper/dvd_dump
    participant SPTD as SPTD (device)
    participant Frame as bd::DataFrame
    participant Scrambler as bd::Scrambler

    Caller->>SPTD: read raw sectors (LBA, count, disc_type=BD, raw)
    SPTD-->>Caller: raw OmniDrive frame bytes
    Caller->>Frame: reinterpret bytes as OmniDriveDataFrame / bd::DataFrame
    Caller->>Scrambler: Scrambler::get().descramble(Frame.main_data, psn)
    Scrambler->>Scrambler: init 16-bit LFSR from PSN
    Scrambler->>Scrambler: XOR bytes with LFSR stream, update register
    Scrambler->>Caller: return descrambled bytes / status (EDC check)
    Caller->>Caller: validate EDC, log, write output or handle error
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I nibble blue discs in moonlit code,
LFSR hops down a scrambled road,
XOR and EDC, a tidy song,
Frames unmasked, the bytes belong,
Hoppy dumps and bytes in tow ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Bluray' is too vague and generic; it does not clearly summarize the specific changes or main functionality being added. Use a more descriptive title that explains the primary change, such as 'Add Blu-ray disc support with scrambler and data frame handling' or similar.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bluray

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
dvd/dvd_dump.ixx (1)

522-543: ⚠️ Potential issue | 🔴 Critical

Guard unsupported raw disc types; current flow can return an unset SPTD::Status.

When raw is true for a non-DVD/non-BD type, no branch assigns status before return. That creates undefined/error-prone behavior depending on SPTD::Status construction.

🔧 Proposed fix
-SPTD::Status read_dvd_sectors(SPTD &sptd, uint8_t *sectors, uint32_t sector_size, int32_t lba, uint32_t sectors_count, bool force_unit_access, DiscType disc_type, bool raw)
+SPTD::Status read_dvd_sectors(SPTD &sptd, uint8_t *sectors, uint32_t sector_size, int32_t lba, uint32_t sectors_count, bool force_unit_access, DiscType disc_type, bool raw)
 {
-    SPTD::Status status;
+    SPTD::Status status{};
@@
     else if(disc_type == DiscType::BLURAY || disc_type == DiscType::BLURAY_R)
     {
@@
         }
     }
+    else
+    {
+        throw_line("raw read is unsupported for this disc type");
+    }

     return status;
 }
@@
-    bool raw = (options.dvd_raw || options.bd_raw || nintendo_key) && omnidrive_firmware;
+    bool raw = omnidrive_firmware &&
+        (nintendo_key
+            || (ctx.disc_type == DiscType::DVD && options.dvd_raw)
+            || ((ctx.disc_type == DiscType::BLURAY || ctx.disc_type == DiscType::BLURAY_R) && options.bd_raw));

Run this read-only check to verify branch coverage and SPTD::Status construction semantics:

#!/bin/bash
set -euo pipefail

echo "== Locate SPTD::Status declaration and fields =="
fd -a 'sptd\.(ixx|hh|hpp|h)$' | while read -r f; do
  echo "--- $f ---"
  rg -n -C3 'struct Status|class Status|status_code|sense_key|asc|ascq|Status\(' "$f" || true
done

echo
echo "== Inspect raw-mode gating and branch coverage in dvd dump =="
rg -n -C4 'bool raw =|SPTD::Status read_dvd_sectors|if\(!raw\)|DiscType::DVD|DiscType::BLURAY_R|DiscType::HDDVD' dvd/dvd_dump.ixx

Expected result: either explicit safe initialization is guaranteed for SPTD::Status, or code should be hardened as shown above.

Also applies to: 877-881

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/dvd_dump.ixx` around lines 522 - 543, The branch where raw==true for
unsupported disc types can leave the SPTD::Status variable (status) unset;
update the read path in the function that calls cmd_read and cmd_read_omnidrive
so that every branch assigns a valid SPTD::Status before use/return: add an
explicit assignment of a safe/failed SPTD::Status (or return early) for the raw
&& disc_type not DVD/BLURAY/BLURAY_R case, or ensure status is
default-initialized where declared; modify the branches around cmd_read,
cmd_read_omnidrive, and the raw check (referencing variables/functions status,
raw, DiscType, cmd_read, cmd_read_omnidrive, and SPTD::Status) so no execution
path can return/consume an uninitialized status.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dvd/dvd_split.ixx`:
- Around line 267-276: When scrambler.descramble(df, lba - bd::LBA_START) fails,
do not write the original (still-scrambled) df to iso_fs; instead preserve the
existing descramble_errors logic (use descramble_errors.emplace_back/extend) but
then, if leave_unchanged is false, zero-fill the payload bytes in df (the
portion that would contain the descrambled data) before the iso_fs.write((char
*)&df, FORM1_DATA_SIZE) call; if leave_unchanged is true, leave df untouched and
write it as-is. Ensure the zero-fill targets the same frame payload region
handled by the DVD invalid-frame code path and keep the write and fail-check
flow unchanged.

---

Outside diff comments:
In `@dvd/dvd_dump.ixx`:
- Around line 522-543: The branch where raw==true for unsupported disc types can
leave the SPTD::Status variable (status) unset; update the read path in the
function that calls cmd_read and cmd_read_omnidrive so that every branch assigns
a valid SPTD::Status before use/return: add an explicit assignment of a
safe/failed SPTD::Status (or return early) for the raw && disc_type not
DVD/BLURAY/BLURAY_R case, or ensure status is default-initialized where
declared; modify the branches around cmd_read, cmd_read_omnidrive, and the raw
check (referencing variables/functions status, raw, DiscType, cmd_read,
cmd_read_omnidrive, and SPTD::Status) so no execution path can return/consume an
uninitialized status.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f03b29f and d893b7a.

📒 Files selected for processing (8)
  • CMakeLists.txt
  • cd/protection.ixx
  • dvd/bd.ixx
  • dvd/bd_scrambler.ixx
  • dvd/dvd_dump.ixx
  • dvd/dvd_split.ixx
  • options.ixx
  • redumper.ixx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
dvd/bd.ixx (1)

21-35: Add compile-time layout guards for BD wire structs.

These structs represent on-disc/raw-frame layout; add static_assert checks to catch accidental ABI/layout drift at compile time.

Suggested patch
 export struct DataFrame
 {
     uint8_t main_data[FORM1_DATA_SIZE];
     uint32_t edc;
 };
+static_assert(sizeof(DataFrame) == FORM1_DATA_SIZE + sizeof(uint32_t));
 
 
 `#pragma` pack(push, 1)
 export struct OmniDriveDataFrame
 {
     DataFrame data_frame;
     uint8_t unknown[18];
 };
 `#pragma` pack(pop)
+static_assert(sizeof(OmniDriveDataFrame) == sizeof(DataFrame) + 18);
+static_assert(alignof(OmniDriveDataFrame) == 1);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/bd.ixx` around lines 21 - 35, Add compile-time layout guards for the BD
wire structs by adding static_asserts that validate sizeof(DataFrame) ==
FORM1_DATA_SIZE + sizeof(uint32_t) and sizeof(OmniDriveDataFrame) equals
sizeof(DataFrame) + 18, plus static_asserts on offsetof(DataFrame, edc) ==
FORM1_DATA_SIZE and offsetof(OmniDriveDataFrame, data_frame) == 0 to ensure
packing; reference the types DataFrame and OmniDriveDataFrame and the constant
FORM1_DATA_SIZE when writing these checks so any ABI/layout drift is caught at
compile time.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@dvd/bd.ixx`:
- Around line 21-35: Add compile-time layout guards for the BD wire structs by
adding static_asserts that validate sizeof(DataFrame) == FORM1_DATA_SIZE +
sizeof(uint32_t) and sizeof(OmniDriveDataFrame) equals sizeof(DataFrame) + 18,
plus static_asserts on offsetof(DataFrame, edc) == FORM1_DATA_SIZE and
offsetof(OmniDriveDataFrame, data_frame) == 0 to ensure packing; reference the
types DataFrame and OmniDriveDataFrame and the constant FORM1_DATA_SIZE when
writing these checks so any ABI/layout drift is caught at compile time.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d893b7a and 4cfcb45.

📒 Files selected for processing (1)
  • dvd/bd.ixx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
dvd/bd_scrambler.ixx (1)

6-8: Remove unused includes.

<optional> and <vector> are included but not used in this module.

🧹 Proposed fix
 `#include` <climits>
 `#include` <cstddef>
 `#include` <cstdint>
-#include <optional>
 `#include` <span>
-#include <vector>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/bd_scrambler.ixx` around lines 6 - 8, The includes <optional> and
<vector> in dvd/bd_scrambler.ixx are unused; remove those two include lines and
keep only the necessary `#include` <span> (or any other actually used headers) so
the module only imports headers it uses; locate the top-of-file include block in
bd_scrambler.ixx and delete the <optional> and <vector> entries.
dvd/dvd_dump.ixx (1)

887-892: Minor comment discrepancy.

The comment mentions 7 * 2072 but sizeof(bd::OmniDriveDataFrame) is actually 2070 bytes (2052 + 18). The calculation still fits within the 16384 byte limit (7 * 2070 = 14490), so this is just a documentation nit.

📝 Suggested comment fix
         else
         {
-            // bd: ensure default total transfer length is less than 16384 (7 * 2072)
+            // bd: ensure default total transfer length is less than 16384 (7 * 2070)
             LOG("warning: setting dump read size to 7 for raw BD dumping");
             dump_read_size = 7;
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/dvd_dump.ixx` around lines 887 - 892, Update the inline comment that
computes the BD dump frame size to use the correct
sizeof(bd::OmniDriveDataFrame) value (2070) instead of 2072 in the explanatory
text near the else block that sets dump_read_size = 7; i.e., change the comment
"7 * 2072" to "7 * 2070" (keeping the LOG and dump_read_size = 7 logic
unchanged) so the documentation matches the actual frame size.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@dvd/bd_scrambler.ixx`:
- Around line 6-8: The includes <optional> and <vector> in dvd/bd_scrambler.ixx
are unused; remove those two include lines and keep only the necessary `#include`
<span> (or any other actually used headers) so the module only imports headers
it uses; locate the top-of-file include block in bd_scrambler.ixx and delete the
<optional> and <vector> entries.

In `@dvd/dvd_dump.ixx`:
- Around line 887-892: Update the inline comment that computes the BD dump frame
size to use the correct sizeof(bd::OmniDriveDataFrame) value (2070) instead of
2072 in the explanatory text near the else block that sets dump_read_size = 7;
i.e., change the comment "7 * 2072" to "7 * 2070" (keeping the LOG and
dump_read_size = 7 logic unchanged) so the documentation matches the actual
frame size.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4cfcb45 and 8057f33.

📒 Files selected for processing (5)
  • dvd/bd.ixx
  • dvd/bd_scrambler.ixx
  • dvd/dvd.ixx
  • dvd/dvd_dump.ixx
  • dvd/dvd_split.ixx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
dvd/bd_scrambler.ixx (1)

2-14: Several imports appear unused.

Headers <algorithm> and <cstddef> are included but not used in this file. Module imports cd.cdrom, dvd, dvd.edc, utils.endian, and utils.misc also don't appear to be referenced in the implementation.

If these are transitive dependencies required by the module system, consider adding a brief comment to clarify their purpose.

♻️ Proposed cleanup if imports are not required
 module;
-#include <algorithm>
 `#include` <climits>
-#include <cstddef>
 `#include` <cstdint>
 `#include` <span>

 export module bd.scrambler;

-import cd.cdrom;
-import dvd;
-import dvd.edc;
-import utils.endian;
-import utils.misc;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/bd_scrambler.ixx` around lines 2 - 14, The includes <algorithm> and
<cstddef> and the module imports cd.cdrom, dvd, dvd.edc, utils.endian and
utils.misc in bd_scrambler.ixx appear unused; remove those unnecessary headers
and module imports from the top of the file (around the export module
bd.scrambler; block) to clean up dependencies, or if any are required only for
transitive/module-interface reasons add a short comment next to each import
explaining why it must remain.
dvd/dvd_dump.ixx (1)

73-73: Clarify the NINTENDO book type assignment.

Book type index 15 is being renamed from "RESERVED5" to "NINTENDO". This appears to be for GameCube/Wii disc identification where the physical structure's first byte is 0xFF (per line 660-661). Consider adding a brief comment explaining this Nintendo-specific book type usage.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/dvd_dump.ixx` at line 73, The "NINTENDO" entry replacing "RESERVED5"
lacks context; add a brief inline comment next to the book type array entry
"NINTENDO" in dvd_dump.ixx explaining that index 15 is used for GameCube/Wii
discs where the physical structure's first byte equals 0xFF (the check performed
elsewhere when determining book type), clarifying this is a Nintendo-specific
identifier and referencing the code path that checks the physical structure byte
so future readers understand why RESERVED5 was repurposed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@dvd/bd_scrambler.ixx`:
- Around line 2-14: The includes <algorithm> and <cstddef> and the module
imports cd.cdrom, dvd, dvd.edc, utils.endian and utils.misc in bd_scrambler.ixx
appear unused; remove those unnecessary headers and module imports from the top
of the file (around the export module bd.scrambler; block) to clean up
dependencies, or if any are required only for transitive/module-interface
reasons add a short comment next to each import explaining why it must remain.

In `@dvd/dvd_dump.ixx`:
- Line 73: The "NINTENDO" entry replacing "RESERVED5" lacks context; add a brief
inline comment next to the book type array entry "NINTENDO" in dvd_dump.ixx
explaining that index 15 is used for GameCube/Wii discs where the physical
structure's first byte equals 0xFF (the check performed elsewhere when
determining book type), clarifying this is a Nintendo-specific identifier and
referencing the code path that checks the physical structure byte so future
readers understand why RESERVED5 was repurposed.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8057f33 and 72c96dc.

📒 Files selected for processing (3)
  • dvd/bd.ixx
  • dvd/bd_scrambler.ixx
  • dvd/dvd_dump.ixx

@superg superg merged commit 217fa2a into main Mar 2, 2026
10 checks passed
This was referenced Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants