ios

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2021 License: AGPL-3.0 Imports: 13 Imported by: 9

Documentation

Index

Constants

View Source
const DefaultUsbmuxdSocket = "/var/run/usbmuxd"

DefaultUsbmuxdSocket this is the unix domain socket address to connect to.

View Source
const Lockdownport uint16 = 32498

Lockdownport is the port of the always running lockdownd on the iOS device.

Variables

This section is empty.

Functions

func GetValuesPlist added in v1.0.4

func GetValuesPlist(device DeviceEntry) (map[string]interface{}, error)

GetValuesPlist returns the full lockdown values response as a map, so it can be converted to JSON easily.

func Ntohs

func Ntohs(port uint16) uint16

Ntohs is a re-implementation of the C function Ntohs. it means networkorder to host oder and basically swaps the endianness of the given int. It returns port converted to little endian.

func ParsePlist

func ParsePlist(data []byte) (map[string]interface{}, error)

ParsePlist tries to parse the given bytes, which should be a Plist, into a map[string]interface. It returns the map or an error if the decoding step fails.

func SetLanguage

func SetLanguage(device DeviceEntry, config LanguageConfiguration) error

SetLanguage creates a new lockdown session for the device and sets a new language and locale. Changes will only be made when the value is not an empty string. To change only the locale, set language to "" and vice versa. If both are empty, nothing is changed. NOTE: Changing a language is an async operation that takes a long time. Springboard will be restarted automatically by the device. If you need to wait for this happen use notificationproxy.WaitUntilSpringboardStarted().

func ToPlist

func ToPlist(data interface{}) string

ToPlist converts a given struct to a Plist using the github.com/DHowett/go-plist library. Make sure your struct is exported. It returns a string containing the plist.

func ToPlistBytes

func ToPlistBytes(data interface{}) []byte

ToPlistBytes converts a given struct to a Plist using the github.com/DHowett/go-plist library. Make sure your struct is exported. It returns a byte slice containing the plist.

Types

type AllValuesType

type AllValuesType struct {
	ActivationState                             string
	ActivationStateAcknowledged                 bool
	BasebandActivationTicketVersion             string
	BasebandCertID                              int `plist:"BasebandCertId"`
	BasebandChipID                              int
	BasebandKeyHashInformation                  BasebandKeyHashInformationType
	BasebandMasterKeyHash                       string
	BasebandRegionSKU                           []byte
	BasebandSerialNumber                        []byte
	BasebandStatus                              string
	BasebandVersion                             string
	BluetoothAddress                            string
	BoardID                                     int `plist:"BoardId"`
	BrickState                                  bool
	BuildVersion                                string
	CPUArchitecture                             string
	CarrierBundleInfoArray                      []interface{}
	CertID                                      int
	ChipID                                      int
	ChipSerialNo                                []byte
	DeviceClass                                 string
	DeviceColor                                 string
	DeviceName                                  string
	DieID                                       int
	EthernetAddress                             string
	FirmwareVersion                             string
	FusingStatus                                int
	HardwareModel                               string
	HardwarePlatform                            string
	HasSiDP                                     bool
	HostAttached                                bool
	InternationalMobileEquipmentIdentity        string
	MLBSerialNumber                             string
	MobileEquipmentIdentifier                   string
	MobileSubscriberCountryCode                 string
	MobileSubscriberNetworkCode                 string
	ModelNumber                                 string
	NonVolatileRAM                              NonVolatileRAMType
	PartitionType                               string
	PasswordProtected                           bool
	PkHash                                      []byte
	ProductName                                 string
	ProductType                                 string
	ProductVersion                              string
	ProductionSOC                               bool
	ProtocolVersion                             string
	ProximitySensorCalibration                  []byte
	RegionInfo                                  string
	SBLockdownEverRegisteredKey                 bool
	SIMStatus                                   string
	SIMTrayStatus                               string
	SerialNumber                                string
	SoftwareBehavior                            []byte
	SoftwareBundleVersion                       string
	SupportedDeviceFamilies                     []int
	TelephonyCapability                         bool
	TimeIntervalSince1970                       float64
	TimeZone                                    string
	TimeZoneOffsetFromUTC                       int
	TrustedHostAttached                         bool
	UniqueChipID                                uint64
	UniqueDeviceID                              string
	UseRaptorCerts                              bool
	Uses24HourClock                             bool
	WiFiAddress                                 string
	WirelessBoardSerialNumber                   string
	KCTPostponementInfoPRIVersion               string `plist:"kCTPostponementInfoPRIVersion"`
	KCTPostponementInfoPRLName                  int    `plist:"kCTPostponementInfoPRLName"`
	KCTPostponementInfoServiceProvisioningState bool   `plist:"kCTPostponementInfoServiceProvisioningState"`
	KCTPostponementStatus                       string `plist:"kCTPostponementStatus"`
}

