Skip to content

Commit

Permalink
first pass at adding support to lockdown for copying crashlogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Moody authored and dylanhitt committed Aug 12, 2024
1 parent cd145ff commit c06bea3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lockdown/lockdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package lockdown

// #cgo pkg-config: libimobiledevice-1.0
// #include <stdlib.h>
// #include <libimobiledevice/libimobiledevice.h>
// #include <libimobiledevice/lockdown.h>
// #include <libimobiledevice/service.h>
import "C"
import (
"errors"
"unsafe"

"github.com/nowsecure/goidevice/idevice"
Expand All @@ -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 {
Expand Down Expand Up @@ -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(":(((")
}
}
}
30 changes: 30 additions & 0 deletions thing/main.go
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit c06bea3

Please sign in to comment.