Esempio n. 1
0
void uninstall_app(AMDeviceRef device) {
    CFStringRef path = CFStringCreateWithCString(NULL, bundle_id, kCFStringEncodingASCII);

    service_conn_t installFd = start_install_proxy_service(device);

    mach_error_t result = AMDeviceUninstallApplication (installFd, path, NULL, operation_callback, NULL);
    if (result != 0)
    {
        PRINT("AMDeviceUninstallApplication failed: %d\n", result);
        exit(1);
    }

    close(installFd);
    CFRelease(path);
}
Esempio n. 2
0
void handle_device(AMDeviceRef device) {
    if (found_device) return; // handle one device only

    CFStringRef found_device_id = AMDeviceCopyDeviceIdentifier(device);

    PRINT ("found device id\n");
    if (device_id != NULL) {
        if(strcmp(device_id, CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding())) == 0) {
            found_device = true;
        } else {
            return;
        }
    } else {
        if (operation == OP_LIST_DEVICES) {
            printf ("%s\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding()));
            CFRetain(device); // don't know if this is necessary?
            return;
        }
        found_device = true;
    }

    CFRetain(device); // don't know if this is necessary?

    PRINT("[  0%%] Found device (%s), beginning install\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding()));

    AMDeviceConnect(device);
    assert(AMDeviceIsPaired(device));
    assert(AMDeviceValidatePairing(device) == 0);
    assert(AMDeviceStartSession(device) == 0);

    CFStringRef path = CFStringCreateWithCString(NULL, app_path, kCFStringEncodingASCII);
    CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, false);
    CFURLRef url = CFURLCopyAbsoluteURL(relative_url);

    CFRelease(relative_url);

    int afcFd;
	int startServiceAFCRetval = AMDeviceStartService(device, CFSTR("com.apple.afc"), (service_conn_t *) &afcFd, NULL);
	printf("trying to start com.apple.afc : %d\n", startServiceAFCRetval);
	
	if( startServiceAFCRetval )
	{
		sleep(1);
		//printf("trying to start com.apple.afc\n");
		startServiceAFCRetval = AMDeviceStartService(device, CFSTR("com.apple.afc"), (service_conn_t *) &afcFd, NULL);
	}
	printf("trying to start com.apple.afc : %d\n", startServiceAFCRetval);
    assert(startServiceAFCRetval == 0);
    assert(AMDeviceStopSession(device) == 0);
    assert(AMDeviceDisconnect(device) == 0);

    if (operation == OP_INSTALL) {
        assert(AMDeviceTransferApplication(afcFd, path, NULL, transfer_callback, NULL) == 0);
        close(afcFd);
    }

    CFStringRef keys[] = { CFSTR("PackageType") };
    CFStringRef values[] = { CFSTR("Developer") };
    CFDictionaryRef options = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    AMDeviceConnect(device);
    assert(AMDeviceIsPaired(device));
    assert(AMDeviceValidatePairing(device) == 0);
    assert(AMDeviceStartSession(device) == 0);

    int installFd;
    assert(AMDeviceStartService(device, CFSTR("com.apple.mobile.installation_proxy"), (service_conn_t *) &installFd, NULL) == 0);

    //assert(AMDeviceStopSession(device) == 0);
    //assert(AMDeviceDisconnect(device) == 0);

    if (operation == OP_INSTALL) {
        mach_error_t result = AMDeviceSecureInstallApplication(0, device, url, options, &operation_callback, 0);
        //mach_error_t result = AMDeviceInstallApplication(installFd, path, options, operation_callback, NULL);
        if (result != 0)
        {
			PRINT("AMDeviceInstallApplication failed: %d\n", result);
			exit(EXIT_FAILURE);
        }
    }
	else if (operation == OP_UNINSTALL) {
        mach_error_t result = AMDeviceUninstallApplication (installFd, path, NULL, operation_callback, NULL);
        if (result != 0)
        {
			PRINT("AMDeviceUninstallApplication failed: %d\n", result);
			exit(EXIT_FAILURE);
        }
    }
    
    assert(AMDeviceStopSession(device) == 0);
    assert(AMDeviceDisconnect(device) == 0);


    close(installFd);

    CFRelease(path);
    CFRelease(options);

    if (operation == OP_INSTALL)
        PRINT("[100%%] Installed package %s\n", app_path);
    else if (operation == OP_UNINSTALL)
        PRINT("[100%%] Uninstalled package %s\n", app_path);


    if (!debug) exit(EXIT_SUCCESS); // no debug phase

    AMDeviceConnect(device);
    assert(AMDeviceIsPaired(device));
    assert(AMDeviceValidatePairing(device) == 0);
    assert(AMDeviceStartSession(device) == 0);

    PRINT("------ Debug phase ------\n");

    mount_developer_image(device);      // put debugserver on the device
    start_remote_debug_server(device);  // start debugserver
    write_gdb_prep_cmds(device, url);   // dump the necessary gdb commands into a file

    CFRelease(url);

    PRINT("[100%%] Connecting to remote debug server\n");
    PRINT("-------------------------\n");

    signal(SIGHUP, gdb_ready_handler);

    pid_t parent = getpid();
    int pid = fork();
    if (pid == 0) {
        system(GDB_SHELL);      // launch gdb
        kill(parent, SIGHUP);  // "No. I am your father."
        _exit(EXIT_SUCCESS);
    }
}