AllValuesType contains all possible values that can be requested from LockDown

type AttachedMessage

type AttachedMessage struct {
	MessageType string
	DeviceID    int
	Properties  DeviceProperties
}

AttachedMessage contains some info about when iOS devices are connected or disconnected from the host

func (AttachedMessage) DeviceAttached

func (msg AttachedMessage) DeviceAttached() bool

DeviceAttached checks if the attached message is about a newly added device

func (AttachedMessage) DeviceDetached

func (msg AttachedMessage) DeviceDetached() bool

DeviceDetached checks if the attachedMessage is about a disconnected device

type BasebandKeyHashInformationType

type BasebandKeyHashInformationType struct {
	AKeyStatus int
	SKeyHash   []byte
	SKeyStatus int
}

BasebandKeyHashInformationType containing some baseband related data directly from the ios device

type DeviceConnection

type DeviceConnection struct {
	// contains filtered or unexported fields
}

DeviceConnection wraps the net.Conn to the ios Device and has support for switching Codecs and enabling SSL

func NewDeviceConnection

func NewDeviceConnection(socketToConnectTo string) *DeviceConnection

NewDeviceConnection creates a new DeviceConnection pointing to the given socket waiting for a call to Connect()

func NewDeviceConnectionWithConn

func NewDeviceConnectionWithConn(conn net.Conn) *DeviceConnection

NewDeviceConnectionWithConn create a DeviceConnection with a already connected network conn.

func (*DeviceConnection) Close

func (conn *DeviceConnection) Close()

Close closes the network connection

func (*DeviceConnection) DisableSessionSSL

func (conn *DeviceConnection) DisableSessionSSL()

DisableSessionSSL is a hack to go back from SSL to an unencrypted conn without closing the connection. It is only used for the debug proxy because certain MAC applications actually disable SSL, use the connection to send unencrypted messages just to then enable SSL again without closing the connection

func (*DeviceConnection) EnableSessionSsl

func (conn *DeviceConnection) EnableSessionSsl(pairRecord PairRecord) error

EnableSessionSsl wraps the underlying net.Conn in a client tls.Conn using the pairRecord.

func (*DeviceConnection) EnableSessionSslHandshakeOnly

func (conn *DeviceConnection) EnableSessionSslHandshakeOnly(pairRecord PairRecord) error

EnableSessionSslHandshakeOnly enables SSL only for the Handshake and then falls back to plaintext DTX based services do that currently

func (*DeviceConnection) EnableSessionSslServerMode

func (conn *DeviceConnection) EnableSessionSslServerMode(pairRecord PairRecord)

EnableSessionSslServerMode wraps the underlying net.Conn in a server tls.Conn using the pairRecord.

func (*DeviceConnection) EnableSessionSslServerModeHandshakeOnly

func (conn *DeviceConnection) EnableSessionSslServerModeHandshakeOnly(pairRecord PairRecord)

