This commit is contained in:
parent
84ae0f6994
commit
1d36961a7c
16 changed files with 734 additions and 48 deletions
159
apps/pkg/bootstrap/bootstrap.go
Normal file
159
apps/pkg/bootstrap/bootstrap.go
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
// Package bootstrap materialises a GitHub-like install tree next to drm.exe
|
||||
// so a single downloaded binary can create apps/, bin/, outputs/, etc. on first run.
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed all:embedded
|
||||
var embedded embed.FS
|
||||
|
||||
const minProxyBytes = 100_000 // stub ELF is tiny; real proxy-android-arm64 is ~9MB
|
||||
|
||||
// InstallRoot is the directory that should contain apps/, bin/, outputs/.
|
||||
// If drm.exe lives in …/bin/, the parent is the root; otherwise the exe directory.
|
||||
func InstallRoot() (string, error) {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
exe, err = filepath.EvalSymlinks(exe)
|
||||
if err != nil {
|
||||
exe, _ = os.Executable()
|
||||
}
|
||||
dir := filepath.Dir(exe)
|
||||
if strings.EqualFold(filepath.Base(dir), "bin") {
|
||||
return filepath.Dir(dir), nil
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
// Ensure writes any missing layout files from the embedded tree into root.
|
||||
// Existing files are left untouched (user edits to module.yaml are kept).
|
||||
func Ensure(root string) (created []string, err error) {
|
||||
if root == "" {
|
||||
root, err = InstallRoot()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
err = fs.WalkDir(embedded, "embedded", func(path string, d fs.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
// embed.FS paths always use forward slashes — do not use filepath.Rel (Windows).
|
||||
slashRel := strings.TrimPrefix(path, "embedded/")
|
||||
if slashRel == path || slashRel == "embedded" || slashRel == "." {
|
||||
return nil
|
||||
}
|
||||
// go:embed rejects files named go.mod. We ship root-go-mod.txt (and
|
||||
// optionally apps/pkg/pkg.gomod) and materialise apps/pkg/go.mod.
|
||||
outSlash := slashRel
|
||||
switch slashRel {
|
||||
case "root-go-mod.txt", "apps/pkg/pkg.gomod":
|
||||
outSlash = "apps/pkg/go.mod"
|
||||
}
|
||||
dest := filepath.Join(root, filepath.FromSlash(outSlash))
|
||||
if d.IsDir() {
|
||||
return os.MkdirAll(dest, 0o755)
|
||||
}
|
||||
if st, err := os.Stat(dest); err == nil && !st.IsDir() {
|
||||
return nil // keep existing
|
||||
}
|
||||
data, err := embedded.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Do not write the tiny release stub as a real MITM binary.
|
||||
if slashRel == "bin/proxy-android-arm64" && len(data) < minProxyBytes {
|
||||
return nil
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
mode := os.FileMode(0o644)
|
||||
if strings.HasSuffix(outSlash, "proxy-android-arm64") || strings.HasSuffix(outSlash, ".sh") {
|
||||
mode = 0o755
|
||||
}
|
||||
if err := os.WriteFile(dest, data, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
created = append(created, outSlash)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return created, err
|
||||
}
|
||||
|
||||
// If drm is not already under bin/, copy/link a drm.exe there for 1:1 layout.
|
||||
if err := ensureBinDrm(root); err != nil {
|
||||
return created, err
|
||||
}
|
||||
return created, nil
|
||||
}
|
||||
|
||||
func ensureBinDrm(root string) error {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
exe, _ = filepath.EvalSymlinks(exe)
|
||||
dest := filepath.Join(root, "bin", "drm.exe")
|
||||
if sameFile(exe, dest) {
|
||||
return nil
|
||||
}
|
||||
if st, err := os.Stat(dest); err == nil && !st.IsDir() {
|
||||
return nil
|
||||
}
|
||||
data, err := os.ReadFile(exe)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(dest, data, 0o755)
|
||||
}
|
||||
|
||||
func sameFile(a, b string) bool {
|
||||
absA, err1 := filepath.Abs(a)
|
||||
absB, err2 := filepath.Abs(b)
|
||||
if err1 != nil || err2 != nil {
|
||||
return false
|
||||
}
|
||||
return strings.EqualFold(absA, absB)
|
||||
}
|
||||
|
||||
// EnsureAndLog runs Ensure and prints what was created (if anything).
|
||||
func EnsureAndLog() error {
|
||||
root, err := InstallRoot()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
created, err := Ensure(root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(created) > 0 {
|
||||
fmt.Printf("[*] Bootstrapped install layout under %s (%d new files)\n", root, len(created))
|
||||
for _, c := range created {
|
||||
fmt.Printf(" + %s\n", filepath.ToSlash(c))
|
||||
}
|
||||
}
|
||||
proxy := filepath.Join(root, "bin", "proxy-android-arm64")
|
||||
if st, err := os.Stat(proxy); err != nil || st.Size() < minProxyBytes {
|
||||
fmt.Fprintf(os.Stderr, "[!] missing bin/proxy-android-arm64 — place it next to drm or use a release build that embeds it\n")
|
||||
}
|
||||
// Module configs are never shipped inside drm.exe — operator must add them.
|
||||
modBBC := filepath.Join(root, "apps", "modules", "bbc", "module.yaml")
|
||||
if _, err := os.Stat(modBBC); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[!] no apps/modules/*/module.yaml yet — create e.g. apps/modules/bbc/module.yaml (not bundled in the exe)\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
154
apps/pkg/bootstrap/embedded/README.md
Normal file
154
apps/pkg/bootstrap/embedded/README.md
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
# DRM-Decryption
|
||||
|
||||
Capture Widevine live sessions from Android streaming apps and restream them.
|
||||
|
||||
Everything is one Go binary — `drm` — with every app module compiled in. Each
|
||||
streaming app (RTE, TG4, …) is a Go package under `apps/modules/`; its secrets and
|
||||
IDs live in a local, gitignored values file that you fill in yourself.
|
||||
|
||||
- **[docs/](docs/)** — architecture, module authoring, per-provider setup
|
||||
- **[docs/quickstart.md](docs/quickstart.md)** — the longer version of what follows
|
||||
|
||||
---
|
||||
|
||||
## Quick start
|
||||
|
||||
### 1. Prerequisites
|
||||
|
||||
| Need | Why |
|
||||
|---|---|
|
||||
| **Go 1.25+** | builds everything |
|
||||
| **Python 3.10+** | `apps/wvkey/wvkey.py` talks to the Widevine CDM |
|
||||
| **adb** (platform-tools) on `PATH` | only for phone capture |
|
||||
| A `.wvd` Widevine device file | only for fetching keys |
|
||||
|
||||
Phone capture additionally needs a rooted Android device (Magisk) so the MITM CA
|
||||
can be injected into the system trust store. Catalog lookups need no phone.
|
||||
|
||||
### 2. Clone and build
|
||||
|
||||
```bash
|
||||
git clone https://git.nulldrm.com/nulldrm/Null-DRM-Official.git
|
||||
cd Null-DRM-Official
|
||||
|
||||
# Linux / macOS
|
||||
go -C apps/cli build -o ../../bin/drm .
|
||||
|
||||
# Windows
|
||||
go -C apps/cli build -o ../../bin/drm.exe .
|
||||
```
|
||||
|
||||
Check it:
|
||||
|
||||
```bash
|
||||
./bin/drm help
|
||||
./bin/drm modules # which app modules this build contains
|
||||
```
|
||||
|
||||
`drm modules` works immediately, but channel lists stay empty until you add
|
||||
values — that is the next step.
|
||||
|
||||
### 3. Python CDM helper
|
||||
|
||||
```bash
|
||||
python -m venv .venv
|
||||
.venv/bin/pip install -r apps/wvkey/requirements.txt # Windows: .venv\Scripts\pip
|
||||
```
|
||||
|
||||
Put your Widevine device file in `data/` (gitignored), e.g. `data/device.wvd`.
|
||||
|
||||
### 4. Fill in a module's values
|
||||
|
||||
Compiled-in module code carries **no** account IDs, policy keys, video IDs,
|
||||
license URLs or key IDs. Those go in a gitignored file per module, which you create:
|
||||
|
||||
```text
|
||||
apps/modules/tg4/module.yaml
|
||||
apps/modules/rte/module.yaml
|
||||
```
|
||||
|
||||
Where each value comes from:
|
||||
|
||||
- **[docs/providers/tg4.md](docs/providers/tg4.md)** — Brightcove account ID, policy key, video IDs
|
||||
- **[docs/providers/rte.md](docs/providers/rte.md)** — license URL, origin hosts, channel KIDs
|
||||
- **[docs/capture.md](docs/capture.md)** — how to discover all of it for a *new* app
|
||||
|
||||
Any value can be passed per-run instead of stored:
|
||||
|
||||
```bash
|
||||
./bin/drm catalog --app tg4 --channel ioi --tg4.policy-key 'BCpkAD...'
|
||||
TG4_POLICY_KEY='BCpkAD...' ./bin/drm catalog --app tg4 --channel ioi
|
||||
```
|
||||
|
||||
### 5. Run something
|
||||
|
||||
```bash
|
||||
# keys from a public catalog — no phone needed
|
||||
./bin/drm catalog --app tg4 --channel ioi --keys --wvd data/device.wvd
|
||||
|
||||
# phone capture: launch the app, drive it to a channel, grab license + keys
|
||||
./bin/drm proxy build # once: cross-compile the on-device MITM
|
||||
./bin/drm capture --app rte --channel rteone --auto-play --wvd data/device.wvd
|
||||
|
||||
# control plane + dashboard on http://127.0.0.1:8083
|
||||
./bin/drm serve --bind 127.0.0.1:8083 --data .cache/streamd --token SECRET
|
||||
|
||||
# always-on refresher: watches streamd, re-captures dead channels
|
||||
STREAMD_TOKEN=SECRET ./bin/drm agent run --config apps/agent/agent.yaml
|
||||
```
|
||||
|
||||
Results land in `outputs/<app>/<timestamp>/`, with `latest/` kept as a copy.
|
||||
|
||||
---
|
||||
|
||||
## Subcommands
|
||||
|
||||
| Command | What it does |
|
||||
|---|---|
|
||||
| `drm modules` | list compiled-in app modules, their channels and config source |
|
||||
| `drm capture` | one-shot phone MITM capture → `outputs/<app>/<stamp>/` |
|
||||
| `drm catalog` | resolve a channel from its public catalog, no phone |
|
||||
| `drm serve` | streamd: REST API + dashboard + media supervisor |
|
||||
| `drm agent` | `run` / `status` / `devices` / `enqueue` / `cancel` |
|
||||
| `drm proxy` | `build` / `push` / `install-ca` / `start` / `stop` / `discover` / `pull` |
|
||||
|
||||
Run any of them with `--help`.
|
||||
|
||||
## Layout
|
||||
|
||||
```text
|
||||
apps/cli/ the binary -> bin/drm
|
||||
apps/modules/ app modules: Go (tracked) + module.yaml (gitignored)
|
||||
apps/pkg/ shared, provider-neutral libraries
|
||||
apps/capture/ phone capture command
|
||||
apps/agent/ always-on key refresher
|
||||
apps/streamd/ control plane: API, SQLite, dashboard, supervisor
|
||||
apps/proxy/ MITM host CLI + on-device proxy source
|
||||
apps/wvkey/ wvkey.py — CDM only
|
||||
docs/ architecture, authoring, provider setup
|
||||
data/ secrets: .wvd, CA (gitignored)
|
||||
outputs/ capture sessions (gitignored)
|
||||
bin/ built binaries (gitignored)
|
||||
www/ static site
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
go -C apps/pkg test ./...
|
||||
go -C apps/modules test ./...
|
||||
go -C apps/streamd test ./...
|
||||
```
|
||||
|
||||
Tests that hit a live origin are behind a build tag, so they stay out of the
|
||||
normal run:
|
||||
|
||||
```bash
|
||||
go -C apps/modules test -tags live ./rte/ -v
|
||||
```
|
||||
|
||||
## Scope
|
||||
|
||||
For use only on services you are authorised to access, with content you have the
|
||||
right to decrypt. [docs/architecture.md](docs/architecture.md) describes what the
|
||||
system does and where it stops.
|
||||
5
apps/pkg/bootstrap/embedded/apps/pkg/pkg.gomod
Normal file
5
apps/pkg/bootstrap/embedded/apps/pkg/pkg.gomod
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module drmdecryption
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require gopkg.in/yaml.v3 v3.0.1
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
#!/system/bin/sh
|
||||
# Transparent redirect: package UID TCP/443 → local appproxy (no Wi‑Fi http_proxy).
|
||||
# Usage:
|
||||
# tproxy_iptables.sh start <package> [port]
|
||||
# tproxy_iptables.sh stop
|
||||
# tproxy_iptables.sh status
|
||||
|
||||
set -eu
|
||||
CHAIN=APPROXY_TPROXY
|
||||
ACTION="${1:-}"
|
||||
|
||||
uid_for_package() {
|
||||
pkg="$1"
|
||||
# dumpsys package <pkg> | grep userId= OR stat on data dir
|
||||
uid=$(dumpsys package "$pkg" 2>/dev/null | grep -m1 -oE 'userId=[0-9]+' | head -1 | cut -d= -f2 || true)
|
||||
if [ -z "$uid" ]; then
|
||||
uid=$(stat -c %u "/data/user/0/$pkg" 2>/dev/null || true)
|
||||
fi
|
||||
echo "$uid"
|
||||
}
|
||||
|
||||
stop_rules() {
|
||||
iptables -t nat -D OUTPUT -j "$CHAIN" 2>/dev/null || true
|
||||
iptables -t nat -F "$CHAIN" 2>/dev/null || true
|
||||
iptables -t nat -X "$CHAIN" 2>/dev/null || true
|
||||
echo "STOPPED"
|
||||
}
|
||||
|
||||
start_rules() {
|
||||
pkg="$1"
|
||||
port="$2"
|
||||
uid=$(uid_for_package "$pkg")
|
||||
if [ -z "$uid" ] || [ "$uid" = "0" ]; then
|
||||
echo "ERR: cannot resolve uid for package $pkg" >&2
|
||||
exit 1
|
||||
fi
|
||||
proxy_uid=$(stat -c %u /data/local/tmp/appproxy 2>/dev/null || echo "")
|
||||
# Prefer the running process uid if available
|
||||
if pidof appproxy >/dev/null 2>&1; then
|
||||
proxy_uid=$(stat -c %u /proc/$(pidof appproxy | awk '{print $1}') 2>/dev/null || echo "$proxy_uid")
|
||||
fi
|
||||
|
||||
stop_rules >/dev/null
|
||||
iptables -t nat -N "$CHAIN"
|
||||
# Never redirect the mitm itself (loop).
|
||||
if [ -n "$proxy_uid" ]; then
|
||||
iptables -t nat -A "$CHAIN" -m owner --uid-owner "$proxy_uid" -j RETURN
|
||||
fi
|
||||
# Skip localhost / link-local.
|
||||
iptables -t nat -A "$CHAIN" -d 127.0.0.0/8 -j RETURN
|
||||
iptables -t nat -A "$CHAIN" -d 10.0.0.0/8 -j RETURN 2>/dev/null || true
|
||||
# Redirect only the target app's HTTPS.
|
||||
iptables -t nat -A "$CHAIN" -p tcp -m owner --uid-owner "$uid" --dport 443 -j REDIRECT --to-ports "$port"
|
||||
iptables -t nat -A OUTPUT -j "$CHAIN"
|
||||
echo "STARTED pkg=$pkg uid=$uid port=$port proxy_uid=${proxy_uid:-unknown}"
|
||||
}
|
||||
|
||||
status_rules() {
|
||||
echo "=== $CHAIN ==="
|
||||
iptables -t nat -L "$CHAIN" -n -v 2>/dev/null || echo "(no chain)"
|
||||
echo "=== OUTPUT head ==="
|
||||
iptables -t nat -L OUTPUT -n -v 2>/dev/null | head -20
|
||||
}
|
||||
|
||||
case "$ACTION" in
|
||||
start)
|
||||
pkg="${2:?package required}"
|
||||
port="${3:-8080}"
|
||||
start_rules "$pkg" "$port"
|
||||
;;
|
||||
stop)
|
||||
stop_rules
|
||||
;;
|
||||
status)
|
||||
status_rules
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 start <package> [port] | stop | status" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
2
apps/pkg/bootstrap/embedded/configs/.gitkeep
Normal file
2
apps/pkg/bootstrap/embedded/configs/.gitkeep
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Optional local configs
|
||||
|
||||
5
apps/pkg/bootstrap/embedded/root-go-mod.txt
Normal file
5
apps/pkg/bootstrap/embedded/root-go-mod.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module drmdecryption
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require gopkg.in/yaml.v3 v3.0.1
|
||||
Loading…
Add table
Add a link
Reference in a new issue