Example #1
0
CFDictionaryRef device_info(int socket, CFDictionaryRef request)
{
    uint8_t dkey[40]={0};
    uint8_t emf[36]={0};

    struct HFSInfos hfsinfos={0};
    
    CFMutableDictionaryRef out  = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                                            0,
                                                            &kCFTypeDictionaryKeyCallBacks,
                                                            &kCFTypeDictionaryValueCallBacks);	
    
    get_device_infos(out);
    
    getHFSInfos(&hfsinfos);
    /*
    printf("NAND block size  : %x\n", hfsinfos.blockSize);
    printf("Data volume UUID : %llx\n", CFSwapInt64BigToHost(hfsinfos.volumeUUID));
    printf("Data volume offset : %x\n", hfsinfos.dataVolumeOffset);
    */
    uint8_t* key835 = IOAES_key835();
    uint8_t* key89B = IOAES_key89B();
    
    if (!AppleEffaceableStorage__getBytes(lockers, 960))
    {
        CFDataRef lockersData = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, lockers, 960, kCFAllocatorNull);
        CFDictionaryAddValue(out, CFSTR("lockers"), lockersData);
        CFRelease(lockersData);
        
        if (!AppleEffaceableStorage__getLockerFromBytes(LOCKER_DKEY, lockers, 960, dkey, 40))
        {
            aes_key_wrap_ctx ctx;

            aes_key_wrap_set_key(&ctx, key835, 16);

            if(aes_key_unwrap(&ctx, dkey, dkey, 32/8))
                printf("FAIL unwrapping DKey with key 0x835\n");
        }
        if (!AppleEffaceableStorage__getLockerFromBytes(LOCKER_EMF, lockers, 960, emf, 36))
        {
            doAES(&emf[4], &emf[4], 32, kIOAESAcceleratorCustomMask, key89B, NULL, kIOAESAcceleratorDecrypt, 128);
        }
        else if (!AppleEffaceableStorage__getLockerFromBytes(LOCKER_LWVM, lockers, 960, lwvm, 0x50))
        {
            doAES(lwvm, lwvm, 0x50, kIOAESAcceleratorCustomMask, key89B, NULL, kIOAESAcceleratorDecrypt, 128);
            memcpy(&emf[4], &lwvm[32+16], 32);
        }
    }
    
    CFNumberRef n = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &hfsinfos.dataVolumeOffset);
    CFDictionaryAddValue(out, CFSTR("dataVolumeOffset"), n);
    CFRelease(n);
    addHexaString(out, CFSTR("dataVolumeUUID"), (uint8_t*) &hfsinfos.volumeUUID, 8);
    addHexaString(out, CFSTR("key835"), key835, 16);
    addHexaString(out, CFSTR("key89B"), key89B, 16);
    addHexaString(out, CFSTR("EMF"), &emf[4], 32);
    addHexaString(out, CFSTR("DKey"), dkey, 32);
    
    return out;
}
Example #2
0
/**
 * Builds a buffer k-d-tree
 *
 * @param *Xtrain Pointer to array of type "FLOAT_TYPE" (either "float" or "double")
 * @param nXtrain Number of rows in *X (i.e., points/patterns)
 * @param dXtrain Number of columns in *X (one column per point/pattern)
 * @param *tree_record Pointer to struct instance storing the model
 * @param *params Pointer to struct instance storing all model parameters
 */
