-
-
Notifications
You must be signed in to change notification settings - Fork 167
/
processlist.go
73 lines (62 loc) · 2.21 KB
/
processlist.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
package instruments
import (
"time"
"github.com/danielpaulus/go-ios/ios"
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
"github.com/danielpaulus/go-ios/ios/nskeyedarchiver"
)
const deviceInfoServiceName = "com.apple.instruments.server.services.deviceinfo"
//ProcessInfo contains all the properties for a process
//running on an iOS devices that we get back from instruments
type ProcessInfo struct {
IsApplication bool
Name string
Pid uint64
RealAppName string
StartDate time.Time
}
//ProcessList returns a []ProcessInfo, one for each process running on the iOS device
func (d DeviceInfoService) ProcessList() ([]ProcessInfo, error) {
resp, err := d.channel.MethodCall("runningProcesses")
result := mapToProcInfo(resp.Payload[0].([]interface{}))
return result, err
}
//NameForPid resolves a process name for a given pid
func (d DeviceInfoService) NameForPid(pid uint64) error {
_, err := d.channel.MethodCall("execnameForPid:", pid)
return err
}
func mapToProcInfo(procList []interface{}) []ProcessInfo {
result := make([]ProcessInfo, len(procList))
for i, procMapInt := range procList {
procMap := procMapInt.(map[string]interface{})
procInf := ProcessInfo{}
procInf.IsApplication = procMap["isApplication"].(bool)
procInf.Name = procMap["name"].(string)
procInf.Pid = procMap["pid"].(uint64)
procInf.RealAppName = procMap["realAppName"].(string)
if date, ok := procMap["startDate"]; ok {
procInf.StartDate = date.(nskeyedarchiver.NSDate).Timestamp
}
result[i] = procInf
}
return result
}
//DeviceInfoService gives us access to retrieving process lists and resolving names for PIDs
type DeviceInfoService struct {
channel *dtx.Channel
conn *dtx.Connection
}
//NewDeviceInfoService creates a new DeviceInfoService for a given device
func NewDeviceInfoService(device ios.DeviceEntry) (*DeviceInfoService, error) {
dtxConn, err := connectInstruments(device)
if err != nil {
return nil, err
}
processControlChannel := dtxConn.RequestChannelIdentifier(deviceInfoServiceName, loggingDispatcher{dtxConn})
return &DeviceInfoService{channel: processControlChannel, conn: dtxConn}, nil
}
//Close closes up the DTX connection
func (d *DeviceInfoService) Close() {
d.conn.Close()
}