Пример #1
0
kern_return_t test_apple_AFCOperationCreateGetConnectionInfo(struct am_device *apple, CFTypeRef *response) {
	kern_return_t apple_return = kAMDUndefinedError;
	kern_return_t result = AMDeviceConnect(apple);
	if (SDM_MD_CallSuccessful(result)) {
		result = AMDeviceStartSession(apple);
		if (SDM_MD_CallSuccessful(result)) {
			service_conn_t test_apple_afc_conn;
			result = AMDeviceStartService(apple, CFSTR(AMSVC_AFC), &test_apple_afc_conn, NULL);
			if (SDM_MD_CallSuccessful(result)) {
				struct afc_connection *afc = NULL;
				result = AFCConnectionOpen(test_apple_afc_conn, 0, &afc);
				if (afc) {
					afc_operation conn_info = AFCOperationCreateGetConnectionInfo(kCFAllocatorDefault, NULL);
					result = AFCConnectionProcessOperation(afc, conn_info, 0);
					if (SDM_MD_CallSuccessful(result)) {
						CFTypeRef test = AFCOperationGetResultObject(conn_info);
						if (test) {
							*response = test;
							apple_return = kAMDSuccess;
						}
					}
					AFCConnectionClose(afc);
				}
			}
			AMDeviceStopSession(apple);
		}
		AMDeviceDisconnect(apple);
	}
	return apple_return;
}
Пример #2
0
kern_return_t test_sdm_AFCConnectionCreate(SDMMD_AMDeviceRef sdm) {
	kern_return_t sdm_return = kAMDUndefinedError;
	kern_return_t result = SDMMD_AMDeviceConnect(sdm);
	if (SDM_MD_CallSuccessful(result)) {
		result = SDMMD_AMDeviceStartSession(sdm);
		if (SDM_MD_CallSuccessful(result)) {
			SDMMD_AMConnectionRef test_sdm_afc_conn;
			if (SDMMD_AMDeviceGetInterfaceType(sdm) == kAMDInterfaceConnectionTypeIndirect) {
				result = SDMMD_AMDeviceSecureStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_afc_conn);
			}
			else {
				result = SDMMD_AMDeviceStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_afc_conn);
			}
			if (SDM_MD_CallSuccessful(result)) {
				SDMMD_AFCConnectionRef afc = SDMMD_AFCConnectionCreate(test_sdm_afc_conn);
				if (afc) {
					sdm_return = kAMDSuccess;
					CFSafeRelease(test_sdm_afc_conn);
					CFSafeRelease(afc);
				}
			}
			SDMMD_AMDeviceStopSession(sdm);
		}
		SDMMD_AMDeviceDisconnect(sdm);
	}
	return sdm_return;
}
Пример #3
0
void EnableExtendedLogging(SDMMD_AMDeviceRef device)
{
	sdmmd_return_t result = SDMMD_AMDeviceConnect(device);
	if (SDM_MD_CallSuccessful(result)) {
		result = SDMMD_AMDeviceStartSession(device);
		if (SDM_MD_CallSuccessful(result)) {
			CFTypeRef value = SDMMD_AMDeviceCopyValue(device, CFSTR(AMSVC_MOBILE_DEBUG), CFSTR(kEnableLockdownExtendedLogging));
			if (CFGetTypeID(value) == CFBooleanGetTypeID()) {
				if (!CFBooleanGetValue(value)) {
					result = SDMMD_AMDeviceSetValue(device, CFSTR(AMSVC_MOBILE_DEBUG), CFSTR(kEnableLockdownExtendedLogging), kCFBooleanTrue);
					if (SDM_MD_CallSuccessful(result)) {
						printf("Enabling extended logging...\n");
					}
				}
				else {
					printf("Extended logging already enabled.\n");
				}
			}
			else {
				PrintCFType(value);
			}
			CFSafeRelease(value);
		}
		SDMMD_AMDeviceStopSession(device);
		SDMMD_AMDeviceDisconnect(device);
	}
}
Пример #4
0
void LookupAppsOnDevice(char *udid)
{
	SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid);
	if (device) {
		sdmmd_return_t result = SDMMD_AMDeviceConnect(device);
		if (SDM_MD_CallSuccessful(result)) {
			result = SDMMD_AMDeviceStartSession(device);
			if (SDM_MD_CallSuccessful(result)) {
				CFDictionaryRef response;

				//CFMutableArrayRef lookupValues = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
				//CFArrayAppendValue(lookupValues, CFSTR(kAppLookupKeyCFBundleIdentifier));
				//CFArrayAppendValue(lookupValues, CFSTR("SequenceNumber"));
				CFArrayRef lookupValues = SDMMD_ApplicationLookupDictionary();
				CFMutableDictionaryRef optionsDict = SDMMD_create_dict();
				CFDictionarySetValue(optionsDict, CFSTR("ReturnAttributes"), lookupValues);

				//CFDictionarySetValue(optionsDict, CFSTR("com.apple.mobile_installation.metadata"), kCFBooleanTrue);
				//CFDictionarySetValue(optionsDict, CFSTR("BundleIDs"), kCFBooleanTrue);

				result = SDMMD_AMDeviceLookupApplications(device, optionsDict, &response);
				if (SDM_MD_CallSuccessful(result)) {
					PrintCFDictionary(response);
				}
				SDMMD_AMDeviceStopSession(device);
			}
			SDMMD_AMDeviceDisconnect(device);
		}
	}
}
Пример #5
0
SDMMD_AMConnectionRef AttachToDeviceAndService(SDMMD_AMDeviceRef device, char *service) {
	SDMMD_AMConnectionRef serviceCon = NULL;
	if (device) {
		sdmmd_return_t result = SDMMD_AMDeviceConnect(device);
		if (SDM_MD_CallSuccessful(result)) {
			result = SDMMD_AMDeviceStartSession(device);
			if (SDM_MD_CallSuccessful(result)) {
				CFStringRef serviceString = CFStringCreateWithCString(kCFAllocatorDefault, service, kCFStringEncodingMacRoman);
				result = SDMMD_AMDeviceStartService(device, serviceString, NULL, &serviceCon);
				if (SDM_MD_CallSuccessful(result)) {
					CFTypeRef deviceName = SDMMD_AMDeviceCopyValue(device, NULL, CFSTR(kDeviceName));
					char *name = (char*)CFStringGetCStringPtr(deviceName,kCFStringEncodingMacRoman);
					if (!name) {
						name = "unnamed device";
					}
					printf("Connected to %s on \"%s\" ...\n",name,service);
					CFSafeRelease(deviceName);
				}
				else {
					SDMMD_AMDeviceStopSession(device);
					SDMMD_AMDeviceDisconnect(device);
					serviceCon = NULL;
				}
				CFSafeRelease(serviceString);
			}
		}
	} else {
		printf("Could not find device with that UDID\n");
	}
	return serviceCon;
}
Пример #6
0
kern_return_t test_sdm_AMDeviceLookupApplications(SDMMD_AMDeviceRef sdm, CFTypeRef *value) {
	CFDictionaryRef sdm_response = NULL;
	kern_return_t sdm_return = kAMDUndefinedError;
	kern_return_t result = SDMMD_AMDeviceConnect(sdm);
	if (SDM_MD_CallSuccessful(result)) {
		result = SDMMD_AMDeviceStartSession(sdm);
		if (SDM_MD_CallSuccessful(result)) {
			CFArrayRef lookupValues = SDMMD_ApplicationLookupDictionary();
			CFMutableDictionaryRef optionsDict = SDMMD_create_dict();
			CFDictionarySetValue(optionsDict, CFSTR("ReturnAttributes"), lookupValues);
			sdm_return = SDMMD_AMDeviceLookupApplications(sdm, optionsDict, &sdm_response);
			if (sdm_return != kAMDSuccess) {
				printf("\t\tSDMMD_AMDeviceLookupApplications: %08x %s\n",sdm_return,SDMMD_AMDErrorString(sdm_return));
			}
			else {
				*value = sdm_response;
			}
			CFSafeRelease(optionsDict);
			CFSafeRelease(lookupValues);
			SDMMD_AMDeviceStopSession(sdm);
		}
		SDMMD_AMDeviceDisconnect(sdm);
	}
	return sdm_return;
}
Пример #7
0
kern_return_t test_sdm_AFCOperationCreateGetConnectionInfo(SDMMD_AMDeviceRef sdm, CFTypeRef *response) {
	kern_return_t sdm_return = kAMDUndefinedError;
	kern_return_t result = SDMMD_AMDeviceConnect(sdm);
	if (SDM_MD_CallSuccessful(result)) {
		result = SDMMD_AMDeviceStartSession(sdm);
		if (SDM_MD_CallSuccessful(result)) {
			SDMMD_AMConnectionRef test_sdm_afc_conn;
			if (SDMMD_AMDeviceGetInterfaceType(sdm) == kAMDInterfaceConnectionTypeIndirect) {
				result = SDMMD_AMDeviceSecureStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_afc_conn);
			}
			else {
				result = SDMMD_AMDeviceStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_afc_conn);
			}
			if (SDM_MD_CallSuccessful(result)) {
				SDMMD_AFCConnectionRef afc = SDMMD_AFCConnectionCreate(test_sdm_afc_conn);
				if (afc) {
					SDMMD_AFCOperationRef conn_info = SDMMD_AFCOperationCreateGetConnectionInfo();
					result = SDMMD_AFCProcessOperation(afc, &conn_info);
					if (SDM_MD_CallSuccessful(result)) {
						CFTypeRef test = SDMMD_AFCOperationGetPacketResponse(conn_info);
						if (test) {
							*response = test;
							sdm_return = kAMDSuccess;
						}
					}
					CFSafeRelease(afc);
				}
			}
			SDMMD_AMDeviceStopSession(sdm);
		}
		SDMMD_AMDeviceDisconnect(sdm);
	}
	return sdm_return;
}
kern_return_t test_apple_AMDeviceStopSession(struct am_device *apple) {
	kern_return_t apple_return = kAMDUndefinedError;
	kern_return_t result = AMDeviceConnect(apple);
	if (SDM_MD_CallSuccessful(result)) {
		result = AMDeviceStartSession(apple);
		if (SDM_MD_CallSuccessful(result)) {
			apple_return = AMDeviceStopSession(apple);
			if (apple_return != kAMDSuccess) {
				printf("\t\tAMDeviceStopSession: %08x %s\n",apple_return,SDMMD_AMDErrorString(apple_return));
			}
		}
		AMDeviceDisconnect(apple);
	}
	return apple_return;
}
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;
}
Пример #10
0
kern_return_t test_sdm_AMDeviceSecureStartService(SDMMD_AMDeviceRef sdm) {
	kern_return_t sdm_return = kAMDUndefinedError;
	kern_return_t result = SDMMD_AMDeviceConnect(sdm);
	if (SDM_MD_CallSuccessful(result)) {
		result = SDMMD_AMDeviceStartSession(sdm);
		if (SDM_MD_CallSuccessful(result)) {
			SDMMD_AMConnectionRef test_sdm_conn;
			sdm_return = SDMMD_AMDeviceSecureStartService(sdm, CFSTR(AMSVC_MOBILE_IMAGE_MOUNT), NULL, &test_sdm_conn);
			if (sdm_return != kAMDSuccess) {
				printf("\t\tSDMMD_AMDeviceSecureStartService: %08x %s\n",sdm_return,SDMMD_AMDErrorString(sdm_return));
			}
			SDMMD_AMDeviceStopSession(sdm);
		}
		SDMMD_AMDeviceDisconnect(sdm);
	}
	return sdm_return;
}
Пример #11
0
kern_return_t test_sdm_AFCFileDescriptorCreateWriteOperation(SDMMD_AMDeviceRef sdm, CFTypeRef *response) {
	kern_return_t sdm_return = kAMDUndefinedError;
	kern_return_t result = SDMMD_AMDeviceConnect(sdm);
	if (SDM_MD_CallSuccessful(result)) {
		result = SDMMD_AMDeviceStartSession(sdm);
		if (SDM_MD_CallSuccessful(result)) {
			SDMMD_AMConnectionRef test_sdm_afc_conn;
			if (SDMMD_AMDeviceGetInterfaceType(sdm) == kAMDInterfaceConnectionTypeIndirect) {
				result = SDMMD_AMDeviceSecureStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_afc_conn);
			}
			else {
				result = SDMMD_AMDeviceStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_afc_conn);
			}
			if (SDM_MD_CallSuccessful(result)) {
				SDMMD_AFCConnectionRef afc = SDMMD_AFCConnectionCreate(test_sdm_afc_conn);
				if (afc) {
					SDMMD_AFCOperationRef file_ref = SDMMD_AFCOperationCreateFileRefOpen(CFSTR(kTestCreateFileForAFC), 2);
					result = SDMMD_AFCProcessOperation(afc, &file_ref);
					if (SDM_MD_CallSuccessful(result)) {
						uint64_t fd = 0;
						CFTypeRef file_ref_response = SDMMD_AFCOperationGetPacketResponse(file_ref);
						memcpy(&fd, CFDataGetBytePtr(file_ref_response), sizeof(uint64_t));
						CFDataRef write_data = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)test_write_bytes, strlen(test_write_bytes));
						SDMMD_AFCOperationRef file_ref_read = SDMMD_AFCFileDescriptorCreateWriteOperation(fd, write_data);
						result = SDMMD_AFCProcessOperation(afc, &file_ref_read);
						if (SDM_MD_CallSuccessful(result)) {
							CFTypeRef file_ref_read_response = SDMMD_AFCOperationGetPacketResponse(file_ref_read);
							if (file_ref_read_response) {
								*response = file_ref_read_response;
								sdm_return = kAMDSuccess;
							}
						}
					}
					CFSafeRelease(afc);
				}
			}
			SDMMD_AMDeviceStopSession(sdm);
		}
		SDMMD_AMDeviceDisconnect(sdm);
	}
	return sdm_return;
}
kern_return_t test_apple_AMDeviceValidatePairing(struct am_device *apple) {
	kern_return_t apple_return = kAMDUndefinedError;
	kern_return_t result = AMDeviceConnect(apple);
	if (SDM_MD_CallSuccessful(result)) {
		apple_return = AMDeviceValidatePairing(apple);
		if (apple_return != kAMDSuccess) {
			printf("\t\tAMDeviceValidatePairing: %i\n",apple_return);
		}
		AMDeviceDisconnect(apple);
	}
	return apple_return;
}
Пример #13
0
kern_return_t test_apple_AFCConnectionCreate(struct am_device *apple) {
	kern_return_t apple_return = kAMDUndefinedError;
	kern_return_t result = AMDeviceConnect(apple);
	if (SDM_MD_CallSuccessful(result)) {
		result = AMDeviceStartSession(apple);
		if (SDM_MD_CallSuccessful(result)) {
			service_conn_t test_apple_afc_conn;
			result = AMDeviceStartService(apple, CFSTR(AMSVC_AFC), &test_apple_afc_conn, NULL);
			if (SDM_MD_CallSuccessful(result)) {
				struct afc_connection *afc = NULL;
				result = AFCConnectionOpen(test_apple_afc_conn, 0, &afc);
				if (afc) {
					apple_return = kAMDSuccess;
					AFCConnectionClose(afc);
				}
			}
			AMDeviceStopSession(apple);
		}
		AMDeviceDisconnect(apple);
	}
	return apple_return;
}
Пример #14
0
sdmmd_return_t SDMMD_ServiceReceiveMessage(SocketConnection handle, CFPropertyListRef *data) {
	CFDataRef dataBuffer = NULL;
	if (SDM_MD_CallSuccessful(SDMMD_ServiceReceive(handle, &dataBuffer))) {
		if (dataBuffer && CFDataGetLength(dataBuffer)) {
			*data = CFPropertyListCreateWithData(0, dataBuffer, kCFPropertyListImmutable, NULL, NULL);
		} else {
			*data = CFDictionaryCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
		}
		return kAMDSuccess;
	} else {
		return kAMDNotConnectedError;
	}
}
Пример #15
0
kern_return_t test_sdm_AMDeviceStartService(SDMMD_AMDeviceRef sdm) {
	kern_return_t sdm_return = kAMDUndefinedError;
	kern_return_t result = SDMMD_AMDeviceConnect(sdm);
	if (SDM_MD_CallSuccessful(result)) {
		result = SDMMD_AMDeviceStartSession(sdm);
		if (SDM_MD_CallSuccessful(result)) {
			SDMMD_AMConnectionRef test_sdm_conn;
			if (SDMMD_AMDeviceGetInterfaceType(sdm) == kAMDInterfaceConnectionTypeIndirect) {
				sdm_return = SDMMD_AMDeviceSecureStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_conn);
			}
			else {
				sdm_return = SDMMD_AMDeviceStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_conn);
			}
			if (sdm_return != kAMDSuccess) {
				printf("\t\tSDMMD_AMDeviceStartService: %08x %s\n",sdm_return,SDMMD_AMDErrorString(sdm_return));
			}
			SDMMD_AMDeviceStopSession(sdm);
		}
		SDMMD_AMDeviceDisconnect(sdm);
	}
	return sdm_return;
}
Пример #16
0
void WhatDoesThisDo(char *udid)
{
	SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid);
	if (device) {
		sdmmd_return_t result = kAMDInvalidArgumentError;
		SDMMD_AMDeviceConnect(device);
		SDMMD_AMDeviceStartSession(device);
		CFDictionaryRef dict = NULL;
		SDMMD_AMConnectionRef conn = SDMMD_AMDServiceConnectionCreate(0, NULL, dict);
		result = SDMMD_AMDeviceSecureStartService(device, CFSTR(AMSVC_DIAG_RELAY), NULL, &conn);
		if (result == 0) {

			CFMutableDictionaryRef optionsDict = SDMMD_create_dict();
			CFDictionarySetValue(optionsDict, CFSTR("Request"), CFSTR("GasGauge"));

			result = SDMMD_ServiceSendMessage(SDMMD_TranslateConnectionToSocket(conn), optionsDict, kCFPropertyListXMLFormat_v1_0);

			CFMutableDictionaryRef response;
			result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(conn), (CFPropertyListRef *)&response);
			if (SDM_MD_CallSuccessful(result)) {
				PrintCFType(response);
			}

			result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(conn), (CFPropertyListRef *)&response);
			if (SDM_MD_CallSuccessful(result)) {
				PrintCFType(response);
			}

			result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(conn), (CFPropertyListRef *)&response);
			if (SDM_MD_CallSuccessful(result)) {
				PrintCFType(response);
			}
		}
		else {
			printf("%s: Was unable to start the service on the device: %i\n", __FUNCTION__, SDMMD_AMDeviceUSBDeviceID(device));
		}
	}
}
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;
}
Пример #18
0
sdmmd_return_t SDMMD_ServiceReceiveStream(SocketConnection handle, CFPropertyListRef *data) {
	CFDataRef dataBuffer = NULL;
	if (SDM_MD_CallSuccessful(SDMMD_ServiceReceive(handle, &dataBuffer))) {
		if (dataBuffer && CFDataGetLength(dataBuffer)) {
			CFReadStreamRef read = CFReadStreamCreateWithBytesNoCopy(kCFAllocatorDefault, CFDataGetBytePtr(dataBuffer), CFDataGetLength(dataBuffer), kCFAllocatorNull);
			CFReadStreamOpen(read);
			*data = CFPropertyListCreateWithStream(kCFAllocatorDefault, read, CFDataGetLength(dataBuffer), 0x2, 0, NULL);
			CFReadStreamClose(read);
			if (read)
				CFRelease(read);
		}
		return kAMDSuccess;
	} else {
		return kAMDNotConnectedError;
	}
}
Пример #19
0
kern_return_t test_sdm_AFCFileDescriptorCreateReadOperation(SDMMD_AMDeviceRef sdm, CFTypeRef *response) {
	kern_return_t sdm_return = kAMDUndefinedError;
	kern_return_t result = SDMMD_AMDeviceConnect(sdm);
	if (SDM_MD_CallSuccessful(result)) {
		result = SDMMD_AMDeviceStartSession(sdm);
		if (SDM_MD_CallSuccessful(result)) {
			SDMMD_AMConnectionRef test_sdm_afc_conn;
			if (SDMMD_AMDeviceGetInterfaceType(sdm) == kAMDInterfaceConnectionTypeIndirect) {
				result = SDMMD_AMDeviceSecureStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_afc_conn);
			}
			else {
				result = SDMMD_AMDeviceStartService(sdm, CFSTR(AMSVC_AFC), NULL, &test_sdm_afc_conn);
			}
			if (SDM_MD_CallSuccessful(result)) {
				SDMMD_AFCConnectionRef afc = SDMMD_AFCConnectionCreate(test_sdm_afc_conn);
				if (afc) {
					SDMMD_AFCOperationRef file_info = SDMMD_AFCOperationCreateGetFileInfo(CFSTR(kTestCreateFileForAFC));
					result = SDMMD_AFCProcessOperation(afc, &file_info);
					if (SDM_MD_CallSuccessful(result)) {
						CFTypeRef file_info_response = SDMMD_AFCOperationGetPacketResponse(file_info);
						int32_t size = CFStringGetIntValue(CFDictionaryGetValue(file_info_response, AFC_File_Info_Keys[AFC_File_Info_Key_size]));
						SDMMD_AFCOperationRef file_ref = SDMMD_AFCOperationCreateFileRefOpen(CFSTR(kTestCreateFileForAFC), 2);
						result = SDMMD_AFCProcessOperation(afc, &file_ref);
						if (SDM_MD_CallSuccessful(result)) {
							uint64_t fd = 0;
							CFTypeRef file_ref_response = SDMMD_AFCOperationGetPacketResponse(file_ref);
							memcpy(&fd, CFDataGetBytePtr(file_ref_response), sizeof(uint64_t));
							SDMMD_AFCOperationRef file_ref_read = SDMMD_AFCFileDescriptorCreateReadOperation(fd, size);
							result = SDMMD_AFCProcessOperation(afc, &file_ref_read);
							if (SDM_MD_CallSuccessful(result)) {
								CFTypeRef file_ref_read_response = SDMMD_AFCOperationGetPacketResponse(file_ref_read);
								if (file_ref_read_response) {
									*response = file_ref_read_response;
									sdm_return = kAMDSuccess;
								}
							}
						}
					}
					CFSafeRelease(afc);
				}
			}
			SDMMD_AMDeviceStopSession(sdm);
		}
		SDMMD_AMDeviceDisconnect(sdm);
	}
	return sdm_return;
}
Пример #20
0
void RunAppOnDeviceWithIdentifier(char *udid, char *identifier, bool waitForDebugger)
{
	SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid);
	if (device) {
		sdmmd_return_t result = SDMMD_AMDeviceConnect(device);
		if (SDM_MD_CallSuccessful(result)) {
			result = SDMMD_AMDeviceStartSession(device);
			if (SDM_MD_CallSuccessful(result)) {
				CFDictionaryRef response;
				CFArrayRef lookupValues = SDMMD_ApplicationLookupDictionary();
				CFMutableDictionaryRef optionsDict = SDMMD_create_dict();
				CFDictionarySetValue(optionsDict, CFSTR("ReturnAttributes"), lookupValues);

				result = SDMMD_AMDeviceLookupApplications(device, optionsDict, &response);
				if (SDM_MD_CallSuccessful(result)) {
					CFStringRef bundleIdentifier = CFStringCreateWithCString(kCFAllocatorDefault, identifier, kCFStringEncodingUTF8);
					CFDictionaryRef details = NULL;
					if (CFDictionaryContainsKey(response, bundleIdentifier)) {
						details = CFDictionaryGetValue(response, bundleIdentifier);
					}
					CFSafeRelease(bundleIdentifier);
					if (details) {
						SDMMD_AMDeviceStopSession(device);
						SDMMD_AMDeviceDisconnect(device);
						SDMMD_AMDebugConnectionRef dconn = SDMMD_AMDebugConnectionCreateForDevice(device);
						sdmmd_return_t result = SDMMD_AMDebugConnectionStart(dconn);
						bool launchSuccess = false;
						if (SDM_MD_CallSuccessful(result)) {

							// setting max packet size
							CFMutableArrayRef maxPacketArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
							CFArrayAppendValue(maxPacketArgs, CFSTR("1024"));
							DebuggerCommandRef maxPacket = SDMMD_CreateDebuggingCommand(kDebugQSetMaxPacketSize, NULL, maxPacketArgs);
							CFSafeRelease(maxPacketArgs);

							CFDataRef maxPacketResponse = NULL;
							result = SDMMD_DebuggingSend(dconn, maxPacket, &maxPacketResponse);
							CFSafeRelease(maxPacketResponse);
							SDMMD_DebuggingCommandRelease(maxPacket);

							// setting the working directory
							CFStringRef path = CFDictionaryGetValue(details, CFSTR("Path"));
							CFStringRef container = CFDictionaryGetValue(details, CFSTR("Container"));
							if (!container) {
								CFURLRef pathURL = CFURLCreateWithString(kCFAllocatorDefault, path, NULL);
								CFURLRef containerURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, pathURL);
								container = CFURLGetString(containerURL);
								CFSafeRelease(pathURL);
							}
							CFMutableArrayRef containerPathArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
							CFArrayAppendValue(containerPathArgs, container);
							DebuggerCommandRef containerPath = SDMMD_CreateDebuggingCommand(kDebugQSetWorkingDir, NULL, containerPathArgs);
							CFSafeRelease(containerPathArgs);

							CFDataRef containerPathResponse = NULL;
							result = SDMMD_DebuggingSend(dconn, containerPath, &containerPathResponse);
							CFSafeRelease(containerPathResponse);
							SDMMD_DebuggingCommandRelease(containerPath);

							// setting launch args
							CFStringRef commandFormat = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("A%d,0,"), (uint32_t)CFStringGetLength(path) * 0x2);

							CFMutableArrayRef setLaunchArgsArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
							CFArrayAppendValue(setLaunchArgsArgs, path);
							DebuggerCommandRef setLaunchArgs = SDMMD_CreateDebuggingCommand(kDebugCUSTOMCOMMAND, commandFormat, setLaunchArgsArgs);
							CFSafeRelease(setLaunchArgsArgs);
							CFSafeRelease(commandFormat);

							CFDataRef setLaunchArgsResponse = NULL;
							result = SDMMD_DebuggingSend(dconn, setLaunchArgs, &setLaunchArgsResponse);
							CFSafeRelease(setLaunchArgsResponse);
							SDMMD_DebuggingCommandRelease(setLaunchArgs);

							// Check for launch success
							CFMutableArrayRef launchSuccessArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
							DebuggerCommandRef launchSuccessCommand = SDMMD_CreateDebuggingCommand(kDebugqLaunchSuccess, NULL, launchSuccessArgs);
							CFSafeRelease(launchSuccessArgs);

							CFDataRef launchSuccessResponse = NULL;
							result = SDMMD_DebuggingSend(dconn, launchSuccessCommand, &launchSuccessResponse);

							if (launchSuccessResponse) {
								char *launchSuccessResponseAsString = (char *)CFDataGetBytePtr(launchSuccessResponse);
								launchSuccess = !strncmp(launchSuccessResponseAsString, "OK", 2);

								if (!launchSuccess) {
									printf("Launch failure: %s\n", launchSuccessResponseAsString);
								}
							}

							CFSafeRelease(launchSuccessResponse);
							SDMMD_DebuggingCommandRelease(launchSuccessCommand);

							if (launchSuccess) {
								printf("Launch success\n");

								if (!waitForDebugger) {
									printf("Continuing with execution...\n");

									// setting thread to attach
									CFMutableArrayRef setThreadArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
									CFArrayAppendValue(setThreadArgs, CFSTR(""));
									DebuggerCommandRef setThread = SDMMD_CreateDebuggingCommand(kDebugCUSTOMCOMMAND, CFSTR("Hc0"), setThreadArgs);
									CFSafeRelease(setThreadArgs);

									CFDataRef setThreadResponse = NULL;
									result = SDMMD_DebuggingSend(dconn, setThread, &setThreadResponse);
									CFSafeRelease(setThreadResponse);
									SDMMD_DebuggingCommandRelease(setThread);

									// setting continue with execution
									CFMutableArrayRef contArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
									CFArrayAppendValue(contArgs, CFSTR(""));
									DebuggerCommandRef cont = SDMMD_CreateDebuggingCommand(kDebugc, NULL, contArgs);
									CFSafeRelease(contArgs);

									CFDataRef contResponse = NULL;
									result = SDMMD_DebuggingSend(dconn, cont, &contResponse);
									CFSafeRelease(contResponse);
									SDMMD_DebuggingCommandRelease(cont);
								}
								else {
									printf("Waiting for debugger to attach...\n");

									CFRunLoopRun();
								}
							}
						}
						/*
						sdmmd_return_t result = SDMMD_StartDebuggingSessionOnDevice(device, &connection);
						if (SDM_MD_CallSuccessful(result)) {
							bool launchSuccess = false;
							CFStringRef path = CFDictionaryGetValue(details, CFSTR("Path"));
							CFStringRef encodedPath = SDMMD_EncodeDebuggingString(path);
							CFStringRef container = CFDictionaryGetValue(details, CFSTR("Container"));
							if (!container) {
								CFURLRef pathURL = CFURLCreateWithString(kCFAllocatorDefault, path, NULL);
								CFURLRef containerURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, pathURL);
								container = CFURLGetString(containerURL);
								CFSafeRelease(pathURL);
								//CFSafeRelease(containerURL);
							}
							if (container) {
								CFStringRef containerPath = SDMMD_EncodeDebuggingString(container);
								sdmmd_debug_return_t dresult;
								CFStringRef maxPacket = SDMMD_EncodeDebuggingString(CFSTR("1024"));
								dresult = SDMMD_DebuggingSend(connection, KnownDebugCommands[kDebugQSetMaxPacketSize], maxPacket);
								CFSafeRelease(maxPacket);
								dresult = SDMMD_DebuggingSend(connection, KnownDebugCommands[kDebugQSetWorkingDir], containerPath);
								CFSafeRelease(containerPath);
								CFStringRef commandFormat = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%d,0,%s"), (uint32_t)CFStringGetLength(encodedPath), CFStringGetCStringPtr(encodedPath, kCFStringEncodingUTF8));
								dresult = SDMMD_DebuggingSend(connection, KnownDebugCommands[kDebugA], commandFormat);
								CFSafeRelease(commandFormat);
								dresult = SDMMD_DebuggingSend(connection, KnownDebugCommands[kDebugH], CFSTR("c0"));
								dresult = SDMMD_DebuggingSend(connection, KnownDebugCommands[kDebugc], CFSTR(""));
								launchSuccess = true;
							}
							CFSafeRelease(encodedPath);
							if (launchSuccess) {
								CFRunLoopRun();
							}
						}
						*/
					}
				}
			}
		}
	}
}