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); } }
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; }
struct SpringboardDeviceInfo* CreateSpringboardInfoFromDevice(SDMMD_AMDeviceRef device) { struct SpringboardDeviceInfo *info = calloc(0x1, S(struct SpringboardDeviceInfo)); CFNumberRef dockCount = SDMMD_AMDeviceCopyValue(device, CFSTR(kiTunesDomain), CFSTR(kHomeScreenIconDockMaxCount)); CFNumberGetValue(dockCount, kCFNumberSInt32Type, &(info->dockCount)); CFSafeRelease(dockCount); CFNumberRef screenRow = SDMMD_AMDeviceCopyValue(device, CFSTR(kiTunesDomain), CFSTR(kHomeScreenIconRows)); CFNumberGetValue(screenRow, kCFNumberSInt32Type, &(info->screenRow)); CFSafeRelease(screenRow); CFNumberRef screenColumn = SDMMD_AMDeviceCopyValue(device, CFSTR(kiTunesDomain), CFSTR(kHomeScreenIconColumns)); CFNumberGetValue(screenColumn, kCFNumberSInt32Type, &(info->screenColumn)); CFSafeRelease(screenColumn); CFNumberRef screenMaxPage = SDMMD_AMDeviceCopyValue(device, CFSTR(kiTunesDomain), CFSTR(kHomeScreenMaxPages)); CFNumberGetValue(screenMaxPage, kCFNumberSInt32Type, &(info->screenMaxPage)); CFSafeRelease(screenMaxPage); CFNumberRef folderRow = SDMMD_AMDeviceCopyValue(device, CFSTR(kiTunesDomain), CFSTR(kIconFolderRows)); CFNumberGetValue(folderRow, kCFNumberSInt32Type, &(info->folderRow)); CFSafeRelease(folderRow); CFNumberRef folderColumn = SDMMD_AMDeviceCopyValue(device, CFSTR(kiTunesDomain), CFSTR(kIconFolderColumns)); CFNumberGetValue(folderColumn, kCFNumberSInt32Type, &(info->folderColumn)); CFSafeRelease(folderColumn); CFNumberRef folderMaxPage = SDMMD_AMDeviceCopyValue(device, CFSTR(kiTunesDomain), CFSTR(kIconFolderMaxPages)); CFNumberGetValue(folderMaxPage, kCFNumberSInt32Type, &(info->folderMaxPage)); CFSafeRelease(folderMaxPage); return info; }
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; }
bool SDMMD_device_os_is_at_least(SDMMD_AMDeviceRef device, CFStringRef version) { bool result = false; if (device) { SDMMD_AMDeviceConnect(device); CFStringRef prodVers = SDMMD_AMDeviceCopyValue(device, NULL, CFSTR(kProductVersion)); if (prodVers) { result = (CFStringCompare(prodVers, version, kCFCompareNumerically) != kCFCompareLessThan ? true : false); } CFSafeRelease(prodVers); } return result; }