Null-DRM-Official/apps/pkg/proxy/embed.go
404errordeveloper 1d36961a7c
All checks were successful
release / build-and-upload (push) Successful in 6m38s
Bugs fixed
2026-10-08 20:44:10 +02:00

58 lines
1.4 KiB
Go

package proxy
import (
_ "embed"
"fmt"
"os"
"path/filepath"
"drmdecryption/adb"
"drmdecryption/repo"
)
//go:embed embedded/tproxy_iptables.sh
var embeddedTProxyScript []byte
// ensureTProxyScript pushes the iptables helper to the phone.
// Prefers the source-tree copy; falls back to the copy embedded in drm.exe
// so a portable release zip does not need apps/proxy/device/.
func ensureTProxyScript(c *adb.Client) error {
candidates := []string{
filepath.Join(repo.Root(), "apps", "proxy", "device", "tproxy_iptables.sh"),
}
if exe, err := os.Executable(); err == nil {
dir := filepath.Dir(exe)
candidates = append(candidates,
filepath.Join(dir, "tproxy_iptables.sh"),
filepath.Join(dir, "apps", "proxy", "device", "tproxy_iptables.sh"),
)
}
var local string
for _, p := range candidates {
if st, err := os.Stat(p); err == nil && !st.IsDir() {
local = p
break
}
}
tmp := filepath.Join(os.TempDir(), "tproxy_iptables.sh")
if local != "" {
data, err := os.ReadFile(local)
if err != nil {
return err
}
if err := os.WriteFile(tmp, data, 0o755); err != nil {
return err
}
} else {
if err := os.WriteFile(tmp, embeddedTProxyScript, 0o755); err != nil {
return err
}
fmt.Println("[*] Using embedded tproxy_iptables.sh")
}
defer os.Remove(tmp)
if err := c.Push(tmp, RemoteTProxyScript); err != nil {
return err
}
_, _ = c.Shell("chmod", "755", RemoteTProxyScript)
return nil
}