diff --git a/go.mod b/go.mod index 07a0f507..0491ebc5 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,8 @@ require ( software.sslmate.com/src/go-pkcs12 v0.2.0 ) +require github.com/mitchellh/go-ps v1.0.0 // indirect + require ( github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -38,6 +40,7 @@ require ( github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect github.com/miekg/dns v1.1.57 // indirect github.com/onsi/ginkgo/v2 v2.9.5 // indirect + github.com/pbar1/pkill-go v1.0.0 github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qtls-go1-20 v0.4.1 // indirect github.com/stretchr/objx v0.1.0 // indirect diff --git a/go.sum b/go.sum index 8e56603d..a5155e47 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/elazarl/goproxy v0.0.0-20240726154733-8b0c20506380 h1:1NyRx2f4W4WBRyg0Kys0ZbaNmDDzZ2R/C7DTi+bbsJ0= github.com/elazarl/goproxy v0.0.0-20240726154733-8b0c20506380/go.mod h1:thX175TtLTzLj3p7N/Q9IiKZ7NF+p72cvL91emV0hzo= +github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM= +github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= @@ -48,10 +50,14 @@ github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40/go.mod h1:vy1vK6w github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= +github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= +github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q= github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k= github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg= +github.com/pbar1/pkill-go v1.0.0 h1:C2nl2baBXGOOzKUtlGTYUIwczmuo1d8P9wOPFitO9iU= +github.com/pbar1/pkill-go v1.0.0/go.mod h1:RZI45YE4C2ZWRp1fLojcncfWj0ksmtKQCqLZBL44RaM= github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= diff --git a/go.work.sum b/go.work.sum index dc019e6f..b382473e 100644 --- a/go.work.sum +++ b/go.work.sum @@ -16,6 +16,7 @@ github.com/containerd/ttrpc v1.1.0/go.mod h1:XX4ZTnoOId4HklF4edwc4DcqskFZuvXB1Ev github.com/containerd/typeurl v1.0.2/go.mod h1:9trJWW2sRlGub4wZJRTW83VtbOLS6hwcDZXTn6oPz9s= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM= github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= diff --git a/ios/remoted/remoted_controller.go b/ios/remoted/remoted_controller.go new file mode 100644 index 00000000..574d7ba8 --- /dev/null +++ b/ios/remoted/remoted_controller.go @@ -0,0 +1,13 @@ +package remoted + +// Sends SIGSTOP to remoted process. +// Implemented only on Darwin systems, as remoted service is present only on Darwin systems +func StopRemoted() error { + return stopRemoted() +} + +// Sends SIGCONT to remoted process. +// Implemented only on Darwin systems, as remoted service is present only on Darwin systems +func ContinueRemoted() error { + return continueRemoted() +} diff --git a/ios/remoted/remoted_darwin.go b/ios/remoted/remoted_darwin.go new file mode 100644 index 00000000..7426f009 --- /dev/null +++ b/ios/remoted/remoted_darwin.go @@ -0,0 +1,19 @@ +//go:build darwin + +package remoted + +import ( + "syscall" + + "github.com/pbar1/pkill-go" +) + +func stopRemoted() error { + _, err := pkill.Pkill("remoted", syscall.SIGSTOP) + return err +} + +func continueRemoted() error { + _, err := pkill.Pkill("remoted", syscall.SIGCONT) + return err +} diff --git a/ios/remoted/remoted_default.go b/ios/remoted/remoted_default.go new file mode 100644 index 00000000..f05e266d --- /dev/null +++ b/ios/remoted/remoted_default.go @@ -0,0 +1,13 @@ +//go:build !darwin + +package remoted + +// As remoted is present only on Darwin systems, default implementation is empty + +func stopRemoted() error { + return nil +} + +func continueRemoted() error { + return nil +} diff --git a/ios/tunnel/tunnel.go b/ios/tunnel/tunnel.go index a88b5512..0e21b597 100644 --- a/ios/tunnel/tunnel.go +++ b/ios/tunnel/tunnel.go @@ -22,7 +22,6 @@ import ( "github.com/quic-go/quic-go" "github.com/sirupsen/logrus" - log "github.com/sirupsen/logrus" "github.com/songgao/water" ) @@ -48,7 +47,7 @@ func (t Tunnel) Close() error { // ManualPairAndConnectToTunnel tries to verify an existing pairing, and if this fails it triggers a new manual pairing process. // After a successful pairing a tunnel for this device gets started and the tunnel information is returned func ManualPairAndConnectToTunnel(ctx context.Context, device ios.DeviceEntry, p PairRecordManager) (Tunnel, error) { - log.Info("ManualPairAndConnectToTunnel: starting manual pairing and tunnel connection, dont forget to stop remoted first with 'sudo pkill -SIGSTOP remoted' and run this with sudo.") + logrus.Info("ManualPairAndConnectToTunnel: starting manual pairing and tunnel connection, dont forget to run this with sudo.") addr, err := ios.FindDeviceInterfaceAddress(ctx, device) if err != nil { return Tunnel{}, fmt.Errorf("ManualPairAndConnectToTunnel: failed to find device ethernet interface: %w", err) diff --git a/ios/tunnel/tunnel_api.go b/ios/tunnel/tunnel_api.go index 14690839..453975a9 100644 --- a/ios/tunnel/tunnel_api.go +++ b/ios/tunnel/tunnel_api.go @@ -16,6 +16,7 @@ import ( "github.com/Masterminds/semver" "github.com/danielpaulus/go-ios/ios" + "github.com/danielpaulus/go-ios/ios/remoted" log "github.com/sirupsen/logrus" "golang.org/x/exp/maps" "golang.org/x/exp/slices" @@ -371,7 +372,12 @@ type manualPairingTunnelStart struct { } func (m manualPairingTunnelStart) StartTunnel(ctx context.Context, device ios.DeviceEntry, p PairRecordManager, version *semver.Version, userspaceTUN bool) (Tunnel, error) { - + if version.Major() >= 17 { + err := remoted.StopRemoted() + if err != nil { + return Tunnel{}, fmt.Errorf("manualPairingTunnelStart: failed to stop remoted: %w", err) + } + } if version.GreaterThan(semver.MustParse("17.4.0")) { if userspaceTUN { tun, err := ConnectUserSpaceTunnelLockdown(device, device.UserspaceTUNPort) diff --git a/main.go b/main.go index fdb0955d..9fada31b 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( "github.com/danielpaulus/go-ios/ios/debugproxy" "github.com/danielpaulus/go-ios/ios/deviceinfo" + "github.com/danielpaulus/go-ios/ios/remoted" "github.com/danielpaulus/go-ios/ios/tunnel" "github.com/danielpaulus/go-ios/ios/amfi" @@ -2114,6 +2115,13 @@ func startTunnel(ctx context.Context, recordsPath string, tunnelInfoPort int, us }() log.Info("Tunnel server started") <-ctx.Done() + + err = remoted.ContinueRemoted() + if err != nil { + log.Errorf("failed to resume remoted: %v", err) + } else { + log.Info("resumed remoted") + } } func deviceWithRsdProvider(device ios.DeviceEntry, udid string, address string, rsdPort int) ios.DeviceEntry {