-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
112 lines (99 loc) · 2.61 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
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"errors"
"flag"
"fmt"
"log"
"unsafe"
"github.com/aktsk/ipa-medit/pkg/idevice"
"github.com/aktsk/ipa-medit/pkg/lldb"
"github.com/aktsk/ipa-medit/pkg/prompt"
)
func runApp(binPath string, bundleID string) error {
// The device app path reported by the device might be stale, so retry
// the lookup of the device path along with the lldb launching below.
deviceAppPath, err := idevice.FindDeviceAppPath(bundleID)
if err != nil {
return err
}
fmt.Printf("Target app: %s\n", deviceAppPath)
fmt.Printf("Target local bin: %s\n", binPath)
platform := "remote-ios"
fmt.Printf("Target platform: %s\n", platform)
stderr, err := lldb.RunLLDB(platform, binPath, deviceAppPath)
if err == nil {
return err
}
if len(stderr) != 0 {
return errors.New(*(*string)(unsafe.Pointer(&stderr)))
}
return nil
}
func runMain() error {
var binPath string
var bundleID string
var pid string
var name string
flag.StringVar(&binPath, "bin", "", "specify ios app binary that unzip and extract from .ipa")
flag.StringVar(&bundleID, "id", "", "specify bundle id")
flag.StringVar(&pid, "pid", "", "specify pid running on the Apple Silicon Mac")
flag.StringVar(&name, "name", "", "specify process name running on the Apple Silicon Mac")
flag.Parse()
if pid != "" {
fmt.Println("Please use `exit` or `Ctrl-D` to exit this program.")
fmt.Printf("Target PID has been set to %s.\n", pid)
if result, err := prompt.CheckPidExists(pid); err == nil {
if result {
prompt.RunPrompt(pid)
} else {
return errors.New("There is no process with the specified pid.")
}
} else {
return err
}
}
if name != "" {
fmt.Println("Please use `exit` or `Ctrl-D` to exit this program.")
fmt.Printf("Target Process name has been set to %s.\n", name)
pid, err := prompt.GetPidByProcessName(name)
if err != nil {
return err
}
if pid == "" {
return errors.New("Process not found.")
}
prompt.RunPrompt(pid)
return nil
}
if binPath == "" {
return errors.New("bin option is required.")
}
if bundleID == "" {
return errors.New("id option is required.")
}
if err := lldb.PreparePythonFile(); err != nil {
return err
}
udid, err := idevice.Init()
if err != nil {
return err
}
fmt.Printf("Target device's UDID: %s\n", udid)
closer, err := idevice.StartDebugBridge()
if err != nil {
return err
}
fmt.Println("Start to proxy a debugserver connection from a device for remote debugging...")
defer closer()
if err := runApp(binPath, bundleID); err != nil {
return err
}
return nil
}
func main() {
defer prompt.HandleExit()
err := runMain()
if err != nil {
log.Fatalf("%v\n", err)
}
}