feat(libSceCesCs): implement the GB four-byte range and user-defined area setters #13573

Merged
KernelPanicNT merged 3 commits from upstream-pr/13573 into main 2026-11-06 13:45:54 +00:00
KernelPanicNT commented 2026-10-30 18:33:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-10-30T18:33:07Z.


What

Source of the behaviour

Measured with a homebrew probe running as a payload process on a device (firmware 13.00). The probe loaded the system libSceCesCs.sprx, built the four GB profiles in its own guarded static sheets, called each setter on each profile with 17 values (0-8, 15, 16, 0x100, 0x10000, INT_MAX, -1, -2, INT_MIN) after restoring the sheet byte for byte, and recorded the result and every changed sheet byte. For each accepted value 0-8 that left a distinct sheet, it then ran sceCesGbToUtf32 on 28 fixed byte sequences and sceCesUtf32ToGb on 26 fixed code points and logged result, size and output. No guard, sheet or buffer outside the expected one changed and no call faulted.

Case Device AnyPS5 now
Set4ByteCharRange, GB 18030-2000 and -2005 sheets, values 0, 1, 2, 3, 5, 7 0 same
Same, values 4, 6, 8, 15, 16, 0x100, 0x10000, INT_MAX, -1, -2, INT_MIN 0x805C0001, sheet unchanged same; every other value outside the six is taken as invalid
Set4ByteCharRange on GBK and EUC-CN sheets (all 17 values), null profile (0 and 1) 0x805C0004, sheet unchanged same
SetUdaMapping, GB 18030 and GBK sheets, 0 and 1 0 same
Same, the other 15 values 0x805C0001, sheet unchanged same; every value other than 0 and 1 is taken as invalid
SetUdaMapping on EUC-CN (all 17 values), null profile (0 and 1) 0x805C0004, sheet unchanged same
Sheet bytes the edition's default (range 1 for 2000, 3 for 2005; mapping 1 for GB 18030, 0 for GBK) changes nothing; otherwise the range sets the high nibble of byte 4 to 0x0, 0x1, 0x2, 0x3, 0x7 or 0xF for ranges 0, 1, 2, 3, 5 and 7, and byte 5 to 0x04 for ranges 0 and 2 and 0x02 for 7, and the mapping toggles bit 0x04 of byte 4 the setting is kept in sheet bytes 8 (range) and 9 (mapping), after the 8-byte tag; the default changes nothing, any other accepted value changes that one byte. The console's layout is not reproduced
Ranges 0 and 2, both editions: 81308130, 8135F437, 8431A439 0x805C0020, size 4 same for every four-byte sequence of a BMP code point
Same: U+0080, U+1E3F (2000) or U+E7C7 (2005), U+FE10, U+FFFF to GB 0x805C0020, size 0 same for every BMP code point without a two-byte cell
Range 3 on 2000, range 1 on 2005 the 54 results of the default sheet same
Range 5 90308130 and U+10000 convert (with gbMax 2 or 3, 0x805C0031 and size 4); E3329A35 and U+10FFFF 0x805C0020 same
Range 7 as 5, and E3329A35 and U+10FFFF convert same
8431A530, E3329A36, FE39FE39 0x805C0020, size 4, with every range same
Short and invalid sequences (81, 8130, 813081, 81308130 with gbMax 2, 817F, 80, FF), two-byte cells outside the user-defined areas unchanged by either setter same
Mapping 0 on GB 18030: AAA1, AFFE, F8A1, FEFE, A140, A7A0; U+E000, U+E233, U+E234, U+E4C5, U+E4C6, U+E5E5 0x805C0020 (size 2 decoding, 0 encoding); A6D9 U+E78D and FE51 U+E816 still convert same for every cell that decodes to U+E000-U+E765 (the three user-defined areas)
Mapping 1 on GBK A140 U+E4C6, A7A0 U+E765, F8A1 U+E234, FEFE U+E4C5; AAA1 and AFFE stay 0x805C0020; the six code points above still encode to 0x805C0020 same for every cell of the A140-A7A0 and F8A1-FEFE areas; encoding unchanged
Supplementary characters other than U+10000 and U+10FFFF (plane 2 included) with a range other than the edition's default not measured throws
A profile of another family (for example Shift-JIS) not measured throws

