communicate with iOS devices implemented with Golang

Overview

Golang-iDevice

go doc go report license

much more easy to use 👉 electricbubble/gidevice-cli

Installation

go get github.com/electricbubble/gidevice

Devices

package main

import (
	giDevice "github.com/electricbubble/gidevice"
	"log"
)

func main() {
	usbmux, err := giDevice.NewUsbmux()
	if err != nil {
		log.Fatalln(err)
	}

	devices, err := usbmux.Devices()
	if err != nil {
		log.Fatal(err)
	}

	for _, dev := range devices {
		log.Println(dev.Properties().SerialNumber, dev.Properties().ProductID, dev.Properties().DeviceID)
	}
}

DeveloperDiskImage

package main

import (
	"encoding/base64"
	giDevice "github.com/electricbubble/gidevice"
	"log"
)

func main() {
	usbmux, err := giDevice.NewUsbmux()
	if err != nil {
		log.Fatal(err)
	}

	devices, err := usbmux.Devices()
	if err != nil {
		log.Fatal(err)
	}

	if len(devices) == 0 {
		log.Fatal("No Device")
	}

	d := devices[0]

	imageSignatures, err := d.Images()
	if err != nil {
		log.Fatalln(err)
	}

	for i, imgSign := range imageSignatures {
		log.Printf("[%d] %s\n", i+1, base64.StdEncoding.EncodeToString(imgSign))
	}

	dmgPath := "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/14.4/DeveloperDiskImage.dmg"
	signaturePath := "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/14.4/DeveloperDiskImage.dmg.signature"

	err = d.MountDeveloperDiskImage(dmgPath, signaturePath)
	if err != nil {
		log.Fatalln(err)
	}
}

App

package main

import (
	giDevice "github.com/electricbubble/gidevice"
	"log"
	"path/filepath"
)

func main() {
	usbmux, err := giDevice.NewUsbmux()
	if err != nil {
		log.Fatalln(err)
	}

	devices, err := usbmux.Devices()
	if err != nil {
		log.Fatalln(err)
	}

	if len(devices) == 0 {
		log.Fatalln("No Device")
	}

	d := devices[0]

	bundleID := "com.apple.Preferences"
	pid, err := d.AppLaunch(bundleID)
	if err != nil {
		log.Fatalln(err)
	}

	err = d.AppKill(pid)
	if err != nil {
		log.Fatalln(err)
	}

	runningProcesses, err := d.AppRunningProcesses()
	if err != nil {
		log.Fatalln(err)
	}

	for _, process := range runningProcesses {
		if process.IsApplication {
			log.Printf("%4d\t%-24s\t%-36s\t%s\n", process.Pid, process.Name, filepath.Base(process.RealAppName), process.StartDate)
		}
	}
}

Screenshot

package main

import (
	giDevice "github.com/electricbubble/gidevice"
	"image"
	"image/jpeg"
	"image/png"
	"log"
	"os"
)

func main() {
	usbmux, err := giDevice.NewUsbmux()
	if err != nil {
		log.Fatalln(err)
	}

	devices, err := usbmux.Devices()
	if err != nil {
		log.Fatalln(err)
	}

	if len(devices) == 0 {
		log.Fatalln("No Device")
	}

	d := devices[0]

	raw, err := d.Screenshot()
	if err != nil {
		log.Fatalln(err)
	}

	img, format, err := image.Decode(raw)
	if err != nil {
		log.Fatalln(err)
	}
	userHomeDir, _ := os.UserHomeDir()
	file, err := os.Create(userHomeDir + "/Desktop/s1." + format)
	if err != nil {
		log.Fatalln(err)
	}
	defer func() { _ = file.Close() }()
	switch format {
	case "png":
		err = png.Encode(file, img)
	case "jpeg":
		err = jpeg.Encode(file, img, nil)
	}
	if err != nil {
		log.Fatalln(err)
	}
	log.Println(file.Name())
}

SimulateLocation

package main

import (
	giDevice "github.com/electricbubble/gidevice"
	"log"
)

func main() {
	usbmux, err := giDevice.NewUsbmux()
	if err != nil {
		log.Fatalln(err)
	}

	devices, err := usbmux.Devices()
	if err != nil {
		log.Fatalln(err)
	}

	if len(devices) == 0 {
		log.Fatalln("No Device")
	}

	d := devices[0]

	// https://api.map.baidu.com/lbsapi/getpoint/index.html
	if err = d.SimulateLocationUpdate(116.024067, 40.362639, giDevice.CoordinateSystemBD09); err != nil {
		log.Fatalln(err)
	}

	// https://developer.amap.com/tools/picker
	// https://lbs.qq.com/tool/getpoint/index.html
	// if err = d.SimulateLocationUpdate(120.116979, 30.252876, giDevice.CoordinateSystemGCJ02); err != nil {
	// 	log.Fatalln(err)
	// }

	// if err = d.SimulateLocationUpdate(121.499763, 31.239580,giDevice.CoordinateSystemWGS84); err != nil {
	// if err = d.SimulateLocationUpdate(121.499763, 31.239580); err != nil {
	// 	log.Fatalln(err)
	// }

	// err = d.SimulateLocationRecover()
	// if err != nil {
	// 	log.Fatalln(err)
	// }
}

XCTest

package main

import (
	"fmt"
	giDevice "github.com/electricbubble/gidevice"
	"log"
	"os"
	"os/signal"
)

func main() {
	usbmux, err := giDevice.NewUsbmux()
	if err != nil {
		log.Fatal(err)
	}

	devices, err := usbmux.Devices()
	if err != nil {
		log.Fatal(err)
	}

	if len(devices) == 0 {
		log.Fatal("No Device")
	}

	d := devices[0]

	out, cancel, err := d.XCTest("com.leixipaopao.WebDriverAgentRunner.xctrunner")
	if err != nil {
		log.Fatal(err)
	}

	done := make(chan os.Signal, 1)
	signal.Notify(done, os.Interrupt)

	go func() {
		for s := range out {
			fmt.Print(s)
		}
	}()

	<-done
	cancel()
	fmt.Println()
	log.Println("DONE")
}

Thanks

About
libimobiledevice/libimobiledevice A cross-platform protocol library to communicate with iOS devices
anonymous5l/iConsole iOS usbmuxd communication impl iTunes protocol
alibaba/taobao-iphone-device tidevice can be used to communicate with iPhone device

Thank you JetBrains for providing free open source licenses

