-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
101 lines (85 loc) · 1.65 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"iconsole/frames"
"iconsole/tunnel"
"os"
"github.com/urfave/cli"
)
var globalFlags = []cli.Flag{
cli.StringFlag{
Name: "UDID, u",
Usage: "device serialNumber UDID",
EnvVar: "DEVICE_UDID",
Value: "",
},
}
func session(udid string, cb func(*tunnel.LockdownConnection) error) error {
device, err := getDevice(udid)
if err != nil {
return err
}
conn, err := tunnel.LockdownDial(device)
if err != nil {
return err
}
defer conn.Close()
if err := conn.StartSession(); err != nil {
return err
}
defer conn.StopSession()
return cb(conn)
}
func getDevice(udid string) (frames.Device, error) {
devices, err := tunnel.Devices()
if err != nil {
return nil, err
}
var ds []frames.Device
for i, d := range devices {
if udid == "" && d.GetConnectionType() == "USB" {
return d, nil
}
if d.GetSerialNumber() == udid {
ds = append(ds, devices[i])
}
}
if len(ds) > 0 {
for _, d := range ds {
if d.GetConnectionType() == "USB" {
return d, nil
}
}
return ds[0], nil
}
return nil, fmt.Errorf("device %s was not found", udid)
}
func main() {
app := cli.NewApp()
app.Name = "iConsole"
app.Usage = "iOS device tools"
app.Version = "1.0.0"
app.Authors = []cli.Author{
{
Name: "anonymous5l",
Email: "[email protected]",
},
}
app.Commands = []cli.Command{
initDevices(),
initSyslogCommond(),
initSimCommond(),
initScreenShotCommond(),
initSyncCommond(),
initValueCommond(),
initTransportCommand(),
initMountCommand(),
initAFCCommand(),
initArrest(),
initProcessCommond(),
}
if err := app.Run(os.Args); err != nil {
fmt.Println(err.Error())
return
}
}