]> git.saurik.com Git - apple/security.git/blob - tests/secfuzzer/secfuzzer.m
Security-59306.61.1.tar.gz
[apple/security.git] / tests / secfuzzer / secfuzzer.m
1 //
2 // secfuzzer.c
3 // Security
4 //
5
6 #import <Foundation/Foundation.h>
7 #import <stdio.h>
8 #import <dlfcn.h>
9 #import <err.h>
10
11 int
12 main(int argc, char **argv)
13 {
14 int (*function)(const void *data, size_t len) = NULL;
15
16 if (argc < 2)
17 err(1, "%s library funcation", getprogname());
18
19 char *libraryName = argv[1];
20 char *funcationName = argv[2];
21 void *library;
22
23 library = dlopen(libraryName, RTLD_NOW);
24 if (library == NULL)
25 errx(1, "failed to open %s: %s", libraryName, dlerror());
26
27
28 function = dlsym(library, funcationName);
29 if (function == NULL)
30 errx(1, "didn't find %s in %s: %s", funcationName, libraryName, dlerror());
31
32 argc -= 3;
33 argv += 3;
34
35 while (argc > 0) {
36 @autoreleasepool {
37 NSError *error = NULL;
38 NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithUTF8String:argv[0]] options:0 error:&error];
39 if (data == NULL)
40 NSLog(@"%s: %@", argv[0], error);
41
42 function([data bytes], [data length]);
43 }
44 argv++;
45 argc--;
46 }
47 return 0;
48 }