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; }
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); }
void USBMuxSend(uint32_t sock, struct USBMuxPacket *packet) { CFDataRef xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, packet->payload); char *buffer = (char *)CFDataGetBytePtr(xmlData); ssize_t result = send(sock, &packet->body, sizeof(struct USBMuxPacketBody), 0x0); if (result == sizeof(struct USBMuxPacketBody)) { if (packet->body.length > result) { ssize_t payloadSize = packet->body.length - result; ssize_t remainder = payloadSize; while (remainder) { result = send(sock, &buffer[payloadSize-remainder], sizeof(char), 0x0); if (result != sizeof(char)) { break; } remainder -= result; } } } CFSafeRelease(xmlData); }
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; }
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; }
void USBMuxReceive(uint32_t sock, struct USBMuxPacket *packet) { ssize_t result = recv(sock, &packet->body, sizeof(struct USBMuxPacketBody), 0x0); if (result == sizeof(struct USBMuxPacketBody)) { ssize_t payloadSize = packet->body.length - result; if (payloadSize) { char *buffer = calloc(0x1, payloadSize); ssize_t remainder = payloadSize; while (remainder) { result = recv(sock, &buffer[payloadSize-remainder], sizeof(char), 0x0); if (result != sizeof(char)) { break; } remainder -= result; } CFDataRef xmlData = CFDataCreate(kCFAllocatorDefault, (UInt8 *)buffer, payloadSize); packet->payload = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, xmlData, kCFPropertyListImmutable, NULL); Safe(free,buffer); CFSafeRelease(xmlData); } } }
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; }
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); } }
kern_return_t test_sdm_AFCOperationCreateGetFileInfo(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(kTestFileForAFC)); result = SDMMD_AFCProcessOperation(afc, &file_info); if (SDM_MD_CallSuccessful(result)) { CFTypeRef test = SDMMD_AFCOperationGetPacketResponse(file_info); if (test) { *response = test; sdm_return = kAMDSuccess; } } CFSafeRelease(afc); } } SDMMD_AMDeviceStopSession(sdm); } SDMMD_AMDeviceDisconnect(sdm); } return sdm_return; }
CFStringRef SDMMD_PathToDeviceSupport(SDMMD_AMDeviceRef device) { CFStringRef dev_support_path = NULL; if (device) { SDMMD_AMDeviceConnect(device); SDMMD_AMDeviceStartSession(device); CFStringRef full_os_version = SDMMD_AMDeviceCopyValue(device, NULL, CFSTR(kProductVersion)); CFStringRef os_version = CFStringCreateWithSubstring(kCFAllocatorDefault, full_os_version, CFRangeMake(0, 3)); CFSafeRelease(full_os_version); CFStringRef build_version = SDMMD_AMDeviceCopyValue(device, NULL, CFSTR(kBuildVersion)); SDMMD_AMDeviceStopSession(device); SDMMD_AMDeviceDisconnect(device); if (os_version && build_version) { CFStringRef sdk_path = SDMMD_CopyDeviceSupportPathFromXCRUN(); CFStringRef device_support = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@/DeviceSupport/%@"), sdk_path, os_version); char *device_support_cstr = SDMCFStringGetString(device_support); bool isDir = false; bool file_exists = FileExistsAtPathIsDir(device_support_cstr, &isDir); if (file_exists && isDir) { dev_support_path = CFStringCreateCopy(kCFAllocatorDefault, device_support); } else { CFStringRef device_support_build = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ (%@)"), device_support, build_version); char *device_support_build_cstr = SDMCFStringGetString(device_support_build); file_exists = FileExistsAtPathIsDir(device_support_build_cstr, &isDir); if (file_exists && isDir) { dev_support_path = CFStringCreateCopy(kCFAllocatorDefault, device_support_build); } Safe(free, device_support_build_cstr); CFSafeRelease(device_support_build); } Safe(free, device_support_cstr); CFSafeRelease(sdk_path); CFSafeRelease(device_support); } CFSafeRelease(os_version); CFSafeRelease(build_version); } return dev_support_path; }
void PrintCFTypeInternalFormat(CFTypeRef value, uint32_t depth) { bool foundType = false; CFStringRef valueType = CFCopyTypeIDDescription(CFGetTypeID(value)); CFStringRef dictionaryType = CFCopyTypeIDDescription(CFDictionaryGetTypeID()); if (CFStringCompare(valueType, dictionaryType, 0x0) == kCFCompareEqualTo) { foundType = true; printf("{\n"); PrintCFDictionaryInternalFormatting(value, depth+0x1); PrintDepth(depth,"}\n"); } CFSafeRelease(dictionaryType); CFStringRef booleanType = CFCopyTypeIDDescription(CFBooleanGetTypeID()); if (CFStringCompare(valueType, booleanType, 0x0) == kCFCompareEqualTo) { foundType = true; printf("%s\n",(CFBooleanGetValue(value) ? "True" : "False")); } CFSafeRelease(booleanType); CFStringRef stringType = CFCopyTypeIDDescription(CFStringGetTypeID()); if (CFStringCompare(valueType, stringType, 0x0) == kCFCompareEqualTo) { foundType = true; printf("%s\n",(char*)CFStringGetCStringPtr(value,kCFStringEncodingUTF8)); } CFSafeRelease(stringType); CFStringRef numberType = CFCopyTypeIDDescription(CFNumberGetTypeID()); if (CFStringCompare(valueType, numberType, 0x0) == kCFCompareEqualTo) { foundType = true; CFIndex numberType = CFNumberGetType(value); switch (numberType) { case kCFNumberSInt8Type: { SInt8 number; CFNumberGetValue(value, numberType, &number); printf("%hhd\n",number); break; }; case kCFNumberSInt16Type: { SInt16 number; CFNumberGetValue(value, numberType, &number); printf("%hd\n",number); break; }; case kCFNumberSInt32Type: { SInt32 number; CFNumberGetValue(value, numberType, &number); printf("%d\n",(int32_t)number); break; }; case kCFNumberSInt64Type: { SInt64 number; CFNumberGetValue(value, numberType, &number); printf("%lld\n",number); break; }; case kCFNumberFloat32Type: { Float32 number; CFNumberGetValue(value, numberType, &number); printf("%.f\n",number); break; }; case kCFNumberFloat64Type: { Float64 number; CFNumberGetValue(value, numberType, &number); printf("%.f\n",number); break; }; case kCFNumberCharType: { char number; CFNumberGetValue(value, numberType, &number); printf("%c\n",number); break; }; case kCFNumberShortType: { short number; CFNumberGetValue(value, numberType, &number); printf("%hd\n",number); break; }; case kCFNumberIntType: { int number; CFNumberGetValue(value, numberType, &number); printf("%d\n",number); break; }; case kCFNumberLongType: { long number; CFNumberGetValue(value, numberType, &number); printf("%ld\n",number); break; }; case kCFNumberLongLongType: { long long number; CFNumberGetValue(value, numberType, &number); printf("%qd\n",number); break; }; case kCFNumberFloatType: { float number; CFNumberGetValue(value, numberType, &number); printf("%.f\n",number); break; }; case kCFNumberDoubleType: { double number; CFNumberGetValue(value, numberType, &number); printf("%.f\n",number); break; }; case kCFNumberCFIndexType: { CFIndex number; CFNumberGetValue(value, numberType, &number); printf("%ld\n",number); break; }; case kCFNumberNSIntegerType: { NSInteger number; CFNumberGetValue(value, numberType, &number); printf("%ld\n",(long)number); break; }; case kCFNumberCGFloatType: { CGFloat number; CFNumberGetValue(value, numberType, &number); printf("%.f\n",number); break; }; default: { break; }; } } CFSafeRelease(numberType); CFStringRef arrayType = CFCopyTypeIDDescription(CFArrayGetTypeID()); if (CFStringCompare(valueType, arrayType, 0x0) == kCFCompareEqualTo) { foundType = true; CFIndex count = CFArrayGetCount(value); printf("[\n"); for (CFIndex i = 0x0; i < count; i++) { CFTypeRef item = CFArrayGetValueAtIndex(value, i); PrintDepth(depth+0x1,""); PrintCFTypeInternalFormat(item, depth+0x1); } PrintDepth(depth,"]\n"); } CFSafeRelease(arrayType); if (!foundType) { CFStringRef description = CFCopyDescription(value); printf("%s\n",(char*)CFStringGetCStringPtr(description,kCFStringEncodingUTF8)); CFSafeRelease(description); } CFSafeRelease(valueType); }
int main(int argc, const char * argv[]) { SDMMobileDevice; char *udid = NULL; char *service = NULL; char *help = NULL; char *domain = NULL; char *key = NULL; char *bundle = NULL; char *diagArg = NULL; bool searchArgs = true; char *installPath = NULL; int c; while (searchArgs) { int option_index = 0x0; c = getopt_long (argc, (char * const *)argv, "lh:d:ais:q:p:t:c:",long_options, &option_index); if (c == -1) { break; } switch (c) { case 'h': { if (optarg) { help = optarg; } optionsEnable[OptionsHelp] = true; searchArgs = false; break; }; case 'l': { optionsEnable[OptionsList] = true; searchArgs = false; break; }; case 'd': { if (optarg && !optionsEnable[OptionsDevice]) { optionsEnable[OptionsDevice] = true; udid = optarg; } break; } case 's': { if (optarg && !optionsEnable[OptionsAttach]) { service = optarg; optionsEnable[OptionsAttach] = true; } else { printf("please specify a service name to attach"); } break; }; case 'q': { if (optarg && !optionsEnable[OptionsQuery]) { CFStringRef argValue = CFStringCreateWithCString(kCFAllocatorDefault, optarg, kCFStringEncodingUTF8); CFArrayRef argsArray = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, argValue, CFSTR("=")); CFIndex argsCounter = CFArrayGetCount(argsArray); if (argsCounter >= 0x1) { domain = (char*)SDMCFStringGetString(CFArrayGetValueAtIndex(argsArray, 0x0)); if (strncmp(domain, "all", sizeof(char)*0x3) == 0x0) { Safe(free, domain); domain = calloc(0x1, sizeof(char)*(strlen(kAllDomains)+0x1)); memcpy(domain, kAllDomains, strlen(kAllDomains)); } optionsEnable[OptionsQuery] = true; } if (argsCounter == 0x2) { key = (char*)SDMCFStringGetString(CFArrayGetValueAtIndex(argsArray, 0x1)); } else { key = calloc(0x1, sizeof(char)*(strlen(kAllKeys)+0x1)); memcpy(key, kAllKeys, strlen(kAllKeys)); } CFSafeRelease(argsArray); CFSafeRelease(argValue); } break; }; case 'a': { optionsEnable[OptionsApps] = true; break; }; case 'i': { optionsEnable[OptionsInfo] = true; break; }; case 'r': { if (optarg && !optionsEnable[OptionsRun]) { bundle = optarg; optionsEnable[OptionsRun] = true; } break; }; case 'p': { if (optarg && !optionsEnable[OptionsDiag]) { diagArg = optarg; optionsEnable[OptionsDiag] = true; } break; }; case 'x': { optionsEnable[OptionsDev] = true; break; } case 't': { if (optarg) { optionsEnable[OptionsInstall] = true; installPath = optarg; } break; } case 'c': { if (optarg) { optionsEnable[OptionsConfig] = true; installPath = optarg; } break; } default: { printf("--help for help"); break; }; } } if (optionsEnable[OptionsHelp]) { if (!help) { printf("%s [service|query] : list available services or queries\n",helpArg); printf("%s : list attached devices\n",listArg); printf("%s [UDID] : specify a device\n",deviceArg); printf("%s [service] : attach to [service]\n",attachArg); printf("%s <domain>=<key> : query value for <key> in <domain>, specify 'null' for global domain\n",queryArg); printf("%s : display installed apps\n",appsArg); printf("%s : display info of a device\n",infoArg); printf("%s [bundle id] : run an application with specified [bundle id]\n",runArg); printf("%s [sleep|reboot|shutdown] : perform diag power operations on a device\n",powerArg); printf("%s : setup device for development\n",devArg); printf("%s [.app path] : install specificed .app to a device\n",installArg); printf("%s [.mobileconfig path] : install specificed .mobileconfig to a device\n",profileArg); } else { if (strncmp(help, "service", strlen("service")) == 0x0) { printf(" shorthand : service identifier\n--------------------------------\n"); for (uint32_t i = 0x0; i < SDM_MD_Service_Count; i++) { printf("%10s : %s\n",SDMMDServiceIdentifiers[i].shorthand, SDMMDServiceIdentifiers[i].identifier); } } if (strncmp(help, "query", strlen("query")) == 0x0) { for (uint32_t i = 0x0; i < SDM_MD_Domain_Count; i++) { printf("Domain: %s\n",SDMMDKnownDomain[i].domain); for (uint32_t j = 0x0; j < SDMMDKnownDomain[i].keyCount; j++) { printf("\t%s\n",SDMMDKnownDomain[i].keys[j]); } printf("\n\n"); } } } } if (optionsEnable[OptionsList]) { ListConnectedDevices(); } if (optionsEnable[OptionsDevice]) { if (optionsEnable[OptionsInfo]) { } else if (optionsEnable[OptionsApps]) { LookupAppsOnDevice(udid); } else if (optionsEnable[OptionsAttach]) { PerformService(udid, service); } else if (optionsEnable[OptionsQuery]) { PerformQuery(udid, domain, key); } else if (optionsEnable[OptionsRun]) { RunAppOnDeviceWithIdentifier(udid, bundle); } else if (optionsEnable[OptionsDiag]) { if (diagArg) { if (strncmp(diagArg, "sleep", strlen("sleep")) == 0x0) { SendSleepToDevice(udid); } else if (strncmp(diagArg, "reboot", strlen("reboot")) == 0x0) { SendRebootToDevice(udid); } else if (strncmp(diagArg, "shutdown", strlen("shutdown")) == 0x0) { SendShutdownToDevice(udid); } } } else if (optionsEnable[OptionsDev]) { SetupDeviceForDevelopment(udid); } else if (optionsEnable[OptionsInstall]) { InstallAppToDevice(udid, installPath); } else if (optionsEnable[OptionsConfig]) { InstallProfileToDevice(udid, installPath); } } Safe(free, domain); Safe(free, key); return 0; }
static void SDMMD_SDMMobileDeviceRefFinalize(CFTypeRef cf) { SDMMobileDeviceRef manager = (SDMMobileDeviceRef)cf; CFSafeRelease(manager->ivars.usbmuxd); CFSafeRelease(manager->ivars.deviceList); }
void SDMMD_AMDebugConnectionClose(SDMMD_AMDebugConnectionRef dconn) { CFSafeRelease(dconn->device); CFSafeRelease(dconn->connection); Safe(free, dconn); }
void growl_init(void) { struct Growl_Delegate * delegateObject; CFStringRef applicationName; CFStringRef identifierString; CFDataRef icon = NULL; CFMutableStringRef iconPath = CFStringCreateMutable(kCFAllocatorDefault, 0); char *home = getenv( "HOME" ); applicationName = CFSTR("growl-irssi"); identifierString = NULL; CFStringAppendCString(iconPath, home, kCFStringEncodingUTF8); CFStringAppend(iconPath, CFSTR("/.irssi/irssi.icns")); icon = (CFDataRef)copyIconData(iconPath); CFSafeRelease(iconPath); // Can't register console app growl without icon data so don't even try g_return_if_fail(icon != NULL); CFStringRef name = NOTIFICATION_NAME; CFArrayRef defaultAndAllNotifications = CFArrayCreate(kCFAllocatorDefault, (const void **)&name, 1, &kCFTypeArrayCallBacks); CFTypeRef registerKeys[4] = { GROWL_APP_NAME, GROWL_NOTIFICATIONS_ALL, GROWL_NOTIFICATIONS_DEFAULT, GROWL_APP_ICON, // GROWL_APP_ID }; CFTypeRef registerValues[4] = { applicationName, defaultAndAllNotifications, defaultAndAllNotifications, icon }; CFDictionaryRef registerInfo = CFDictionaryCreate(kCFAllocatorDefault, registerKeys, registerValues, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); delegateObject = (struct Growl_Delegate *)calloc(1, sizeof(struct Growl_Delegate)); delegateObject->applicationName = CFSTR("growl-irssi"); delegateObject->registrationDictionary = registerInfo; delegateObject->applicationIconData = icon; Growl_SetDelegate(delegateObject); CFRelease(defaultAndAllNotifications); CFRelease(icon); CFRelease(applicationName); // Setup irssi signal_add_last("message private", (SIGNAL_FUNC) message_incoming); signal_add_last("message public", (SIGNAL_FUNC) message_public); command_bind("growlhelp", NULL, (SIGNAL_FUNC) command_helpgrowl); command_bind("helpgrowl", NULL, (SIGNAL_FUNC) command_helpgrowl); // Growl_NotifyWithTitleDescriptionNameIconPriorityStickyClickContext(CFSTR("growl-irssi"), CFSTR("Plugin successfully loaded."), NOTIFICATION_NAME, NULL, 0, FALSE, NULL); printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Growl Support successfully loaded\n" "Try /helpgrowl or /growlhelp for a short command overview"); module_register("growl", "core"); }
CFMutableDictionaryRef SDMMD__CreatePairingMaterial(CFDataRef devicePubkey) { CFMutableDictionaryRef record = NULL; RSA *rsaBIOData = NULL; BIO *deviceBIO = SDMMD__create_bio_from_data(devicePubkey); if (deviceBIO) { PEM_read_bio_RSAPublicKey(deviceBIO, &rsaBIOData, NULL, NULL); BIO_free(deviceBIO); } else { printf("Could not decode device public key\\n"); } RSA *rootKeyPair = RSA_generate_key(2048, 65537, NULL, NULL); if (!rootKeyPair) { printf("Could not allocate root key pair\n"); } RSA *hostKeyPair = RSA_generate_key(2048, 65537, NULL, NULL); if (!hostKeyPair) { printf("Could not allocate host key pair\n"); } sdmmd_return_t result = kAMDSuccess; EVP_PKEY *rootEVP = EVP_PKEY_new(); if (!rootEVP) { printf("Could not allocate root EVP key\\n"); } else { result = EVP_PKEY_assign(rootEVP, EVP_CTRL_RAND_KEY, PtrCast(rootKeyPair, char *)); if (!result) { printf("Could not assign root key pair\n"); } } EVP_PKEY *hostEVP = EVP_PKEY_new(); if (!hostEVP) { printf("Could not allocate host EVP key\\n"); } else { result = EVP_PKEY_assign(hostEVP, EVP_CTRL_RAND_KEY, PtrCast(hostKeyPair, char *)); if (!result) { printf("Could not assign host key pair\n"); } } EVP_PKEY *deviceEVP = EVP_PKEY_new(); if (!deviceEVP) { printf("Could not allocate device EVP key\\n"); } else { result = EVP_PKEY_assign(deviceEVP, EVP_CTRL_RAND_KEY, PtrCast(rsaBIOData, char *)); if (!result) { printf("Could not assign device key pair\n"); } } X509 *rootX509 = X509_new(); if (!rootX509) { printf("Could not create root X509\\n"); } else { X509_set_pubkey(rootX509, rootEVP); X509_set_version(rootX509, 2); ASN1_INTEGER *rootSerial = X509_get_serialNumber(rootX509); ASN1_INTEGER_set(rootSerial, 0); ASN1_TIME *rootAsn1time = ASN1_TIME_new(); ASN1_TIME_set(rootAsn1time, 0); X509_set_notBefore(rootX509, rootAsn1time); ASN1_TIME_set(rootAsn1time, 0x12cc0300); // 60 sec * 60 minutes * 24 hours * 365 days * 10 years X509_set_notAfter(rootX509, rootAsn1time); ASN1_TIME_free(rootAsn1time); SDMMD__add_ext(rootX509, NID_basic_constraints, "critical,CA:TRUE"); SDMMD__add_ext(rootX509, NID_subject_key_identifier, "hash"); result = X509_sign(rootX509, rootEVP, EVP_sha1()); if (!result) { printf("Could not sign root cert\\n"); } } X509 *hostX509 = X509_new(); if (!hostX509) { printf("Could not create host X509\\n"); } else { X509_set_pubkey(hostX509, hostEVP); X509_set_version(hostX509, 2); ASN1_INTEGER *hostSerial = X509_get_serialNumber(hostX509); ASN1_INTEGER_set(hostSerial, 0); ASN1_TIME *hostAsn1time = ASN1_TIME_new(); ASN1_TIME_set(hostAsn1time, 0); X509_set_notBefore(hostX509, hostAsn1time); ASN1_TIME_set(hostAsn1time, 0x12cc0300); // 60 sec * 60 minutes * 24 hours * 365 days * 10 years X509_set_notAfter(hostX509, hostAsn1time); ASN1_TIME_free(hostAsn1time); SDMMD__add_ext(hostX509, NID_basic_constraints, "critical,CA:FALSE"); SDMMD__add_ext(hostX509, NID_subject_key_identifier, "hash"); SDMMD__add_ext(hostX509, NID_key_usage, "critical,digitalSignature,keyEncipherment"); result = X509_sign(hostX509, rootEVP, EVP_sha1()); if (!result) { printf("Could not sign host cert\\n"); } } X509 *deviceX509 = X509_new(); if (!deviceX509) { printf("Could not create device X509\\n"); } else { X509_set_pubkey(deviceX509, deviceEVP); X509_set_version(deviceX509, 2); ASN1_INTEGER *deviceSerial = X509_get_serialNumber(deviceX509); ASN1_INTEGER_set(deviceSerial, 0); ASN1_TIME *deviceAsn1time = ASN1_TIME_new(); ASN1_TIME_set(deviceAsn1time, 0); X509_set_notBefore(deviceX509, deviceAsn1time); ASN1_TIME_set(deviceAsn1time, 0x12cc0300); // 60 sec * 60 minutes * 24 hours * 365 days * 10 years X509_set_notAfter(deviceX509, deviceAsn1time); ASN1_TIME_free(deviceAsn1time); SDMMD__add_ext(deviceX509, NID_basic_constraints, "critical,CA:FALSE"); SDMMD__add_ext(deviceX509, NID_subject_key_identifier, "hash"); SDMMD__add_ext(deviceX509, NID_key_usage, "critical,digitalSignature,keyEncipherment"); result = X509_sign(deviceX509, rootEVP, EVP_sha1()); if (!result) { printf("Could not sign device cert\\n"); } } CFDataRef rootCert = SDMMD_CreateDataFromX509Certificate(rootX509); CFDataRef hostCert = SDMMD_CreateDataFromX509Certificate(hostX509); CFDataRef deviceCert = SDMMD_CreateDataFromX509Certificate(deviceX509); CFDataRef rootPrivKey = SDMMD_CreateDataFromPrivateKey(rootEVP); CFDataRef hostPrivKey = SDMMD_CreateDataFromPrivateKey(hostEVP); CFStringRef hostId = SDMMD_CreateUUID(); record = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (record) { CFDictionarySetValue(record, CFSTR("RootCertificate"), rootCert); CFDictionarySetValue(record, CFSTR("HostCertificate"), hostCert); CFDictionarySetValue(record, CFSTR("DeviceCertificate"), deviceCert); CFDictionarySetValue(record, CFSTR("RootPrivateKey"), rootPrivKey); CFDictionarySetValue(record, CFSTR("HostPrivateKey"), hostPrivKey); CFDictionarySetValue(record, CFSTR("HostID"), hostId); } CFSafeRelease(rootCert); CFSafeRelease(hostCert); CFSafeRelease(deviceCert); CFSafeRelease(rootPrivKey); CFSafeRelease(hostPrivKey); CFSafeRelease(hostId); Safe(EVP_PKEY_free, rootEVP); Safe(EVP_PKEY_free, hostEVP); Safe(EVP_PKEY_free, deviceEVP); Safe(X509_free, rootX509); Safe(X509_free, hostX509); Safe(X509_free, deviceX509); return record; }
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; } }
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(); } } */ } } } } } }
static void SDMMD_AFCConnectionRefFinalize(CFTypeRef cf) { SDMMD_AFCConnectionRef connection = (SDMMD_AFCConnectionRef)cf; SDMMD_AMDServiceConnectionInvalidate(connection->ivars.handle); CFSafeRelease(connection->ivars.handle); Safe(dispatch_release, connection->ivars.operationQueue); }
sdmmd_return_t SDMMD_perform_command(SDMMD_AMConnectionRef conn, CFStringRef command, uint64_t code, CallBack handle, uint32_t argsCount, void* paramStart, ...) { sdmmd_return_t result = kAMDSuccess; CFMutableDictionaryRef message = SDMMD_create_dict(); if (message) { va_list args; CFDictionarySetValue(message, CFSTR("Command"), command); va_start(args, paramStart); CFTypeRef key, value; for (uint32_t i = 0; i < argsCount; i++) { key = va_arg(args, CFTypeRef); value = va_arg(args, CFTypeRef); CFDictionarySetValue(message, key, value); i++; } va_end(args); SocketConnection sock = SDMMD_TranslateConnectionToSocket(conn); result = SDMMD_ServiceSendStream(sock, message, kCFPropertyListXMLFormat_v1_0); CFSafeRelease(message); if (result == 0) { CFDictionaryRef response = NULL; result = SDMMD_ServiceReceiveStream(sock, (CFPropertyListRef*)&response); if (result == 0 && response) { while (result == 0) { result = SDMMD__ErrorHandler(SDMMD__ConvertServiceError, response); CheckErrorAndReturn(result); CFTypeRef status = CFDictionaryGetValue(response, CFSTR("Status")); if (status) { if (CFStringCompare(status, CFSTR("Complete"), 0) != 0) { CFArrayRef responses = CFDictionaryGetValue(response, CFSTR("CurrentList")); if (responses) { uint64_t count = CFArrayGetCount(responses); for (uint32_t i = 0; i < count; i++) { CFDictionaryRef value = CFArrayGetValueAtIndex(responses, i); handle(value, paramStart); } } else { handle(response, 0); } } else { break; } } SDMMD_ServiceReceiveStream(sock, (CFPropertyListRef*)&response); } } else { result = kAMDReceiveMessageError; printf("call_and_response: Could not receive response from proxy.\n"); } } else { result = kAMDSendMessageError; printf("call_and_response: Could not send request to proxy.\n"); } } else { result = kAMDUndefinedError; } ExitLabelAndReturn(result); }
void AMAuthInstallSetFusingServerURL(AMAuthInstallClassRef install, CFStringRef url) { if (url) { CFSafeRelease(install->ivars.fusingServer); install->ivars.fusingServer = url; } }
void AMAuthInstallBasebandSetVendorData(AMAuthInstallClassRef install, CFDataRef vendor_data) { CFDataRef vendor = install->ivars.VendorData; CFSafeRelease(vendor); install->ivars.VendorData = vendor_data; }
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); }
sdmmd_return_t SDMMD_AMDeviceTransferApplication(SDMMD_AMConnectionRef conn, CFStringRef path, CFDictionaryRef options, CallBack transferCallback, void* unknown) { sdmmd_return_t result = kAMDInvalidArgumentError; if (path) { if (conn) { char *cpath = calloc(1, sizeof(char[1024])); ATR_UNUSED struct stat pathStat, remoteStat; Boolean status = CFStringGetCString(path, cpath, 1024, kCFStringEncodingUTF8); if (status) { CFURLRef deviceURL = SDMMD__AMDCFURLCreateFromFileSystemPathWithSmarts(path); if (deviceURL) { CFStringRef lastComp = CFURLCopyLastPathComponent(deviceURL); if (lastComp) { CFURLRef base = SDMMD__AMDCFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault, CFSTR("PublicStaging"), 0, true); CFURLRef copy = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, base, lastComp, true); char *copyPath = calloc(1024, sizeof(char)); SDMMD__AMDCFURLGetCStringForFileSystemPath(copy, copyPath); SDMMD_fire_callback_767f4(transferCallback, unknown, 0, CFSTR("PreflightingTransfer")); //SDMMD_preflight_transfer(&cpath, &pathStat, &remoteStat); SDMMD_fire_callback_767f4(transferCallback, unknown, 0, CFSTR("TransferingPackage")); SDMMD_AFCConnectionRef afcConn = SDMMD_AFCConnectionCreate(conn);//(r12, conn, 0x0, 0x0, &var_72); if (afcConn) { result = kAMDSuccess; } CheckErrorAndReturn(result); result = SDMMD_AMDeviceCopy(afcConn, cpath, copyPath); /* CFDataRef touchResponse; result = SDMMD_check_can_touch(afcConn, &touchResponse); CheckErrorAndReturn(result); CFURLRef parent = CFURLCreateCopyDeletingLastPathComponent(r12, r13); result = SDMMD_make_path(afcConn, parent); CheckErrorAndReturn(result); result = SDMMD_nuke_path(afcConn, r13); if ((result | 0x8) == 0x8) { int statResult = lstat(cpath, &pathStat); if (statResult != 0xff) { if ((var_84 & 0xffff & 0xf000) != 0xa000) { if (rax == 0x8000) { rbx = SDMMD_copy_touch_file(&remoteStat, transferCallback, unknown, afcConn, &cpath, ©Path); } else { if (rax == 0x4000) { rbx = SDMMD_copy_directory(&remoteStat, transferCallback, unknown, afcConn, &cpath, ©Path); } else { printf("transfer_package: Don't know how to copy this type of file: %s\n", cpath); } } } else { rbx = SDMMD_copy_symlink(afcConn, &cpath, ©Path); } r14 = 0x0; if (rbx != 0x0) { r9 = SDMMD_AFCErrorString(rbx); printf("transfer_package: Could not copy %s to %s on the device.\n", cpath, copyPath); result = kAMDUndefinedError; } result = SDMMD_AFCConnectionClose(afcConn); if (result) { printf("transfer_package: Could not close AFC connection. error: %i\n", result); } CFSafeRelease(r12); } */ CFSafeRelease(base); CFSafeRelease(copy); } CFSafeRelease(lastComp); } CFSafeRelease(deviceURL); } else { result = kAMDUndefinedError; } Safe(free, cpath); } } ExitLabelAndReturn(result); }
void StartDebuggingAndDetach(char *udid, char *app_path) { SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid); if (device) { CFStringRef bundleId = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8 *)app_path, strlen(app_path), kCFStringEncodingUTF8, false); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, bundleId, kCFURLPOSIXPathStyle, false); CFURLRef disk_app_url = CFURLCopyAbsoluteURL(relative_url); CFStringRef bundle_identifier = copy_disk_app_identifier(disk_app_url); SDMMD_AMDebugConnectionRef debug = SDMMD_AMDebugConnectionCreateForDevice(device); SDMMD_AMDebugConnectionStart(debug); uintptr_t socket = SDMMD_AMDServiceConnectionGetSocket(debug->connection); CFSocketContext context = { 0, (void*)socket, NULL, NULL, NULL }; CFSocketRef fdvendor = CFSocketCreate(NULL, AF_UNIX, 0, 0, kCFSocketAcceptCallBack, &socket_callback, &context); int yes = 1; setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); struct sockaddr_un address; memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; strcpy(address.sun_path, SDM_LLDB_SOCKET); address.sun_len = SUN_LEN(&address); CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&address, sizeof(address)); unlink(SDM_LLDB_SOCKET); CFSocketSetAddress(fdvendor, address_data); CFRelease(address_data); CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes); SDMMD_AMDeviceRef device = SDMMD_AMDServiceConnectionGetDevice(debug->connection); CFMutableStringRef cmds = CFStringCreateMutableCopy(NULL, 0, LLDB_PREP_CMDS); CFRange range = { 0, CFStringGetLength(cmds) }; CFURLRef device_app_url = copy_device_app_url(device, bundle_identifier); CFStringRef device_app_path = CFURLCopyFileSystemPath(device_app_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{DEVICE_PATH}"), device_app_path, range, 0); range.length = CFStringGetLength(cmds); CFStringRef disk_app_path = CFURLCopyFileSystemPath(disk_app_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{APP_PATH}"), disk_app_path, range, 0); range.length = CFStringGetLength(cmds); CFURLRef device_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, device_app_url); CFStringRef device_container_path = CFURLCopyFileSystemPath(device_container_url, kCFURLPOSIXPathStyle); CFMutableStringRef dcp_noprivate = CFStringCreateMutableCopy(NULL, 0, device_container_path); range.length = CFStringGetLength(dcp_noprivate); CFStringFindAndReplace(dcp_noprivate, CFSTR("/private/var/"), CFSTR("/var/"), range, 0); range.length = CFStringGetLength(cmds); CFStringFindAndReplace(cmds, CFSTR("{device_container}"), dcp_noprivate, range, 0); range.length = CFStringGetLength(cmds); CFURLRef disk_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, disk_app_url); CFStringRef disk_container_path = CFURLCopyFileSystemPath(disk_container_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{disk_container}"), disk_container_path, range, 0); CFDataRef cmds_data = CFStringCreateExternalRepresentation(NULL, cmds, kCFStringEncodingASCII, 0); FILE *out = fopen(PREP_CMDS_PATH, "w"); fwrite(CFDataGetBytePtr(cmds_data), CFDataGetLength(cmds_data), 1, out); fclose(out); CFSafeRelease(cmds); CFSafeRelease(bundle_identifier); CFSafeRelease(device_app_url); CFSafeRelease(device_app_path); CFSafeRelease(disk_app_path); CFSafeRelease(device_container_url); CFSafeRelease(device_container_path); CFSafeRelease(dcp_noprivate); CFSafeRelease(disk_container_url); CFSafeRelease(disk_container_path); CFSafeRelease(cmds_data); signal(SIGHUP, exit); pid_t parent = getpid(); int pid = fork(); if (pid == 0) { system("xcrun -sdk iphoneos lldb /tmp/sdmmd-lldb-prep"); kill(parent, SIGHUP); _exit(0); } CFRunLoopRun(); } }
void SDMMD_AFCConnectionRelease(SDMMD_AFCConnectionRef conn) { if (conn) { CFSafeRelease(conn->handle); dispatch_release(conn->operationQueue); } }