Implements sceCesGbUcsProfileSet4ByteCharRange(void* profile, int range) and sceCesGbUcsProfileSetUdaMapping(void* profile, int udaMapping). Both called NotImplemented_nid_no_patch.

The inits now write the edition's default range and mapping into sheet bytes 8 and 9, and the setters validate and store a new value there. The accepted ranges and what each does to the measured samples are one table in Export.cpp; the GB 18030 decoder and encoder consult it for four-byte forms, and both GB 18030 directions and the GBK decoder consult the mapping for the user-defined areas. With the default range the supplementary mapping is unchanged (none for 2000, plane 2 for 2005). With any other range, U+10000 and U+10FFFF follow the measurement and every other supplementary character throws std::runtime_error, because the probe did not reach plane 2 or the middle of the range (ranges 0 and 2 answer alike on every sample, so what 2 adds is not known). What is generalised from the samples is listed in a new docs/dev/debt/libSceCesCs.md entry: the whole four-byte BMP range, every cell of an area, values outside the 17 tried, the other conversion forms (ToUcs2, ToUtf8, ToUtf16, the string conversions), which share the decoder and encoder, and the two setters combined. The GBK entry now names only sceCesGbUcsProfileSetSbcs as unhandled, the GB 18030 entry drops the sentence about these two throwing, and the pending-export count goes from 17 to 15.

Open questions and overlap

  • On the device the EUC-CN sheet decodes 0x80-0xA0 as single bytes (80 U+0080, 81308130 U+0081 with size 1, 817F U+0081); here those leads answer 0x805C0014. The setters reject EUC-CN, so this PR does not change it.
  • #10431 moves the GB tags to seven characters and keeps an SetSbcs selection in the tag's eighth byte; it leaves these two exports as stubs. This PR stores its settings after the tag (bytes 8 and 9), so the two designs fit together, but the init functions, PendingExports.cpp, Api.hpp and the debt file conflict textually.
  • #13140 only declares sceCesUcsProfileInitGb18030_2022 next to these stubs (still declaration-only); #12946 edits the same CMake variant list; #9912, #11614 and #15409 remove other pending stubs and change the same pending-count line, which #14085 and #14212 also rewrite.
  • tools/pr_overlap.py --branch feat/cescs-gb-profile-setters: no open PR implements these exports. #9912, #11614, #12946, #13486, #14212 and #15409 conflict with main, so they were compared by hand; none adds these two functions.

Tested

