From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Format:Dreamcast IP.BIN" |
|---|
| claim | "The Dreamcast 1ST_READ.BIN scrambler (Marcus Comstedt's scramble.c, in KallistiOS and flycast) is a deterministic permutation of 32-byte slices: seed = file size & 0xFFFF; rand() = ((seed = (seed*2109 + 9273) & 0x7FFF) + 0xC000) & 0xFFFF; the file is processed in chunks of 2 MiB while at least 2 MiB remain, then 1 MiB, 512 KiB ... down to 32 bytes; inside a chunk of n slices, for i = n-1 down to 0 take x = (rand()*i) >> 16, swap idx[i] and idx[x] (idx starts as identity), and the next 32 bytes of the scrambled stream belong to slice idx[i] of the plain data; a final tail under 32 bytes is copied unchanged. Descrambling is the same walk with the scrambled stream read sequentially into plain positions." |
|---|
| scope | | level | "format" |
|---|
| applies_to | "Format:Dreamcast IP.BIN" |
|---|
| observed_in | |
|---|
|
|---|
| data | | trigger | "preparing or loading 1ST_READ.BIN" |
|---|
| effect | "slice permutation as in claim" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "my_srand/my_rand, load_chunk, load_file, save_chunk, save_file" |
|---|
| repo | "KallistiOS/KallistiOS" |
|---|
| commit | "8e704086ecd4990627b85fb4905770dfffe29c00" |
|---|
| path | "utils/scramble/scramble.c" |
|---|
| lines | "5-18, 29-76, 116-163" |
|---|
|
| type | "source" |
|---|
| detail | "identical descrambl_buffer" |
|---|
| repo | "flyinghead/flycast" |
|---|
| commit | "6bb0fc3e18dac4b01694f488c7a71f5930e8a648" |
|---|
| path | "core/reios/descrambl.cpp" |
|---|
| lines | "14-76" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "1ST_READ.BIN scrambling algorithm" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-19T00:08:08.072Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T04:15:17.043Z" |
|---|
| result | "confirmed" |
|---|
| method | "Read KallistiOS utils/scramble/scramble.c whole at the cited commit: my_srand/my_rand constants, MAXCHUNK 2 MiB, chunk sizes halving down to 32 bytes while filesz >= chunksz, swap loop i = n-1..0 with x = (my_rand()*i) >> 16, final incomplete tail copied unchanged. The flycast copy was not re-read." |
|---|
|
|
|---|