void SpringboardQuery(char *udid) {
	SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid);
	if (device) {
		//struct SpringboardDeviceInfo *info = CreateSpringboardInfoFromDevice(device);
		
		SDMMD_AMConnectionRef springboard = AttachToDeviceAndService(device, AMSVC_SPRINGBOARD_SERVICES);
		CFMutableDictionaryRef request = SDMMD_create_dict();
		CFDictionarySetValue(request, CFSTR(kCommand), CFSTR(kCommandGetIconState));
		CFDictionarySetValue(request, CFSTR(kFormatVersion), CFSTR("2"));
		SocketConnection socket = SDMMD_TranslateConnectionToSocket(springboard);
		sdmmd_return_t result = SDMMD_ServiceSendMessage(socket, request, kCFPropertyListBinaryFormat_v1_0);
		if (result == kAMDSuccess) {
			CFPropertyListRef response = NULL;
			result = SDMMD_ServiceReceiveMessage(socket, &response);
			if (result == kAMDSuccess && response) {
				PrintCFType(response);
			}
		}
		
		/*
		CFMutableDictionaryRef setrequest = SDMMD_create_dict();
		CFDictionarySetValue(setrequest, CFSTR(kCommand), CFSTR(kCommandSetIconState));
		CFDictionarySetValue(setrequest, CFSTR("iconState"), newformat);
		result = SDMMD_ServiceSendMessage(socket, setrequest, kCFPropertyListBinaryFormat_v1_0);
		if (result == kAMDSuccess) {
			CFPropertyListRef response = NULL;
			result = SDMMD_ServiceReceiveMessage(socket, &response);
			if (result == kAMDSuccess && response) {
				PrintCFType(response);
			}
		}
		*/
	}
}
示例#2
0
void InstallProfileToDevice(char *udid, char *path)
{
	SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid);
	if (device) {
		SDMMD_AMDeviceConnect(device);
		SDMMD_AMDeviceStartSession(device);
		SDMMD_AMConnectionRef conn = NULL;
		SDMMD_AMDeviceStartService(device, CFSTR(AMSVC_MCINSTALL), NULL, &conn);
		CFDataRef config_data = CFDataCreateFromFilePath(path);

		CFMutableDictionaryRef request = SDMMD_create_dict();
		CFDictionaryAddValue(request, CFSTR("RequestType"), CFSTR("InstallProfile"));
		CFDictionaryAddValue(request, CFSTR("Payload"), config_data);

		SDMMD_ServiceSendMessage(SDMMD_TranslateConnectionToSocket(conn), request, kCFPropertyListXMLFormat_v1_0);
		CFSafeRelease(request);
		CFSafeRelease(config_data);

		CFPropertyListRef response = NULL;
		SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(conn), &response);
		CFSafeRelease(response);

		CFSafeRelease(conn);
		SDMMD_AMDeviceStopSession(device);
		SDMMD_AMDeviceDisconnect(device);
	}
}
sdmmd_return_t SDMMD_lockconn_send_message(SDMMD_AMDeviceRef device, CFDictionaryRef dict) {
	sdmmd_return_t result = 0x0;
	if (device->ivars.lockdown_conn) {
		if (dict) {			
			//uint32_t xmlLength = CFDataGetLength(xml);
			//char *xmlPtr = (char*)CFDataGetBytePtr(xml);
			//uint32_t sentLen = 0;
			bool useSSL = (device->ivars.lockdown_conn->ssl ? true : false);
			SocketConnection conn;
			if (useSSL)
				conn = (SocketConnection){true, {.ssl = device->ivars.lockdown_conn->ssl}};
			else
				conn = (SocketConnection){false, {.conn = device->ivars.lockdown_conn->connection}};
			
			//uint32_t length = CFDataGetLength(xml);
			//CFDataRef size = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, &length, 0x4, kCFAllocatorNull);
			//CFShowsize);
			//result = SDMMD_ServiceSend(conn, size);
			SDMMD_ServiceSendMessage(conn, dict, kCFPropertyListXMLFormat_v1_0);
			/*if (device->ivars.lockdown_conn->ssl) {
				sentLen = SSL_write(device->ivars.lockdown_conn->ssl, &xmlLength, 0x4);
				sentLen = SSL_write(device->ivars.lockdown_conn->ssl, &xmlPtr, xmlLength);
			} else {
				SDMMD_ServiceSendMessage(device->ivars.lockdown_conn->connection, xml);
			}*/
		} else {
sdmmd_return_t SDMMD_MB2SendEndStream(SDMMD_AMConnectionRef conn) {
	sdmmd_return_t result = kAMDSuccess;
	
	uint32_t zero_stream = 0x0;
	CFDataRef stream_end = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)&zero_stream, sizeof(uint32_t));
	result = SDMMD_DirectServiceSend(SDMMD_TranslateConnectionToSocket(conn), stream_end);
	CFSafeRelease(stream_end);
	
	CFMutableArrayRef status_response = SDMMD_MB2StatusResponseMessage();
	result = SDMMD_ServiceSendMessage(SDMMD_TranslateConnectionToSocket(conn), status_response, kCFPropertyListBinaryFormat_v1_0);

	return result;
}
sdmmd_return_t SDMMD_mount_image(SDMMD_AMConnectionRef connection, CFStringRef image_type, CFDataRef signature, bool *mounted)
{
	sdmmd_return_t result = kAMDSuccess;
	CFMutableDictionaryRef mountDict = SDMMD_create_dict();
	if (mountDict) {
		CFDictionarySetValue(mountDict, CFSTR("Command"), CFSTR("MountImage"));
		CFDictionarySetValue(mountDict, CFSTR("ImageType"), image_type);
		CFDictionarySetValue(mountDict, CFSTR("ImagePath"), CFSTR("/var/mobile/Media/PublicStaging/staging.dimage"));
		if (signature) {
			CFDictionarySetValue(mountDict, CFSTR("ImageSignature"), signature);
		}
		result = SDMMD_ServiceSendMessage(SDMMD_TranslateConnectionToSocket(connection), mountDict, kCFPropertyListXMLFormat_v1_0);
		CFSafeRelease(mountDict);
		CheckErrorAndReturn(result);

		CFDictionaryRef response;
		result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(connection), (CFPropertyListRef *)&response);
		CheckErrorAndReturn(result);

		if (response) {
			result = SDMMD__ErrorHandler(SDMMD_ImageMounterErrorConvert, response);

			CheckErrorAndReturn(result);

			CFTypeRef status = CFDictionaryGetValue(response, CFSTR("Status"));
			if (status) {
				if (CFEqual(status, CFSTR("Complete"))) {
					*mounted = true;
				}
				else {
					result = kAMDMissingDigestError;
				}
			}
		}
		else {
			result = kAMDReadError;
		}
	}
	else {
		result = kAMDReadError;
	}

	ExitLabelAndReturn(result);
}
sdmmd_return_t SDMMD__hangup_with_image_mounter_service(SDMMD_AMConnectionRef connection)
{
	sdmmd_return_t result = kAMDNoResourcesError;
	CFMutableDictionaryRef dict = SDMMD_create_dict();
	if (dict) {
		CFDictionarySetValue(dict, CFSTR("Command"), CFSTR("Hangup"));
	}
	if (connection) {
		SocketConnection socket = SDMMD_TranslateConnectionToSocket(connection);
		result = SDMMD_ServiceSendMessage(socket, dict, kCFPropertyListXMLFormat_v1_0);
		CheckErrorAndReturn(result);

		CFPropertyListRef response = NULL;
		result = SDMMD_ServiceReceiveMessage(socket, &response);
		PrintCFDictionary(response);
	}

ExitLabel:
	CFSafeRelease(dict);
	return result;
}
示例#7
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));
		}
	}
}
sdmmd_return_t SDMMD_AMDeviceMountImage(SDMMD_AMDeviceRef device, CFStringRef path, CFDictionaryRef dict, CallBack handle, void *unknown)
{
	sdmmd_return_t result = kAMDSuccess;
	if (dict) {
		SDMMD_AMConnectionRef connection = NULL;
		CFTypeRef digest = NULL;
		CFTypeRef signature = CFDictionaryGetValue(dict, CFSTR("ImageSignature"));
		CFStringRef image_type = CFDictionaryGetValue(dict, CFSTR("ImageType"));
		if (image_type) {
			unsigned char sum_digest[SHA1_HASH_LENGTH];
			result = SDMMD_AMDeviceDigestFile(path, PtrCast(&sum_digest, unsigned char **));
			CheckErrorAndReturn(result);

			SDMMD_AMDeviceRef device_copy = SDMMD_AMDeviceCreateCopy(device);
			if (SDMMD_AMDeviceIsValid(device_copy)) {
				result = SDMMD_AMDeviceSecureStartSessionedService(device, CFSTR(AMSVC_MOBILE_IMAGE_MOUNT), &connection);
				CheckErrorAndReturn(result);

				SDMMD_fire_callback(handle, unknown, CFSTR("LookingUpImage"));
				if (connection) {
					CFMutableDictionaryRef commandDict = SDMMD_create_dict();
					if (commandDict) {
						CFDictionarySetValue(commandDict, CFSTR("Command"), CFSTR("LookupImage"));
						CFDictionarySetValue(commandDict, CFSTR("ImageType"), image_type);
					}
					else {
						result = kAMDNoResourcesError;
					}

					CheckErrorAndReturn(result);

					result = SDMMD_ServiceSendMessage(SDMMD_TranslateConnectionToSocket(connection), commandDict, kCFPropertyListXMLFormat_v1_0);
					CFSafeRelease(commandDict);

					CheckErrorAndReturn(result);

					CFDictionaryRef response;
					result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(connection), (CFPropertyListRef *)&response);

					CheckErrorAndReturn(result);

					if (response) {
						result = SDMMD__ErrorHandler(SDMMD__ConvertServiceError, response);

						CheckErrorAndReturn(result);

						CFTypeRef image = CFDictionaryGetValue(response, CFSTR("ImagePresent"));
						if (image) {
							if (CFEqual(image, kCFBooleanTrue)) {
								digest = CFDictionaryGetValue(response, CFSTR("ImageDigest"));
							}
							else {
								result = kAMDMissingDigestError;
							}
						}
					}

					if (!digest) {
						bool use_stream = SDMMD_device_os_is_at_least(device, CFSTR("7.0"));
						if (use_stream) {
							SDMMD_fire_callback(handle, unknown, CFSTR("StreamingImage"));
							result = SDMMD_stream_image(connection, path, image_type);
						}
						else {
							SDMMD_fire_callback(handle, unknown, CFSTR("CopyingImage"));
							result = SDMMD_copy_image(device, path);
						}
					}

					CheckErrorAndReturn(result);

					bool mounted = false;
					SDMMD_fire_callback(handle, unknown, CFSTR("MountingImage"));
					result = SDMMD_mount_image(connection, image_type, signature, &mounted);

					if (mounted) {
						result = SDMMD__hangup_with_image_mounter_service(connection);
					}
				}
				CFSafeRelease(connection);
				CFSafeRelease(device_copy);
				CheckErrorAndReturn(result);
			}
			else {
				result = kAMDUndefinedError;
			}
		}
		else {
			result = kAMDMissingImageTypeError;
		}
	}
