Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fsync: support app container jails #280

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions ios/afc/fsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package afc
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"os"
Expand All @@ -13,6 +14,7 @@ import (

"github.com/danielpaulus/go-ios/ios"
log "github.com/sirupsen/logrus"
"howett.net/plist"
)

const serviceName = "com.apple.afc"
Expand Down Expand Up @@ -48,6 +50,67 @@ func New(device ios.DeviceEntry) (*Connection, error) {
return &Connection{deviceConn: deviceConn}, nil
}

func NewContainer(device ios.DeviceEntry, bundleID string) (*Connection, error) {
deviceConn, err := ios.ConnectToService(device, "com.apple.mobile.house_arrest")
if err != nil {
return nil, err
}
err = vendContainer(deviceConn, bundleID)
if err != nil {
return nil, err
}
return &Connection{deviceConn: deviceConn}, nil
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⬇️ all this is simply copied from house_arrest.go

func vendContainer(deviceConn ios.DeviceConnectionInterface, bundleID string) error {
plistCodec := ios.NewPlistCodec()
vendContainer := map[string]interface{}{"Command": "VendContainer", "Identifier": bundleID}
msg, err := plistCodec.Encode(vendContainer)
if err != nil {
return fmt.Errorf("VendContainer Encoding cannot fail unless the encoder is broken: %v", err)
}
err = deviceConn.Send(msg)
if err != nil {
return err
}
reader := deviceConn.Reader()
response, err := plistCodec.Decode(reader)
if err != nil {
return err
}
return checkResponse(response)
}

func checkResponse(vendContainerResponseBytes []byte) error {
response, err := plistFromBytes(vendContainerResponseBytes)
if err != nil {
return err
}
if "Complete" == response.Status {
return nil
}
if response.Error != "" {
return errors.New(response.Error)
}
return errors.New("unknown error during vendcontainer")
}

func plistFromBytes(plistBytes []byte) (vendContainerResponse, error) {
var vendResponse vendContainerResponse
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))

err := decoder.Decode(&vendResponse)
if err != nil {
return vendResponse, err
}
return vendResponse, nil
}

type vendContainerResponse struct {
Status string
Error string
}

// NewFromConn allows to use AFC on a DeviceConnectionInterface, see crashreport for an example
func NewFromConn(deviceConn ios.DeviceConnectionInterface) *Connection {
return &Connection{deviceConn: deviceConn}
Expand Down
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ Usage:
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]... [options]
ios ax [options]
ios debug [options] [--stop-at-entry] <app_path>
ios fsync (rm [--r] | tree | mkdir) --path=<targetPath>
ios fsync (pull | push) --srcPath=<srcPath> --dstPath=<dstPath>
ios fsync [--app=bundleId] [options] (rm [--r] | tree | mkdir) --path=<targetPath>
ios fsync [--app=bundleId] [options] (pull | push) --srcPath=<srcPath> --dstPath=<dstPath>
ios reboot [options]
ios -h | --help
ios --version | version [options]
Expand Down Expand Up @@ -206,8 +206,8 @@ The commands work as following:
> specify runtime args and env vars like --env ENV_1=something --env ENV_2=else and --arg ARG1 --arg ARG2
ios ax [options] Access accessibility inspector features.
ios debug [--stop-at-entry] <app_path> Start debug with lldb
ios fsync (rm [--r] | tree | mkdir) --path=<targetPath> Remove | treeview | mkdir in target path. --r used alongside rm will recursively remove all files and directories from target path.
ios fsync (pull | push) --srcPath=<srcPath> --dstPath=<dstPath> Pull or Push file from srcPath to dstPath.
ios fsync [--app=bundleId] [options] (rm [--r] | tree | mkdir) --path=<targetPath> Remove | treeview | mkdir in target path. --r used alongside rm will recursively remove all files and directories from target path.
ios fsync [--app=bundleId] [options] (pull | push) --srcPath=<srcPath> --dstPath=<dstPath> Pull or Push file from srcPath to dstPath.
ios reboot [options] Reboot the given device
ios -h | --help Prints this screen.
ios --version | version [options] Prints the version
Expand Down Expand Up @@ -825,7 +825,13 @@ The commands work as following:

b, _ = arguments.Bool("fsync")
if b {
afcService, err := afc.New(device)
containerBundleId, _ := arguments.String("--app")
var afcService *afc.Connection
if containerBundleId == "" {
afcService, err = afc.New(device)
} else {
afcService, err = afc.NewContainer(device, containerBundleId)
}
exitIfError("fsync: connect afc service failed", err)
b, _ = arguments.Bool("rm")
if b {
Expand Down