# caremeos-dev/kernelpatch architecture

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

- Interactive diagram: https://gitdiagram.com/caremeos-dev/kernelpatch
- Repository: https://github.com/caremeos-dev/kernelpatch

## Overview

KernelPatch modifies Linux kernels from stripped images, either by producing static image patches or by loading an LKM for runtime changes. The runtime path initializes symbol and memory support, installs hooks and a syscall supercall channel, then exposes KPM loading and Android SU features. The README also documents symbol discovery and inline/syscall hooks. Relationships for unsampled subsystems are included only where documented; dashed links mark workflows implied by the product description rather than verified in the excerpts.

Main entry points: [`lkm/core/init.c`](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/core/init.c) (LKM initialization), [`tools/patch.c`](https://github.com/caremeos-dev/kernelpatch/blob/main/tools/patch.c) (Static image patch), [`lkm/supercall/dispatch.c`](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/supercall/dispatch.c) (Supercall dispatch), [`kernel/base/hook.c`](https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/base/hook.c) (Hook relocation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_analysis["Image analysis"]
  node_symbol_scan["Symbol discovery<br/>[kallsym.c]"]
  node_image_map["Image mapping<br/>[map.c]"]
end

subgraph group_static["Static patching"]
  node_image_patch["Static image patch<br/>[patch.c]"]
  node_arm_hook["Hook relocation<br/>[hook.c]"]
  node_setup_config["Kernel setup<br/>[setup.h]"]
  node_preset_config["Kernel presets<br/>[preset.h]"]
  node_compression["LZ4 compression<br/>[lz4.c]"]
end

subgraph group_runtime["Runtime kernel"]
  node_lkm_entry["LKM initialization<br/>[init.c]"]
  node_symbol_resolver["Symbol resolver<br/>[symbol_resolver.h]"]
  node_patch_memory["Patch memory<br/>[patch_memory.h]"]
  node_hook_runtime["Hook runtime<br/>[hook_runtime.c]"]
  node_hook_engine["Hook engine<br/>[hook_engine.c]"]
  node_syscall_table["Syscall table<br/>[syscall_table.h]"]
end

subgraph group_features["Kernel features"]
  node_kpm_loader["KPM loader<br/>[module.c]"]
  node_manager_scan["Trusted manager scan<br/>[manager.c]"]
  node_key_storage[("Kernel key storage<br/>[kstorage.c]")]
  node_su_access["Android SU access<br/>[su.c]"]
end

subgraph group_interfaces["User interface"]
  node_supercall["Supercall dispatch<br/>[dispatch.c]"]
  node_user_cli["Userspace CLI<br/>[main.c]"]
end

node_operator(("Operator"))
node_kernel_image["Stripped kernel image"]
node_kernel["Linux kernel"]

node_operator -.->|"provides"| node_kernel_image
node_kernel_image -.->|"scans symbols"| node_symbol_scan
node_symbol_scan -.->|"informs mapping"| node_image_map
node_image_map -.->|"maps image"| node_image_patch
node_image_patch -.->|"patches image"| node_kernel_image
node_image_patch -.->|"uses relocations"| node_arm_hook
node_image_patch -.->|"configures"| node_setup_config
node_setup_config -->|"uses presets"| node_preset_config
node_image_patch -.->|"compresses data"| node_compression
node_operator -.->|"loads module"| node_lkm_entry
node_lkm_entry -->|"initializes"| node_symbol_resolver
node_lkm_entry -->|"initializes"| node_syscall_table
node_lkm_entry -->|"initializes"| node_patch_memory
node_lkm_entry -->|"initializes"| node_hook_runtime
node_hook_runtime -.->|"uses engine"| node_hook_engine
node_hook_engine -->|"reuses code"| node_arm_hook
node_lkm_entry -->|"initializes"| node_kpm_loader
node_lkm_entry -->|"installs channel"| node_supercall
node_lkm_entry -->|"initializes"| node_manager_scan
node_lkm_entry -->|"initializes"| node_key_storage
node_lkm_entry -->|"initializes hooks"| node_su_access
node_user_cli -.->|"sends commands"| node_supercall
node_supercall -.->|"dispatches KPM"| node_kpm_loader
node_supercall -.->|"dispatches storage"| node_key_storage
node_supercall -.->|"dispatches SU"| node_su_access
node_manager_scan -->|"reads app metadata"| node_kernel
node_lkm_entry -->|"runs in"| node_kernel
node_arm_hook -.->|"hooks functions"| node_kernel
node_syscall_table -.->|"hooks syscalls"| node_kernel

click node_symbol_scan "https://github.com/caremeos-dev/kernelpatch/blob/main/tools/kallsym.c"
click node_image_map "https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/arm/map.c"
click node_image_patch "https://github.com/caremeos-dev/kernelpatch/blob/main/tools/patch.c"
click node_arm_hook "https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/base/hook.c"
click node_setup_config "https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/base/setup.h"
click node_preset_config "https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/include/preset.h"
click node_compression "https://github.com/caremeos-dev/kernelpatch/blob/main/tools/lib/lz4/lz4.c"
click node_lkm_entry "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/core/init.c"
click node_symbol_resolver "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/infra/symbol_resolver.h"
click node_patch_memory "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/infra/patch_memory.h"
click node_hook_runtime "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/hook/hook_runtime.c"
click node_hook_engine "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/hook/hook_engine.c"
click node_syscall_table "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/infra/syscall_table.h"
click node_supercall "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/supercall/dispatch.c"
click node_kpm_loader "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/kpm/module.c"
click node_manager_scan "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/manager/manager.c"
click node_key_storage "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/supercall/kstorage.c"
click node_su_access "https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/supercall/su.c"
click node_user_cli "https://github.com/caremeos-dev/kernelpatch/blob/main/user_deprecated/main.c"

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_symbol_scan,node_image_map toneBlue
class node_image_patch,node_arm_hook,node_setup_config,node_preset_config,node_compression toneAmber
class node_lkm_entry,node_symbol_resolver,node_patch_memory,node_hook_runtime,node_hook_engine,node_syscall_table toneMint
class node_kpm_loader,node_manager_scan,node_key_storage,node_su_access toneRose
class node_supercall,node_user_cli,node_operator,node_kernel_image,node_kernel toneIndigo
```

## Components

### Image analysis

- [Symbol discovery](https://github.com/caremeos-dev/kernelpatch/blob/main/tools/kallsym.c): `tools/kallsym.c`
- [Image mapping](https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/arm/map.c): `kernel/arm/map.c`

### Static patching

- [Static image patch](https://github.com/caremeos-dev/kernelpatch/blob/main/tools/patch.c): `tools/patch.c`
- [Hook relocation](https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/base/hook.c): `kernel/base/hook.c`
- [Kernel setup](https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/base/setup.h): `kernel/base/setup.h`
- [Kernel presets](https://github.com/caremeos-dev/kernelpatch/blob/main/kernel/include/preset.h): `kernel/include/preset.h`
- [LZ4 compression](https://github.com/caremeos-dev/kernelpatch/blob/main/tools/lib/lz4/lz4.c): `tools/lib/lz4/lz4.c`

### Runtime kernel

- [LKM initialization](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/core/init.c): `lkm/core/init.c`
- [Symbol resolver](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/infra/symbol_resolver.h): `lkm/infra/symbol_resolver.h`
- [Patch memory](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/infra/patch_memory.h): `lkm/infra/patch_memory.h`
- [Hook runtime](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/hook/hook_runtime.c): `lkm/hook/hook_runtime.c`
- [Hook engine](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/hook/hook_engine.c): `lkm/hook/hook_engine.c`
- [Syscall table](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/infra/syscall_table.h): `lkm/infra/syscall_table.h`

### Kernel features

- [KPM loader](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/kpm/module.c): `lkm/kpm/module.c`
- [Trusted manager scan](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/manager/manager.c): `lkm/manager/manager.c`
- [Kernel key storage](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/supercall/kstorage.c): `lkm/supercall/kstorage.c`
- [Android SU access](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/supercall/su.c): `lkm/supercall/su.c`

### User interface

- [Supercall dispatch](https://github.com/caremeos-dev/kernelpatch/blob/main/lkm/supercall/dispatch.c): `lkm/supercall/dispatch.c`
- [Userspace CLI](https://github.com/caremeos-dev/kernelpatch/blob/main/user_deprecated/main.c): `user_deprecated/main.c`

### Other components

- **Operator**
- **Stripped kernel image**
- **Linux kernel**

## Connections

- Operator → Stripped kernel image: provides (evidence: `README.md`)
- Stripped kernel image → Symbol discovery: scans symbols (evidence: `README.md`)
- Symbol discovery → Image mapping: informs mapping
- Image mapping → Static image patch: maps image
- Static image patch → Stripped kernel image: patches image (evidence: `README.md`)
- Static image patch → Hook relocation: uses relocations
- Static image patch → Kernel setup: configures
- Kernel setup → Kernel presets: uses presets (evidence: `kernel/base/setup.h`)
- Static image patch → LZ4 compression: compresses data
- Operator → LKM initialization: loads module (evidence: `README.md`)
- LKM initialization → Symbol resolver: initializes (evidence: `lkm/core/init.c`)
- LKM initialization → Syscall table: initializes (evidence: `lkm/core/init.c`)
- LKM initialization → Patch memory: initializes (evidence: `lkm/core/init.c`)
- LKM initialization → Hook runtime: initializes (evidence: `lkm/core/init.c`)
- Hook runtime → Hook engine: uses engine
- Hook engine → Hook relocation: reuses code (evidence: `lkm/hook/hook_engine.c`)
- LKM initialization → KPM loader: initializes (evidence: `lkm/core/init.c`)
- LKM initialization → Supercall dispatch: installs channel (evidence: `lkm/core/init.c`)
- LKM initialization → Trusted manager scan: initializes (evidence: `lkm/core/init.c`)
- LKM initialization → Kernel key storage: initializes (evidence: `lkm/core/init.c`)
- LKM initialization → Android SU access: initializes hooks (evidence: `lkm/core/init.c`)
- Userspace CLI → Supercall dispatch: sends commands (evidence: `README.md`)
- Supercall dispatch → KPM loader: dispatches KPM
- Supercall dispatch → Kernel key storage: dispatches storage
- Supercall dispatch → Android SU access: dispatches SU
- Trusted manager scan → Linux kernel: reads app metadata (evidence: `lkm/manager/manager.c`)
- LKM initialization → Linux kernel: runs in (evidence: `lkm/core/init.c`)
- Hook relocation → Linux kernel: hooks functions (evidence: `README.md`)
- Syscall table → Linux kernel: hooks syscalls (evidence: `README.md`)
