Skip to content

Commit

Permalink
fix: make remoted management OS specific
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-przytarski committed Sep 20, 2024
1 parent 317ae7c commit 0dc2543
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 18 deletions.
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
13 changes: 13 additions & 0 deletions ios/remoted/remoted_controller.go
Original file line number Diff line number Diff line change
@@ -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()
}
19 changes: 19 additions & 0 deletions ios/remoted/remoted_darwin.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions ios/remoted/remoted_default.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 6 additions & 9 deletions ios/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import (
"math/big"
"os/exec"
"runtime"
"syscall"
"time"

"github.com/danielpaulus/go-ios/ios"
"github.com/danielpaulus/go-ios/ios/http"
"github.com/pbar1/pkill-go"
"github.com/danielpaulus/go-ios/ios/remoted"

"github.com/quic-go/quic-go"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -50,13 +49,11 @@ func (t Tunnel) Close() error {
// 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) {
logrus.Info("ManualPairAndConnectToTunnel: starting manual pairing and tunnel connection, dont forget run this with sudo.")
if runtime.GOOS == "darwin" {
_, err := pkill.Pkill("remoted", syscall.SIGSTOP)
if err != nil {
return Tunnel{}, fmt.Errorf("ManualPairAndConnectToTunnel: failed to stop remoted: %w", err)
} else {
logrus.Info("ManualPairAndConnectToTunnel: stopped remoted")
}
err := remoted.StopRemoted()
if err != nil {
return Tunnel{}, fmt.Errorf("ManualPairAndConnectToTunnel: failed to stop remoted: %w", err)
} else {
logrus.Info("ManualPairAndConnectToTunnel: stopped remoted")
}
addr, err := ios.FindDeviceInterfaceAddress(ctx, device)
if err != nil {
Expand Down
15 changes: 6 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os/signal"
"path"
"path/filepath"
"runtime"
"runtime/debug"
"sort"
"strconv"
Expand All @@ -21,8 +20,8 @@ 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/pbar1/pkill-go"

"github.com/danielpaulus/go-ios/ios/amfi"
"github.com/danielpaulus/go-ios/ios/mobileactivation"
Expand Down Expand Up @@ -2117,13 +2116,11 @@ func startTunnel(ctx context.Context, recordsPath string, tunnelInfoPort int, us
log.Info("Tunnel server started")
<-ctx.Done()

if runtime.GOOS == "darwin" {
_, err := pkill.Pkill("remoted", syscall.SIGCONT)
if err != nil {
log.Errorf("failed to resume remoted: %v", err)
} else {
log.Info("resumed remoted")
}
err = remoted.ContinueRemoted()
if err != nil {
log.Errorf("failed to resume remoted: %v", err)
} else {
log.Info("resumed remoted")
}
}

Expand Down

0 comments on commit 0dc2543

Please sign in to comment.