Created
May 8, 2015 06:06
-
-
Save comex/dae8412238361503622b to your computer and use it in GitHub Desktop.
4 year old code to talk to a DeveloperDiskImage service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MobileDevice.h" | |
#include <assert.h> | |
#include <unistd.h> | |
#include <sys/socket.h> | |
#define bswap32 __builtin_bswap32 | |
static uint32_t read32(int fd) { | |
uint32_t ret; | |
assert(read(fd, &ret, sizeof(ret)) == sizeof(ret)); | |
return bswap32(ret); | |
} | |
static void write32(int fd, uint32_t val) { | |
val = bswap32(val); | |
assert(write(fd, &val, sizeof(val)) == sizeof(val)); | |
} | |
static int filenum; | |
static void cb(am_device_notification_callback_info *info, void *foo) { | |
struct am_device *dev; | |
if(info->msg == ADNCI_MSG_CONNECTED) { | |
dev = info->dev; | |
service_conn_t socket = 0; | |
AMDeviceConnect(dev); | |
assert(AMDeviceIsPaired(dev)); | |
assert(!AMDeviceValidatePairing(dev)); | |
assert(!AMDeviceStartSession(dev)); | |
assert(!AMDeviceStartService(dev, CFSTR("com.apple.dt.fetchsymbols"), (void*)&socket, NULL)); | |
if(filenum == -1) { | |
write32(socket, 0); | |
assert(read32(socket) == 0); | |
uint32_t nitems = read32(socket); | |
for(uint32_t i = 0; i < nitems; i++) { | |
uint32_t length = read32(socket); | |
void *buf = malloc(length); | |
assert(read(socket, buf, length) == length); | |
printf("%u: %*s\n", i, (int) length, (char *) buf); | |
free(buf); | |
} | |
} else { | |
write32(socket, 1); | |
assert(read32(socket) == 1); | |
write32(socket, (uint32_t) filenum); | |
uint32_t err = read32(socket), length = read32(socket); | |
fprintf(stderr, "%x\n", length); | |
assert(!err); | |
void *buf = malloc(length); | |
assert(recv(socket, buf, length, MSG_WAITALL) == length); | |
assert(write(1, buf, length) == length); | |
} | |
exit(0); | |
} | |
} | |
int main(int argc, char **argv) { | |
if(argv[1]) { | |
filenum = atoi(argv[1]); | |
} else { | |
filenum = -1; | |
} | |
am_device_notification *notif; | |
assert(!AMDeviceNotificationSubscribe(cb, 0, 0, NULL, ¬if)); | |
CFRunLoopRun(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment