# ru0qian/cpwn architecture

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

- Interactive diagram: https://gitdiagram.com/ru0qian/cpwn
- Repository: https://github.com/ru0qian/cpwn

## Overview

cpwn is a command-line ELF patching tool for selecting a glibc version and setting an executable’s interpreter and rpath. The main workflow identifies the ELF architecture, uses a matching local glibc or prompts for a catalog match and invokes a configured download script, then runs patchelf/ldd and repairs debug symbols. README capabilities include i386/amd64 support and old-version fallback. The implementation is concentrated in main.go; download scripts and glibc files are supplied externally, so their internal behavior is not shown.

Main entry points: [`main.go`](https://github.com/ru0qian/cpwn/blob/master/main.go) (CLI workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and config"]
  node_cli["CLI workflow<br/>[main.go]"]
  node_config["Base path config"]
end

subgraph group_selection["glibc selection"]
  node_architecture["ELF architecture<br/>[main.go]"]
  node_catalog["Version catalogs"]
  node_selector["Version selection<br/>[main.go]"]
  node_download["Download scripts"]
  node_glibc["glibc files"]
end

subgraph group_patching["ELF patching"]
  node_patcher["Patch and verify<br/>[main.go]"]
  node_symbols["Debug symbol repair<br/>[main.go]"]
end

node_user(("User"))
node_patchelf["patchelf"]
node_ldd["ldd"]

node_user -->|"invokes"| node_cli
node_cli -->|"reads or writes"| node_config
node_cli -->|"identifies"| node_architecture
node_cli -->|"selects version"| node_selector
node_cli -->|"looks up"| node_glibc
node_selector -->|"reads"| node_catalog
node_selector -->|"runs selected"| node_download
node_download -.->|"provides files"| node_glibc
node_cli -->|"requests patch"| node_patcher
node_patcher -->|"sets interpreter and rpath"| node_patchelf
node_patcher -->|"verifies dependencies"| node_ldd
node_cli -->|"repairs symbols"| node_symbols
node_symbols -->|"reads debug files"| node_glibc

click node_cli "https://github.com/ru0qian/cpwn/blob/master/main.go"
click node_architecture "https://github.com/ru0qian/cpwn/blob/master/main.go"
click node_selector "https://github.com/ru0qian/cpwn/blob/master/main.go"
click node_patcher "https://github.com/ru0qian/cpwn/blob/master/main.go"
click node_symbols "https://github.com/ru0qian/cpwn/blob/master/main.go"

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_cli,node_config,node_user toneBlue
class node_architecture,node_catalog,node_selector,node_download,node_glibc toneAmber
class node_patcher,node_symbols toneMint
class node_patchelf,node_ldd toneIndigo
```

## Components

### CLI and config

- [CLI workflow](https://github.com/ru0qian/cpwn/blob/master/main.go): `main.go`
- **Base path config**

### glibc selection

- [ELF architecture](https://github.com/ru0qian/cpwn/blob/master/main.go): `main.go`
- **Version catalogs**
- [Version selection](https://github.com/ru0qian/cpwn/blob/master/main.go): `main.go`
- **Download scripts**
- **glibc files**

### ELF patching

- [Patch and verify](https://github.com/ru0qian/cpwn/blob/master/main.go): `main.go`
- [Debug symbol repair](https://github.com/ru0qian/cpwn/blob/master/main.go): `main.go`

### Other components

- **User**
- **patchelf**
- **ldd**

## Connections

- User → CLI workflow: invokes
- CLI workflow → Base path config: reads or writes
- CLI workflow → ELF architecture: identifies
- CLI workflow → Version selection: selects version
- CLI workflow → glibc files: looks up
- Version selection → Version catalogs: reads
- Version selection → Download scripts: runs selected
- Download scripts → glibc files: provides files
- CLI workflow → Patch and verify: requests patch
- Patch and verify → patchelf: sets interpreter and rpath
- Patch and verify → ldd: verifies dependencies
- CLI workflow → Debug symbol repair: repairs symbols
- Debug symbol repair → glibc files: reads debug files