Issues
  • iOS 15.0 MountDeveloperDiskImage failed

    iOS 15.0 MountDeveloperDiskImage failed

    err := device.MountDeveloperDiskImage(xxx,xxx.sign)
     if err != nil {
       fmt.Println(err)
     }
    

    iOS 15.0,镜像用的这里面的 https://github.com/iGhibli/iOS-DeviceSupport/tree/master/DeviceSupport err报错提示为 tls: failed to find any PEM data in key input

    opened by ZhouYixun 13
  • panic: runtime error: invalid memory address or nil pointer dereference

    panic: runtime error: invalid memory address or nil pointer dereference

    用的过程会有偶现这个报错,一般重试可以正常运行,但是想看看能不能优化一下这部分

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xc0000005 code=0x0 addr=0x20 pc=0x704070]
    
    goroutine 9 [running]:
    github.com/electricbubble/gidevice/pkg/libimobiledevice.(*dtxMessageClient).startReceive.func1()
            *********/go/pkg/mod/github.com/electricbubble/[email protected]/pkg/libimobiledevice/client_dtxmessage.go:342 +0x30
    created by github.com/electricbubble/gidevice/pkg/libimobiledevice.(*dtxMessageClient).startReceive
           ********/go/pkg/mod/github.com/electricbubble/[email protected]/pkg/libimobiledevice/client_dtxmessage.go:339 +0x56
    exit status 2
    
    
    opened by ZhouYixun 11
  • 反复插拔usb 加载gidevice 会panic 建议增加Recover

    反复插拔usb 加载gidevice 会panic 建议增加Recover

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xabaa90]
    
    goroutine 232 [running]:
    github.com/electricbubble/gidevice/pkg/libimobiledevice.(*dtxMessageClient).startReceive.func1()
    	/home/work/go/pkg/mod/github.com/electricbubble/[email protected]/pkg/libimobiledevice/client_dtxmessage.go:323 +0x30
    created by github.com/electricbubble/gidevice/pkg/libimobiledevice.(*dtxMessageClient).startReceive
    	/home/work/go/pkg/mod/github.com/electricbubble/[email protected]/pkg/libimobiledevice/client_dtxmessage.go:320 +0x5b
    
    opened by aichy126 5
  • XCTest multiple-start fail

    XCTest multiple-start fail

    多次重复启动wda会造成失败 详见https://github.com/SonicCloudOrg/sonic-ios-bridge/issues/21 我cli多了自动挂载镜像处理,我这边debug了应该不是cli问题 请问有想法吗? 我启动wda的gofile https://github.com/SonicCloudOrg/sonic-ios-bridge/blob/main/cmd/wda.go

    opened by ZhouYixun 2
  • gidevice 和 gwda 如何在一个项目里配合使用呢?

    gidevice 和 gwda 如何在一个项目里配合使用呢?

    gidevice 开启 XCTest 确认连接状态使用 gwda控制

    	out, cancel, err := ID.XCTest(bundleID)
    	if err != nil {
    		log.Fatal(err)
    	}
    
    	done := make(chan os.Signal, 1)
    	signal.Notify(done, os.Interrupt)
    
    	go func() {
    		for s := range out {
    			fmt.Print(s)
    			has := strings.Contains(s, "Using singleton test manager")
    			if has {
    				driver, _ := gwda.NewUSBDriver(nil)
    				driver.PressButton(gwda.DeviceButtonHome)
    				driver.SiriActivate("What's the weather like today")
    			}
    		}
    	}()
    
    	<-done
    	cancel()
    

    或者有更好的办法么?

    opened by aichy126 2
  • undefined: io.ReadAll

    undefined: io.ReadAll

    package main
    import (
    
    	giDevice "github.com/electricbubble/gidevice"
    	"github.com/electricbubble/gidevice/pkg/libimobiledevice"
    
    )
    
    func main() {
    	libimobiledevice.SetDebug(true)
    	giDevice.NewUsbmux()
    }
    

    vendor/github.com/electricbubble/gidevice/pkg/ipa/ipa.go:35:17: undefined: io.ReadAll

    我需要初始化什么么?

    opened by aichy126 2
  • SimulateLocationUpdate return InvalidService error

    SimulateLocationUpdate return InvalidService error

    hi, I ran the example code of SimulateLocation but return error as below

    2021/06/12 01:07:39 receive packet: InvalidService
    

    Here is my code and iOS version is 14.0.1

    package main
    
    import (
    	"log"
    
    	giDevice "github.com/electricbubble/gidevice"
    	"github.com/electricbubble/gidevice/pkg/libimobiledevice"
    )
    
    func main() {
    	libimobiledevice.SetDebug(true)
    
    	usbmux, err := giDevice.NewUsbmux()
    	if err != nil {
    		log.Fatalln(err)
    	}
    
    	devices, err := usbmux.Devices()
    	if err != nil {
    		log.Fatalln(err)
    	}
    
    	if len(devices) == 0 {
    		log.Fatalln("No Device")
    	}
    
    	d := devices[0]
    
    	// https://developer.amap.com/tools/picker
    	// https://lbs.qq.com/tool/getpoint/index.html
    	if err = d.SimulateLocationUpdate(113.925734, 22.511836, giDevice.CoordinateSystemWGS84); err != nil {
    		log.Fatalln(err)
    	}
    }
    

    I tried to debug this program and found it break at this function

    func (c *lockdown) startService(service string, escrowBag []byte) (dynamicPort int, enableSSL bool, err error) {
    	req := c.client.NewStartServiceRequest(service)
    	if escrowBag != nil {
    		req.EscrowBag = escrowBag
    	}
    
    	var pkt libimobiledevice.Packet
    	if pkt, err = c.client.NewXmlPacket(req); err != nil {
    		return 0, false, err
    	}
    
    	if err = c.client.SendPacket(pkt); err != nil {
    		return 0, false, err
    	}
            // returned error InvalidService
    	respPkt, err := c.client.ReceivePacket()
    	if err != nil {
    		return 0, false, err
    	}
    
    	var reply libimobiledevice.LockdownStartServiceResponse
    	if err = respPkt.Unmarshal(&reply); err != nil {
    		return 0, false, err
    	}
    
    	if reply.Error != "" {
    		return 0, false, fmt.Errorf("lockdown start service: %s", reply.Error)
    	}
    
    	dynamicPort = reply.Port
    	enableSSL = reply.EnableServiceSSL
    
    	return
    }
    

    Any Suggestion?

    opened by x1nchen 2
  • 运行时偶现 panic

    运行时偶现 panic

    运行命令

    ./gidevice xctest com.facebook.WebDriverAgentRunner.xctrunner -u xxxx --env=USE_PORT=8100 --env=MJPEG_SERVER_PORT=9100
    

    执行一段时间后,运行基于 appium 的 UI 自动化脚本时,出现如下报错然后自动退出:

     t =  3505.76s     Requesting snapshot of accessibility hierarchy for app with pid 566
        t =  3506.16s     Find: Descendants matching type Any
        t =  3506.17s     Find: Elements matching predicate '(wdType == "XCUIElementTypeTextField" AND wdValue == "请输入手机号") AND (1 == 1 OR identifier == 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0 OR selected == 0)'
    panic: runtime error: slice bounds out of range [:209106] with capacity 132768
    
    goroutine 8 [running]:
    github.com/electricbubble/gidevice/pkg/libimobiledevice.(*dtxMessageClient).ReceiveDTXMessage(0xc00038b1a0, 0xc000096000, 0x0, 0x0)
    	/home/runner/go/pkg/mod/github.com/electricbubble/[email protected]/pkg/libimobiledevice/client_dtxmessage.go:180 +0x1265
    github.com/electricbubble/gidevice/pkg/libimobiledevice.(*dtxMessageClient).startReceive.func1(0xc00038b1a0)
    	/home/runner/go/pkg/mod/github.com/electricbubble/[email protected]/pkg/libimobiledevice/client_dtxmessage.go:326 +0x5e
    created by github.com/electricbubble/gidevice/pkg/libimobiledevice.(*dtxMessageClient).startReceive
    	/home/runner/go/pkg/mod/github.com/electricbubble/[email protected]/pkg/libimobiledevice/client_dtxmessage.go:320 +0x3f
    

    目前为偶现,暂时未找到稳定复现步骤。

    opened by chenhengjie123 7
  • 同学,您这个项目引入了9个开源组件,存在2个漏洞,辛苦升级一下

    同学,您这个项目引入了9个开源组件,存在2个漏洞,辛苦升级一下

    检测到 electricbubble/gidevice 一共引入了9个开源组件,存在2个漏洞

    漏洞标题:go-yaml < 2.2.8拒绝服务漏洞
    缺陷组件:gopkg.in/[email protected]
    漏洞编号:CVE-2019-11254
    漏洞描述:gopkg.in/yaml.v2是go语言中用于处理yaml格式的包。
    在2.2.8之前的版本中,处理恶意的yaml数据时,会导致CPU资源耗尽。
    漏洞由Kubernetes开发者在fuzz测试中发现并提交修复补丁。
    国家漏洞库信息:https://www.cnvd.org.cn/flaw/show/CNVD-2020-35519
    影响范围:(∞, 2.2.8)
    最小修复版本:2.2.8
    缺陷组件引入路径:github.com/electricbubble/[email protected]>gopkg.in/[email protected]
    

    另外还有2个漏洞,详细报告:https://mofeisec.com/jr?p=a68dca

    opened by dependasec[bot] 2
  • Fail when installing big ipa file

    Fail when installing big ipa file

    When installing a big ipa file (3.3G), it will report error after uploading to PublicStaging:

    device_test.go:104: receive packet: read tcp 127.0.0.1:15119->127.0.0.1:27015: wsarecv: An established connection was aborted by the software in your host machine.

    It seems like lockdown connection has been closed by the phone. A simple fix would work: `

    func (d *device) AppInstall(ipaPath string) (err error) { if _, err = d.AfcService(); err != nil { return err }

    stagingPath := "PublicStaging"
    if _, err = d.afc.Stat(stagingPath); err != nil {
    	if err != ErrAfcStatNotExist {
    		return err
    	}
    	if err = d.afc.Mkdir(stagingPath); err != nil {
    		return fmt.Errorf("app install: %w", err)
    	}
    }
    
    var info map[string]interface{}
    if info, err = ipa.Info(ipaPath); err != nil {
    	return err
    }
    bundleID, ok := info["CFBundleIdentifier"]
    if !ok {
    	return errors.New("can't find 'CFBundleIdentifier'")
    }
    
    installationPath := path.Join(stagingPath, fmt.Sprintf("%s.ipa", bundleID))
    
    var data []byte
    if data, err = os.ReadFile(ipaPath); err != nil {
    	return err
    }
    if err = d.afc.WriteFile(installationPath, data, AfcFileModeWr); err != nil {
    	return err
    }
    
    d.lockdown = nil
    
    if _, err = d.installationProxyService(); err != nil {
    	return err
    }
    
    return d.installationProxy.Install(fmt.Sprintf("%s", bundleID), installationPath)
    

    }

    `

    Add a d.lockdown = nil before loading installation proxy service. But I'm not sure that's the best way of fixing.

    opened by jessehardy 9
