Skip to content

Commit

Permalink
Fix makefile and clean up library
Browse files Browse the repository at this point in the history
  • Loading branch information
sbingner committed Dec 22, 2018
1 parent d782fbf commit 28b3bce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ TOOL_NAME = inject
inject_CODESIGN_FLAGS = -Sentitlements.xml
inject_LIBRARIES = mis
inject_FRAMEWORKS = IOKit Security
inject_FILES = main.c $(libinjection_FILES)
inject_FILES = main.c inject.m patchfinder64.c kern_funcs.c

include $(THEOS_MAKE_PATH)/tool.mk
2 changes: 1 addition & 1 deletion inject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#ifndef _INJECT_H_
#define _INJECT_H_

int injectTrustCache(int argc, char* argv[], uint64_t trust_chain);
int injectTrustCache(int filecount, char* files[], uint64_t trust_chain);

#endif
28 changes: 14 additions & 14 deletions inject.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool check_amfi(NSString *path) {
#endif
}

int injectTrustCache(int argc, char* argv[], uint64_t trust_chain) {
int injectTrustCache(int filecount, char* files[], uint64_t trust_chain) {
@autoreleasepool {
struct trust_mem mem;
uint64_t kernel_trust = 0;
Expand All @@ -117,15 +117,15 @@ int injectTrustCache(int argc, char* argv[], uint64_t trust_chain) {
CFDictionaryRef cfinfo;
int duplicates=0;

for (int i = 1; i < argc; i++) {
OSStatus result = SecStaticCodeCreateWithPathAndAttributes(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)@(argv[i]), kCFURLPOSIXPathStyle, false), kSecCSDefaultFlags, NULL, &staticCode);
for (int i = 0; i < filecount; i++) {
OSStatus result = SecStaticCodeCreateWithPathAndAttributes(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)@(files[i]), kCFURLPOSIXPathStyle, false), kSecCSDefaultFlags, NULL, &staticCode);
if (result != errSecSuccess) {
if (_SecCopyErrorMessageString != NULL) {
CFStringRef error = _SecCopyErrorMessageString(result, NULL);
fprintf(stderr, "Unable to generate cdhash for %s: %s\n", argv[i], [(__bridge id)error UTF8String]);
fprintf(stderr, "Unable to generate cdhash for %s: %s\n", files[i], [(__bridge id)error UTF8String]);
CFRelease(error);
} else {
fprintf(stderr, "Unable to generate cdhash for %s: %d\n", argv[i], result);
fprintf(stderr, "Unable to generate cdhash for %s: %d\n", files[i], result);
}
continue;
}
Expand All @@ -135,31 +135,31 @@ int injectTrustCache(int argc, char* argv[], uint64_t trust_chain) {
NSDictionary *info = CFBridgingRelease(cfinfo);
CFRelease(staticCode);
if (result != errSecSuccess) {
fprintf(stderr, "Unable to copy cdhash info for %s\n", argv[i]);
fprintf(stderr, "Unable to copy cdhash info for %s\n", files[i]);
continue;
}
NSArray *cdhashes = info[@"cdhashes"];
NSArray *algos = info[@"digest-algorithms"];
NSUInteger algoIndex = [algos indexOfObject:@(cdHashTypeSHA256)];

if (cdhashes == nil) {
printf("%s: no cdhashes\n", argv[i]);
printf("%s: no cdhashes\n", files[i]);
} else if (algos == nil) {
printf("%s: no algos\n", argv[i]);
printf("%s: no algos\n", files[i]);
} else if (algoIndex == NSNotFound) {
printf("%s: does not have SHA256 hash\n", argv[i]);
printf("%s: does not have SHA256 hash\n", files[i]);
} else {
NSData *cdhash = [cdhashes objectAtIndex:algoIndex];
if (cdhash != nil) {
if (hashes[cdhash] == nil) {
printf("%s: OK\n", argv[i]);
hashes[cdhash] = @(argv[i]);
printf("%s: OK\n", files[i]);
hashes[cdhash] = @(files[i]);
} else {
printf("%s: same as %s (ignoring)", argv[i], [hashes[cdhash] UTF8String]);
printf("%s: same as %s (ignoring)", files[i], [hashes[cdhash] UTF8String]);
duplicates++;
}
} else {
printf("%s: missing SHA256 cdhash entry\n", argv[i]);
printf("%s: missing SHA256 cdhash entry\n", files[i]);
}
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ int injectTrustCache(int argc, char* argv[], uint64_t trust_chain) {
kwrite(kernel_trust + sizeof(mem), buffer, mem.count * TRUST_CDHASH_LEN);
wk64(trust_chain, kernel_trust);

return argc - numHashes - duplicates;
return filecount - numHashes - duplicates;
}
}

Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) {
uint64_t trust_chain = find_trustcache();
term_kernel();
printf("Injecting to trust cache...\n");
int errs = injectTrustCache(argc, argv, trust_chain);
int errs = injectTrustCache(argc - 1, argv + 1, trust_chain);
printf("Successfully injected [%d/%d] to trust cache.\n", argc - errs - 1, argc - 1);
return errs;
}

0 comments on commit 28b3bce

Please sign in to comment.