sdmmd_return_t SDMMD_stream_image(SDMMD_AMConnectionRef connection, CFStringRef path, CFStringRef image_type)
{
	sdmmd_return_t result = kAMDSuccess;
	char fspath[0x400] = {0};
	Boolean fsRep = CFStringGetFileSystemRepresentation(path, fspath, 0x400);
	if (fsRep) {
		struct stat fileStat;
		lstat(fspath, &fileStat);
		CFNumberRef size = CFNumberCreate(kCFAllocatorDefault, 0xb, &fileStat.st_size);
		CFMutableDictionaryRef streamDict = SDMMD_create_dict();
		CFDictionarySetValue(streamDict, CFSTR("Command"), CFSTR("ReceiveBytes"));
		CFDictionarySetValue(streamDict, CFSTR("ImageType"), image_type);
		CFDictionarySetValue(streamDict, CFSTR("ImageSize"), size);
		result = SDMMD_ServiceSendMessage(SDMMD_TranslateConnectionToSocket(connection), streamDict, kCFPropertyListXMLFormat_v1_0);
		CFSafeRelease(streamDict);
		CFSafeRelease(size);

		CheckErrorAndReturn(result);

		CFDictionaryRef response;
		result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(connection), (CFPropertyListRef *)&response);

		CheckErrorAndReturn(result);

		if (response) {
			result = SDMMD__ErrorHandler(SDMMD_ImageMounterErrorConvert, response);

			CheckErrorAndReturn(result);

			CFTypeRef status = CFDictionaryGetValue(response, CFSTR("Status"));
			if (status) {
				if (CFStringCompare(status, CFSTR("ReceiveBytesAck"), 0) == 0) {
					// block code
					CFDataRef image_file = CFDataCreateFromPath(path);
					uint64_t offset = 0;
					uint64_t remainder = 0;
					while (offset < fileStat.st_size) {
						remainder = (fileStat.st_size - offset);
						remainder = (remainder > kDeveloperImageStreamSize ? kDeveloperImageStreamSize : remainder);
						CFRange current_read = CFRangeMake((CFIndex)offset, (CFIndex)remainder);
						CFDataRef image_stream = CFDataCreateFromSubrangeOfData(image_file, current_read);
						result = SDMMD_DirectServiceSend(SDMMD_TranslateConnectionToSocket(connection), image_stream);
						CheckErrorAndReturn(result);
						offset += remainder;
						CFSafeRelease(image_stream);
					}
					CFDictionaryRef getStatus;
					result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(connection), (CFPropertyListRef *)&getStatus);

					if (result == 0) {
						result = SDMMD__ErrorHandler(SDMMD_ImageMounterErrorConvert, response);

						CheckErrorAndReturn(result);

						CFTypeRef streamStatus = CFDictionaryGetValue(getStatus, CFSTR("Status"));
						if (streamStatus) {
							if (CFStringCompare(streamStatus, CFSTR("Complete"), 0x0) == 0) {
								result = kAMDSuccess;
							}
						}
					}
					CFSafeRelease(getStatus);
					CFSafeRelease(image_file);
				}
			}
			else {
				result = kAMDUndefinedError;
			}
		}
		else {
			result = kAMDReadError;
		}
	}
	else {
		result = kAMDNoResourcesError;
	}

	ExitLabelAndReturn(result);
}