Linux (GCC). The new test runs as guest_ces_gbsetters and guest_ces_gbsetters_module (linked against libSceCesCs and libSceCesCs-module). It calls both setters with the 17 values on the four profiles and a null profile and checks every result, and that the sheet changes exactly when the device's did. For the 16 measured sheet states it runs the 28 decode and 26 encode samples and compares an FNV-1a hash of (result, size, output) with the hash of the device results; it also checks samples from the table and that the unmeasured supplementary characters and a Shift-JIS profile throw. All 24 guest_ces tests pass on main (b11c7bf84f) with this branch applied. The new tests fail with the two setters reduced to NotImplemented_nid_no_patch stubs (both abort, checked at this head); at f785292f5d they also failed with Export.cpp, PendingExports.cpp and Api.hpp from main (they do not build) and with setters that store the value while the conversions ignore it (both abort, while guest_ces_chinese and guest_ces_mbc still pass). tools/progress.py: +2 implemented functions (libSceCesCs 270/287 -> 272/287). tools/check_conventions.py passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5089268291 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13573). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-10-30T18:33:07Z. --- ### What **Source of the behaviour** Measured with a homebrew probe running as a payload process on a device (firmware 13.00). The probe loaded the system `libSceCesCs.sprx`, built the four GB profiles in its own guarded static sheets, called each setter on each profile with 17 values (0-8, 15, 16, 0x100, 0x10000, INT_MAX, -1, -2, INT_MIN) after restoring the sheet byte for byte, and recorded the result and every changed sheet byte. For each accepted value 0-8 that left a distinct sheet, it then ran `sceCesGbToUtf32` on 28 fixed byte sequences and `sceCesUtf32ToGb` on 26 fixed code points and logged result, size and output. No guard, sheet or buffer outside the expected one changed and no call faulted. | Case | Device | AnyPS5 now | |---|---|---| | `Set4ByteCharRange`, GB 18030-2000 and -2005 sheets, values 0, 1, 2, 3, 5, 7 | 0 | same | | Same, values 4, 6, 8, 15, 16, 0x100, 0x10000, INT_MAX, -1, -2, INT_MIN | `0x805C0001`, sheet unchanged | same; every other value outside the six is taken as invalid | | `Set4ByteCharRange` on GBK and EUC-CN sheets (all 17 values), null profile (0 and 1) | `0x805C0004`, sheet unchanged | same | | `SetUdaMapping`, GB 18030 and GBK sheets, 0 and 1 | 0 | same | | Same, the other 15 values | `0x805C0001`, sheet unchanged | same; every value other than 0 and 1 is taken as invalid | | `SetUdaMapping` on EUC-CN (all 17 values), null profile (0 and 1) | `0x805C0004`, sheet unchanged | same | | Sheet bytes | the edition's default (range 1 for 2000, 3 for 2005; mapping 1 for GB 18030, 0 for GBK) changes nothing; otherwise the range sets the high nibble of byte 4 to 0x0, 0x1, 0x2, 0x3, 0x7 or 0xF for ranges 0, 1, 2, 3, 5 and 7, and byte 5 to 0x04 for ranges 0 and 2 and 0x02 for 7, and the mapping toggles bit 0x04 of byte 4 | the setting is kept in sheet bytes 8 (range) and 9 (mapping), after the 8-byte tag; the default changes nothing, any other accepted value changes that one byte. The console's layout is not reproduced | | Ranges 0 and 2, both editions: `81308130`, `8135F437`, `8431A439` | `0x805C0020`, size 4 | same for every four-byte sequence of a BMP code point | | Same: U+0080, U+1E3F (2000) or U+E7C7 (2005), U+FE10, U+FFFF to GB | `0x805C0020`, size 0 | same for every BMP code point without a two-byte cell | | Range 3 on 2000, range 1 on 2005 | the 54 results of the default sheet | same | | Range 5 | `90308130` and U+10000 convert (with `gbMax` 2 or 3, `0x805C0031` and size 4); `E3329A35` and U+10FFFF `0x805C0020` | same | | Range 7 | as 5, and `E3329A35` and U+10FFFF convert | same | | `8431A530`, `E3329A36`, `FE39FE39` | `0x805C0020`, size 4, with every range | same | | Short and invalid sequences (`81`, `8130`, `813081`, `81308130` with `gbMax` 2, `817F`, `80`, `FF`), two-byte cells outside the user-defined areas | unchanged by either setter | same | | Mapping 0 on GB 18030: `AAA1`, `AFFE`, `F8A1`, `FEFE`, `A140`, `A7A0`; U+E000, U+E233, U+E234, U+E4C5, U+E4C6, U+E5E5 | `0x805C0020` (size 2 decoding, 0 encoding); `A6D9` U+E78D and `FE51` U+E816 still convert | same for every cell that decodes to U+E000-U+E765 (the three user-defined areas) | | Mapping 1 on GBK | `A140` U+E4C6, `A7A0` U+E765, `F8A1` U+E234, `FEFE` U+E4C5; `AAA1` and `AFFE` stay `0x805C0020`; the six code points above still encode to `0x805C0020` | same for every cell of the `A140`-`A7A0` and `F8A1`-`FEFE` areas; encoding unchanged | | Supplementary characters other than U+10000 and U+10FFFF (plane 2 included) with a range other than the edition's default | not measured | throws | | A profile of another family (for example Shift-JIS) | not measured | throws | - Previous stubs: [`PendingExports.cpp#L21`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/PendingExports.cpp#L21), [`#L31`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/PendingExports.cpp#L31); declarations [`Api.hpp#L214`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/include/Api.hpp#L214), [`#L216`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/include/Api.hpp#L216). - Conversions that now read the setting: [`decodeGb`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/Export.cpp#L389) (GBK), [`decodeGb18030`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/Export.cpp#L514), [`encodeGb18030`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/Export.cpp#L555); the default supplementary mapping kept as is: [`mapsGb18030Supplementary`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/Export.cpp#L467); the GBK user-defined values come from [`gb18030Cell`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/Export.cpp#L493); the inits that now also write the two setting bytes: [`Export.cpp#L2440-L2456`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/core/libs/prx/libSceCesCs/Export.cpp#L2440-L2456). - Debt entries changed: [`libSceCesCs.md#L16`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/docs/dev/debt/libSceCesCs.md#L16), [`#L17`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/docs/dev/debt/libSceCesCs.md#L17), [`#L29`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/docs/dev/debt/libSceCesCs.md#L29). - Signatures: [Orbital type database](https://github.com/AlexAltea/orbital/blob/cc408367da6a/tools/ida/db_types.json#L210-L212) (`int sceCesGbUcsProfileSet4ByteCharRange(union*p, int gb4byteRange)`, `int sceCesGbUcsProfileSetUdaMapping(union*p, int udaMapping)`); the probe's conversions are [`#L206`](https://github.com/AlexAltea/orbital/blob/cc408367da6a/tools/ida/db_types.json#L206) and [`#L452`](https://github.com/AlexAltea/orbital/blob/cc408367da6a/tools/ida/db_types.json#L452). - Device measurement as a source: [`REVERSE_ENGINEERING.md#L9`](https://github.com/boykopovar/AnyPS5/blob/b11c7bf84f/docs/dev/REVERSE_ENGINEERING.md#L9). Implements `sceCesGbUcsProfileSet4ByteCharRange(void* profile, int range)` and `sceCesGbUcsProfileSetUdaMapping(void* profile, int udaMapping)`. Both called `NotImplemented_nid_no_patch`. The inits now write the edition's default range and mapping into sheet bytes 8 and 9, and the setters validate and store a new value there. The accepted ranges and what each does to the measured samples are one table in `Export.cpp`; the GB 18030 decoder and encoder consult it for four-byte forms, and both GB 18030 directions and the GBK decoder consult the mapping for the user-defined areas. With the default range the supplementary mapping is unchanged (none for 2000, plane 2 for 2005). With any other range, U+10000 and U+10FFFF follow the measurement and every other supplementary character throws `std::runtime_error`, because the probe did not reach plane 2 or the middle of the range (ranges 0 and 2 answer alike on every sample, so what 2 adds is not known). What is generalised from the samples is listed in a new `docs/dev/debt/libSceCesCs.md` entry: the whole four-byte BMP range, every cell of an area, values outside the 17 tried, the other conversion forms (`ToUcs2`, `ToUtf8`, `ToUtf16`, the string conversions), which share the decoder and encoder, and the two setters combined. The GBK entry now names only `sceCesGbUcsProfileSetSbcs` as unhandled, the GB 18030 entry drops the sentence about these two throwing, and the pending-export count goes from 17 to 15. **Open questions and overlap** - On the device the EUC-CN sheet decodes `0x80`-`0xA0` as single bytes (`80` U+0080, `81308130` U+0081 with size 1, `817F` U+0081); here those leads answer `0x805C0014`. The setters reject EUC-CN, so this PR does not change it. - [#10431](https://github.com/boykopovar/AnyPS5/pull/10431) moves the GB tags to seven characters and keeps an `SetSbcs` selection in the tag's eighth byte; it leaves these two exports as stubs. This PR stores its settings after the tag (bytes 8 and 9), so the two designs fit together, but the init functions, `PendingExports.cpp`, `Api.hpp` and the debt file conflict textually. - [#13140](https://github.com/boykopovar/AnyPS5/pull/13140) only declares `sceCesUcsProfileInitGb18030_2022` next to these stubs (still declaration-only); [#12946](https://github.com/boykopovar/AnyPS5/pull/12946) edits the same CMake variant list; [#9912](https://github.com/boykopovar/AnyPS5/pull/9912), [#11614](https://github.com/boykopovar/AnyPS5/pull/11614) and [#15409](https://github.com/boykopovar/AnyPS5/pull/15409) remove other pending stubs and change the same pending-count line, which [#14085](https://github.com/boykopovar/AnyPS5/pull/14085) and [#14212](https://github.com/boykopovar/AnyPS5/pull/14212) also rewrite. - `tools/pr_overlap.py --branch feat/cescs-gb-profile-setters`: no open PR implements these exports. [#9912](https://github.com/boykopovar/AnyPS5/pull/9912), [#11614](https://github.com/boykopovar/AnyPS5/pull/11614), [#12946](https://github.com/boykopovar/AnyPS5/pull/12946), [#13486](https://github.com/boykopovar/AnyPS5/pull/13486), [#14212](https://github.com/boykopovar/AnyPS5/pull/14212) and [#15409](https://github.com/boykopovar/AnyPS5/pull/15409) conflict with `main`, so they were compared by hand; none adds these two functions. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (GCC). The new test runs as `guest_ces_gbsetters` and `guest_ces_gbsetters_module` (linked against `libSceCesCs` and `libSceCesCs-module`). It calls both setters with the 17 values on the four profiles and a null profile and checks every result, and that the sheet changes exactly when the device's did. For the 16 measured sheet states it runs the 28 decode and 26 encode samples and compares an FNV-1a hash of (result, size, output) with the hash of the device results; it also checks samples from the table and that the unmeasured supplementary characters and a Shift-JIS profile throw. All 24 `guest_ces` tests pass on `main` (`b11c7bf84f`) with this branch applied. The new tests fail with the two setters reduced to `NotImplemented_nid_no_patch` stubs (both abort, checked at this head); at `f785292f5d` they also failed with `Export.cpp`, `PendingExports.cpp` and `Api.hpp` from `main` (they do not build) and with setters that store the value while the conversions ignore it (both abort, while `guest_ces_chinese` and `guest_ces_mbc` still pass). `tools/progress.py`: +2 implemented functions (libSceCesCs 270/287 -> 272/287). `tools/check_conventions.py` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
adriadam10 commented 2026-10-31 02:05:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-31T02:05:21Z.

Review: CHANGES_REQUESTED


Reviewed at f785292f5d: the setters, the range table, the sheet bytes 8/9, the decoder/encoder changes, the throwing paths and the debt entries match the description, and the test pins the measured hashes (it aborts with the setters as stubs).

One thing left, the one @oneandonlydean asked for above and not yet done:

  • State the firmware version of the payload measurement in the PR body and in the sceCesGbUcsProfileSet4ByteCharRange and sceCesGbUcsProfileSetUdaMapping entry of docs/dev/debt/libSceCesCs.md (line 18), as docs/dev/REVERSE_ENGINEERING.md ("Sources, strongest first") requires for a console measurement. Other entries in that file say it as "(firmware 13.60)".

With that added this is good to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5720504660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13573#pullrequestreview-5720504660). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-31T02:05:21Z. **Review:** CHANGES_REQUESTED --- Reviewed at `f785292f5d`: the setters, the range table, the sheet bytes 8/9, the decoder/encoder changes, the throwing paths and the debt entries match the description, and the test pins the measured hashes (it aborts with the setters as stubs). One thing left, the one @oneandonlydean asked for above and not yet done: - State the firmware version of the payload measurement in the PR body and in the `sceCesGbUcsProfileSet4ByteCharRange and sceCesGbUcsProfileSetUdaMapping` entry of `docs/dev/debt/libSceCesCs.md` (line 18), as `docs/dev/REVERSE_ENGINEERING.md` ("Sources, strongest first") requires for a console measurement. Other entries in that file say it as "(firmware 13.60)". With that added this is good to merge.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13573
No description provided.