EnableSessionSslServerModeHandshakeOnly enables SSL only for the Handshake and then falls back to plaintext DTX based services do that currently. Server mode is needed only in the debugproxy.

func (*DeviceConnection) Reader

func (conn *DeviceConnection) Reader() io.Reader

Reader exposes the underlying net.Conn as io.Reader

func (*DeviceConnection) Send

func (conn *DeviceConnection) Send(bytes []byte) error

Send sends a message

func (*DeviceConnection) Writer

func (conn *DeviceConnection) Writer() io.Writer

Writer exposes the underlying net.Conn as io.Writer

type DeviceConnectionInterface

type DeviceConnectionInterface interface {
	Close()
	Send(message []byte) error
	Reader() io.Reader
	Writer() io.Writer
	EnableSessionSsl(pairRecord PairRecord) error
	EnableSessionSslServerMode(pairRecord PairRecord)
	EnableSessionSslHandshakeOnly(pairRecord PairRecord) error
	EnableSessionSslServerModeHandshakeOnly(pairRecord PairRecord)
	DisableSessionSSL()
}

DeviceConnectionInterface contains a physical network connection to a usbmuxd socket.

func ConnectToService

func ConnectToService(device DeviceEntry, serviceName string) (DeviceConnectionInterface, error)

ConnectToService connects to a service on the phone and returns the ready to use DeviceConnectionInterface

type DeviceEntry

type DeviceEntry struct {
	DeviceID    int
	MessageType string
	Properties  DeviceProperties
}

DeviceEntry contains the DeviceID with is sometimes needed f.ex. to enable LockdownSSL. More importantly it contains DeviceProperties where the udid is stored.

func GetDevice

func GetDevice(udid string) (DeviceEntry, error)

GetDevice returns the device for udid. If udid equals emptystring, it returns the first device in the list.

type DeviceList

type DeviceList struct {
	DeviceList []DeviceEntry
}

DeviceList is a simple wrapper for a array of DeviceEntry

func DeviceListfromBytes

func DeviceListfromBytes(plistBytes []byte) DeviceList

DeviceListfromBytes parses a DeviceList from a byte array

func ListDevices

func ListDevices() DeviceList

ListDevices returns a DeviceList containing data about all currently connected iOS devices using a new UsbMuxConnection

func (DeviceList) CreateMapForJSONConverter

func (deviceList DeviceList) CreateMapForJSONConverter() map[string]interface{}

CreateMapForJSONConverter creates a simple json ready map containing all UDIDs

func (DeviceList) String

func (deviceList DeviceList) String() string

String returns a list of all udids in a formatted string

type DeviceProperties

type DeviceProperties struct {
	ConnectionSpeed int
	ConnectionType  string
	DeviceID        int
	LocationID      int
	ProductID       int
	SerialNumber    string
}

DeviceProperties contains important device related info like the udid which is named SerialNumber here

type GetAllValuesResponse

type GetAllValuesResponse struct {
	Request string
	Value   AllValuesType
}

GetAllValuesResponse just the wrapper for AllValuesType

func GetValues

func GetValues(device DeviceEntry) GetAllValuesResponse

GetValues returns all values of deviceInformation from lockdown

type LanguageConfiguration

type LanguageConfiguration struct {
	Language string
	Locale   string
}

LanguageConfiguration is a simple struct encapsulating a language and locale string

func GetLanguage

func GetLanguage(device DeviceEntry) (LanguageConfiguration, error)

GetLanguage creates a new lockdown session for the device and retrieves language and locale. It returns a LanguageConfiguration or an error.

type ListenType

type ListenType struct {
	MessageType         string
	ProgName            string
	ClientVersionString string
	ConnType            int
	// contains filtered or unexported fields
}

ListenType contains infos for creating a LISTEN message for USBMUX

func NewListen

func NewListen() ListenType

NewListen creates a new Listen Message for USBMUX

type LockDownConnection

type LockDownConnection struct {
	// contains filtered or unexported fields
}

