# echostretch/kstuff architecture

> Architecture diagram of the GitHub repository echostretch/kstuff, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/echostretch/kstuff
- Repository: https://github.com/echostretch/kstuff

## Overview

This repository provides PS5 kernel debugging and patching components, a kernel payload with syscall/trap handling, a user-mode payload loader, and a firmware-porting tool. The principal workflow is to use the porting tool against a PS5 target to gather/debug firmware information and prepare payload artifacts; the kernel payload then handles traps and routes supported syscalls to features such as SELF/FPKG handling and syscall fixes. The graph also includes the GDB/debugging layer and the Capstone x86 interface. Connections are limited to those shown in excerpts or the SOURCE INDEX; several implementation details are unsampled.

Main entry points: [`ps5-kstuff/main.c`](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/main.c) (Kernel Payload), [`ps5-kstuff/porting_tool/main.py`](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/main.py) (Porting Tool), [`prosper0gdb/r0gdb.h`](https://github.com/echostretch/kstuff/blob/elfldr-compatability/prosper0gdb/r0gdb.h) (R0GDB Core), [`gdb_stub/dbg.h`](https://github.com/echostretch/kstuff/blob/elfldr-compatability/gdb_stub/dbg.h) (GDB API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_porting["Firmware Porting"]
  node_port_tool["Porting Tool<br/>[main.py]"]
  node_gdb_rpc["GDB RPC<br/>[gdb_rpc.py]"]
  node_trace_tool["Trace Utilities<br/>[traces.py]"]
  node_fself_tool["SELF Builder<br/>[make_fself.py]"]
end

subgraph group_debug["Kernel Debugging"]
  node_r0gdb["R0GDB Core<br/>[r0gdb.h]"]
  node_prosper_gdb["R0GDB Entrypoint<br/>[main.c]"]
  node_gdb_stub["GDB Stub<br/>[main.c]"]
  node_gdb_api["GDB API<br/>[dbg.h]"]
  node_trap_state["Trap State<br/>[trap_state.h]"]
  node_offsets["Firmware Offsets<br/>[offsets.h]"]
end

subgraph group_payload["PS5 Payload"]
  node_loader["Payload Loader<br/>[main.c]"]
  node_kstuff["Kernel Payload<br/>[main.c]"]
  node_uelf["uELF Trap Handler<br/>[main.c]"]
  node_parasites["Parasite Handling<br/>[parasites.h]"]
  node_uelf_structs["uELF Structures<br/>[structs.h]"]
  node_parasite_desc["Parasite Descriptors<br/>[parasite_desc.h]"]
end

subgraph group_interfaces["System Interfaces"]
  node_syscalls["PS5 Syscall Map<br/>[syscalls-ps5.py]"]
  node_capstone_x86["Capstone x86 API<br/>[x86.h]"]
  node_capstone_platform["Capstone Platform API<br/>[platform.h]"]
end

node_engineer(("Engineer"))
node_ps5_target(("PS5 Target"))

node_engineer -->|"runs"| node_port_tool
node_port_tool -->|"uses RPC"| node_gdb_rpc
node_port_tool -->|"uses traces"| node_trace_tool
node_port_tool -->|"uses builder"| node_fself_tool
node_port_tool -.->|"connects to"| node_ps5_target
node_loader -.->|"loads payload"| node_kstuff
node_kstuff -->|"initializes"| node_r0gdb
node_kstuff -->|"uses offsets"| node_offsets
node_kstuff -->|"uses API"| node_gdb_api
node_kstuff -->|"includes types"| node_uelf_structs
node_kstuff -->|"uses descriptors"| node_parasite_desc
node_uelf -->|"includes handler"| node_parasites
node_uelf -->|"includes types"| node_parasite_desc
node_prosper_gdb -->|"uses API"| node_gdb_api
node_prosper_gdb -->|"initializes"| node_r0gdb
node_gdb_stub -->|"uses API"| node_gdb_api
node_r0gdb -->|"uses state"| node_trap_state
node_capstone_x86 -->|"includes"| node_capstone_platform

click node_port_tool "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/main.py"
click node_gdb_rpc "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/gdb_rpc.py"
click node_trace_tool "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/traces.py"
click node_fself_tool "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/make_fself.py"
click node_loader "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff-ldr/main.c"
click node_kstuff "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/main.c"
click node_uelf "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/uelf/main.c"
click node_parasites "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/uelf/parasites.h"
click node_uelf_structs "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/uelf/structs.h"
click node_parasite_desc "https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/uelf/parasite_desc.h"
click node_r0gdb "https://github.com/echostretch/kstuff/blob/elfldr-compatability/prosper0gdb/r0gdb.h"
click node_prosper_gdb "https://github.com/echostretch/kstuff/blob/elfldr-compatability/prosper0gdb/main.c"
click node_gdb_stub "https://github.com/echostretch/kstuff/blob/elfldr-compatability/gdb_stub/main.c"
click node_gdb_api "https://github.com/echostretch/kstuff/blob/elfldr-compatability/gdb_stub/dbg.h"
click node_trap_state "https://github.com/echostretch/kstuff/blob/elfldr-compatability/gdb_stub/trap_state.h"
click node_offsets "https://github.com/echostretch/kstuff/blob/elfldr-compatability/prosper0gdb/offsets.h"
click node_syscalls "https://github.com/echostretch/kstuff/blob/elfldr-compatability/lib/syscalls-ps5.py"
click node_capstone_x86 "https://github.com/echostretch/kstuff/blob/elfldr-compatability/freebsd-headers/capstone/x86.h"
click node_capstone_platform "https://github.com/echostretch/kstuff/blob/elfldr-compatability/freebsd-headers/capstone/platform.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_port_tool,node_gdb_rpc,node_trace_tool,node_fself_tool toneBlue
class node_r0gdb,node_prosper_gdb,node_gdb_stub,node_gdb_api,node_trap_state,node_offsets toneAmber
class node_loader,node_kstuff,node_uelf,node_parasites,node_uelf_structs,node_parasite_desc toneMint
class node_syscalls,node_capstone_x86,node_capstone_platform toneRose
class node_engineer,node_ps5_target toneIndigo
```

## Components

### Firmware Porting

- [Porting Tool](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/main.py): `ps5-kstuff/porting_tool/main.py`
- [GDB RPC](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/gdb_rpc.py): `ps5-kstuff/porting_tool/gdb_rpc.py`
- [Trace Utilities](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/traces.py): `ps5-kstuff/porting_tool/traces.py`
- [SELF Builder](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/porting_tool/make_fself.py): `ps5-kstuff/porting_tool/make_fself.py`

### Kernel Debugging

- [R0GDB Core](https://github.com/echostretch/kstuff/blob/elfldr-compatability/prosper0gdb/r0gdb.h): `prosper0gdb/r0gdb.h`
- [R0GDB Entrypoint](https://github.com/echostretch/kstuff/blob/elfldr-compatability/prosper0gdb/main.c): `prosper0gdb/main.c`
- [GDB Stub](https://github.com/echostretch/kstuff/blob/elfldr-compatability/gdb_stub/main.c): `gdb_stub/main.c`
- [GDB API](https://github.com/echostretch/kstuff/blob/elfldr-compatability/gdb_stub/dbg.h): `gdb_stub/dbg.h`
- [Trap State](https://github.com/echostretch/kstuff/blob/elfldr-compatability/gdb_stub/trap_state.h): `gdb_stub/trap_state.h`
- [Firmware Offsets](https://github.com/echostretch/kstuff/blob/elfldr-compatability/prosper0gdb/offsets.h): `prosper0gdb/offsets.h`

### PS5 Payload

- [Payload Loader](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff-ldr/main.c): `ps5-kstuff-ldr/main.c`
- [Kernel Payload](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/main.c): `ps5-kstuff/main.c`
- [uELF Trap Handler](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/uelf/main.c): `ps5-kstuff/uelf/main.c`
- [Parasite Handling](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/uelf/parasites.h): `ps5-kstuff/uelf/parasites.h`
- [uELF Structures](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/uelf/structs.h): `ps5-kstuff/uelf/structs.h`
- [Parasite Descriptors](https://github.com/echostretch/kstuff/blob/elfldr-compatability/ps5-kstuff/uelf/parasite_desc.h): `ps5-kstuff/uelf/parasite_desc.h`

### System Interfaces

- [PS5 Syscall Map](https://github.com/echostretch/kstuff/blob/elfldr-compatability/lib/syscalls-ps5.py): `lib/syscalls-ps5.py`
- [Capstone x86 API](https://github.com/echostretch/kstuff/blob/elfldr-compatability/freebsd-headers/capstone/x86.h): `freebsd-headers/capstone/x86.h`
- [Capstone Platform API](https://github.com/echostretch/kstuff/blob/elfldr-compatability/freebsd-headers/capstone/platform.h): `freebsd-headers/capstone/platform.h`

### Other components

- **Engineer**
- **PS5 Target**

## Connections

- Engineer → Porting Tool: runs (evidence: `ps5-kstuff/porting_tool/main.py`)
- Porting Tool → GDB RPC: uses RPC (evidence: `ps5-kstuff/porting_tool/main.py`)
- Porting Tool → Trace Utilities: uses traces (evidence: `ps5-kstuff/porting_tool/main.py`)
- Porting Tool → SELF Builder: uses builder (evidence: `ps5-kstuff/porting_tool/main.py`)
- Porting Tool → PS5 Target: connects to
- Payload Loader → Kernel Payload: loads payload
- Kernel Payload → R0GDB Core: initializes (evidence: `ps5-kstuff/main.c`)
- Kernel Payload → Firmware Offsets: uses offsets (evidence: `ps5-kstuff/main.c`)
- Kernel Payload → GDB API: uses API (evidence: `ps5-kstuff/main.c`)
- Kernel Payload → uELF Structures: includes types (evidence: `ps5-kstuff/main.c`)
- Kernel Payload → Parasite Descriptors: uses descriptors (evidence: `ps5-kstuff/main.c`)
- uELF Trap Handler → Parasite Handling: includes handler (evidence: `ps5-kstuff/uelf/main.c`)
- uELF Trap Handler → Parasite Descriptors: includes types
- R0GDB Entrypoint → GDB API: uses API (evidence: `prosper0gdb/main.c`)
- R0GDB Entrypoint → R0GDB Core: initializes (evidence: `prosper0gdb/main.c`)
- GDB Stub → GDB API: uses API (evidence: `gdb_stub/main.c`)
- R0GDB Core → Trap State: uses state (evidence: `prosper0gdb/r0gdb.h`)
- Capstone x86 API → Capstone Platform API: includes (evidence: `freebsd-headers/capstone/x86.h`)
