eden/src/core/loader
PavelBARABANOV 815325ccec
[loader] add ZBIC (zstd variant) NSO decompression support for Switch 22.0+ (#4482)
- [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions).
- [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md)
- [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability.

-------------------
A new NSO compression method was introduced in Switch 22.0.0. This is a
customized variant of zstd and is used when NSO flags have bit 7 set.

Key characteristics:
  - ZSTD_MAGICNUMBER is set to 0x4349425A (b'ZBIC') instead of 0xFD2FB528
  - ZSTD_LEGACY_SUPPORT is set to 0
  - ZSTD_TRACE is set to 1, zstd version used is 1.5.7 (10507)
  - FSE_readNCount is replaced with a BIC (Binary Interpolative Coding)
    version which improves compression of entropy tables significantly

Source: https://switchbrew.org/wiki/22.0.0

Implementation:
  - Detect ZBIC segments via NSO flag bit 7 (NsoFlags_UseZbicCompression)
    and/or ZBIC magic scan in nso.cpp
  - Fall back to LZ4 when ZBIC is not detected or returns unexpected size
  - Handle segment 0 alternate offset (0x100 vs 0x108) for both ZBIC and LZ4

References:
  - Atmosphère loader/strat zstd-zbic integration:
    082115187a
  - nxdumptool ZBIC segment compression support:
    441e5c0904
  - STORM_SWITCH ZBIC implementation:
    1e09eb82b7

Tested with firmware 23.0.0 and ZBIC-compressed NSOs.

Co-authored-by: xbzk <xbzk@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4482
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Reviewed-by: lizzie <lizzie@eden-emu.dev>
Reviewed-by: Maufeat <sahyno1996@gmail.com>
2026-09-27 12:48:45 +02:00
..
deconstructed_rom_directory.cpp [fmt] use {#:x} instead of 0x{:#x} (#4170) 2026-07-25 21:47:07 +02:00
deconstructed_rom_directory.h [hle] Fixes for nxident, nxmp and nxplay, remove hbl.nsp workarounds (#3996) 2026-06-12 23:48:24 +02:00
kip.cpp [fmt] use {#:x} instead of 0x{:#x} (#4170) 2026-07-25 21:47:07 +02:00
kip.h general: Convert source file copyright comments over to SPDX 2022-04-23 05:55:32 -04:00
loader.cpp [core, hle, video_core, memory] Improve multi-process, display layers, dynamic shader cache and rework overlay (#4238) 2026-08-29 01:04:02 +02:00
loader.h [android/fs] external content loader + nca/xci patches (#3596) 2026-03-04 22:51:35 +01:00
nax.cpp vfs: expand support for NCA reading 2023-08-15 17:47:25 -04:00
nax.h vfs: expand support for NCA reading 2023-08-15 17:47:25 -04:00
nca.cpp [core, hle, video_core, memory] Improve multi-process, display layers, dynamic shader cache and rework overlay (#4238) 2026-08-29 01:04:02 +02:00
nca.h [core, hle, video_core, memory] Improve multi-process, display layers, dynamic shader cache and rework overlay (#4238) 2026-08-29 01:04:02 +02:00
nro.cpp [video_core, hle] remove redundant parent references in system structs (#3908) 2026-06-23 06:31:25 +02:00
nro.h arm: Implement native code execution backend 2023-11-25 00:46:47 -05:00
nso.cpp [loader] add ZBIC (zstd variant) NSO decompression support for Switch 22.0+ (#4482) 2026-09-27 12:48:45 +02:00
nso.h [loader] add ZBIC (zstd variant) NSO decompression support for Switch 22.0+ (#4482) 2026-09-27 12:48:45 +02:00
nsp.cpp [core, hle, video_core, memory] Improve multi-process, display layers, dynamic shader cache and rework overlay (#4238) 2026-08-29 01:04:02 +02:00
nsp.h core: implement basic integrity verification 2023-09-06 16:49:27 -04:00
xci.cpp [android/fs] external content loader + nca/xci patches (#3596) 2026-03-04 22:51:35 +01:00
xci.h core: implement basic integrity verification 2023-09-06 16:49:27 -04:00