From c06bea365578511ac8ca5e9571038252d20f6735 Mon Sep 17 00:00:00 2001 From: Jacob Moody Date: Wed, 31 Jul 2024 13:58:11 -0500 Subject: [PATCH] first pass at adding support to lockdown for copying crashlogs --- lockdown/lockdown.go | 53 ++++++++++++++++++++++++++++++++++++++++++++ thing/main.go | 30 +++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 thing/main.go diff --git a/lockdown/lockdown.go b/lockdown/lockdown.go index 51e604b..df0d515 100644 --- a/lockdown/lockdown.go +++ b/lockdown/lockdown.go @@ -2,9 +2,12 @@ package lockdown // #cgo pkg-config: libimobiledevice-1.0 // #include +// #include // #include +// #include import "C" import ( + "errors" "unsafe" "github.com/nowsecure/goidevice/idevice" @@ -19,6 +22,7 @@ type Client interface { DeviceName() (string, error) PList(domain string) (*plist.PList, error) Close() error + StartService(d idevice.Device, serviceName string) (*Service, error) } type client struct { @@ -102,3 +106,52 @@ func (s *client) Close() error { } return err } + +type Service struct { + s C.service_client_t +} + +const ( + CRASH_REPORT_MOVER_SERVICE = "com.apple.crashreportmover" +) + +func (s *client) StartService(d idevice.Device, serviceName string) (*Service, error) { + var p C.lockdownd_service_descriptor_t + + svc := C.CString(serviceName) + defer C.free(unsafe.Pointer(svc)) + err := resultToError(C.lockdownd_start_service(s.p, svc, &p)) + if err != nil { + return nil, err + } + + var c C.service_client_t + res := C.service_client_new((C.idevice_t)(idevice.GetPointer(d)), p, &c) + C.lockdownd_service_descriptor_free(p) + if res != 0 { + return nil, errors.New(":(") + } + return &Service{c}, nil +} + +func (s *Service) ReadPing() error { + var msg [4]int8 + var n C.uint32_t + + var attempts = 0 + for { + res := C.service_receive_with_timeout(s.s, (*C.char)(&msg[0]), 4, &n, 2000) + switch res { + case 0: + return nil + case -7: + attempts++ + if attempts == 10 { + return errors.New("failed 10 attempts to ping") + } + continue + default: + return errors.New(":(((") + } + } +} diff --git a/thing/main.go b/thing/main.go new file mode 100644 index 0000000..8b11834 --- /dev/null +++ b/thing/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "log" + "os" + + "github.com/nowsecure/goidevice/idevice" + "github.com/nowsecure/goidevice/lockdown" +) + +func main() { + device, err := idevice.New(os.Args[1]) + if err != nil { + log.Fatal(err) + } + lock, err := lockdown.NewClientWithHandshake(device, "thingy") + if err != nil { + log.Fatal(err) + } + client, err := lock.StartService(device, lockdown.CRASH_REPORT_MOVER_SERVICE) + if err != nil { + log.Fatal(err) + } + err = client.ReadPing() + if err != nil { + log.Fatal(err) + } else { + log.Println("yay we did it") + } +}