From cc004d3051f90a77601f4221a8855604ede7bc26 Mon Sep 17 00:00:00 2001 From: Sam Bingner Date: Thu, 21 Mar 2019 00:29:05 -1000 Subject: Getting inject running --- inject.m | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'inject.m') diff --git a/inject.m b/inject.m index 5f39e2b..a99c811 100644 --- a/inject.m +++ b/inject.m @@ -89,7 +89,7 @@ NSString *cdhashFor(NSString *file) { NSUInteger algoIndex = [algos indexOfObject:@(requiredHash)]; if (cdhashes == nil) { - printf("%s: no cdhashes\n", filename); + //printf("%s: no cdhashes\n", filename); } else if (algos == nil) { printf("%s: no algos\n", filename); } else if (algoIndex == NSNotFound) { @@ -158,7 +158,8 @@ int injectTrustCache(NSArray *files, uint64_t trust_chain, int (*pma mem.next = rk64(trust_chain); mem.count = 0; - arc4random_buf(&mem.uuid, 16); + uuid_generate(mem.uuid); + NSMutableDictionary *hashes = [NSMutableDictionary new]; int errors=0; @@ -166,13 +167,14 @@ int injectTrustCache(NSArray *files, uint64_t trust_chain, int (*pma NSString *cdhash = cdhashFor(file); if (cdhash == nil) { errors++; + continue; + } + + if (hashes[cdhash] == nil) { + //printf("%s: OK\n", file.UTF8String); + hashes[cdhash] = file; } else { - if (hashes[cdhash] == nil) { - printf("%s: OK\n", file.UTF8String); - hashes[cdhash] = file; - } else { - printf("%s: same as %s (ignoring)", file.UTF8String, [hashes[cdhash] UTF8String]); - } + printf("%s: same as %s (ignoring)\n", file.UTF8String, [hashes[cdhash] UTF8String]); } } unsigned numHashes = (unsigned)[hashes count]; @@ -190,7 +192,7 @@ int injectTrustCache(NSArray *files, uint64_t trust_chain, int (*pma return errors; } - size_t length = (sizeof(mem) + hashesToInject * TRUST_CDHASH_LEN + 0x3FFF) & ~0x3FFF; + size_t length = (32 + hashesToInject * TRUST_CDHASH_LEN + 0x3FFF) & ~0x3FFF; char *buffer = malloc(hashesToInject * TRUST_CDHASH_LEN); if (buffer == NULL) { fprintf(stderr, "Unable to allocate memory for cdhashes: %s\n", strerror(errno)); @@ -206,7 +208,13 @@ int injectTrustCache(NSArray *files, uint64_t trust_chain, int (*pma mem.count = hashesToInject; kwrite(kernel_trust, &mem, sizeof(mem)); kwrite(kernel_trust + sizeof(mem), buffer, mem.count * TRUST_CDHASH_LEN); - pmap_load_trust_cache(kernel_trust, length); + if (pmap_load_trust_cache != NULL) { + if (pmap_load_trust_cache(kernel_trust, length) != ERR_SUCCESS) { + return -4; + } + } else { + wk64(trust_chain, kernel_trust); + } return (int)errors; } -- cgit v1.2.3