Owner
雷系泡泡
雷系泡泡
Golang based RPC client to communicate with Metasploit

gomsf Golang based RPC client to communicate with Metasploit https://docs.rapid7.com/metasploit/rpc-api ⚠️ This is experimental and subject to breakin

Frank Hübner 5 Jul 14, 2022
Kiara is a Go equivalent of Phoenix PubSub that makes it easy for Go applications to communicate with each other.

Kiara is a Go equivalent of Phoenix PubSub that makes it easy for Go applications to communicate with each other. Examples Basic Usage Custom Co

Genta Kamitani 138 Apr 23, 2022
Client-Server App Using RPC to Communicate

rpc-client-server Client-Server App Using RPC to Communicate How to run the application Start the server From the root execute the following command i

Andrei Ionescu 0 Nov 24, 2021
Go-komoot - An easy way to communicate your user with Komoot

Go Komoot library This is an easy way to communicate your user with Komoot. Via

João Paulo Vanzuita 0 Feb 5, 2022
Jazigo is a tool written in Go for retrieving configuration for multiple devices, similar to rancid, fetchconfig, oxidized, Sweet.

Table of Contents About Jazigo Supported Platforms Features Requirements Quick Start - Short version Quick Start - Detailed version Global Settings Im

null 181 Jul 5, 2022
mdmb is a tool for simulating Apple devices interacting with Apple MDM servers.

