Skip to content

Commit

Permalink
initial attempt to use com.apple.mobile.MCInstall to fetch profiles (#63
Browse files Browse the repository at this point in the history
)

Co-authored-by: jochen <[email protected]>
Co-authored-by: danielpaulus <[email protected]>
  • Loading branch information
3 people authored Apr 11, 2022
1 parent 77a1834 commit 6e7b53a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
69 changes: 69 additions & 0 deletions ios/mcinstall/mcinstall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package mcinstall

import (
"bytes"
"fmt"
"io"

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

type plistArray []interface{}

const serviceName string = "com.apple.mobile.MCInstall"

type Connection struct {
deviceConn ios.DeviceConnectionInterface
plistCodec ios.PlistCodec
}

func New(device ios.DeviceEntry) (*Connection, error) {
deviceConn, err := ios.ConnectToService(device, serviceName)
if err != nil {
return &Connection{}, err
}

var mcInstallConn Connection
mcInstallConn.deviceConn = deviceConn
mcInstallConn.plistCodec = ios.NewPlistCodec()

return &mcInstallConn, nil
}

func (mcInstallConn *Connection) readExchangeResponse(reader io.Reader) error {
responseBytes, err := mcInstallConn.plistCodec.Decode(reader)
fmt.Printf("Go %u %s", responseBytes, err)
if err != nil {
return err
}

response := getArrayFromBytes(responseBytes)
readyMessage, ok := response[0].(string)

fmt.Printf("Go %s - %s", readyMessage, ok)
return nil
}

func getArrayFromBytes(plistBytes []byte) plistArray {
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
var data plistArray
_ = decoder.Decode(&data)
return data
}

func (mcInstallConn *Connection) HandleList() error {
reader := mcInstallConn.deviceConn.Reader()
bytes, err := mcInstallConn.plistCodec.Encode([]interface{}{"RequestType", "GetProfileList"})
if err != nil {
return err
}
mcInstallConn.deviceConn.Send(bytes)
mcInstallConn.readExchangeResponse(reader)
return nil
}

//Close closes the underlying DeviceConnection
func (mcInstallConn *Connection) Close() {
mcInstallConn.deviceConn.Close()
}
24 changes: 23 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/danielpaulus/go-ios/ios/notificationproxy"
"github.com/danielpaulus/go-ios/ios/pcap"
"github.com/danielpaulus/go-ios/ios/screenshotr"
"github.com/danielpaulus/go-ios/ios/mcinstall"
syslog "github.com/danielpaulus/go-ios/ios/syslog"
"github.com/docopt/docopt-go"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -67,6 +68,9 @@ Usage:
ios lang [--setlocale=<locale>] [--setlang=<newlang>] [options]
ios mobilegestalt <key>... [--plist] [options]
ios diagnostics list [options]
ios profiles list
ios profiles remove <profileName>
ios profiles add <profileName>
ios pair [--p12file=<orgid>] [--password=<p12password>] [options]
ios ps [options]
ios ip [options]
Expand Down Expand Up @@ -126,6 +130,9 @@ The commands work as following:
ios pair [--p12file=<orgid>] [--password=<p12password>] [options] Pairs the device. If the device is supervised, specify the path to the p12 file
> to pair without a trust dialog. Specify the password either with the argument or
> by setting the environment variable 'P12_PASSWORD'
ios profiles list List the profiles on the device
ios profiles remove <profileName> Remove the profileName from the device
ios profiles add <profileName> Add the profileName to the device
ios ps [options] Dumps a list of running processes on the device
ios ip [options] Uses the live pcap iOS packet capture to wait until it finds one that contains the IP address of the device.
> It relies on the MAC address of the WiFi adapter to know which is the right IP.
Expand Down Expand Up @@ -196,8 +203,9 @@ The commands work as following:
diagnosticsCommand, _ := arguments.Bool("diagnostics")
imageCommand, _ := arguments.Bool("image")
deviceStateCommand, _ := arguments.Bool("devicestate")
profileCommand, _ := arguments.Bool("profiles")

if listCommand && !diagnosticsCommand && !imageCommand && !deviceStateCommand {
if listCommand && !diagnosticsCommand && !imageCommand && !deviceStateCommand && !profileCommand {
b, _ = arguments.Bool("--details")
printDeviceList(b)
return
Expand Down Expand Up @@ -389,6 +397,14 @@ The commands work as following:
return
}

b, _ = arguments.Bool("profiles")
if b {
if listCommand {
handleProfileList(device)
}
return
}

b, _ = arguments.Bool("forward")
if b {
hostPort, _ := arguments.Int("<hostPort>")
Expand Down Expand Up @@ -736,6 +752,12 @@ func startDebugProxy(device ios.DeviceEntry, binaryMode bool) {
proxy.Close()
}

func handleProfileList(device ios.DeviceEntry) {
profileService, err := mcinstall.New(device)
exitIfError("Starting mcInstall failed with", err)
profileService.HandleList()
}

func startForwarding(device ios.DeviceEntry, hostPort int, targetPort int) {
forward.Forward(device, uint16(hostPort), uint16(targetPort))
c := make(chan os.Signal, 1)
Expand Down

0 comments on commit 6e7b53a

Please sign in to comment.