Null-DRM-Official/apps/capture/capturecmd/capturecmd.go
404errordeveloper f9c28be3f1
All checks were successful
release / build-and-upload (push) Successful in 6m8s
modules-release / build-and-upload (push) Successful in 4m47s
v0.1.1: external modules, publish YAML, proxy reset, binary-first README
- Host discovers/builds modules under modules/ (bbc, rte, tg4)
- module-publish.yaml tracked; local module.yaml gitignored
- drm --modules-dir / DRM_MODULES_DIR
- drm proxy reset; Magisk reinject reliability
- modules-v* Forgejo release workflow + build scripts
- BBC full Explore channel map including S4C
- README quickstart based on release binaries
2026-10-08 23:16:14 +02:00

144 lines
4.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package capturecmd is the one-shot phone MITM capture command, exposed as a
// library so the single drm binary can host it as a subcommand.
package capturecmd
import (
"flag"
"fmt"
"strings"
"time"
"unicode"
"drmdecryption/adb"
"drmdecryption/app"
"drmdecryption/modcfg"
"drmdecryption/modhost"
"drmdecryption/phonecap"
"drmdecryption/repo"
)
// Run performs one capture. Providers live under modules/<name>/ and are built
// and executed by modhost — they are not linked into drm.exe.
func Run(args []string) error {
args = normalizeArgs(args)
root := repo.Root()
available, _ := modhost.Names(root)
appChoices := strings.Join(available, "|")
if appChoices == "" {
appChoices = "NAME"
}
fs := flag.NewFlagSet("capture", flag.ContinueOnError)
appName := fs.String("app", "", "app module under modules/<name>/. Empty = passive MITM, no launch/auto-play")
channel := fs.String("channel", "", "channel id for --auto-play")
autoPlay := fs.Bool("auto-play", false, "auto-navigate to --channel (implied when --channel is set)")
waitSec := fs.Int("wait", 180, "seconds to wait for license/mpd capture")
python := fs.String("python", "", "python for wvkey.py (default: .venv)")
wvd := fs.String("wvd", "", "path to .wvd device file (required for key fetch)")
userAgent := fs.String("user-agent", "", "optional User-Agent for license requests")
serial := fs.String("serial", "", "adb device serial (default: sole/USB selected device)")
closeApp := fs.Bool("close", true, "force-stop --app when capture finishes (ignored in passive mode)")
keyMode := fs.String("key-mode", "", "override the app's key mode: modulardrm | raw | none")
fs.Usage = func() {
fmt.Fprintf(fs.Output(), "capture — one-shot phone MITM capture\n\nUsage:\n capture --app <%s> [--channel ID] [--auto-play] [--wvd PATH]\n capture (passive: play anything on the phone)\n\nExample (BBC + NordVPN UK):\n capture --app bbc --channel bbcone --wait 120\n\nFlags:\n", appChoices)
fs.PrintDefaults()
}
if err := fs.Parse(args); err != nil {
return err
}
if rest := fs.Args(); len(rest) > 0 {
return fmt.Errorf("unexpected arguments %v — use flags only (example: capture --app bbc --channel bbcone)", rest)
}
c := adb.New()
if *serial != "" {
c = c.WithSerial(*serial)
}
// No --app: passive MITM — the operator plays whatever they want and we dump
// whatever DRM traffic appears.
if strings.TrimSpace(*appName) == "" {
_, err := phonecap.RunPassive(phonecap.Options{
Client: c,
Python: *python,
WVD: *wvd,
UserAgent: *userAgent,
Wait: time.Duration(*waitSec) * time.Second,
KeyMode: *keyMode,
ClearProxy: true,
})
return err
}
a, err := modhost.Open(root, *appName)
if err != nil {
return modhost.FormatUnknown(root, *appName)
}
channelID := strings.TrimSpace(*channel)
// --channel implies interactive auto-play (Explore → channel → Watch live).
doAutoPlay := *autoPlay || channelID != ""
if *autoPlay && channelID == "" {
return fmt.Errorf("--auto-play requires --channel (%s)", knownChannels(a))
}
if channelID != "" && !a.HasChannel(channelID) {
return fmt.Errorf("unknown channel %q for %s (%s)", channelID, a.Name(), knownChannels(a))
}
_, err = phonecap.Run(phonecap.Options{
App: a,
Channel: channelID,
Client: c,
Python: *python,
WVD: *wvd,
UserAgent: *userAgent,
Wait: time.Duration(*waitSec) * time.Second,
NoAutoPlay: !doAutoPlay,
CloseApp: *closeApp,
KeyMode: *keyMode,
ClearProxy: true,
})
return err
}
// normalizeArgs rewrites Unicode dashes Word/Terminal often insert (— – −)
// into ASCII - so `--app` is not silently dropped as a positional token.
func normalizeArgs(args []string) []string {
out := make([]string, len(args))
for i, a := range args {
var b strings.Builder
b.Grow(len(a) + 4)
for _, r := range a {
switch r {
case '\u2014', '\u2013', '\u2212': // em, en, minus
// "—app" → "--app"; standalone dash stays single "-"
if b.Len() == 0 {
b.WriteString("--")
} else {
b.WriteByte('-')
}
default:
if unicode.Is(unicode.Cf, r) {
continue // strip zero-width / format chars
}
b.WriteRune(r)
}
}
out[i] = b.String()
}
return out
}
// knownChannels describes what the operator can pick, or where to declare it when
// the module has no local values file yet.
func knownChannels(a app.App) string {
ids := []string{}
for _, ch := range a.Channels() {
ids = append(ids, ch.ID)
}
if len(ids) == 0 {
return "no channels configured — add " + modcfg.Path(a.Name())
}
return "known: " + strings.Join(ids, ", ")
}