void build_bufferkdtree(FLOAT_TYPE * Xtrain,
		INT_TYPE nXtrain,
		INT_TYPE dXtrain,
		TREE_RECORD *tree_record,
		TREE_PARAMETERS *params) {

	int i;
	for (i = 0; i < 25; i++) {
		INIT_MY_TIMER(tree_record->timers + i);
	}

	int err_device = get_device_infos(params->platform_id, params->device_id, &(tree_record->device_infos));

	if (err_device < 0){
		printf("Error: Could not retrieve device information!");
		exit(EXIT_FAILURE);
	}

	// update tree record parameters
	tree_record->dXtrain = dXtrain;
	tree_record->nXtrain = nXtrain;
	tree_record->n_nodes = pow(2, params->tree_depth) - 1;
	tree_record->n_leaves = pow(2, params->tree_depth);
	tree_record->max_visited = 6 * (tree_record->n_leaves - 3 + 1);

	// variable buffer sizes: increase/decrease depending on the three depth
	if (params->tree_depth > 16) {
		tree_record->leaves_initial_buffer_sizes = 128;
		PRINT(params)("Warning: tree depth %i might be too large (memory consumption)!", params->tree_depth);
	} else {
		tree_record->leaves_initial_buffer_sizes = pow(2, 24 - params->tree_depth);
	}

	// memory needed for storing training data (in bytes)
	double device_mem_bytes = (double)tree_record->device_infos.device_mem_bytes;
	double device_max_alloc_bytes = (double)tree_record->device_infos.device_max_alloc_bytes;

	double train_mem_bytes = get_raw_train_mem_device_bytes(tree_record, params);
	PRINT(params)("Memory needed for all training patterns: %f (GB)\n", train_mem_bytes / MEM_GB);

	if (train_mem_bytes / params->n_train_chunks > device_mem_bytes * params->allowed_train_mem_percent_chunk) {
		params->n_train_chunks = (INT_TYPE) ceil(train_mem_bytes / (device_mem_bytes * params->allowed_train_mem_percent_chunk));
		// if set automatically, then use at least 3 chunks (hide computations and data transfer)
		if (params->n_train_chunks < 3){
			params->n_train_chunks = 3;
		}

		PRINT(params)("WARNING: Increasing number of chunks to %i ...\n", params->n_train_chunks);
	}

	double train_chunk_gb = get_train_mem_with_chunks_device_bytes(tree_record, params);
	if (params->n_train_chunks > 1){
		PRINT(params)("Memory allocated for both chunks: %f (GB)\n", (2*train_chunk_gb) / MEM_GB);
	}


	// we empty a buffer as soon as it has reached a certain filling status (here: 50%)
	tree_record->leaves_buffer_sizes_threshold = 0.9 * tree_record->leaves_initial_buffer_sizes;

	// the amount of indices removed from both queues (input and reinsert) in each round; has to
	// be reasonably large to provide sufficient work for a call to FIND_LEAF_IDX_BATCH
	tree_record->approx_number_of_avail_buffer_slots = 10 * tree_record->leaves_initial_buffer_sizes;

	PRINT(params)("Number of nodes (internal and leaves) in the top tree: %i\n",
			tree_record->n_nodes + tree_record->n_leaves);
	PRINT(params)("Number of buffers attached to the top tree: %i\n", tree_record->n_leaves);
	PRINT(params)("Buffer sizes (leaf structure): %i\n", tree_record->leaves_initial_buffer_sizes);
	PRINT(params)("Buffer empty thresholds: %i\n", tree_record->leaves_buffer_sizes_threshold);
	PRINT(params)("Indices fetched in each round (to fill buffers): %i\n",
			tree_record->approx_number_of_avail_buffer_slots);

	// array that contains the training patterns and the (original indices)
	tree_record->XtrainI = (void*) malloc(
			tree_record->nXtrain * (sizeof(FLOAT_TYPE) * tree_record->dXtrain + sizeof(INT_TYPE)));

	// the nodes and leaves arrays of the buffer kd-tree (host)
	tree_record->nodes = (TREE_NODE *) malloc(tree_record->n_nodes * sizeof(TREE_NODE));
	tree_record->leaves = (FLOAT_TYPE *) malloc(tree_record->n_leaves * LEAF_WIDTH * sizeof(FLOAT_TYPE));

	// create copy of training patterns (along with the original indices)
	kd_tree_generate_training_patterns_indices(tree_record->XtrainI, Xtrain, tree_record->nXtrain,
			tree_record->dXtrain);

	// build kd-tree and store it in nodes (medians) and leaves (fr,to values)
	kd_tree_build_tree(tree_record, params);

	// create copy of sorted training patterns (will be called by brute-force NN search)
	tree_record->Xtrain_sorted = (FLOAT_TYPE *) malloc(tree_record->nXtrain * tree_record->dXtrain * sizeof(FLOAT_TYPE));

	// create copy of original training indices on host system
	tree_record->Itrain_sorted = (INT_TYPE*) malloc(tree_record->nXtrain * sizeof(INT_TYPE));

	WRITE_SORTED_TRAINING_PATTERNS(tree_record, params);

	/* ------------------------------------- OPENCL -------------------------------------- */
	INIT_OPENCL_DEVICES(tree_record, params);
	/* ------------------------------------- OPENCL -------------------------------------- */

}
int main(int argc, char* argv[])
{
    int i;
    int nandReadOnly=0;
    struct stat st;
    
    printf("Starting ramdisk tool\n");
    printf("Compiled " __DATE__ " " __TIME__ "\n");
    printf("Revision " HGVERSION "\n");
    
    CFMutableDictionaryRef matching;
    io_service_t service = 0;
    matching = IOServiceMatching("IOWatchDogTimer");
    if (matching == NULL) {
        printf("unable to create matching dictionary for class IOWatchDogTimer\n");
    }
    
    service = IOServiceGetMatchingService(kIOMasterPortDefault, matching);
    if (service == 0) {
        printf("unable to create matching dictionary for class IOWatchDogTimer\n");
    }
    uint32_t zero = 0;
    CFNumberRef n = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &zero);
    IORegistryEntrySetCFProperties(service, n);
    IOObjectRelease(service);
    
    CFMutableDictionaryRef deviceInfos = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                                            0,
                                                            &kCFTypeDictionaryKeyCallBacks,
                                                            &kCFTypeDictionaryValueCallBacks);	
    
    get_device_infos(deviceInfos);
    init_tcp();

    sysctlbyname("kern.bootargs", bootargs, &bootargs_len, NULL, 0);
    
    if (strstr(bootargs, "nand-readonly") || strstr(bootargs, "nand-disable"))
    {
        printf("NAND read only mode, data partition wont be mounted\n");
        nandReadOnly = 1;
    }
    else
    {
        printf("Waiting for data partition\n");
        for(i=0; i < 10; i++)
        {
            if(!stat("/dev/disk0s2s1", &st))
            {
                system("/sbin/fsck_hfs  /dev/disk0s2s1");
                break;
            }
            if(!stat("/dev/disk0s1s2", &st))
            {
                system("/sbin/fsck_hfs  /dev/disk0s1s2");
                break;
            }
            if(!stat("/dev/disk0s2", &st))
            {
                system("/sbin/fsck_hfs  /dev/disk0s2");
                break;
            }
            sleep(5);
        }
    }
    init_usb(CFDictionaryGetValue(deviceInfos, CFSTR("udid")));
    printf("USB init done\n");

    system("mount /"); //make ramdisk writable
   
    chmod("/var/root/.ssh/authorized_keys", 0600); 
    chown("/var/root/.ssh/authorized_keys", 0, 0); 
    chown("/var/root/.ssh", 0, 0); 
    chown("/var/root/", 0, 0); 

    printf(" #######  ##    ##\n");
    printf("##     ## ##   ## \n");
    printf("##     ## ##  ##  \n");
    printf("##     ## #####   \n");
    printf("##     ## ##  ##  \n");
    printf("##     ## ##   ## \n"); 
    printf(" #######  ##    ##\n");
    printf("iphone-dataprotection ramdisk\n");
    printf("revision: " HGVERSION " "  __DATE__ " " __TIME__ "\n");
    
    if(!stat(execve_params[0], &st))
    {
        printf("Running %s\n", execve_params[0]);
        if((i = posix_spawn(NULL, execve_params[0], NULL, NULL, execve_params, execve_env)))
            printf("posix_spawn(%s) returned %d\n", execve_params[0], i);
    }
    else
    {
        printf("%s is missing\n", execve_params[0]);
    }
    
    /*if (nandReadOnly)
    {*/
        if(!stat(ioflash[0], &st))
        {
            printf("Running %s\n", ioflash[0]);
            if((i = posix_spawn(NULL, ioflash[0], NULL, NULL, ioflash, execve_env)))
                printf("posix_spawn(%s) returned %d\n", execve_params[0], i);
        }
    /*}*/
    
    CFMutableDictionaryRef handlers = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, NULL);
    CFDictionaryAddValue(handlers, CFSTR("DeviceInfo"), device_info);
    CFDictionaryAddValue(handlers, CFSTR("GetSystemKeyBag"), load_system_keybag);
    CFDictionaryAddValue(handlers, CFSTR("BruteforceSystemKeyBag"), bruteforce_system_keybag);
    CFDictionaryAddValue(handlers, CFSTR("KeyBagGetPasscodeKey"), keybag_get_passcode_key);
    CFDictionaryAddValue(handlers, CFSTR("GetEscrowRecord"), get_escrow_record);
    CFDictionaryAddValue(handlers, CFSTR("DownloadFile"), download_file);
    CFDictionaryAddValue(handlers, CFSTR("AES"), remote_aes);
    CFDictionaryAddValue(handlers, CFSTR("Reboot"), reboot__);

    serve_plist_rpc(1999, handlers);
    return 0;
}
Example #4
0
/**
 * Checks if platform and device are valid
 *
 * @param platform_id The OpenCL platform id to be used
 * @param device_id The OpenCL device id to be used
 *
 */
int extern_check_platform_device(int platform_id,
		int device_id){

	return get_device_infos(platform_id, device_id, NULL);

}