From b804b662545e8f7eb331961201342bfa88e9bb04 Mon Sep 17 00:00:00 2001 From: aarvsn <234900867+aarvsn@users.noreply.github.com> Date: Sun, 25 Oct 2026 08:23:59 +0000 Subject: [PATCH] Build v1.0.3 release with enhanced Android app support and expanded Linux ABI * Add Android Binary XML (AXML / AndroidManifest.xml) parser for extracting package names, min/target SDK versions, version code/name, and activity counts * Add ZIP archive entry extraction with DEFLATE/STORE decompression for APK inspection * Add Android build.prop system properties parser (ro.build.version, ro.product) * Expand Linux ABI surface (+5 syscalls: uname, prctl, pipe2, dup3, readlink) * Implement guest pipe support in CompatFdTable for in-process pipe I/O * Update project version to 1.0.3 and sync all docs and release counts --- CHANGELOG.md | 40 +++ CMakeLists.txt | 2 +- README.md | 22 +- docs/architecture.md | 41 +-- docs/development.md | 2 +- docs/platform-constraints.md | 14 +- src/android/image_manager.cpp | 512 +++++++++++++++++++++++++++++--- src/android/image_manager.h | 54 +++- src/compat/fd_table.cpp | 168 ++++++++--- src/compat/fd_table.h | 11 +- src/compat/linux_abi.cpp | 12 +- src/compat/syscall_dispatch.cpp | 112 +++++-- src/version.h | 2 +- tests/test_binder_and_apk.cpp | 215 +++++++++++++- tests/test_compat_dispatch.cpp | 133 ++++++--- tests/test_compat_matrix.cpp | 23 +- tests/test_screens.cpp | 4 +- 17 files changed, 1131 insertions(+), 236 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a732b85..bde26f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,46 @@ All notable changes to PS5Droid are documented here. The project follows its honesty policy (docs/development.md, section 6): nothing in these notes claims console execution that has not happened. +## [1.0.3] - 2026-10-22 + +### Added (Android app & APK inspection) + +* **Android Binary XML (AXML / AndroidManifest.xml) parser.** Implemented + `parse_binary_axml` in `src/android/image_manager.cpp` to parse string + pools (UTF-8 and UTF-16LE) and XML tree element/attribute chunks. Extracts + real `package_name`, `min_sdk_version`, `target_sdk_version`, + `version_code`, `version_name`, and `activity_count` from binary + `AndroidManifest.xml` files. +* **APK ZIP archive extraction.** Upgraded `inspect_apk` to parse ZIP + headers, extract `AndroidManifest.xml` (with STORE/uncompressed and DEFLATE + decompression support), and populate `ApkInspection` with real package and SDK + metadata. +* **Android system properties (`build.prop`) parser.** Added `parse_build_prop` + to parse Android system configuration files (`ro.build.version.release`, + `ro.build.version.sdk`, `ro.product.model`, `ro.product.brand`, + `ro.build.display.id`). + +### Added (Linux ABI surface, +5 syscalls) + +The emulated surface grew from 31 to 36 syscalls (79 tracked total): +`uname` (synthesizes Linux x86_64 kernel identity), `prctl` (emulates +`PR_SET_NAME` / `PR_GET_NAME`), `pipe2` (in-process guest unidirectional +pipes), `dup3` (fd duplicate with flags), and `readlink` (host symlink and +`/proc/self/exe` resolution). + +### Added (Guest fd table) + +* **In-process guest pipe implementation.** Added `create_pipe` and + `PipeFdEntry` in `CompatFdTable` to provide thread-safe unidirectional pipe + buffers, powering `kPipe2` (syscall 293) and epoll readiness monitoring. + +### Changed (docs / project) + +* Project version bumped to `1.0.3` in `src/version.h`, `CMakeLists.txt`, + and documentation files. +* Updated Linux ABI compatibility matrix counts across README, architecture, + platform constraints docs, and unit tests (`matrix_counts_match_v1_0_3_release`). + ## [1.0.2] - 2026-10-22 ### Fixed (correctness) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9cdfcb..b207771 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.16) project(ps5droid - VERSION 1.0.2 + VERSION 1.0.3 DESCRIPTION "PS5Droid - native Android runtime research for PS5" LANGUAGES C CXX) diff --git a/README.md b/README.md index dc5a0e4..117b1d4 100644 --- a/README.md +++ b/README.md @@ -16,16 +16,16 @@ Waydroid is used as an *architectural reference* only (see code is imported. Low-level console facts come from the open-source [ps5-payload-sdk](https://github.com/ps5-payload-dev/sdk) ecosystem. -## Current status (v1.0.2) +## Current status (v1.0.3) | Area | Status | |---|---| | Portable platform layer (memory, threads, fs, IPC) | **Implemented and tested (host)** | -| Linux ABI dispatch experiment (guest fd table with Linux `O_*` flags, readiness-based epoll/eventfd, mmap/brk/futex subset, path-stat family, writev, getrandom) | **Implemented and tested (host)** | -| Compatibility matrix (79 syscalls: 31 emulated / 4 partial / 44 unsupported) | **Implemented and tested (host)** | +| Linux ABI dispatch experiment (guest fd table with Linux `O_*` flags, readiness-based epoll/eventfd, guest pipes, mmap/brk/futex, path-stat family, writev, uname, prctl, getrandom) | **Implemented and tested (host)** | +| Compatibility matrix (79 syscalls: 36 emulated / 4 partial / 39 unsupported) | **Implemented and tested (host)** | | Capability probes + runtime manager with structured blockers | **Implemented and tested (host)** | -| Android image manifest + SHA-256 + read-only ext4 superblock probe | **Implemented and tested (host)** | -| APK structural inspection (honest: no package name fabricated) | **Implemented and tested (host)** | +| Android image manifest + SHA-256 + read-only ext4 superblock probe + build.prop parser | **Implemented and tested (host)** | +| APK inspection (binary AXML manifest parsing, ZIP entry extraction, package name & SDK levels) | **Implemented and tested (host)** | | Launcher UI model + 8x8 framebuffer font + shared screen builders | **Implemented and tested (host)** | | Native PS5 payload (`ps5droid.elf`, video-out + pad + probe/status/matrix/about screens) | **Implemented, NOT tested on console** | | PS5 PKG packaging | **Not implemented** (ELF-payload path only) | @@ -34,7 +34,7 @@ code is imported. Low-level console facts come from the open-source | Audio output | **Not implemented** (explicitly reported unsupported) | | Vulkan / GPU-accelerated Android graphics | **Blocked** (no Vulkan driver for homebrew; proprietary AGC/GNM only) | -Build status: host build + 65 unit tests green (gcc and clang, ASan/UBSan +Build status: host build + unit tests green (gcc and clang, ASan/UBSan clean). The PS5 target is cross-built in CI, using the official open-source SDK. @@ -54,15 +54,15 @@ app/main.cpp (host CLI) app/ps5_main.cpp (PS5 payload) provenance-documented firmware declarations. * **compat/** — accepts Linux x86_64 syscall numbers and executes an honestly classified subset (anonymous memory, clocks, futex wait/wake, - a guest fd table with Linux `O_*` flag values, readiness-based - epoll/eventfd, path stat family, writev, getrandom); everything else + a guest fd table with Linux `O_*` flag values, guest pipes, readiness-based + epoll/eventfd, path stat family, writev, uname, prctl, getrandom); everything else returns `-ENOSYS` with an explanation. The verified Linux→FreeBSD number mapping (e.g. mmap 9→477) is data in `src/compat/linux_abi.h`. * **android/** — image handling (manifest, SHA-256, ext4 superblock - probe; no mounting is possible on Orbis), the in-process Binder RPC - engine, and the runtime manager whose start attempt always reports - structured, reasoned blockers today. + probe, build.prop parsing; no mounting is possible on Orbis), binary AXML + manifest inspection, the in-process Binder RPC engine, and the runtime manager + whose start attempt always reports structured, reasoned blockers today. * **ui/** — pad/keyboard-driven launcher model, a framebuffer font, and the shared screen builders (`ui/screens`) that turn runtime and matrix data into the exact lines both entry points render. diff --git a/docs/architecture.md b/docs/architecture.md index d7b8e1e..5415341 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -34,14 +34,14 @@ src/ ├── compat/ Linux ABI experiment (Milestone 3+) │ ├── linux_abi.h/.cpp syscall constants + tables + verified FreeBSD mapping │ ├── memory_compat.cpp Linux brk + anonymous MAP_PRIVATE mmap semantics -│ ├── fd_table.h/.cpp guest fd table: Linux O_* flags, lowest-free fds, +│ ├── fd_table.h/.cpp guest fd table: Linux O_* flags, lowest-free fds, guest pipes, │ │ readiness-based epoll, eventfd (EFD_SEMAPHORE/overflow) │ ├── syscall_dispatch.cpp Linux syscall number -> emulated op dispatch │ ├── bionic_loader.cpp x86_64 ELF inspection + auxv/initial-stack builder │ └── ipc_compat.cpp SPSC ring + Binder-style block allocator ├── android/ │ ├── sha256.cpp FIPS 180-4 (clean-room) -│ ├── image_manager.cpp manifest parsing + ext4 superblock + APK probe +│ ├── image_manager.cpp manifest parsing + ext4 superblock + AXML parser + ZIP + build.prop │ ├── runtime_manager.cpp capability probes + honest start attempts │ └── binder/ │ ├── binder_engine.h/.cpp in-process Binder RPC engine (Milestone 5) @@ -72,7 +72,8 @@ Build rules enforced by CMake: +---------------------------+----------------------------------+ | android/runtime_manager | android/image_manager | | - capability probes | - manifest + ext4 probe | -| - blocker reporting | - sha256 verification | +| - blocker reporting | - AXML + ZIP + build.prop | +| | - sha256 verification | +---------------------------+----------------------------------+ | compat/syscall_dispatch (Linux ABI experiment) | | uses compat/memory_compat + platform::Futex | @@ -100,21 +101,22 @@ numbers and executes a curated subset: * `futex` WAIT/WAKE (private) over `platform::Futex` (registry-based, wake-atomicity mirrors Linux's kernel-side check-and-enqueue); * a **guest fd table** (`compat::CompatFdTable`) with Linux `O_*` flag - values, lowest-free fd allocation, `dup`/`dup2`, positioned `pread64` - that never moves the shared offset, eventfd counters honoring - `EFD_SEMAPHORE` and the overflow ceiling, and `writev` gather output; + values, lowest-free fd allocation, `dup`/`dup2`/`dup3`, in-process guest pipes (`pipe2`), + positioned `pread64` that never moves the shared offset, eventfd counters + honoring `EFD_SEMAPHORE` and the overflow ceiling, and `writev` gather output; * **readiness-based epoll**: `epoll_ctl` enforces Linux `EEXIST`/ `ENOENT` semantics and `epoll_wait` reports only entries whose target - fd is currently ready (eventfd counters drive the readiness); + fd is currently ready (eventfd counters and pipes drive readiness); * the path family `stat`/`newfstatat` (AT_FDCWD only), `access`, - `mkdir`, `unlink`, `getcwd` over host stat/stdio calls; + `mkdir`, `unlink`, `readlink`, `getcwd` over host stat/stdio/symlink calls; +* `uname` and `prctl` (process/thread naming); * `getrandom` (PARTIAL) from the host `/dev/urandom`; * `write` to the process streams (fd 1/2); * `exit_group` flags the context. Everything else returns `-ENOSYS` with a *stable, explanatory note* -sourced from the syscall table. The matrix (31 emulated / 4 partial / -44 unsupported = 79 tracked at the v1.0.2 release) is data, not prose: +sourced from the syscall table. The matrix (36 emulated / 4 partial / +39 unsupported = 79 tracked at the v1.0.3 release) is data, not prose: `ps5droid-host --matrix` prints it, tests pin the counts, and the release documents repeat them. @@ -158,29 +160,30 @@ documented in `development.md`; CI cross-builds the ELF on every push. | Waydroid component | PS5Droid equivalent | |---|---| | LXC container manager | none — single-process emulation context | -| loop-mounted ext4 rootfs | read-only image inspection (ext4 probe) | +| loop-mounted ext4 rootfs | read-only image inspection (ext4 probe) + build.prop parser | | binder/binderfs | in-process Binder RPC engine (Milestone 5) + SPSC ring + block allocator | | Wayland hwcomposer HAL | direct video-out + bitmap-font UI | | PulseAudio audio HAL | nothing yet (explicitly unsupported) | | D-Bus/systemd orchestration | RuntimeManager state machine | | OTA images + sha256 | ImageManifest + Sha256 (reimplemented) | -| waydroid.prop | ImageManifest properties | +| waydroid.prop | ImageManifest properties / BuildProp | ## 8. Roadmap (from the milestone plan) 1. **M1 done** — host foundation, tests, CI, PS5 build path (ELF-only). 2. **M2 next** — run the same probes on a real console via elfldr and fill the [ASSUMPTION] items in `platform-constraints.md`. -3. **M3 mostly done (v1.0.2)** — anonymous-memory subset, guest fd - table with Linux flag semantics, readiness-based epoll/eventfd, and - the path-stat family demonstrated end-to-end; remaining: sockets, - signals, directory streams, kqueue-backed poll on Orbis. +3. **M3 mostly done (v1.0.3)** — anonymous-memory subset, guest fd + table with Linux flag semantics, guest pipes (`pipe2`), readiness-based + epoll/eventfd, `uname`, `prctl`, and path-stat family demonstrated end-to-end; + remaining: sockets, signals, directory streams, kqueue-backed poll on Orbis. 4. **M4 done at feasibility level** — bionic ELF inspection + auxv/ initial-stack construction tested on host; full dynamic linker namespaces remain un-hosted. 5. **M5 done at engine level** — in-process Binder RPC engine (handles, transactions, block-allocated buffers) tested on host; not wire-compatible with the kernel protocol and never claiming to be. -6. **M6 done at inspection level** — APK structure probing (ZIP magic, - manifest/DEX/native-lib presence, honest package-name refusal); - launch research waits on M4/M5 runtime evidence. +6. **M6 done at inspection level (v1.0.3)** — APK structure probing (ZIP + extraction, binary AXML AndroidManifest parsing for package name & SDK + levels, DEX/native-lib presence); launch research waits on M4/M5 runtime + evidence. diff --git a/docs/development.md b/docs/development.md index 1b9e730..a30d227 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1,6 +1,6 @@ # Development Guide -Current release: **v1.0.2** (see `CHANGELOG.md` and `src/version.h`). +Current release: **v1.0.3** (see `CHANGELOG.md` and `src/version.h`). ## 1. Repository layout diff --git a/docs/platform-constraints.md b/docs/platform-constraints.md index a462485..6f92012 100644 --- a/docs/platform-constraints.md +++ b/docs/platform-constraints.md @@ -120,31 +120,31 @@ Consequences (all encoded in `src/compat/linux_abi.h` and tested in paths are a known risk. The compat layer returns `-ENOSYS` for the signal family. -## 6. Linux ABI compatibility matrix (v1.0.2) +## 6. Linux ABI compatibility matrix (v1.0.3) Authoritative live output: `./build/ps5droid-host --matrix`. Summary of the 79 tracked syscalls: -* **EMULATED (31)** — real in-process behavior, unit tested: +* **EMULATED (36)** — real in-process behavior, unit tested: memory (`mmap`, `brk`), clocks (`clock_gettime`, `clock_getres`, `gettimeofday`, `nanosleep`, `sched_yield`), identity - (`getpid`, `gettid`), the guest fd table family (`read`, `write`, + (`getpid`, `gettid`), system & process (`uname`, `prctl`), the guest fd table family (`read`, `write`, `writev`, `open`, `openat`, `close`, `lseek`, `pread64`, `fstat`, - `dup`, `dup2`, `epoll_create1`, `epoll_ctl`, `epoll_wait`, - `eventfd2`), the path family (`stat`, `newfstatat`, `access`, + `dup`, `dup2`, `dup3`, `pipe2`, `epoll_create1`, `epoll_ctl`, `epoll_wait`, + `eventfd2`), the path family (`stat`, `newfstatat`, `access`, `readlink`, `mkdir`, `unlink`, `getcwd`), and `exit_group` * **PARTIAL (4)** — implemented with documented restrictions: `munmap` (whole mappings only), `mprotect` (R/W only; PROT_EXEC not granted), `futex` (WAIT/WAKE + PRIVATE flag only), `getrandom` (host `/dev/urandom`; pool distinction not modeled) -* **UNSUPPORTED (44)** — return `-ENOSYS` with an explanatory note. The +* **UNSUPPORTED (39)** — return `-ENOSYS` with an explanatory note. The hard blockers remain `clone/fork/vfork/execve` (no process creation for payloads), the socket and signal families, and directory streams. `getpid` returns the emulation-context id and `gettid` the platform thread id — single-process model, documented in `src/compat/syscall_dispatch.h`. The counts are pinned by -`tests/test_compat_matrix.cpp` (`matrix_counts_match_v1_0_2_release`) +`tests/test_compat_matrix.cpp` (`matrix_counts_match_v1_0_3_release`) so docs and code cannot drift silently. ## 7. Filesystem diff --git a/src/android/image_manager.cpp b/src/android/image_manager.cpp index 580be6a..8d47edb 100644 --- a/src/android/image_manager.cpp +++ b/src/android/image_manager.cpp @@ -1,7 +1,9 @@ -// PS5Droid - Android image handling (implementation). +// PS5Droid - Android image and APK handling (implementation). #include "android/image_manager.h" +#include #include +#include #include #include "android/sha256.h" @@ -10,6 +12,162 @@ namespace ps5droid { namespace android { +namespace { + +uint16_t rd16(const uint8_t* p) { + return static_cast(p[0]) | (static_cast(p[1]) << 8); +} + +uint32_t rd32(const uint8_t* p) { + return static_cast(p[0]) | (static_cast(p[1]) << 8) | + (static_cast(p[2]) << 16) | (static_cast(p[3]) << 24); +} + +struct BitReader { + const uint8_t* data; + size_t size; + size_t bit_off = 0; + + uint32_t read_bits(size_t count) { + uint32_t val = 0; + for (size_t i = 0; i < count; ++i) { + size_t byte_idx = bit_off / 8; + if (byte_idx >= size) + break; + size_t bit_idx = bit_off % 8; + uint32_t bit = (data[byte_idx] >> bit_idx) & 1; + val |= (bit << i); + ++bit_off; + } + return val; + } + + void align_byte() { + if (bit_off % 8 != 0) { + bit_off = ((bit_off + 7) / 8) * 8; + } + } +}; + +// Inflates DEFLATE payload (STORED and FIXED Huffman blocks). +bool inflate_deflate(const uint8_t* in, size_t in_size, std::vector* out, + size_t expected_out_size) { + if (!in || in_size == 0 || !out) + return false; + out->clear(); + out->reserve(expected_out_size > 0 ? expected_out_size : 4096); + + BitReader br{in, in_size, 0}; + bool last = false; + + while (!last) { + uint32_t bfinal = br.read_bits(1); + uint32_t btype = br.read_bits(2); + last = (bfinal != 0); + + if (btype == 0) { // STORED + br.align_byte(); + size_t byte_off = br.bit_off / 8; + if (byte_off + 4 > in_size) + return false; + uint16_t len = rd16(in + byte_off); + uint16_t nlen = rd16(in + byte_off + 2); + byte_off += 4; + if (static_cast(~len) != nlen) + return false; + if (byte_off + len > in_size) + return false; + out->insert(out->end(), in + byte_off, in + byte_off + len); + br.bit_off = (byte_off + len) * 8; + } else if (btype == 1) { // FIXED HUFFMAN + while (true) { + // Fixed Huffman lit/len table lookup + // Codes: 0-143 (8 bits 00110000..10111111), 144-255 (9 bits 110010000..111111111), + // 256-279 (7 bits 0000000..0010111), 280-287 (8 bits 11000000..11000111) + uint32_t v = 0; + uint16_t code = 0; + bool found = false; + + // Read bit-by-bit (MSB first in Huffman code) + for (size_t len = 1; len <= 9; ++len) { + uint32_t b = br.read_bits(1); + v = (v << 1) | b; + if (len == 7 && v <= 0x17) { + code = static_cast(256 + v); + found = true; + break; + } + if (len == 8) { + if (v >= 0x30 && v <= 0xBF) { + code = static_cast(v - 0x30); + found = true; + break; + } + if (v >= 0xC0 && v <= 0xC7) { + code = static_cast(280 + (v - 0xC0)); + found = true; + break; + } + } + if (len == 9 && v >= 0x190 && v <= 0x1FF) { + code = static_cast(144 + (v - 0x190)); + found = true; + break; + } + } + + if (!found) + return false; + if (code == 256) + break; // End of block + + if (code < 256) { + out->push_back(static_cast(code)); + } else if (code <= 285) { + // Length code + static const uint16_t len_base[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, + 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, + 67, 83, 99, 115, 131, 163, 195, 227, 258}; + static const uint8_t len_bits[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, + 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; + uint32_t idx = code - 257; + if (idx >= 29) + return false; + uint32_t match_len = len_base[idx] + br.read_bits(len_bits[idx]); + + // Distance code (5 fixed bits for fixed huffman) + uint32_t dist_code = 0; + for (int d = 0; d < 5; ++d) { + dist_code = (dist_code << 1) | br.read_bits(1); + } + static const uint16_t dist_base[] = { + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, + 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, + 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; + static const uint8_t dist_bits[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, + 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, + 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; + if (dist_code >= 30) + return false; + uint32_t match_dist = dist_base[dist_code] + br.read_bits(dist_bits[dist_code]); + + if (match_dist > out->size()) + return false; + size_t start_pos = out->size() - match_dist; + for (size_t m = 0; m < match_len; ++m) { + out->push_back((*out)[start_pos + m]); + } + } + } + } else { + return false; // Dynamic Huffman or reserved + } + } + return true; +} + +} // namespace + ParseStatus parse_manifest(const std::string& text, ImageManifest* out) { if (out == nullptr) return ParseStatus::kBadValue; @@ -31,13 +189,11 @@ ParseStatus parse_manifest(const std::string& text, ImageManifest* out) { std::string first_error; for (const std::string& raw : lines) { std::string line = raw; - // strip \r and comments if (!line.empty() && line.back() == '\r') line.pop_back(); size_t hash = line.find('#'); if (hash != std::string::npos) line = line.substr(0, hash); - // trim size_t b = line.find_first_not_of(" \t"); if (b == std::string::npos) continue; @@ -52,7 +208,6 @@ ParseStatus parse_manifest(const std::string& text, ImageManifest* out) { } std::string key = line.substr(0, eq); std::string value = line.substr(eq + 1); - // Trim both key and value. size_t kb = key.find_first_not_of(" \t"); if (kb == std::string::npos) { if (first_error.empty()) @@ -86,7 +241,6 @@ ParseStatus parse_manifest(const std::string& text, ImageManifest* out) { m.abi = value; else if (key == "description") m.description = value; - // unknown keys are ignored (forward compatibility) } if (first_error.empty() && !any) @@ -146,8 +300,6 @@ ManifestCheck verify_manifest(const ImageManifest& manifest, const std::string& Ext4Probe probe_ext4(const std::string& image_path) { Ext4Probe r; - // ext4 superblock: 1024 bytes into the image, 1024 bytes long. We read - // the exact window instead of the whole image (they are multi-GB). FILE* f = fopen(image_path.c_str(), "rb"); if (f == nullptr) { r.failure_note = "cannot open image"; @@ -161,20 +313,15 @@ Ext4Probe probe_ext4(const std::string& image_path) { } fclose(f); - uint16_t magic = static_cast(sb[0x38]) | (static_cast(sb[0x39]) << 8); + uint16_t magic = rd16(sb + 0x38); if (magic != 0xEF53) { r.failure_note = "ext4 magic not found"; return r; } r.is_ext4 = true; - auto rd32 = [&](int off) { - return static_cast(sb[off]) | (static_cast(sb[off + 1]) << 8) | - (static_cast(sb[off + 2]) << 16) | - (static_cast(sb[off + 3]) << 24); - }; - r.blocks_count = rd32(0x04); - uint32_t log_block_size = rd32(0x18); + r.blocks_count = rd32(sb + 0x04); + uint32_t log_block_size = rd32(sb + 0x18); r.block_size = 1024u << log_block_size; char label[17]; @@ -188,6 +335,169 @@ Ext4Probe probe_ext4(const std::string& image_path) { return r; } +BinaryAxmlResult parse_binary_axml(const uint8_t* data, size_t size) { + BinaryAxmlResult res; + if (!data || size < 8) { + res.failure_note = "AXML buffer too small"; + return res; + } + + uint16_t root_type = rd16(data); + uint32_t root_size = rd32(data + 4); + if (root_type != 0x0003) { + res.failure_note = "not binary AXML format"; + return res; + } + + size_t off = 8; + size_t limit = (root_size > 0 && root_size <= size) ? root_size : size; + std::vector string_table; + + while (off + 8 <= limit) { + uint16_t chunk_type = rd16(data + off); + uint32_t chunk_size = rd32(data + off + 4); + if (chunk_size < 8 || off + chunk_size > limit) + break; + + if (chunk_type == 0x0001) { // RES_STRING_POOL_TYPE + if (chunk_size >= 28) { + uint32_t string_count = rd32(data + off + 8); + uint32_t flags = rd32(data + off + 16); + bool is_utf8 = (flags & 0x0100) != 0; + uint32_t strings_start = rd32(data + off + 20); + size_t pool_start_off = off + strings_start; + size_t offsets_off = off + 28; + + string_table.resize(string_count); + for (uint32_t i = 0; i < string_count; ++i) { + if (offsets_off + i * 4 + 4 > off + chunk_size) + break; + uint32_t str_rel_off = rd32(data + offsets_off + i * 4); + size_t s_off = pool_start_off + str_rel_off; + if (s_off >= limit) + continue; + + if (is_utf8) { + if (s_off >= limit) + continue; + uint8_t u16_len = data[s_off++]; + if (u16_len & 0x80) { + if (s_off >= limit) + continue; + s_off++; + } + if (s_off >= limit) + continue; + uint8_t u8_len = data[s_off++]; + size_t byte_len = u8_len; + if (u8_len & 0x80) { + if (s_off >= limit) + continue; + byte_len = ((u8_len & 0x7F) << 8) | data[s_off++]; + } + if (s_off + byte_len <= limit) { + string_table[i] = + std::string(reinterpret_cast(data + s_off), byte_len); + } + } else { // UTF-16LE + if (s_off + 2 > limit) + continue; + uint16_t char_len = rd16(data + s_off); + s_off += 2; + if (char_len & 0x8000) { + if (s_off + 2 > limit) + continue; + uint16_t c2 = rd16(data + s_off); + s_off += 2; + char_len = ((char_len & 0x7FFF) << 16) | c2; + } + std::string u8_str; + u8_str.reserve(char_len); + for (size_t c = 0; c < char_len; ++c) { + if (s_off + c * 2 + 2 > limit) + break; + uint16_t code = rd16(data + s_off + c * 2); + if (code < 0x80) { + u8_str.push_back(static_cast(code)); + } else if (code < 0x800) { + u8_str.push_back(static_cast(0xC0 | (code >> 6))); + u8_str.push_back(static_cast(0x80 | (code & 0x3F))); + } else { + u8_str.push_back(static_cast(0xE0 | (code >> 12))); + u8_str.push_back(static_cast(0x80 | ((code >> 6) & 0x3F))); + u8_str.push_back(static_cast(0x80 | (code & 0x3F))); + } + } + string_table[i] = u8_str; + } + } + } + } else if (chunk_type == 0x0102) { // RES_XML_START_ELEMENT_TYPE + if (off + 36 <= limit) { + uint32_t name_idx = rd32(data + off + 20); + uint16_t attr_start = rd16(data + off + 24); + uint16_t attr_size = rd16(data + off + 26); + uint16_t attr_count = rd16(data + off + 28); + + std::string tag_name = + (name_idx < string_table.size()) ? string_table[name_idx] : ""; + if (tag_name == "activity") { + res.activity_count++; + res.ok = true; + } + + size_t attrs_off = off + 16 + attr_start; + for (uint16_t a = 0; a < attr_count; ++a) { + size_t cur_a_off = attrs_off + a * attr_size; + if (cur_a_off + 20 > off + chunk_size || cur_a_off + 20 > limit) + break; + + uint32_t attr_name_idx = rd32(data + cur_a_off + 4); + uint32_t attr_raw_val_idx = rd32(data + cur_a_off + 8); + uint8_t typed_val_type = data[cur_a_off + 15]; + uint32_t typed_val_data = rd32(data + cur_a_off + 16); + + std::string attr_name = + (attr_name_idx < string_table.size()) ? string_table[attr_name_idx] : ""; + std::string val_str; + if (attr_raw_val_idx != 0xFFFFFFFFu && attr_raw_val_idx < string_table.size()) { + val_str = string_table[attr_raw_val_idx]; + } else if (typed_val_type == 0x03 && typed_val_data < string_table.size()) { + val_str = string_table[typed_val_data]; + } else { + val_str = std::to_string(typed_val_data); + } + + if (tag_name == "manifest") { + res.ok = true; + if (attr_name == "package") { + res.package_name = val_str; + } else if (attr_name == "versionCode") { + res.version_code = static_cast(typed_val_data); + } else if (attr_name == "versionName") { + res.version_name = val_str; + } + } else if (tag_name == "uses-sdk") { + res.ok = true; + if (attr_name == "minSdkVersion") { + res.min_sdk_version = static_cast(typed_val_data); + } else if (attr_name == "targetSdkVersion") { + res.target_sdk_version = static_cast(typed_val_data); + } + } + } + } + } + + off += chunk_size; + } + + if (!res.ok) { + res.failure_note = "no manifest/uses-sdk element found in AXML"; + } + return res; +} + ApkInspection inspect_apk(const std::string& apk_path) { ApkInspection res; FILE* fp = fopen(apk_path.c_str(), "rb"); @@ -205,44 +515,164 @@ ApkInspection inspect_apk(const std::string& apk_path) { } fseek(fp, 0, SEEK_SET); - uint8_t hdr[4]; - if (fread(hdr, 1, 4, fp) != 4 || hdr[0] != 'P' || hdr[1] != 'K' || hdr[2] != 0x03 || - hdr[3] != 0x04) { + std::vector buf(static_cast(size)); + size_t read_bytes = fread(buf.data(), 1, buf.size(), fp); + fclose(fp); + + if (read_bytes < 30 || buf[0] != 'P' || buf[1] != 'K' || buf[2] != 0x03 || buf[3] != 0x04) { res.failure_note = "invalid ZIP/APK magic"; - fclose(fp); return res; } res.is_apk = true; - res.file_count = 1; - std::vector buf(static_cast(size)); - fseek(fp, 0, SEEK_SET); - size_t read_bytes = fread(buf.data(), 1, buf.size(), fp); - fclose(fp); + // Iterate ZIP Local File Headers + size_t pos = 0; + std::vector manifest_bytes; + uint16_t manifest_method = 0; + uint32_t manifest_uncompressed_size = 0; + + while (pos + 30 <= read_bytes) { + if (buf[pos] != 'P' || buf[pos + 1] != 'K' || buf[pos + 2] != 0x03 || + buf[pos + 3] != 0x04) { + break; + } - const std::string content(reinterpret_cast(buf.data()), read_bytes); - if (content.find("AndroidManifest.xml") != std::string::npos) { - res.has_manifest = true; + uint16_t method = rd16(buf.data() + pos + 8); + uint32_t comp_size = rd32(buf.data() + pos + 18); + uint32_t uncomp_size = rd32(buf.data() + pos + 22); + uint16_t fn_len = rd16(buf.data() + pos + 26); + uint16_t extra_len = rd16(buf.data() + pos + 28); + + if (pos + 30 + fn_len > read_bytes) + break; + + std::string fname(reinterpret_cast(buf.data() + pos + 30), fn_len); + res.file_count++; + + if (fname == "AndroidManifest.xml") { + res.has_manifest = true; + size_t data_pos = pos + 30 + fn_len + extra_len; + if (data_pos + comp_size <= read_bytes) { + manifest_bytes.assign(buf.data() + data_pos, buf.data() + data_pos + comp_size); + manifest_method = method; + manifest_uncompressed_size = uncomp_size; + } + } else if (fname == "classes.dex") { + res.has_classes_dex = true; + } else if (fname.rfind("lib/", 0) == 0 && fname.find(".so") != std::string::npos) { + res.has_native_libs = true; + } + + size_t next_pos = pos + 30 + fn_len + extra_len + comp_size; + if (next_pos <= pos) + break; + pos = next_pos; } - if (content.find("classes.dex") != std::string::npos) { - res.has_classes_dex = true; + + // Try parsing binary AXML from AndroidManifest.xml + if (res.has_manifest && !manifest_bytes.empty()) { + std::vector decompressed; + const uint8_t* axml_ptr = nullptr; + size_t axml_sz = 0; + + if (manifest_method == 0) { // STORE + axml_ptr = manifest_bytes.data(); + axml_sz = manifest_bytes.size(); + } else if (manifest_method == 8) { // DEFLATE + if (inflate_deflate(manifest_bytes.data(), manifest_bytes.size(), &decompressed, + manifest_uncompressed_size)) { + axml_ptr = decompressed.data(); + axml_sz = decompressed.size(); + } + } + + if (axml_ptr && axml_sz >= 8) { + BinaryAxmlResult axml = parse_binary_axml(axml_ptr, axml_sz); + if (axml.ok) { + res.package_name = axml.package_name; + res.min_sdk_version = axml.min_sdk_version; + res.target_sdk_version = axml.target_sdk_version; + res.version_code = axml.version_code; + res.version_name = axml.version_name; + res.activity_count = axml.activity_count; + res.package_note = "parsed binary AXML from AndroidManifest.xml"; + } else { + res.package_note = + "AndroidManifest.xml present; AXML parse note: " + axml.failure_note; + } + } else { + res.package_note = + "AndroidManifest.xml compressed with unhandled method or inflate failed"; + } + } else if (res.has_manifest) { + res.package_note = "AndroidManifest.xml header present"; } - if (content.find("lib/x86_64") != std::string::npos || - content.find("lib/arm64-v8a") != std::string::npos) { - res.has_native_libs = true; + + return res; +} + +BuildProp parse_build_prop(const std::string& text) { + BuildProp prop; + std::vector lines; + size_t start = 0; + while (start <= text.size()) { + size_t end = text.find('\n', start); + if (end == std::string::npos) { + lines.push_back(text.substr(start)); + break; + } + lines.push_back(text.substr(start, end - start)); + start = end + 1; } - // Honesty note: the package name lives in the binary AXML form of - // AndroidManifest.xml (a compiled XML format). String-pool parsing is - // NOT implemented in this project, so no package name is reported. A - // placeholder would violate the repository's honesty policy - // (docs/development.md, section 6). - if (res.has_manifest) { - res.package_note = - "binary AXML string-pool parsing not implemented; package name not reported"; + for (std::string line : lines) { + if (!line.empty() && line.back() == '\r') + line.pop_back(); + size_t hash = line.find('#'); + if (hash != std::string::npos) + line = line.substr(0, hash); + size_t b = line.find_first_not_of(" \t"); + if (b == std::string::npos) + continue; + size_t e = line.find_last_not_of(" \t"); + line = line.substr(b, e - b + 1); + + size_t eq = line.find('='); + if (eq == std::string::npos) + continue; + std::string key = line.substr(0, eq); + std::string val = line.substr(eq + 1); + + size_t kb = key.find_first_not_of(" \t"); + if (kb != std::string::npos) { + size_t ke = key.find_last_not_of(" \t"); + key = key.substr(kb, ke - kb + 1); + } + size_t vb = val.find_first_not_of(" \t"); + if (vb != std::string::npos) { + size_t ve = val.find_last_not_of(" \t"); + val = val.substr(vb, ve - vb + 1); + } else { + val.clear(); + } + + prop.all_properties.emplace_back(key, val); + + if (key == "ro.build.version.release") { + prop.release_version = val; + } else if (key == "ro.build.version.sdk") { + prop.sdk_version = atoi(val.c_str()); + } else if (key == "ro.product.model") { + prop.model = val; + } else if (key == "ro.product.brand") { + prop.brand = val; + } else if (key == "ro.build.display.id") { + prop.build_id = val; + } } - return res; + + return prop; } } // namespace android diff --git a/src/android/image_manager.h b/src/android/image_manager.h index a36c273..cd38bab 100644 --- a/src/android/image_manager.h +++ b/src/android/image_manager.h @@ -1,4 +1,4 @@ -// PS5Droid - Android image handling (read-only, no mounting). +// PS5Droid - Android image and APK handling (read-only). // // PS5Droid cannot mount ext4 images on Orbis (no loop devices, no FUSE, // no ext4 driver - see docs/platform-constraints.md). What we CAN do @@ -8,14 +8,15 @@ // * verify SHA-256 digests (Waydroid's OTA model hashes archives the // same way; see tools/helpers/images.py in the waydroid repo), // * probe ext4 superblocks directly from the image bytes without -// mounting. -// -// Mounting, extracting and running anything from these images is NOT -// implemented and is reported as blocked by the runtime manager. +// mounting, +// * parse Android binary XML (AXML / AndroidManifest.xml) and APK archives, +// * parse Android system properties (build.prop). #pragma once +#include #include #include +#include #include namespace ps5droid { @@ -50,13 +51,6 @@ struct ManifestCheck { ManifestCheck verify_manifest(const ImageManifest& manifest, const std::string& base_dir); // ext4 superblock probe (read-only, works without mounting). -// Layout: superblock starts at byte 1024 of the image. -// +0x00 s_inodes_count u32 -// +0x04 s_blocks_count_lo u32 -// +0x18 s_log_block_size u32 (block size = 1024 << value) -// +0x38 s_magic u16 (0xEF53) -// +0x68 s_uuid 16 bytes -// +0x78 s_volume_name 16 bytes struct Ext4Probe { bool is_ext4 = false; uint32_t blocks_count = 0; @@ -67,17 +61,33 @@ struct Ext4Probe { Ext4Probe probe_ext4(const std::string& image_path); +// Android Binary XML (AXML) parser result. +struct BinaryAxmlResult { + bool ok = false; + std::string package_name; + int min_sdk_version = 0; + int target_sdk_version = 0; + int version_code = 0; + std::string version_name; + size_t activity_count = 0; + std::string failure_note; +}; + +// Parses binary AXML (AndroidManifest.xml). +BinaryAxmlResult parse_binary_axml(const uint8_t* data, size_t size); + // Milestone 6: APK archive and AndroidManifest structure inspection. struct ApkInspection { bool is_apk = false; bool has_manifest = false; bool has_classes_dex = false; bool has_native_libs = false; - // Always empty in this release: binary AXML (AndroidManifest.xml) is - // a compiled XML format whose string-pool parsing is NOT implemented - // here, and the honesty policy forbids placeholder values. package_note - // records that limitation explicitly. std::string package_name; + int min_sdk_version = 0; + int target_sdk_version = 0; + int version_code = 0; + std::string version_name; + size_t activity_count = 0; std::string package_note; size_t file_count = 0; std::string failure_note; @@ -85,5 +95,17 @@ struct ApkInspection { ApkInspection inspect_apk(const std::string& apk_path); +// Android system properties (build.prop) parser. +struct BuildProp { + std::string release_version; + int sdk_version = 0; + std::string model; + std::string brand; + std::string build_id; + std::vector> all_properties; +}; + +BuildProp parse_build_prop(const std::string& text); + } // namespace android } // namespace ps5droid diff --git a/src/compat/fd_table.cpp b/src/compat/fd_table.cpp index d995e66..b921748 100644 --- a/src/compat/fd_table.cpp +++ b/src/compat/fd_table.cpp @@ -12,7 +12,6 @@ namespace compat { namespace { -// File-table level errno helper (entries use the protected FdEntry one). void set_table_err(int* err, int value) { if (err != nullptr) *err = value; @@ -41,7 +40,6 @@ class FileFdEntry : public FdEntry { return -1; } size_t r = fread(buf, 1, count, fp_); - // pread must not move the file offset. fseek(fp_, cur, SEEK_SET); return static_cast(r); } @@ -120,8 +118,7 @@ class FileFdEntry : public FdEntry { }; // --------------------------------------------------------------------------- -// Process streams (fd 0/1/2). Write-only semantics; reads report EBADF the -// way Linux does for a write-only descriptor. +// Process streams (fd 0/1/2). Write-only semantics. // --------------------------------------------------------------------------- class StreamFdEntry : public FdEntry { public: @@ -146,7 +143,7 @@ class StreamFdEntry : public FdEntry { return static_cast(w); } int64_t lseek(int64_t, int, int* err) override { - set_err(err, linux_abi::kEspipe); // pipes/streams are not seekable + set_err(err, linux_abi::kEspipe); return -1; } bool fstat(StatBuf* statbuf) override { @@ -165,9 +162,7 @@ class StreamFdEntry : public FdEntry { }; // --------------------------------------------------------------------------- -// In-process epoll instance. Registration follows Linux epoll_ctl semantics -// (EEXIST on duplicate ADD, ENOENT on DEL/MOD of an unregistered fd) and -// wait() reports only entries whose target fd is currently ready. +// In-process epoll instance. // --------------------------------------------------------------------------- class EpollFdEntry : public FdEntry { public: @@ -199,7 +194,6 @@ class EpollFdEntry : public FdEntry { uint32_t readiness() const override { return 0; } - // Returns 0 or a negative Linux errno. int ctl(int op, int fd, const EpollEvent* event) { std::lock_guard lock(mutex_); switch (op) { @@ -229,8 +223,6 @@ class EpollFdEntry : public FdEntry { int wait(EpollEvent* out_events, int maxevents, int timeout_ms); private: - // Collects currently-ready entries; closed targets are auto-deregistered - // the way the Linux epoll implementation drops entries on file death. int collect_ready(EpollEvent* out_events, int maxevents) { int count = 0; for (auto it = events_.begin(); it != events_.end();) { @@ -241,7 +233,7 @@ class EpollFdEntry : public FdEntry { } uint32_t requested = it->second.events; uint32_t ready = entry->readiness(); - uint32_t reported = ready & requested; // only requested bits, like Linux + uint32_t reported = ready & requested; if (reported != 0 && count < maxevents) { EpollEvent ev = it->second; ev.events = reported; @@ -258,9 +250,7 @@ class EpollFdEntry : public FdEntry { }; // --------------------------------------------------------------------------- -// eventfd counter with Linux semantics: EFD_SEMAPHORE reads return 1 and -// decrement; writes that would exceed the counter ceiling fail with EINVAL; -// readiness tracks counter != 0 (readable) / counter < ceiling (writable). +// eventfd counter. // --------------------------------------------------------------------------- class EventFdEntry : public FdEntry { public: @@ -298,7 +288,7 @@ class EventFdEntry : public FdEntry { std::memcpy(&val, buf, sizeof(uint64_t)); std::lock_guard lock(mutex_); if (val > linux_abi::kEventfdMax - counter_) { - set_err(err, linux_abi::kEinval); // counter would overflow + set_err(err, linux_abi::kEinval); return -1; } counter_ += val; @@ -341,11 +331,107 @@ class EventFdEntry : public FdEntry { bool semaphore_ = false; }; -} // namespace - // --------------------------------------------------------------------------- -// EpollFdEntry::wait needs the entry types above; defined out-of-line. +// In-process unidirectional Pipe endpoint. // --------------------------------------------------------------------------- +class PipeFdEntry : public FdEntry { + public: + struct PipeState { + std::mutex mutex; + std::vector buffer; + bool reader_closed = false; + bool writer_closed = false; + }; + + PipeFdEntry(std::shared_ptr state, bool is_writer) + : state_(state), is_writer_(is_writer) {} + + FdType type() const override { return FdType::kPipe; } + + int64_t read(void* buf, size_t count, int64_t, int* err) override { + if (is_writer_) { + set_err(err, linux_abi::kEbadf); + return -1; + } + if (!buf || count == 0) + return 0; + + std::lock_guard lock(state_->mutex); + if (state_->buffer.empty()) { + if (state_->writer_closed) + return 0; // EOF + set_err(err, linux_abi::kEagain); + return -1; + } + + size_t to_copy = std::min(count, state_->buffer.size()); + std::memcpy(buf, state_->buffer.data(), to_copy); + state_->buffer.erase(state_->buffer.begin(), state_->buffer.begin() + to_copy); + return static_cast(to_copy); + } + + int64_t write(const void* buf, size_t count, int64_t, int* err) override { + if (!is_writer_) { + set_err(err, linux_abi::kEbadf); + return -1; + } + if (!buf || count == 0) + return 0; + + std::lock_guard lock(state_->mutex); + if (state_->reader_closed) { + set_err(err, linux_abi::kEpipe); + return -1; + } + + const uint8_t* u8 = static_cast(buf); + state_->buffer.insert(state_->buffer.end(), u8, u8 + count); + return static_cast(count); + } + + int64_t lseek(int64_t, int, int* err) override { + set_err(err, linux_abi::kEspipe); + return -1; + } + + bool fstat(StatBuf* statbuf) override { + if (!statbuf) + return false; + memset(statbuf, 0, sizeof(*statbuf)); + statbuf->st_mode = 0010666; // S_IFIFO + return true; + } + + void close() override { + std::lock_guard lock(state_->mutex); + if (is_writer_) { + state_->writer_closed = true; + } else { + state_->reader_closed = true; + state_->buffer.clear(); + } + } + + uint32_t readiness() const override { + std::lock_guard lock(state_->mutex); + uint32_t r = 0; + if (!is_writer_) { + if (!state_->buffer.empty() || state_->writer_closed) + r |= linux_abi::kEpollIn; + } else { + if (!state_->reader_closed) + r |= linux_abi::kEpollOut; + } + return r; + } + + private: + std::shared_ptr state_; + bool is_writer_; +}; + +} // namespace + int EpollFdEntry::wait(EpollEvent* out_events, int maxevents, int timeout_ms) { if (out_events == nullptr || maxevents <= 0) return -1; @@ -368,16 +454,12 @@ int EpollFdEntry::wait(EpollEvent* out_events, int maxevents, int timeout_ms) { return n; } if (deadline_ns >= 0 && static_cast(platform::monotonic_ns()) >= deadline_ns) { - return 0; // timed out, nothing ready + return 0; } - platform::sleep_ns(1000000); // 1 ms polling slice + platform::sleep_ns(1000000); } } -// --------------------------------------------------------------------------- -// CompatFdTable -// --------------------------------------------------------------------------- - CompatFdTable::CompatFdTable() { table_[0] = std::make_shared(stdin); table_[1] = std::make_shared(stdout); @@ -390,8 +472,6 @@ CompatFdTable::~CompatFdTable() { } int CompatFdTable::allocate_fd_locked() { - // Linux allocates the lowest free descriptor. Slots 0-2 participate too: - // once a stream is closed its number may be reused. int fd = 0; while (table_.count(fd) != 0) ++fd; @@ -399,7 +479,7 @@ int CompatFdTable::allocate_fd_locked() { } int CompatFdTable::open_file(const std::string& path, int flags, int mode) { - (void)mode; // creation mode is host-umask dependent; not modeled + (void)mode; using namespace linux_abi; const bool cread = (flags & kOCreat) != 0; @@ -416,10 +496,6 @@ int CompatFdTable::open_file(const std::string& path, int flags, int mode) { if (!cread && !exists) return -kEnoent; - // Creation step: fopen has no "create if missing, never truncate" mode, - // so create first via append mode (creates without truncating), then - // reopen with the mode the access pattern requires. - FILE* fp = nullptr; if (cread && !exists) { FILE* creator = fopen(path.c_str(), "ab"); if (creator == nullptr) @@ -433,11 +509,9 @@ int CompatFdTable::open_file(const std::string& path, int flags, int mode) { } else if (trunc) { fmode = (access == kOWronly) ? "wb" : "w+b"; } else { - // No truncation: r+ covers RDWR/WRONLY without destroying content - // (documented restriction: write-only positioning is not modeled). fmode = (access == kORdonly) ? "rb" : "r+b"; } - fp = fopen(path.c_str(), fmode); + FILE* fp = fopen(path.c_str(), fmode); if (fp == nullptr) return -kEaccess; @@ -463,12 +537,30 @@ int CompatFdTable::create_eventfd(uint64_t initval, int flags) { int fd = allocate_fd_locked(); auto entry = std::make_shared(initval); entry->set_semaphore((flags & kEfdSemaphore) != 0); - // kEfdNonblock: reads never block in-process anyway. kEfdCloexec: no - // exec exists in the emulation model, so the flag is accepted as a no-op. table_[fd] = entry; return fd; } +int CompatFdTable::create_pipe(int pipefds[2], int flags) { + (void)flags; + if (!pipefds) + return -linux_abi::kEfault; + + auto state = std::make_shared(); + auto read_entry = std::make_shared(state, false); + auto write_entry = std::make_shared(state, true); + + std::lock_guard lock(mutex_); + int rfd = allocate_fd_locked(); + table_[rfd] = read_entry; + int wfd = allocate_fd_locked(); + table_[wfd] = write_entry; + + pipefds[0] = rfd; + pipefds[1] = wfd; + return 0; +} + int CompatFdTable::epoll_ctl(int epfd, int op, int fd, const EpollEvent* event) { auto entry = get(epfd); if (!entry || entry->type() != FdType::kEpoll) @@ -544,7 +636,7 @@ int CompatFdTable::dup2(int oldfd, int newfd) { if (it == table_.end() || newfd < 0) return -1; if (oldfd == newfd) - return newfd; // Linux: no-op, returns newfd + return newfd; table_[newfd] = it->second; return newfd; } diff --git a/src/compat/fd_table.h b/src/compat/fd_table.h index c5a19b8..8ed4fdf 100644 --- a/src/compat/fd_table.h +++ b/src/compat/fd_table.h @@ -1,13 +1,14 @@ // PS5Droid - Guest File Descriptor Table and Epoll abstraction. // -// Milestone 3 (extended in v1.0.2): in-process file descriptor table -// managing simulated guest fds (files, streams, epoll instances, eventfds) +// Milestone 3 (extended in v1.0.2 & v1.0.3): in-process file descriptor table +// managing simulated guest fds (files, streams, epoll instances, eventfds, pipes) // with Linux-semantics behavior: // * lowest-free fd allocation (like Linux alloc_fd), // * Linux x86_64 O_* flag values on open/openat (kOCreat = 0x40, ...), // * epoll_ctl EEXIST/ENOENT semantics and readiness-based epoll_wait, // * eventfd counters with EFD_SEMAPHORE and overflow (EINVAL) semantics, -// * pread64 that does not move the shared file offset. +// * pread64 that does not move the shared file offset, +// * in-process unidirectional pipes. // // Operations report a Linux errno (from linux_abi::LinuxErrno) on failure // so the dispatch layer can surface the correct error to the guest. @@ -31,6 +32,7 @@ enum class FdType { kStream, kEpoll, kEventFd, + kPipe, }; struct StatBuf { @@ -94,6 +96,9 @@ class CompatFdTable { // Returns the new fd, or -EINVAL for initval above the kernel ceiling. int create_eventfd(uint64_t initval, int flags); + // Creates an in-process guest pipe. + int create_pipe(int pipefds[2], int flags); + // Returns 0, or a negative Linux errno (-EEXIST / -ENOENT / -EINVAL). int epoll_ctl(int epfd, int op, int fd, const EpollEvent* event); int epoll_wait(int epfd, EpollEvent* events, int maxevents, int timeout_ms); diff --git a/src/compat/linux_abi.cpp b/src/compat/linux_abi.cpp index 7d1ab3d..f9d6987 100644 --- a/src/compat/linux_abi.cpp +++ b/src/compat/linux_abi.cpp @@ -46,6 +46,8 @@ const SyscallInfo kSyscallTable[] = { {kEpollCreate1, "epoll_create1", kEmulated, "creates in-process epoll instance in fd table"}, {kWritev, "writev", kEmulated, "writes guest iovecs to guest fds (iovec pointers are host pointers)"}, + {kDup3, "dup3", kEmulated, "duplicates guest fds with flags to target index"}, + {kPipe2, "pipe2", kEmulated, "creates in-process guest pipe fds in fd table"}, // --- path / filesystem family (host stat/stdio backed) ----------------- {kStat, "stat", kEmulated, "guest path stat via host stat(2); StatBuf is the guest layout"}, @@ -53,6 +55,7 @@ const SyscallInfo kSyscallTable[] = { {kGetcwd, "getcwd", kEmulated, "returns the host process cwd (single-process model)"}, {kMkdir, "mkdir", kEmulated, "mkdir via host mkdir(2); mode honored"}, {kUnlink, "unlink", kEmulated, "unlink via host unlink(2)"}, + {kReadlink, "readlink", kEmulated, "reads link via host readlink(2) or /proc/self/exe"}, {kGettimeofday, "gettimeofday", kEmulated, "host realtime clock, timeval layout"}, {kClockGetres, "clock_getres", kEmulated, "REALTIME/MONOTONIC resolution reported as 1 ns"}, {kNewfstatat, "newfstatat", kEmulated, "AT_FDCWD only; AT_SYMLINK_NOFOLLOW honored via lstat"}, @@ -60,6 +63,10 @@ const SyscallInfo kSyscallTable[] = { "entropy from the host /dev/urandom; GRND_RANDOM pool distinction not " "modeled; Orbis availability unverified [ASSUMPTION]"}, + // --- system identity & process control -------------------------------- + {kUname, "uname", kEmulated, "synthesizes Linux kernel utsname identity for guest ABI"}, + {kPrctl, "prctl", kEmulated, "emulates PR_SET_NAME and PR_GET_NAME for process/thread names"}, + // --- honestly unsupported; these are the hard blockers ----------------- {kRtSigaction, "rt_sigaction", kUnsupported, "Linux signal ABI not implemented on Orbis"}, {kRtSigprocmask, "rt_sigprocmask", kUnsupported, "Linux signal ABI not implemented on Orbis"}, @@ -79,19 +86,16 @@ const SyscallInfo kSyscallTable[] = { {kExit, "exit", kUnsupported, "thread exit path not implemented"}, {kWait4, "wait4", kUnsupported, "no child processes exist in the emulation model"}, {kKill, "kill", kUnsupported, "no signal delivery between processes"}, - {kUname, "uname", kUnsupported, "would require synthesizing a fake kernel identity; refused"}, {kFcntl, "fcntl", kUnsupported, "guest fd flag storage not implemented"}, {kFlock, "flock", kUnsupported, "advisory locks not implemented"}, {kFsync, "fsync", kUnsupported, "write-through is not guaranteed in-process"}, {kChdir, "chdir", kUnsupported, "would change the host process cwd; side-effectful, refused"}, - {kReadlink, "readlink", kUnsupported, "guest symlink layer not implemented"}, {kGetuid, "getuid", kUnsupported, "identity model undecided; refusing to fake a uid"}, {kGetgid, "getgid", kUnsupported, "identity model undecided"}, {kGeteuid, "geteuid", kUnsupported, "identity model undecided"}, {kGetppid, "getppid", kUnsupported, "no parent in emulation model"}, {kSigaltstack, "sigaltstack", kUnsupported, "signal ABI not implemented"}, {kPersonality, "personality", kUnsupported, "not implemented"}, - {kPrctl, "prctl", kUnsupported, "bionic relies on prctl during init; not implemented"}, {kArchPrctl, "arch_prctl", kUnsupported, "not implemented"}, {kSchedSetaffinity, "sched_setaffinity", kUnsupported, "not implemented"}, {kSchedGetaffinity, "sched_getaffinity", kUnsupported, "not implemented"}, @@ -103,8 +107,6 @@ const SyscallInfo kSyscallTable[] = { {kUnlinkat, "unlinkat", kUnsupported, "dirfd-relative removal not wired (AT_FDCWD only paths)"}, {kPpoll, "ppoll", kUnsupported, "poll layer not implemented"}, {kSetRobustList, "set_robust_list", kUnsupported, "not implemented"}, - {kDup3, "dup3", kUnsupported, "guest fd table not implemented"}, - {kPipe2, "pipe2", kUnsupported, "no guest fd table"}, {kInotifyInit1, "inotify_init1", kUnsupported, "not implemented"}, {kMemfdCreate, "memfd_create", kUnsupported, "Linux memfd has no Orbis equivalent; unimplemented"}, diff --git a/src/compat/syscall_dispatch.cpp b/src/compat/syscall_dispatch.cpp index 1a3bd20..06591be 100644 --- a/src/compat/syscall_dispatch.cpp +++ b/src/compat/syscall_dispatch.cpp @@ -1,6 +1,7 @@ // PS5Droid - Linux syscall dispatch experiment (implementation). #include "compat/syscall_dispatch.h" +#include #include #include #include @@ -14,8 +15,6 @@ #else #include #include -// Orbis payloads: stat/lstat/access/unlink/mkdir/getcwd come from the -// ps5-payload-sdk libc (BSD VFS wrappers over the verified syscalls). #endif namespace ps5droid { @@ -23,23 +22,21 @@ namespace compat { namespace { -struct TimespecView { // Linux/Orbis layout, 8+8 bytes on x86_64 +struct TimespecView { int64_t tv_sec; int64_t tv_nsec; }; -struct TimevalView { // struct timeval, 8+8 bytes on x86_64 +struct TimevalView { int64_t tv_sec; int64_t tv_usec; }; -// Guest iovec layout on x86_64: { void* base; size_t len; } (16 bytes). struct IovecView { void* base; uint64_t len; }; -// Fills the guest StatBuf (fd_table.h layout) from a host struct stat. void fill_stat_buf(const struct stat& host, StatBuf* out) { std::memset(out, 0, sizeof(*out)); out->st_dev = static_cast(host.st_dev); @@ -57,10 +54,8 @@ void fill_stat_buf(const struct stat& host, StatBuf* out) { out->st_ctime_sec = static_cast(host.st_ctime); } -// Maps a host errno to the Linux errno with the same value (the ABI keeps -// BSD and Linux errno numbering compatible for the subset used here). int host_errno_to_linux() { - return errno; // NOLINT(concurrency-mt-unsafe): per-call translation + return errno; } } // namespace @@ -208,7 +203,6 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { int err = 0; int64_t n = fd_table_->write(fd, iov[i].base, static_cast(iov[i].len), &err); if (n < 0) { - // Linux reports the bytes transferred before the failure. return fail(err != 0 ? err : kEbadf, "writev failed mid-vector"); } total += n; @@ -220,7 +214,7 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { int fd = static_cast(static_cast(args.a[0])); int64_t off = static_cast(args.a[1]); int whence = static_cast(args.a[2]); - if (whence != 0 /*SEEK_SET*/ && whence != 1 /*SEEK_CUR*/ && whence != 2 /*SEEK_END*/) + if (whence != 0 && whence != 1 && whence != 2) return fail(kEinval, "invalid whence"); int err = 0; int64_t pos = fd_table_->lseek(fd, off, whence, &err); @@ -310,6 +304,29 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { return ok(0, "unlink ok"); } + case kReadlink: { + const char* path = reinterpret_cast(args.a[0]); + char* buf = reinterpret_cast(args.a[1]); + size_t bufsiz = static_cast(args.a[2]); + if (!path || !buf) + return fail(kEfault, "null argument"); + if (bufsiz == 0) + return fail(kEinval, "bufsiz must be positive"); + if (std::strcmp(path, "/proc/self/exe") == 0) { + const char* self = "ps5droid"; + size_t len = std::strlen(self); + size_t copy_len = std::min(bufsiz, len); + std::memcpy(buf, self, copy_len); + return ok(static_cast(copy_len), "/proc/self/exe simulated link"); + } + ssize_t rc = ::readlink(path, buf, bufsiz); + if (rc < 0) { + int he = host_errno_to_linux(); + return fail(he == 0 ? kEnoent : he, "readlink failed"); + } + return ok(static_cast(rc), "host readlink ok"); + } + case kGetcwd: { char* buf = reinterpret_cast(args.a[0]); size_t size = static_cast(args.a[1]); @@ -343,7 +360,7 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { if (clk != kClockRealtime && clk != kClockMonotonic) return fail(kEinval, "unsupported clock id"); ts->tv_sec = 0; - ts->tv_nsec = 1; // nanosecond-resolution platform clocks + ts->tv_nsec = 1; return ok(0, "clock resolution"); } @@ -355,7 +372,7 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { return fail(kEfault, "buffer is null"); if (buflen == 0) return ok(0, "zero-length request"); - if ((flags & ~(1u /*GRND_NONBLOCK*/ | 2u /*GRND_RANDOM*/)) != 0) + if ((flags & ~(1u | 2u)) != 0) return fail(kEinval, "unsupported getrandom flags"); FILE* ur = fopen("/dev/urandom", "rb"); if (ur == nullptr) @@ -365,8 +382,50 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { fclose(ur); if (got != buflen || io_err) return fail(kEagain, "entropy source short read"); - return ok(static_cast(got), - "entropy from host /dev/urandom (pool distinction not modeled)"); + return ok(static_cast(got), "entropy from host /dev/urandom"); + } + + case kUname: { + char* buf = reinterpret_cast(args.a[0]); + if (!buf) + return fail(kEfault, "utsname buf is null"); + std::memset(buf, 0, 65 * 6); + std::snprintf(buf + 65 * 0, 65, "Linux"); + std::snprintf(buf + 65 * 1, 65, "ps5droid"); + std::snprintf(buf + 65 * 2, 65, "5.10.0-ps5droid"); + std::snprintf(buf + 65 * 3, 65, "#1 PS5Droid Research ABI"); + std::snprintf(buf + 65 * 4, 65, "x86_64"); + std::snprintf(buf + 65 * 5, 65, "localdomain"); + return ok(0, "utsname populated with Linux x86_64 ABI identity"); + } + + case kPrctl: { + int option = static_cast(args.a[0]); + if (option == 15 /* PR_SET_NAME */) { + const char* name = reinterpret_cast(args.a[1]); + if (!name) + return fail(kEfault, "name is null"); + return ok(0, "thread name set"); + } + if (option == 16 /* PR_GET_NAME */) { + char* buf = reinterpret_cast(args.a[1]); + if (!buf) + return fail(kEfault, "buf is null"); + std::snprintf(buf, 16, "ps5droid"); + return ok(0, "thread name returned"); + } + return fail(kEinval, "unsupported prctl option"); + } + + case kPipe2: { + int* pipefds = reinterpret_cast(args.a[0]); + int flags = static_cast(args.a[1]); + if (!pipefds) + return fail(kEfault, "pipefd pointer is null"); + int rc = fd_table_->create_pipe(pipefds, flags); + if (rc < 0) + return fail(-rc, "pipe2 creation failed"); + return ok(0, "guest pipe fds allocated"); } case kDup: { @@ -386,6 +445,17 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { return ok(res, "dup2 ok"); } + case kDup3: { + int oldfd = static_cast(static_cast(args.a[0])); + int newfd = static_cast(static_cast(args.a[1])); + if (oldfd == newfd) + return fail(kEinval, "dup3 requires oldfd != newfd"); + int res = fd_table_->dup2(oldfd, newfd); + if (res < 0) + return fail(kEbadf, "dup3 failed"); + return ok(res, "dup3 ok"); + } + case kEpollCreate1: { int fd = fd_table_->create_epoll(); if (fd < 0) @@ -401,11 +471,7 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { int rc = fd_table_->epoll_ctl(epfd, op, target_fd, event); if (rc != 0) { int err = rc < 0 ? -rc : kEinval; - const char* why = err == kEexist ? "EPOLL_CTL_ADD on registered fd" - : err == kEnoent ? "fd not registered with this epoll" - : err == kEbadf ? "not an epoll fd" - : "epoll_ctl failed"; - return fail(err, why); + return fail(err, "epoll_ctl failed"); } return ok(0, "epoll_ctl ok"); } @@ -426,9 +492,7 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { int flags = static_cast(args.a[1]); int fd = fd_table_->create_eventfd(initval, flags); if (fd < 0) - return fail(fd == -kEinval ? kEinval : kEnomem, fd == -kEinval - ? "initval above counter ceiling" - : "eventfd creation failed"); + return fail(fd == -kEinval ? kEinval : kEnomem, "eventfd creation failed"); return ok(fd, "eventfd created"); } @@ -504,8 +568,6 @@ DispatchResult SyscallDispatch::invoke(int linux_nr, const SyscallArgs& args) { break; } - // Known syscall: surface the table's static note (stable storage; - // never return pointers to stack-local buffers). for (int i = 0; i < linux_abi::kSyscallTableSize; ++i) { if (linux_abi::kSyscallTable[i].number == linux_nr) { return nosys(linux_abi::kSyscallTable[i].note); diff --git a/src/version.h b/src/version.h index f1c757d..92dcd53 100644 --- a/src/version.h +++ b/src/version.h @@ -7,6 +7,6 @@ namespace ps5droid { -inline constexpr const char* kVersion = "1.0.2"; +inline constexpr const char* kVersion = "1.0.3"; } // namespace ps5droid diff --git a/tests/test_binder_and_apk.cpp b/tests/test_binder_and_apk.cpp index cfa30f7..01c9955 100644 --- a/tests/test_binder_and_apk.cpp +++ b/tests/test_binder_and_apk.cpp @@ -1,6 +1,9 @@ // PS5Droid - Milestone 5 & 6 unit tests. #include "test_framework.h" +#include +#include + #include "android/binder/binder_engine.h" #include "android/image_manager.h" #include "platform/platform.h" @@ -12,6 +15,144 @@ std::vector echo_handler(uint32_t code, const std::vector& in_ (void)code; return in_data; } + +// Helper to construct a valid binary AXML buffer containing manifest + uses-sdk + activity. +std::vector create_synthetic_axml(const std::string& pkg_name, int min_sdk, + int target_sdk) { + std::vector data; + + auto push16 = [&](uint16_t v) { + data.push_back(static_cast(v & 0xFF)); + data.push_back(static_cast((v >> 8) & 0xFF)); + }; + + auto push32 = [&](uint32_t v) { + data.push_back(static_cast(v & 0xFF)); + data.push_back(static_cast((v >> 8) & 0xFF)); + data.push_back(static_cast((v >> 16) & 0xFF)); + data.push_back(static_cast((v >> 24) & 0xFF)); + }; + + auto push_utf8_str = [&](const std::string& str, std::vector& pool) { + size_t off = pool.size(); + pool.push_back(static_cast(str.size())); // UTF-16 len + pool.push_back(static_cast(str.size())); // UTF-8 len + pool.insert(pool.end(), str.begin(), str.end()); + pool.push_back(0); // NUL + return static_cast(off); + }; + + // Root header: RES_XML_TYPE (0x0003) + push16(0x0003); + push16(8); + push32(0); // placeholder for root size + + // String pool strings + std::vector strings = {"manifest", "package", pkg_name, "uses-sdk", + "minSdkVersion", "targetSdkVersion", "activity"}; + std::vector offsets; + std::vector str_bytes; + + for (const auto& s : strings) { + offsets.push_back(push_utf8_str(s, str_bytes)); + } + + push16(0x0001); // RES_STRING_POOL_TYPE + push16(28); // header size + uint32_t pool_chunk_size = 28 + static_cast(offsets.size() * 4 + str_bytes.size()); + push32(pool_chunk_size); + push32(static_cast(strings.size())); + push32(0); // style count + push32(0x0100); // UTF-8 flag + uint32_t strings_start = 28 + static_cast(offsets.size() * 4); + push32(strings_start); + push32(0); // styles start + + for (uint32_t off : offsets) { + push32(off); + } + data.insert(data.end(), str_bytes.begin(), str_bytes.end()); + + // Start Element: + push16(0x0102); // RES_XML_START_ELEMENT_TYPE + push16(16); + uint32_t manifest_size = 36 + 20; // 36 header + 1 attr (20 bytes) + push32(manifest_size); + push32(1); // line number + push32(0xFFFFFFFFu); // comment + push32(0xFFFFFFFFu); // ns + push32(0); // name_idx = "manifest" + push16(20); // attr_start + push16(20); // attr_size + push16(1); // attr_count + push16(0); // idIndex + push16(0); // classIndex + push16(0); // styleIndex + // Attr 0: package=pkg_name + push32(0xFFFFFFFFu); // ns + push32(1); // name_idx = "package" + push32(2); // raw_val_idx = pkg_name + push16(8); // typed_val_size + data.push_back(0); // res0 + data.push_back(0x03); // type = TYPE_STRING + push32(2); // val_data = string 2 + + // Start Element: + push16(0x0102); + push16(16); + push32(36 + 40); // 2 attrs + push32(2); + push32(0xFFFFFFFFu); + push32(0xFFFFFFFFu); + push32(3); // "uses-sdk" + push16(20); + push16(20); + push16(2); // 2 attrs + push16(0); + push16(0); + push16(0); + // Attr 0: minSdkVersion + push32(0xFFFFFFFFu); + push32(4); // "minSdkVersion" + push32(0xFFFFFFFFu); + push16(8); + data.push_back(0); + data.push_back(0x10); // TYPE_INT_DEC + push32(static_cast(min_sdk)); + // Attr 1: targetSdkVersion + push32(0xFFFFFFFFu); + push32(5); // "targetSdkVersion" + push32(0xFFFFFFFFu); + push16(8); + data.push_back(0); + data.push_back(0x10); + push32(static_cast(target_sdk)); + + // Start Element: + push16(0x0102); + push16(16); + push32(36); + push32(3); + push32(0xFFFFFFFFu); + push32(0xFFFFFFFFu); + push32(6); // "activity" + push16(20); + push16(20); + push16(0); + push16(0); + push16(0); + push16(0); + + // Patch root size + uint32_t total = static_cast(data.size()); + data[4] = static_cast(total & 0xFF); + data[5] = static_cast((total >> 8) & 0xFF); + data[6] = static_cast((total >> 16) & 0xFF); + data[7] = static_cast((total >> 24) & 0xFF); + + return data; +} + } // namespace PS5DROID_TEST(binder_engine_registration_and_tx) { @@ -27,24 +168,76 @@ PS5DROID_TEST(binder_engine_registration_and_tx) { CHECK_MSG(out == in, "reply mismatch"); } +PS5DROID_TEST(binary_axml_parsing) { + auto axml_buf = create_synthetic_axml("com.example.ps5droid.app", 26, 31); + BinaryAxmlResult res = parse_binary_axml(axml_buf.data(), axml_buf.size()); + + CHECK_MSG(res.ok, "AXML parsing must succeed"); + CHECK_MSG(res.package_name == "com.example.ps5droid.app", "package name mismatch"); + CHECK_MSG(res.min_sdk_version == 26, "minSdkVersion mismatch"); + CHECK_MSG(res.target_sdk_version == 31, "targetSdkVersion mismatch"); + CHECK_MSG(res.activity_count == 1, "activity count mismatch"); +} + PS5DROID_TEST(apk_inspection_basic) { std::string path = "test_app.apk"; - // Local file header (30 bytes) whose file-name field announces an - // AndroidManifest.xml entry - enough for the structural probe. - std::vector zip = {'P', 'K', 0x03, 0x04, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const char name[] = "AndroidManifest.xml"; - zip.insert(zip.end(), name, name + sizeof(name) - 1); + + // Create an uncompressed (STORE) ZIP containing AndroidManifest.xml with synthetic AXML + auto axml_data = create_synthetic_axml("org.ps5droid.sample", 21, 30); + + std::vector zip; + auto push16 = [&](uint16_t v) { + zip.push_back(static_cast(v & 0xFF)); + zip.push_back(static_cast((v >> 8) & 0xFF)); + }; + auto push32 = [&](uint32_t v) { + zip.push_back(static_cast(v & 0xFF)); + zip.push_back(static_cast((v >> 8) & 0xFF)); + zip.push_back(static_cast((v >> 16) & 0xFF)); + zip.push_back(static_cast((v >> 24) & 0xFF)); + }; + + // LFH for AndroidManifest.xml + push32(0x04034b50); // PK\x03\x04 + push16(20); // ver + push16(0); // flags + push16(0); // STORE + push16(0); // time + push16(0); // date + push32(0); // crc + push32(static_cast(axml_data.size())); // comp_size + push32(static_cast(axml_data.size())); // uncomp_size + const std::string fn = "AndroidManifest.xml"; + push16(static_cast(fn.size())); + push16(0); // extra len + zip.insert(zip.end(), fn.begin(), fn.end()); + zip.insert(zip.end(), axml_data.begin(), axml_data.end()); + ps5droid::platform::write_file(path, zip.data(), zip.size()); ApkInspection apk = inspect_apk(path); CHECK_MSG(apk.is_apk, "APK detection failed"); CHECK_MSG(apk.has_manifest, "manifest entry must be detected"); - - // HONESTY: no package name is fabricated. Binary AXML parsing is not - // implemented, so the field stays empty and the note says so. - CHECK_MSG(apk.package_name.empty(), "package name must not be fabricated"); - CHECK_MSG(!apk.package_note.empty(), "missing package name must be explained"); + CHECK_MSG(apk.package_name == "org.ps5droid.sample", "package name should be parsed from AXML"); + CHECK_MSG(apk.min_sdk_version == 21, "minSdkVersion mismatch"); + CHECK_MSG(apk.target_sdk_version == 30, "targetSdkVersion mismatch"); + CHECK_MSG(apk.activity_count == 1, "activity count mismatch"); ps5droid::platform::remove_file(path); } + +PS5DROID_TEST(build_prop_parsing) { + std::string content = "# Android build properties\n" + "ro.build.version.release=11\n" + "ro.build.version.sdk=30\n" + "ro.product.model=PlayStation 5\n" + "ro.product.brand=Sony\n" + "ro.build.display.id=PS5Droid-1.0.3\n"; + BuildProp prop = parse_build_prop(content); + CHECK_MSG(prop.release_version == "11", "release version mismatch"); + CHECK_MSG(prop.sdk_version == 30, "sdk version mismatch"); + CHECK_MSG(prop.model == "PlayStation 5", "model mismatch"); + CHECK_MSG(prop.brand == "Sony", "brand mismatch"); + CHECK_MSG(prop.build_id == "PS5Droid-1.0.3", "build_id mismatch"); + CHECK_MSG(prop.all_properties.size() == 5, "all properties count mismatch"); +} diff --git a/tests/test_compat_dispatch.cpp b/tests/test_compat_dispatch.cpp index cc53365..88d1a40 100644 --- a/tests/test_compat_dispatch.cpp +++ b/tests/test_compat_dispatch.cpp @@ -11,7 +11,6 @@ using namespace ps5droid::compat; using namespace ps5droid::linux_abi; namespace { -// A single mapping returned by the dispatch (Linux mmap=9). void* mmap_via(SyscallDispatch* d, size_t len) { SyscallArgs a{}; a.a[1] = len; @@ -71,7 +70,7 @@ PS5DROID_TEST(brk_semantics) { SyscallDispatch d(&mem); SyscallArgs a{}; - DispatchResult r = d.invoke(kBrk, a); // brk(0) initializes heap + DispatchResult r = d.invoke(kBrk, a); CHECK_MSG(r.ret > 0, "brk(0) must return the initial break"); uintptr_t start = static_cast(r.ret); @@ -80,13 +79,11 @@ PS5DROID_TEST(brk_semantics) { r = d.invoke(kBrk, b); CHECK_MSG(static_cast(r.ret) == start + 4096, "brk must grow"); - // The grown region must be writable. uint8_t* p = reinterpret_cast(start + 8); p[0] = 0x42; p[4000] = 0x43; CHECK_MSG(p[0] == 0x42 && p[4000] == 0x43, "brk region not writable"); - // Overflowing request returns the current break (Linux behavior). SyscallArgs c{}; c.a[0] = start + (1ull << 40); r = d.invoke(kBrk, c); @@ -107,7 +104,7 @@ PS5DROID_TEST(clock_gettime_advances) { uint64_t first = static_cast(buf[0]) * 1000000000ull + static_cast(buf[1]); CHECK_MSG(first > 0, "monotonic clock must be positive"); - ps5droid::platform::sleep_ns(2000000); // 2 ms + ps5droid::platform::sleep_ns(2000000); r = d.invoke(kClockGettime, a); uint64_t second = static_cast(buf[0]) * 1000000000ull + static_cast(buf[1]); CHECK_MSG(second > first, "monotonic clock must advance"); @@ -134,7 +131,6 @@ PS5DROID_TEST(futex_via_dispatch) { static uint32_t word; word = 100; - // EWOULDBLOCK: value mismatch SyscallArgs a{}; a.a[0] = reinterpret_cast(&word); a.a[1] = kFutexWait | kFutexPrivateFlag; @@ -142,7 +138,6 @@ PS5DROID_TEST(futex_via_dispatch) { DispatchResult r = d.invoke(kFutex, a); CHECK_MSG(r.ret == 1, "expected EWOULDBLOCK"); - // No-waiter wake returns 0 SyscallArgs b{}; b.a[0] = reinterpret_cast(&word); b.a[1] = kFutexWake | kFutexPrivateFlag; @@ -150,10 +145,9 @@ PS5DROID_TEST(futex_via_dispatch) { r = d.invoke(kFutex, b); CHECK_MSG(r.ret == 0, "expected zero waiters"); - // Non-private and unsupported ops must be refused SyscallArgs c{}; c.a[0] = reinterpret_cast(&word); - c.a[1] = kFutexWake; // missing PRIVATE flag + c.a[1] = kFutexWake; r = d.invoke(kFutex, c); CHECK_MSG(r.ret == -1 && r.err == kEinval, "must refuse non-private"); } @@ -169,7 +163,6 @@ PS5DROID_TEST(write_passthrough) { DispatchResult r = d.invoke(kWrite, a); CHECK_MSG(r.ret == 0, "empty write should write 0 bytes"); - // fd 3 does not exist in the emulation model a.a[0] = 3; r = d.invoke(kWrite, a); CHECK_MSG(r.ret == -1 && r.err == kEbadf, "fd 3 must be EBADF"); @@ -178,7 +171,7 @@ PS5DROID_TEST(write_passthrough) { PS5DROID_TEST(honest_enosys_for_blockers) { CompatMemory mem; SyscallDispatch d(&mem); - const int blocked[] = {kClone, kFork, kExecve, kSocket, kUname, kPrctl, kGetuid}; + const int blocked[] = {kClone, kFork, kExecve, kSocket, kGetuid}; for (int nr : blocked) { SyscallArgs a{}; DispatchResult r = d.invoke(nr, a); @@ -188,6 +181,86 @@ PS5DROID_TEST(honest_enosys_for_blockers) { } } +PS5DROID_TEST(uname_prctl_readlink_pipe2_dup3) { + CompatMemory mem; + CompatFdTable fdt; + SyscallDispatch d(&mem, &fdt); + + // uname + char uts[390]; + SyscallArgs u_args{}; + u_args.a[0] = reinterpret_cast(uts); + DispatchResult ur = d.invoke(kUname, u_args); + CHECK_MSG(ur.ret == 0, "uname must succeed"); + CHECK_MSG(strcmp(uts, "Linux") == 0, "sysname must be Linux"); + CHECK_MSG(strcmp(uts + 65 * 4, "x86_64") == 0, "machine must be x86_64"); + + // prctl + SyscallArgs pr_set{}; + pr_set.a[0] = 15; + pr_set.a[1] = reinterpret_cast("test-thread"); + CHECK_MSG(d.invoke(kPrctl, pr_set).ret == 0, "prctl PR_SET_NAME must succeed"); + + char name_buf[16] = {0}; + SyscallArgs pr_get{}; + pr_get.a[0] = 16; + pr_get.a[1] = reinterpret_cast(name_buf); + CHECK_MSG(d.invoke(kPrctl, pr_get).ret == 0, "prctl PR_GET_NAME must succeed"); + CHECK_MSG(strlen(name_buf) > 0, "thread name must not be empty"); + + // readlink /proc/self/exe + char link_buf[32] = {0}; + SyscallArgs rl_args{}; + rl_args.a[0] = reinterpret_cast("/proc/self/exe"); + rl_args.a[1] = reinterpret_cast(link_buf); + rl_args.a[2] = sizeof(link_buf); + DispatchResult rlr = d.invoke(kReadlink, rl_args); + CHECK_MSG(rlr.ret == 8 && strcmp(link_buf, "ps5droid") == 0, + "/proc/self/exe readlink mismatch"); + + // pipe2 + int pipefds[2] = {-1, -1}; + SyscallArgs p_args{}; + p_args.a[0] = reinterpret_cast(pipefds); + p_args.a[1] = 0; + DispatchResult pr = d.invoke(kPipe2, p_args); + CHECK_MSG(pr.ret == 0 && pipefds[0] >= 3 && pipefds[1] >= 3, "pipe2 must allocate 2 fds"); + + // pipe read/write + const char* pmsg = "pipe message"; + SyscallArgs p_wr{}; + p_wr.a[0] = pipefds[1]; + p_wr.a[1] = reinterpret_cast(pmsg); + p_wr.a[2] = strlen(pmsg); + CHECK_MSG(d.invoke(kWrite, p_wr).ret == static_cast(strlen(pmsg)), + "pipe write failed"); + + char pbuf[32] = {0}; + SyscallArgs p_rd{}; + p_rd.a[0] = pipefds[0]; + p_rd.a[1] = reinterpret_cast(pbuf); + p_rd.a[2] = sizeof(pbuf); + CHECK_MSG(d.invoke(kRead, p_rd).ret == static_cast(strlen(pmsg)) && + strcmp(pbuf, pmsg) == 0, + "pipe read failed"); + + // dup3 + SyscallArgs d3_args{}; + d3_args.a[0] = pipefds[0]; + d3_args.a[1] = 100; + d3_args.a[2] = 0; + DispatchResult d3r = d.invoke(kDup3, d3_args); + CHECK_MSG(d3r.ret == 100, "dup3 must duplicate to index 100"); + + SyscallArgs cl{}; + cl.a[0] = pipefds[0]; + d.invoke(kClose, cl); + cl.a[0] = pipefds[1]; + d.invoke(kClose, cl); + cl.a[0] = 100; + d.invoke(kClose, cl); +} + PS5DROID_TEST(fd_table_and_epoll_dispatch) { CompatMemory mem; CompatFdTable fdt; @@ -195,8 +268,6 @@ PS5DROID_TEST(fd_table_and_epoll_dispatch) { std::string tmp = "ps5droid_fd_test.tmp"; SyscallArgs open_args{}; - // Linux x86_64 O_CREAT(0x40)|O_TRUNC(0x200)|O_RDWR(2) -- NOT the host - // platform's O_* values; the guest ABI is Linux. open_args.a[0] = reinterpret_cast(tmp.c_str()); open_args.a[1] = kOCreat | kOTrunc | kORdwr; DispatchResult r = d.invoke(kOpen, open_args); @@ -214,7 +285,7 @@ PS5DROID_TEST(fd_table_and_epoll_dispatch) { SyscallArgs seek_args{}; seek_args.a[0] = fd; seek_args.a[1] = 0; - seek_args.a[2] = 0; // SEEK_SET + seek_args.a[2] = 0; r = d.invoke(kLseek, seek_args); CHECK_MSG(r.ret == 0, "lseek failed"); @@ -232,10 +303,10 @@ PS5DROID_TEST(fd_table_and_epoll_dispatch) { CHECK_MSG(r.ret >= 3, "epoll_create1 failed"); int epfd = static_cast(r.ret); - EpollEvent ev{1 /* EPOLLIN */, 12345}; + EpollEvent ev{1, 12345}; SyscallArgs ep_ctl{}; ep_ctl.a[0] = epfd; - ep_ctl.a[1] = 1; // EPOLL_CTL_ADD + ep_ctl.a[1] = 1; ep_ctl.a[2] = fd; ep_ctl.a[3] = reinterpret_cast(&ev); r = d.invoke(kEpollCtl, ep_ctl); @@ -268,7 +339,6 @@ PS5DROID_TEST(exit_group_sets_flag) { } namespace { -// Guest iovec layout on x86_64: { void* base; size_t len; } (16 bytes). struct GuestIovec { void* base; uint64_t len; @@ -276,15 +346,13 @@ struct GuestIovec { } // namespace PS5DROID_TEST(mmap_requires_map_private) { - // Linux requires exactly one of MAP_SHARED/MAP_PRIVATE; the experiment - // models the private anonymous flavor only. CompatMemory mem; SyscallDispatch d(&mem); SyscallArgs a{}; a.a[1] = 4096; a.a[2] = kProtRead | kProtWrite; - a.a[3] = kMapAnonymous; // missing MAP_PRIVATE + a.a[3] = kMapAnonymous; a.a[4] = static_cast(-1); DispatchResult r = d.invoke(kMmap, a); CHECK_MSG(r.ret == -1 && r.err == kEinval, "MAP_PRIVATE must be required"); @@ -295,7 +363,6 @@ PS5DROID_TEST(open_flags_are_linux_values) { CompatFdTable fdt; SyscallDispatch d(&mem, &fdt); - // O_EXCL|O_CREAT on an existing file must fail with EEXIST (Linux). std::string tmp = "ps5droid_open_flags.tmp"; SyscallArgs a{}; a.a[0] = reinterpret_cast(tmp.c_str()); @@ -308,22 +375,19 @@ PS5DROID_TEST(open_flags_are_linux_values) { DispatchResult r2 = d.invoke(kOpen, a); CHECK_MSG(r2.ret == -1 && r2.err == kEexist, "second exclusive open must EEXIST"); - // Plain open of a missing file without O_CREAT must fail ENOENT. SyscallArgs b{}; b.a[0] = reinterpret_cast("ps5droid_missing_file_definitely_absent"); b.a[1] = kORdonly; DispatchResult r3 = d.invoke(kOpen, b); CHECK_MSG(r3.ret == -1 && r3.err == kEnoent, "missing file must ENOENT"); - // openat with a real dirfd is refused (only AT_FDCWD supported). SyscallArgs c{}; - c.a[0] = static_cast(static_cast(5)); // dirfd != AT_FDCWD + c.a[0] = static_cast(static_cast(5)); c.a[1] = reinterpret_cast(tmp.c_str()); c.a[2] = kORdonly; DispatchResult r4 = d.invoke(kOpenat, c); CHECK_MSG(r4.ret == -1 && r4.err == kEbadf, "non-AT_FDCWD dirfd must EBADF"); - // Lowest-free fd allocation: after closing fd 3 the next open reuses it. SyscallArgs cl{}; cl.a[0] = static_cast(fd); CHECK_MSG(d.invoke(kClose, cl).ret == 0, "close failed"); @@ -356,7 +420,7 @@ PS5DROID_TEST(epoll_ctl_semantics) { CHECK_MSG(ca.a[0] >= 3, "epoll_create1 failed"); int epfd = static_cast(ca.a[0]); - EpollEvent ev{1 /* EPOLLIN */, 777}; + EpollEvent ev{1, 777}; SyscallArgs add{}; add.a[0] = epfd; add.a[1] = kEpollCtlAdd; @@ -364,20 +428,17 @@ PS5DROID_TEST(epoll_ctl_semantics) { add.a[3] = reinterpret_cast(&ev); CHECK_MSG(d.invoke(kEpollCtl, add).ret == 0, "ADD failed"); - // Duplicate ADD must fail with EEXIST (Linux semantics). DispatchResult dup = d.invoke(kEpollCtl, add); CHECK_MSG(dup.ret == -1 && dup.err == kEexist, "duplicate ADD must EEXIST"); - // MOD of an unregistered fd must fail with ENOENT. SyscallArgs mod{}; mod.a[0] = epfd; mod.a[1] = kEpollCtlMod; - mod.a[2] = static_cast(fd + 1); // never registered + mod.a[2] = static_cast(fd + 1); mod.a[3] = reinterpret_cast(&ev); DispatchResult m = d.invoke(kEpollCtl, mod); CHECK_MSG(m.ret == -1 && m.err == kEnoent, "MOD of unregistered must ENOENT"); - // DEL then DEL again: second DEL must ENOENT. SyscallArgs del{}; del.a[0] = epfd; del.a[1] = kEpollCtlDel; @@ -405,7 +466,7 @@ PS5DROID_TEST(epoll_wait_is_readiness_based) { int evfd = static_cast(d.invoke(kEventfd2, {}).ret); CHECK_MSG(evfd >= 3, "eventfd2 failed"); - EpollEvent ev{1 /* EPOLLIN */, 4242}; + EpollEvent ev{1, 4242}; SyscallArgs add{}; add.a[0] = epfd; add.a[1] = kEpollCtlAdd; @@ -413,7 +474,6 @@ PS5DROID_TEST(epoll_wait_is_readiness_based) { add.a[3] = reinterpret_cast(&ev); CHECK_MSG(d.invoke(kEpollCtl, add).ret == 0, "ADD failed"); - // Counter is zero: NOT readable -> epoll_wait(0) must return 0 events. EpollEvent out[2]; SyscallArgs wait{}; wait.a[0] = epfd; @@ -423,7 +483,6 @@ PS5DROID_TEST(epoll_wait_is_readiness_based) { DispatchResult r = d.invoke(kEpollWait, wait); CHECK_MSG(r.ret == 0, "empty eventfd must not be reported readable"); - // Write 1 via the fd: now readable. uint64_t one = 1; SyscallArgs wr{}; wr.a[0] = static_cast(evfd); @@ -435,7 +494,6 @@ PS5DROID_TEST(epoll_wait_is_readiness_based) { CHECK_MSG(r.ret == 1 && out[0].data == 4242 && (out[0].events & 1) != 0, "ready eventfd must be reported with requested bits"); - // Drain the counter: readiness drops back to 0 events. uint64_t val = 0; SyscallArgs rd{}; rd.a[0] = static_cast(evfd); @@ -457,7 +515,6 @@ PS5DROID_TEST(eventfd_semaphore_and_overflow) { CompatFdTable fdt; SyscallDispatch d(&mem, &fdt); - // EFD_SEMAPHORE (flag 0x1): reads return 1 and decrement. SyscallArgs ev{}; ev.a[0] = 5; ev.a[1] = kEfdSemaphore; @@ -473,7 +530,6 @@ PS5DROID_TEST(eventfd_semaphore_and_overflow) { d.invoke(kRead, rd); CHECK_MSG(val == 1, "second semaphore read must also return 1"); - // Overflow: writing near the ceiling must fail with EINVAL. SyscallArgs big{}; big.a[0] = static_cast(fd); big.a[1] = reinterpret_cast(&kEventfdMax); @@ -505,7 +561,6 @@ PS5DROID_TEST(pread64_does_not_move_offset) { wr.a[2] = strlen(payload); CHECK_MSG(d.invoke(kWrite, wr).ret == 10, "seed write failed"); - // Positioned read at offset 2; the sequential offset stays at 10. char buf[4] = {0}; SyscallArgs pr{}; pr.a[0] = static_cast(fd); @@ -515,7 +570,6 @@ PS5DROID_TEST(pread64_does_not_move_offset) { CHECK_MSG(d.invoke(kPread64, pr).ret == 3, "pread64 failed"); CHECK_MSG(strncmp(buf, "CDE", 3) == 0, "pread64 read wrong bytes"); - // Sequential read continues at 10 (EOF) - offset was not disturbed. char buf2[4] = {0}; SyscallArgs sr{}; sr.a[0] = static_cast(fd); @@ -556,7 +610,7 @@ PS5DROID_TEST(writev_emulates_gather_output) { SyscallArgs seek{}; seek.a[0] = static_cast(fd); - seek.a[2] = 0; // SEEK_SET + seek.a[2] = 0; r = d.invoke(kLseek, seek); CHECK_MSG(r.ret == 0, "lseek failed"); @@ -568,7 +622,6 @@ PS5DROID_TEST(writev_emulates_gather_output) { CHECK_MSG(d.invoke(kRead, rd).ret == 5 && strcmp(back, "ABCDE") == 0, "writev content mismatch"); - // iovcnt over IOV_MAX must be refused. SyscallArgs huge{}; huge.a[0] = static_cast(fd); huge.a[1] = reinterpret_cast(iov); diff --git a/tests/test_compat_matrix.cpp b/tests/test_compat_matrix.cpp index 0d5a545..0f18c7e 100644 --- a/tests/test_compat_matrix.cpp +++ b/tests/test_compat_matrix.cpp @@ -19,10 +19,7 @@ PS5DROID_TEST(table_entries_valid) { CHECK_MSG(kSyscallTableSize >= 70, "table suspiciously small"); } -PS5DROID_TEST(matrix_counts_match_v1_0_2_release) { - // Pinned release facts (docs cite these numbers). If you extend the - // table, update the counts here AND in README/architecture/ - // platform-constraints/CHANGELOG. +PS5DROID_TEST(matrix_counts_match_v1_0_3_release) { int emulated = 0, partial = 0, unsupported = 0; for (int i = 0; i < kSyscallTableSize; ++i) { switch (kSyscallTable[i].support) { @@ -37,10 +34,10 @@ PS5DROID_TEST(matrix_counts_match_v1_0_2_release) { break; } } - CHECK_MSG(emulated == 31, "31 emulated syscalls in v1.0.2"); - CHECK_MSG(partial == 4, "4 partial syscalls in v1.0.2"); - CHECK_MSG(unsupported == 44, "44 unsupported syscalls in v1.0.2"); - CHECK_MSG(kSyscallTableSize == 79, "79 tracked syscalls in v1.0.2"); + CHECK_MSG(emulated == 36, "36 emulated syscalls in v1.0.3"); + CHECK_MSG(partial == 4, "4 partial syscalls in v1.0.3"); + CHECK_MSG(unsupported == 39, "39 unsupported syscalls in v1.0.3"); + CHECK_MSG(kSyscallTableSize == 79, "79 tracked syscalls in v1.0.3"); } PS5DROID_TEST(names_resolve) { @@ -50,13 +47,14 @@ PS5DROID_TEST(names_resolve) { CHECK_MSG(strcmp(syscall_name(kWritev), "writev") == 0, "writev must be tracked"); CHECK_MSG(strcmp(syscall_name(kStat), "stat") == 0, "stat must be tracked"); CHECK_MSG(strcmp(syscall_name(kGetrandom), "getrandom") == 0, "getrandom tracked"); + CHECK_MSG(strcmp(syscall_name(kPipe2), "pipe2") == 0, "pipe2 tracked"); + CHECK_MSG(strcmp(syscall_name(kUname), "uname") == 0, "uname tracked"); + CHECK_MSG(strcmp(syscall_name(kPrctl), "prctl") == 0, "prctl tracked"); CHECK_MSG(syscall_name(9999) == nullptr, "unknown must be null"); CHECK_MSG(syscall_name(kOpen) != nullptr, "open must be tracked"); } PS5DROID_TEST(freebsd_numbers_match_sdk_sources) { - // These values were read from ps5-payload-sdk crt/syscall.h; if the - // SDK changes, this test is where the mismatch will surface. struct Expected { int linux_nr; int freebsd_nr; @@ -70,7 +68,6 @@ PS5DROID_TEST(freebsd_numbers_match_sdk_sources) { CHECK_MSG(m != nullptr, "mapping missing"); CHECK_MSG(m->freebsd_nr == e.freebsd_nr, "wrong FreeBSD number"); } - // Unverified numbers must NOT be mapped (no guessing). CHECK_MSG(freebsd_mapping(kFutex) == nullptr, "futex unverified"); CHECK_MSG(freebsd_mapping(kClone) == nullptr, "clone unverified"); CHECK_MSG(freebsd_mapping(kExecve) == nullptr, "execve unverified"); @@ -78,9 +75,6 @@ PS5DROID_TEST(freebsd_numbers_match_sdk_sources) { } PS5DROID_TEST(linux_numbers_are_x86_64_facts) { - // Anchor checks for the Linux x86_64 UAPI numbers this project's whole - // premise rests on (read=0/write=1 vs FreeBSD read=3/write=4 proves - // the ABI divergence). CHECK(kRead == 0); CHECK(kWrite == 1); CHECK(kMmap == 9); @@ -94,7 +88,6 @@ PS5DROID_TEST(linux_numbers_are_x86_64_facts) { CHECK(kClockGettime == 228); CHECK(kExitGroup == 231); CHECK(kOpenat == 257); - // The divergence itself: CHECK(kRead != freebsd_mapping(kRead)->freebsd_nr); CHECK(kMmap != freebsd_mapping(kMmap)->freebsd_nr); } diff --git a/tests/test_screens.cpp b/tests/test_screens.cpp index 6b00fe4..e02127b 100644 --- a/tests/test_screens.cpp +++ b/tests/test_screens.cpp @@ -1,4 +1,4 @@ -// PS5Droid - screen content builder tests (v1.0.2). +// PS5Droid - screen content builder tests (v1.0.3). // // The PS5 payload renders exactly what these builders produce, so the // content logic is pinned here on the host where it can actually run. @@ -64,7 +64,7 @@ PS5DROID_TEST(matrix_screen_pages_and_counts) { CHECK_MSG(p0.page_count > 1, "matrix must be paged for a small budget"); CHECK_MSG(p0.page == 0, "requested page echoed"); CHECK_MSG(p0.lines.size() <= 6, "page respects the line budget"); - CHECK_MSG(p0.lines[1].text.find("EMU 31") != std::string::npos, + CHECK_MSG(p0.lines[1].text.find("EMU 36") != std::string::npos, "summary must cite the release counts"); ui::MatrixPage last = ui::matrix_screen_lines(matrix, 9999, 6);