mdmb mdmb — short for MDM Benchmark, à la ab — is a tool for simulating Apple devices interacting with Apple MDM servers. mdmb creates sets of fake Ap

Jesse Peterson 37 Jul 2, 2022
Automatically compress podcasts to tiny file sizes for bandwidth constrained devices like cellular.

tinycast Automatically compress podcasts to tiny file sizes for bandwidth constrained connections like cellular or satellite.

Stephen Holiday 4 Jan 15, 2022
Connect your devices into a single private WireGuard®-based mesh network.

Wiretrustee A WireGuard®-based mesh network that connects your devices into a single private network. Why using Wiretrustee? Connect multiple devices

null 2.8k Aug 4, 2022
Tool for monitoring network devices (mainly using SNMP) - monitoring check plugin

Thola Description A tool for monitoring network devices written in Go. It features a check mode which complies with the monitoring plugins development

inexio 249 Jul 13, 2022
Prometheus exporter for counting connected devices to a network using nmap

nmapprom Prometheus exporter for counting the hosts connected to a network using nmap · Report Bug · Request Feature Table of Contents About The Proje

Oisín Aylward 3 Oct 17, 2021
Manage SwOS devices

swosman Manage SwOS devices This application for management MikroTik devices running of SWoS TODO Link Getting setting Save new setting Getting status

Kirill 0 Nov 4, 2021
Demo of EdgeX Foundry Ireland (or Jakarta) release with real Modbus, SNMP and GPIO pin devices

Ireland Demo This demo shows the Ireland (or Jakarta - it works for both) release of EdgeX with the following devices: Comet Systems T0310 temperature

Jim White 0 Nov 6, 2021
Nomad plugin for reserving device mappings used by ebs devices.

Nomad Skeleton Device Plugin Skeleton project for Nomad device plugins. This project is intended for bootstrapping development of a new device plugin.

Turbine Inc. 0 Jan 5, 2022
User Agents detector for tv, phone, tablet and desktop devices.

gouseragents Accurate and fresh list of desktop, phone, tablet and tv user agents. install go get github.com/emetriq/gouseragents usage import ( "f

emetriq GmbH 2 Apr 26, 2022
Provides communication with USB Human Interface Devices.

This package is discontinued This package does not work with Go1.6+. I won't be updating this package since a better alternative is already available,

Geert-Johan Riemer 53 Apr 8, 2022
many tools implemented in Golang

Go-Tools many tools implemented in Golang tools project comments abtest AB测试分流 dag_flow DAG工作流 hugo_themes Hugo主题 log_monitor 日志监控服务 pepper_cache 内存kv

殷雅俊 0 Dec 12, 2021
A simple FTP protocol with client and server implemented in TypeScript and Golang

websocket-ftp A simple FTP protocol with client and server implemented in TypeScript and Golang. Example (Client) const buffer: Uint8Array = (new Text

LQR471814 0 Apr 14, 2022
Absystem - Golang implemented absystem core api

环境初始化 export GOPROXY=https://goproxy.cn,direct && export GO111MODULE=on # OR go

liangchengming 2 Feb 16, 2022