LockDownConnection allows you to interact with the Lockdown service on the phone. You can use this to grab basic info from the device and start other services on the phone.

func ConnectLockdownWithSession

func ConnectLockdownWithSession(device DeviceEntry) *LockDownConnection

func NewLockDownConnection

func NewLockDownConnection(dev DeviceConnectionInterface) *LockDownConnection

NewLockDownConnection creates a new LockDownConnection with empty sessionId and a PlistCodec.

func (*LockDownConnection) Close

func (lockDownConn *LockDownConnection) Close()

Close closes the underlying DeviceConnection

func (LockDownConnection) DisableSessionSSL

func (lockDownConn LockDownConnection) DisableSessionSSL()

DisableSessionSSL see documentation in DeviceConnection

func (LockDownConnection) EnableSessionSsl

func (lockDownConn LockDownConnection) EnableSessionSsl(pairRecord PairRecord) error

EnableSessionSsl see documentation in DeviceConnection

func (LockDownConnection) EnableSessionSslServerMode

func (lockDownConn LockDownConnection) EnableSessionSslServerMode(pairRecord PairRecord)

EnableSessionSslServerMode see documentation in DeviceConnection

func (*LockDownConnection) GetProductVersion

func (lockDownConn *LockDownConnection) GetProductVersion() string

GetProductVersion returns the ProductVersion of the device f.ex. "10.3"

func (*LockDownConnection) GetValue

func (lockDownConn *LockDownConnection) GetValue(key string) (interface{}, error)

GetValue gets and returns the string value for the lockdown key

func (*LockDownConnection) GetValueForDomain

func (lockDownConn *LockDownConnection) GetValueForDomain(key string, domain string) (interface{}, error)

GetValueForDomain gets and returns the string value for the lockdown key and domain

func (*LockDownConnection) GetValues

func (lockDownConn *LockDownConnection) GetValues() (GetAllValuesResponse, error)

GetValues retrieves a GetAllValuesResponse containing all values lockdown returns

func (*LockDownConnection) ReadMessage

func (lockDownConn *LockDownConnection) ReadMessage() ([]byte, error)

ReadMessage grabs the next LockDown Message using the PlistDecoder from the underlying DeviceConnection and returns the Plist as a byte slice.

func (LockDownConnection) Send

func (lockDownConn LockDownConnection) Send(msg interface{}) error

Send takes a go struct, converts it to a PLIST and sends it with a 4 byte length field.

func (*LockDownConnection) SetValueForDomain

func (lockDownConn *LockDownConnection) SetValueForDomain(key string, domain string, value string) error

SetValueForDomain sets the string value for the lockdown key and domain. If the device returns an error it will be returned as a go error.

func (*LockDownConnection) StartService

func (lockDownConn *LockDownConnection) StartService(serviceName string) (StartServiceResponse, error)

StartService sends a StartServiceRequest using the provided serviceName and returns the Port of the services in a BigEndian Integer. This port cann be used with a new UsbMuxClient and the Connect call.

func (*LockDownConnection) StartSession

func (lockDownConn *LockDownConnection) StartSession(pairRecord PairRecord) (StartSessionResponse, error)

StartSession will send a StartSession Request to Lockdown, wait for the response and enable SSL on the underlying connection if necessary. The devices usually always requests to enable SSL. It returns a StartSessionResponse

func (*LockDownConnection) StopSession

func (lockDownConn *LockDownConnection) StopSession()

StopSession sends a Lockdown StopSessionRequest to the device

type MuxResponse

type MuxResponse struct {
	MessageType string
	Number      uint32
}

MuxResponse is a generic response message sent by usbmuxd it contains a Number response code

func MuxResponsefromBytes

func MuxResponsefromBytes(plistBytes []byte) MuxResponse

MuxResponsefromBytes parses a MuxResponse struct from bytes

func (MuxResponse) IsSuccessFull

