Beispiel #1
0
CFStringRef copy_developer_disk_image_path(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
    const char *home = getenv("HOME");
    CFStringRef path;
    bool found = false;

	CFStringRef xcodeDevPath = copy_xcode_dev_path();

	path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@ (%@)/DeveloperDiskImage.dmg"), home, version, build);
	found = path_exists(path);

	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@/DeveloperDiskImage.dmg"), home, version);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/Latest/DeveloperDiskImage.dmg"), home);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@)/DeveloperDiskImage.dmg"), xcodeDevPath, version, build);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/%@/DeveloperDiskImage.dmg"), xcodeDevPath, version);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/Latest/DeveloperDiskImage.dmg"), xcodeDevPath);
		found = path_exists(path);
	}

	CFRelease(version);
	CFRelease(build);
	CFRelease(xcodeDevPath);

    if (!found)
	{
		PRINT("[ !! ] Unable to locate DeviceSupport directory containing DeveloperDiskImage.dmg.\n");

		CFIndex pathLength = CFStringGetLength(path);
		char *buffer = calloc(pathLength + 1, sizeof(char));
		Boolean success = CFStringGetCString(path, buffer, pathLength + 1, kCFStringEncodingUTF8);
		CFRelease(path);

		if (success) PRINT("[ !! ] Last path checked: %s\n", buffer);
		exit(EXIT_FAILURE);
	}

	return path;
}
Beispiel #2
0
CFStringRef copy_device_support_path(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
    const char* home = getenv("HOME");
    CFStringRef path;
    bool found = false;

	CFStringRef xcodeDevPath = copy_xcode_dev_path();

	path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@ (%@)"), home, version, build);
	found = path_exists(path);

	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@"), home, version);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/Latest"), home);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@)"), xcodeDevPath, version, build);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/%@"), xcodeDevPath, version);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/Latest"), xcodeDevPath);
		found = path_exists(path);
	}

	CFRelease(version);
	CFRelease(build);
	CFRelease(xcodeDevPath);

	if (!found)
	{
		PRINT("[ !! ] Unable to locate DeviceSupport directory.\n");
		CFRelease(path);
		exit(EXIT_FAILURE);
	}

	return path;
}
kern_return_t test_apple_AMDeviceCopyValue(struct am_device *apple, CFTypeRef *value) {
	kern_return_t apple_return = kAMDUndefinedError;
	CFTypeRef apple_value = NULL;
	kern_return_t result = AMDeviceConnect(apple);
	if (SDM_MD_CallSuccessful(result)) {
		
		if (SDMMD_AMDeviceGetInterfaceType((SDMMD_AMDeviceRef)apple) == kAMDInterfaceConnectionTypeIndirect) {
			AMDeviceStartSession(apple);
		}
		
		apple_value = AMDeviceCopyValue(apple, NULL, CFSTR(kUniqueDeviceID));
		if (apple_value == NULL || CFStringCompare(apple_value, CFSTR("GetProhibited"), 0) == kCFCompareEqualTo) {
			printf("\t\tAMDeviceCopyValue: GetProhibited\n");
			apple_return = kAMDGetProhibitedError;
			CFSafeRelease(apple_value);
		}
		else {
			*value = apple_value;
			apple_return = kAMDSuccess;
		}
		
		if (SDMMD_AMDeviceGetInterfaceType((SDMMD_AMDeviceRef)apple) == kAMDInterfaceConnectionTypeIndirect) {
			AMDeviceStopSession(apple);
		}
		
		AMDeviceDisconnect(apple);
	}
	return apple_return;
}
Beispiel #4
0
CFStringRef copy_developer_disk_image_path(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
    const char *home = getenv("HOME");
    CFStringRef path;
    bool found = false;

    path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@ (%@)/DeveloperDiskImage.dmg"), home, version, build);
    found = path_exists(path);

    if (!found) {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@/DeveloperDiskImage.dmg)"), version, build);
        found = path_exists(path);
    }
    if (!found) {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/@%/DeveloperDiskImage.dmg"), home, version);
        found = path_exists(path);
    }
    if (!found) {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/@%/DeveloperDiskImage.dmg"), version);
        found = path_exists(path);
    }
    if (!found) {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/Latest/DeveloperDiskImage.dmg"), home);
        found = path_exists(path);
    }
    if (!found) {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/Latest/DeveloperDiskImage.dmg"));
        found = path_exists(path);
    }
    if (!found)
    {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/6.1 (10B141)/DeveloperDiskImage.dmg"));
        found = path_exists(path);
    }

    CFRelease(version);
    CFRelease(build);

    if (!found) {
        CFRelease(path);
        PRINT("[ !! ] Unable to locate DeviceSupport directory containing DeveloperDiskImage.dmg.\n");
        exit(1);
    }

    return path;
}
CFMutableArrayRef get_device_product_version_parts(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFArrayRef parts = CFStringCreateArrayBySeparatingStrings(NULL, version, CFSTR("."));
    CFMutableArrayRef result = CFArrayCreateMutableCopy(NULL, CFArrayGetCount(parts), parts);
    CFRelease(version);
    CFRelease(parts);
    return result;
}
Beispiel #6
0
CFStringRef copy_device_support_path(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
    CFStringRef path_with_build = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@)"), version, build);
    CFStringRef path_without_build = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@"), version);
    CFRelease(version);
    CFRelease(build);

    // they tack the build number on for beta builds
    // there is almost certainly a better way of doing this
    if (path_exists(path_with_build)) {
        CFRelease(path_without_build);
        return path_with_build;
    } else if (path_exists(path_without_build)) {
        CFRelease(path_with_build);
        return path_without_build;
    } else {
        printf("[ !! ] Unable to locate DeviceSupport directory.\n");
        exit(1);
    }
}
void FIOSDeviceHelper::DoDeviceConnect(void* deviceHandle)
{
    // connect to the device
    IOSDevice* Device = new IOSDevice(deviceHandle);
    bool Connected = Device->Connect();
    if (Connected)
    {
        // get the needed data
        CFStringRef deviceName = AMDeviceCopyValue(deviceHandle, 0, CFSTR("DeviceName"));
        CFStringRef deviceId = AMDeviceCopyValue(deviceHandle, 0, CFSTR("UniqueDeviceID"));
		CFStringRef productType = AMDeviceCopyValue(deviceHandle, 0, CFSTR("ProductType"));

        // fire the event
        TCHAR idBuffer[128];
		TCHAR nameBuffer[256];
		TCHAR productBuffer[128];
		FPlatformString::CFStringToTCHAR(deviceId, idBuffer);
		FPlatformString::CFStringToTCHAR(deviceName, nameBuffer);
		FPlatformString::CFStringToTCHAR(productType, productBuffer);
		FIOSLaunchDaemonPong Event;
        Event.DeviceID = FString::Printf(TEXT("%s@%s"), (FString(productBuffer).Contains("AppleTV") ? TEXT("TVOS") : TEXT("IOS")), idBuffer);
		Event.DeviceName = FString::Printf(TEXT("%s"), nameBuffer);
        Event.bCanReboot = false;
        Event.bCanPowerOn = false;
        Event.bCanPowerOff = false;
		Event.DeviceType = FString::Printf(TEXT("%s"), productBuffer);
		FIOSDeviceHelper::OnDeviceConnected().Broadcast(Event);
                
        // add to the device list
        ConnectedDevices.Add(Device, Event);
        
        // disconnect the device for now
        Device->Disconnect();
    }
    else
    {
        UE_LOG(LogTemp, Display, TEXT("Couldn't connect to device"));
    }
}
CFStringRef copy_device_support_path(AMDeviceRef device) {
    CFStringRef version = NULL;
    CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
    CFStringRef path = NULL;
    CFMutableArrayRef version_parts = get_device_product_version_parts(device);

    while (CFArrayGetCount(version_parts) > 0) {
        version = CFStringCreateByCombiningStrings(NULL, version_parts, CFSTR("."));
        if (path == NULL) {
            path = copy_xcode_path_for(CFSTR("iOS DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), version, build));
        }
        if (path == NULL) {
            path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), version, build));
        }
        if (path == NULL) {
            path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (*)"), version, build));
        }
        if (path == NULL) {
            path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), version);
        }
        if (path == NULL) {
            path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport/Latest"), CFSTR(""));
        }
        CFRelease(version);
        if (path != NULL) {
            break;
        }
        CFArrayRemoveValueAtIndex(version_parts, CFArrayGetCount(version_parts) - 1);
    }
    
    CFRelease(version_parts);
    CFRelease(build);

    if (path == NULL)
    {
        printf("[ !! ] Unable to locate DeviceSupport directory.\n[ !! ] This probably means you don't have Xcode installed, you will need to launch the app manually and logging output will not be shown!\n");
        exit(1);
    }

    return path;
}
kern_return_t test_apple_Sessioned_AMDeviceCopyValue(struct am_device *apple, CFTypeRef *value) {
	kern_return_t apple_return = kAMDUndefinedError;
	CFTypeRef apple_value = NULL;
	kern_return_t result = AMDeviceConnect(apple);
	if (SDM_MD_CallSuccessful(result)) {
		result = AMDeviceStartSession(apple);
		if (SDM_MD_CallSuccessful(result)) {
			apple_value = AMDeviceCopyValue(apple, CFSTR(kInternationalDomain), CFSTR(kLanguage));
			if (apple_value == NULL || CFStringCompare(apple_value, CFSTR("GetProhibited"), 0) == kCFCompareEqualTo) {
				printf("\t\tappleMD_AMDeviceCopyValue (w/ Session): GetProhibited\n");
				apple_return = kAMDGetProhibitedError;
				CFSafeRelease(apple_value);
			}
			else {
				*value = apple_value;
				apple_return = kAMDSuccess;
			}
			AMDeviceStopSession(apple);
		}
		AMDeviceDisconnect(apple);
	}
	return apple_return;
}
Beispiel #10
0
static void cb(am_device_notification_callback_info * info, void *foo)
{
	struct am_device *dev;

	if (info->msg == ADNCI_MSG_CONNECTED) {
		dev = info->dev;

		AMDeviceConnect(dev);
		assert(AMDeviceIsPaired(dev));
		assert(!AMDeviceValidatePairing(dev));
		assert(!AMDeviceStartSession(dev));

		CFStringRef product =
		    AMDeviceCopyValue(dev, 0, CFSTR("ProductVersion"));
		assert(product);
		UniChar first = CFStringGetCharacterAtIndex(product, 0);
		int epoch = first - '0';
Retry:	{}
		printf("Attempting to mount image...\n");

		service_conn_t afc_socket = 0;
		struct afc_connection *afc = NULL;
		assert(!AMDeviceStartService(dev, CFSTR("com.apple.afc"), &afc_socket, NULL));
		assert(!AFCConnectionOpen(afc_socket, 0, &afc));
		assert(!AFCDirectoryCreate(afc, "PublicStaging"));

		AFCRemovePath(afc, "PublicStaging/staging.dimage");
		qwrite(afc, real_dmg, "PublicStaging/staging.dimage");
		qwrite(afc, ddi_dmg, "PublicStaging/ddi.dimage");

		service_conn_t mim_socket1 = 0;
		service_conn_t mim_socket2 = 0;
		assert(!AMDeviceStartService(dev, CFSTR("com.apple.mobile.mobile_image_mounter"), &mim_socket1, NULL));
		assert(mim_socket1);

		CFPropertyListRef result = NULL;
		CFMutableDictionaryRef dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
		CFDictionarySetValue(dict, CFSTR("Command"), CFSTR("MountImage"));
		CFDictionarySetValue(dict, CFSTR("ImageType"), CFSTR("Developer"));

		CFDictionarySetValue(dict, CFSTR("ImagePath"), CFSTR("/var/mobile/Media/PublicStaging/staging.dimage"));

		int fd = open(real_dmg_signature, O_RDONLY);
		assert(fd != -1);
		uint8_t sig[128];
		assert(read(fd, sig, sizeof(sig)) == sizeof(sig));
		close(fd);

		CFDictionarySetValue(dict, CFSTR("ImageSignature"), CFDataCreateWithBytesNoCopy(NULL, sig, sizeof(sig), kCFAllocatorNull));
		send_message(mim_socket1, dict);

		usleep(timesl);
		assert(!AFCRenamePath(afc, "PublicStaging/ddi.dimage", "PublicStaging/staging.dimage"));

		result = receive_message(mim_socket1);

		int len = CFDataGetLength(CFPropertyListCreateXMLData(NULL, result));
		char* bytes = CFDataGetBytePtr(CFPropertyListCreateXMLData(NULL, result));

		if(strstr(bytes, "Complete")) {
			char* the_service = "CopyIt";
			service_conn_t socket = 0;
			sleep(2);
			printf("Image mounted, running helper...\n");
			assert(!AMDeviceStartService(dev, CFStringCreateWithCStringNoCopy(NULL, the_service, kCFStringEncodingUTF8, kCFAllocatorNull),
				&socket, NULL));
			assert(!fcntl(socket, F_SETFL, O_NONBLOCK));
			assert(!fcntl(0, F_SETFL, O_NONBLOCK));
		} else {
			printf("Failed to inject image, trying again... (if it fails, try a different time), delay ... %dus\n", timesl);
			timesl += 1000;
			goto Retry;
		}

		exit(0);
	}
}
Beispiel #11
0
void handle_device(AMDeviceRef device) {
    if (found_device) return; // handle one device only

    CFStringRef found_device_id = AMDeviceCopyDeviceIdentifier(device);

    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) {
            CFStringEncoding encoding = CFStringGetSystemEncoding();
            const char *udi = CFStringGetCStringPtr(found_device_id, encoding);
            
	    AMDeviceConnect(device);            
            if(AMDeviceIsPaired(device) && (AMDeviceValidatePairing(device) == 0) && (AMDeviceStartSession(device) == 0)) {
                const char *device_name  = CFStringGetCStringPtr(AMDeviceCopyValue(device, 0, CFSTR("DeviceName")),     encoding);
                const char *product_type = CFStringGetCStringPtr(AMDeviceCopyValue(device, 0, CFSTR("ProductType")),    encoding);
                const char *ios_version  = CFStringGetCStringPtr(AMDeviceCopyValue(device, 0, CFSTR("ProductVersion")), encoding);
                
                printf ("%s %s %s %s\n", udi, product_type, ios_version, device_name);
            } else {
                printf("%s\n", udi);
            }
            fflush(stdout);
            return;
        }
        found_device = true;
    }

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

        install_app(device);

        PRINT("[100%%] Installed package %s\n", app_path);

        if (debug)
            do_debug(device);

    } else if (operation == OP_UNINSTALL) {
        PRINT("[  0%%] Found device (%s), beginning uninstall\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding()));

        uninstall_app(device);

        PRINT("[100%%] uninstalled package %s\n", bundle_id);

    } else if (operation == OP_UPLOAD_FILE) {
        PRINT("[  0%%] Found device (%s), sending file\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding()));

        upload_file(device);

        PRINT("[100%%] file sent %s\n", doc_file_path);

    } else if (operation == OP_LIST_FILES) {
        PRINT("[  0%%] Found device (%s), listing / ...\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding()));

        list_files(device);

        PRINT("[100%%] done.\n");
    }
    exit(0);
}
void onDevice(am_device_notification_callback_info* info, void* _) {
    if (info->msg!=ADNCI_MSG_CONNECTED) return;

    am_device* device = info->dev;

    CFStringRef id = AMDeviceCopyDeviceIdentifier(device);
    // CFShow(id);
    CFRelease(id);

    check("Connecting to device",
            AMDeviceConnect(device));
    check("Validate pairing",
            AMDeviceValidatePairing(device));
    check("Starting a session",
            AMDeviceStartSession(device));

    char* properties[] = {
        // "ActivationPublicKey",
        "ActivationState",
        "BluetoothAddress",
        "BuildVersion",
        "CPUArchitecture",
        // "DeviceCertificate",
        "DeviceClass",  // iPhone, iPad, iPod, etc.
        "DeviceColor",
        "DeviceName",
        //"DieID",
        "FirmwareVersion",
        "HardwareModel",
        "HardwarePlatform",
        "InternationalMobileEquipmentIdentity",
        "MLBSerialNumber",
        "ModelNumber",
        "PhoneNumber",
        "ProductType",
        "ProductVersion", // iOS version
        "SerialNumber",
        "SIMStatus",
        // "SupportedDeviceFamilies",
        // "UniqueChipID",
        "UniqueDeviceID",
        "WiFiAddress",
        NULL}; 

    int i;
    for (i=0; properties[i]!=NULL; i++) {
        char* prop = properties[i];
        CFStringRef cprop = CFStringCreateWithCString(NULL,prop,kCFStringEncodingUTF8);
        CFStringRef s = AMDeviceCopyValue(device,0,cprop);

        if (s==NULL) {
            // no property value
        } else {
            //CFShow(s);
            int cflen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(s),kCFStringEncodingUTF8);
            char* p = (char*)malloc(cflen+1);

            CFStringGetCString(s, p, cflen, kCFStringEncodingUTF8);

            printf("%s=%s\n", prop,p,cflen);
            CFRelease(s);
        }
        CFRelease(cprop);
    }
    puts(""); // separator
    check("Disconnecting",AMDeviceStopSession(device));
}