#include "MobileDevice.h"
#include <assert.h>
static void cb(am_device_notification_callback_info *info, void *foo) {
struct am_device *dev;
CFStringRef error;
printf("... %x\n", info->msg);
if(info->msg == ADNCI_MSG_CONNECTED) {
dev = info->dev;
afc_connection *socket = NULL;
AMDeviceConnect(dev);
assert(AMDeviceIsPaired(dev));
assert(AMDeviceValidatePairing(dev) == 0);
assert(AMDeviceStartSession(dev) == 0);
AMDeviceStartService(dev, CFSTR("com.apple.syslog_relay"), (void*)&socket, NULL);
printf("socket=%p\n", socket);
char c;
while(recv((int) socket, &c, 1, 0) == 1) {
if(c != 0)
putchar(c);
}
}
}
int main(int argc, char **argv) {
am_device_notification *notif;
int ret = AMDeviceNotificationSubscribe(cb, 0, 0, NULL, ¬if);
CFRunLoopRun();
}
#ifndef MOBILEDEVICE_H
#define MOBILEDEVICE_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(WIN32)
#include <CoreFoundation.h>
typedef unsigned int mach_error_t;
#elif defined(__APPLE__)
#include <CoreFoundation/CoreFoundation.h>
#include <mach/error.h>
#endif
#define MDERR_APPLE_MOBILE (err_system(0x3a))
#define MDERR_IPHONE (err_sub(0))
#define MDERR_OK ERR_SUCCESS
#define MDERR_SYSCALL (ERR_MOBILE_DEVICE | 0x01)
#define MDERR_OUT_OF_MEMORY (ERR_MOBILE_DEVICE | 0x03)
#define MDERR_QUERY_FAILED (ERR_MOBILE_DEVICE | 0x04)
#define MDERR_INVALID_ARGUMENT (ERR_MOBILE_DEVICE | 0x0b)
#define MDERR_DICT_NOT_LOADED (ERR_MOBILE_DEVICE | 0x25)
#define MDERR_AFC_OUT_OF_MEMORY 0x03
#define MDERR_USBMUX_ARG_NULL 0x16
#define MDERR_USBMUX_FAILED 0xffffffff
#define ADNCI_MSG_CONNECTED 1
#define ADNCI_MSG_DISCONNECTED 2
#define ADNCI_MSG_UNKNOWN 3
#define AMD_IPHONE_PRODUCT_ID 0x1290
#define AMD_IPHONE_SERIAL "3391002d9c804d105e2c8c7d94fc35b6f3d214a3"
#define AMSVC_AFC CFSTR("com.apple.afc")
#define AMSVC_BACKUP CFSTR("com.apple.mobilebackup")
#define AMSVC_CRASH_REPORT_COPY CFSTR("com.apple.crashreportcopy")
#define AMSVC_DEBUG_IMAGE_MOUNT CFSTR("com.apple.mobile.debug_image_mount")
#define AMSVC_NOTIFICATION_PROXY CFSTR("com.apple.mobile.notification_proxy")
#define AMSVC_PURPLE_TEST CFSTR("com.apple.purpletestr")
#define AMSVC_SOFTWARE_UPDATE CFSTR("com.apple.mobile.software_update")
#define AMSVC_SYNC CFSTR("com.apple.mobilesync")
#define AMSVC_SCREENSHOT CFSTR("com.apple.screenshotr")
#define AMSVC_SYSLOG_RELAY CFSTR("com.apple.syslog_relay")
#define AMSVC_SYSTEM_PROFILER CFSTR("com.apple.mobile.system_profiler")
typedef unsigned int afc_error_t;
typedef unsigned int usbmux_error_t;
typedef unsigned int service_conn_t;
struct am_recovery_device;
typedef struct am_device_notification_callback_info {
struct am_device *dev;
unsigned int msg;
} __attribute__ ((packed)) am_device_notification_callback_info;
typedef void (*am_restore_device_notification_callback)(struct
am_recovery_device *);
typedef struct am_recovery_device {
unsigned char unknown0[8];
am_restore_device_notification_callback callback;
void *user_info;
unsigned char unknown1[12];
unsigned int readwrite_pipe;
unsigned char read_pipe;
unsigned char write_ctrl_pipe;
unsigned char read_unknown_pipe;
unsigned char write_file_pipe;
unsigned char write_input_pipe;
} __attribute__ ((packed)) am_recovery_device;
typedef struct am_restore_device {
unsigned char unknown[32];
int port;
} __attribute__ ((packed)) am_restore_device;
typedef void(*am_device_notification_callback)(struct
am_device_notification_callback_info *, void* arg);
typedef void *amd_device_attached_callback;
typedef struct am_device {
unsigned char unknown0[16];
unsigned int device_id;
unsigned int product_id;
char *serial;
unsigned int unknown1;
unsigned char unknown2[4];
unsigned int lockdown_conn;
unsigned char unknown3[8];
} __attribute__ ((packed)) am_device;
typedef struct am_device_notification {
unsigned int unknown0;
unsigned int unknown1;
unsigned int unknown2;
am_device_notification_callback callback;
unsigned int unknown3;
} __attribute__ ((packed)) am_device_notification;
typedef struct afc_connection {
unsigned int handle;
unsigned int unknown0;
unsigned char unknown1;
unsigned char padding[3];
unsigned int unknown2;
unsigned int unknown3;
unsigned int unknown4;
unsigned int fs_block_size;
unsigned int sock_block_size;
unsigned int io_timeout;
void *afc_lock;
unsigned int context;
} __attribute__ ((packed)) afc_connection;
typedef struct afc_directory {
unsigned char unknown[0];
} __attribute__ ((packed)) afc_directory;
typedef struct afc_dictionary {
unsigned char unknown[0];
} __attribute__ ((packed)) afc_dictionary;
typedef unsigned long long afc_file_ref;
typedef struct usbmux_listener_1 {
unsigned int unknown0;
unsigned char *unknown1;
amd_device_attached_callback callback;
unsigned int unknown3;
unsigned int unknown4;
unsigned int unknown5;
} __attribute__ ((packed)) usbmux_listener_1;
typedef struct usbmux_listener_2 {
unsigned char unknown0[4144];
} __attribute__ ((packed)) usbmux_listener_2;
typedef struct am_bootloader_control_packet {
unsigned char opcode;
unsigned char length;
unsigned char magic[2];
unsigned char payload[0];
} __attribute__ ((packed)) am_bootloader_control_packet;
void AMDSetLogLevel(int level);
mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback
callback, unsigned int unused0, unsigned int unused1, void*
dn_unknown3, struct am_device_notification **notification);
mach_error_t AMDeviceConnect(struct am_device *device);
int AMDeviceIsPaired(struct am_device *device);
mach_error_t AMDeviceValidatePairing(struct am_device *device);
mach_error_t AMDeviceStartSession(struct am_device *device);
mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef
service_name, service_conn_t *handle, unsigned int *
unknown);
mach_error_t AMDeviceStartHouseArrestService(struct am_device *device, CFStringRef identifier, void *unknown, service_conn_t *handle, unsigned int *what);
mach_error_t AMDeviceStopSession(struct am_device *device);
afc_error_t AFCConnectionOpen(service_conn_t handle, unsigned int io_timeout,
struct afc_connection **conn);
afc_error_t AFCDeviceInfoOpen(afc_connection *conn, struct
afc_dictionary **info);
void AFCPlatformInit();
afc_error_t AFCDirectoryOpen(afc_connection *conn, const char *path,
struct afc_directory **dir);
afc_error_t AFCDirectoryRead(afc_connection *conn, struct afc_directory *dir,
char **dirent);
afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);
afc_error_t AFCDirectoryCreate(afc_connection *conn, const char *dirname);
afc_error_t AFCRemovePath(afc_connection *conn, const char *dirname);
afc_error_t AFCRenamePath(afc_connection *conn, const char *from, const char *to);
afc_error_t AFCLinkPath(afc_connection *conn, long long int linktype, const char *target, const char *linkname);
unsigned int AFCConnectionGetContext(afc_connection *conn);
unsigned int AFCConnectionGetFSBlockSize(afc_connection *conn);
unsigned int AFCConnectionGetIOTimeout(afc_connection *conn);
unsigned int AFCConnectionGetSocketBlockSize(afc_connection *conn);
afc_error_t AFCConnectionClose(afc_connection *conn);
unsigned int AMRestoreRegisterForDeviceNotifications(
am_restore_device_notification_callback dfu_connect_callback,
am_restore_device_notification_callback recovery_connect_callback,
am_restore_device_notification_callback dfu_disconnect_callback,
am_restore_device_notification_callback recovery_disconnect_callback,
unsigned int unknown0,
void *user_info);
unsigned int AMRestoreEnableFileLogging(char *path);
CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);
afc_error_t AFCFileRefOpen(afc_connection *conn, const char *path,
unsigned long long mode, afc_file_ref *ref);
afc_error_t AFCFileRefSeek(afc_connection *conn, afc_file_ref ref,
unsigned long long offset1, unsigned long long offset2);
afc_error_t AFCFileRefRead(afc_connection *conn, afc_file_ref ref,
void *buf, unsigned int *len);
afc_error_t AFCFileRefSetFileSize(afc_connection *conn, afc_file_ref ref,
unsigned long long offset);
afc_error_t AFCFileRefWrite(afc_connection *conn, afc_file_ref ref,
const void *buf, unsigned int len);
afc_error_t AFCFileRefClose(afc_connection *conn, afc_file_ref ref);
afc_error_t AFCFileInfoOpen(afc_connection *conn, const char *path, struct
afc_dictionary **info);
afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **
val);
afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);
unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *
rdev, CFDictionaryRef opts, void *callback, void *user_info);
unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *
rdev, CFDictionaryRef opts, void *callback, void *user_info);
struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,
unsigned int connection_id, unsigned int unknown1);
unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,
CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int
unknown0, CFStringRef *firmware_dir_path, CFStringRef *
kernelcache_restore_path, unsigned int unknown1, CFStringRef *
ramdisk_path);
unsigned int AMDeviceGetConnectionID(struct am_device *device);
mach_error_t AMDeviceEnterRecovery(struct am_device *device);
mach_error_t AMDeviceDisconnect(struct am_device *device);
mach_error_t AMDeviceRetain(struct am_device *device);
mach_error_t AMDeviceRelease(struct am_device *device);
CFStringRef AMDeviceCopyValue(struct am_device *device, unsigned int, CFStringRef cfstring);
CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);
typedef void (*notify_callback)(CFStringRef notification, void *data);
mach_error_t AMDPostNotification(service_conn_t socket, CFStringRef notification, CFStringRef userinfo);
mach_error_t AMDObserveNotification(void *socket, CFStringRef notification);
mach_error_t AMDListenForNotifications(void *socket, notify_callback cb, void *data);
mach_error_t AMDShutdownNotificationProxy(void *socket);
mach_error_t AMDeviceDeactivate(struct am_device *device);
mach_error_t AMDeviceActivate(struct am_device *device, CFMutableDictionaryRef);
void *AMDeviceSerialize(struct am_device *device);
void AMDAddLogFileDescriptor(int fd);
kern_return_t AMDeviceSendMessage(service_conn_t socket, void *unused, CFPropertyListRef plist);
kern_return_t AMDeviceReceiveMessage(service_conn_t socket, CFDictionaryRef options, CFPropertyListRef * result);
usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct
usbmux_listener_2 **eax_fp12);
usbmux_error_t USBMuxListenerHandleData(void *);
typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,
CFDictionaryRef op);
#ifdef __cplusplus
}
#endif
#endif