func (u MuxResponse) IsSuccessFull() bool

IsSuccessFull returns UsbMuxResponse.Number==0

type NonVolatileRAMType

type NonVolatileRAMType struct {
	AutoBoot              []byte `plist:"auto-boot"`
	BacklightLevel        []byte `plist:"backlight-level"`
	BootArgs              string `plist:"boot-args"`
	Bootdelay             []byte `plist:"bootdelay"`
	ComAppleSystemTz0Size []byte `plist:"com.apple.System.tz0-size"`
	OblitBegins           []byte `plist:"oblit-begins"`
	Obliteration          []byte `plist:"obliteration"`
}

NonVolatileRAMType contains some internal device info and can be retrieved by getting all values

type PairRecord

type PairRecord struct {
	HostID            string
	SystemBUID        string
	HostCertificate   []byte
	HostPrivateKey    []byte
	DeviceCertificate []byte
	EscrowBag         []byte
	WiFiMACAddress    string
	RootCertificate   []byte
	RootPrivateKey    []byte
}

PairRecord contains the HostID string, the SystemBUID string, the HostCertificate []byte and the HostPrivateKey []byte. It is needed for enabling SSL Connections over Lockdown

func PairRecordfromBytes

func PairRecordfromBytes(plistBytes []byte) PairRecord

PairRecordfromBytes parsed a plist into a PairRecord

func ReadPairRecord

func ReadPairRecord(udid string) PairRecord

ReadPairRecord creates a new USBMuxConnection just to read the pair record and closes it right after than.

type PairRecordData

type PairRecordData struct {
	PairRecordData []byte
}

PairRecordData only holds a []byte containing the PairRecord data as a serialized Plist.

type PlistCodec

type PlistCodec struct {
}

PlistCodec is a codec for PLIST based services with [4 byte big endian length][plist-payload] based messages

func NewPlistCodec

func NewPlistCodec() PlistCodec

NewPlistCodec create a codec for PLIST based services with [4 byte big endian length][plist-payload] based messages

func (PlistCodec) Decode

func (plistCodec PlistCodec) Decode(r io.Reader) ([]byte, error)

Decode reads a Lockdown Message from the provided reader and sends it to the ResponseChannel

func (PlistCodec) Encode

func (plistCodec PlistCodec) Encode(message interface{}) ([]byte, error)

Encode encodes a LockDown Struct to a byte[] with the lockdown plist format. It returns a byte array that contains a 4 byte length unsigned big endian integer followed by the plist as a string

type ReadDevicesType

type ReadDevicesType struct {
	MessageType         string
	ProgName            string
	ClientVersionString string
}

ReadDevicesType contains all the data necessary to request a DeviceList from usbmuxd. Can be created with newReadDevices

func NewReadDevices

func NewReadDevices() ReadDevicesType

NewReadDevices creates a struct containing a request for a device list that can be sent to UsbMuxD.

type ReadPair

type ReadPair struct {
	BundleID            string
	ClientVersionString string
	MessageType         string
	ProgName            string
	LibUSBMuxVersion    uint32 `plist:"kLibUSBMuxVersion"`
	PairRecordID        string
}

ReadPair contains all the Infos necessary to request a PairRecord from usbmuxd. use newReadPair(udid string) to create one.

type StartServiceResponse

type StartServiceResponse struct {
	Port             uint16
	Request          string
	Service          string
	EnableServiceSSL bool
	Error            string
}

StartServiceResponse is sent by the phone after starting a service, it contains servicename, port and tells us whether we should enable SSL or not.

func StartService

func StartService(device DeviceEntry, serviceName string) (StartServiceResponse, error)

StartService conveniently starts a service on a device and cleans up the used UsbMuxconnection. It returns the service port as a uint16 in BigEndian byte order.

type StartSessionResponse

type StartSessionResponse struct {
	EnableSessionSSL bool
	Request          string
	SessionID        string
}

StartSessionResponse contains the information sent by the device as a response to a StartSessionRequest.

type UsbMuxConnection

type UsbMuxConnection struct {
	// contains filtered or unexported fields
}

UsbMuxConnection can send and read messages to the usbmuxd process to manage pairrecors, listen for device changes and connect to services on the phone. Usually messages follow a request-response pattern. there is a tag integer in the message header, that is increased with every sent message.

func NewUsbMuxConnection

func NewUsbMuxConnection(deviceConn DeviceConnectionInterface) *UsbMuxConnection

NewUsbMuxConnection creates a new UsbMuxConnection with from an already initialized DeviceConnectionInterface and

func (*UsbMuxConnection) Connect

func (muxConn *UsbMuxConnection) Connect(deviceID int, port uint16) error

Connect issues a Connect Message to UsbMuxd for the given deviceID on the given port enabling the newCodec for it. It returns an error containing the UsbMux error code should the connect fail.

func (*UsbMuxConnection) ConnectLockdown

func (muxConn *UsbMuxConnection) ConnectLockdown(deviceID int) (*LockDownConnection, error)

ConnectLockdown connects this Usbmux connection to the LockDown service that always runs on the device on the same port. The connect call needs the deviceID which can be retrieved from a DeviceList using the ListDevices function. After this function is done, the UsbMuxConnection cannot be used anymore because the same underlying network connection is used for talking to Lockdown. Sending usbmux commands would break it. It returns a new LockDownConnection.

func (*UsbMuxConnection) ListDevices

func (muxConn *UsbMuxConnection) ListDevices() DeviceList

ListDevices returns a DeviceList containing data about all currently connected iOS devices

func (*UsbMuxConnection) Listen

func (muxConn *UsbMuxConnection) Listen() (func() (AttachedMessage, error), error)

Listen will send a listen command to usbmuxd which will cause this connection to stay open indefinitely and receive messages whenever devices are connected or disconnected

func (*UsbMuxConnection) ReadMessage

func (muxConn *UsbMuxConnection) ReadMessage() (UsbMuxMessage, error)

ReadMessage blocks until the next muxMessage is available on the underlying DeviceConnection and returns it.

func (*UsbMuxConnection) ReadPair

func (muxConn *UsbMuxConnection) ReadPair(udid string) PairRecord

ReadPair reads the PairRecord from the usbmux socket for the given udid. It returns the deserialized PairRecord.

func (*UsbMuxConnection) ReleaseDeviceConnection

func (muxConn *UsbMuxConnection) ReleaseDeviceConnection() DeviceConnectionInterface

ReleaseDeviceConnection dereferences this UsbMuxConnection from the underlying DeviceConnection and it returns the DeviceConnection for later use. This UsbMuxConnection cannot be used after calling this.

func (*UsbMuxConnection) Send

func (muxConn *UsbMuxConnection) Send(msg interface{}) error

Send sends and encodes a Plist using the usbmux Encoder. Increases the connection tag by one.

func (*UsbMuxConnection) SendMuxMessage

func (muxConn *UsbMuxConnection) SendMuxMessage(msg UsbMuxMessage) error

SendMuxMessage serializes and sends a UsbMuxMessage to the underlying DeviceConnection. This does not increase the tag on the connection. Is used mainly by the debug proxy to forward messages between device and host

type UsbMuxHeader

type UsbMuxHeader struct {
	Length  uint32
	Version uint32
	Request uint32
	Tag     uint32
}

UsbMuxHeader contains the header for plist messages for the usbmux daemon.

type UsbMuxMessage

type UsbMuxMessage struct {
	Header  UsbMuxHeader
	Payload []byte
}

UsbMuxMessage contains header and payload for a message to usbmux

type ValueResponse

type ValueResponse struct {
	Key     string
	Request string
	Error   string
	Domain  string
	Value   interface{}
}

ValueResponse contains the response for a GetValue or SetValue Request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL