#import <ImageIO/ImageIO.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
NSFileHandle *stdin = [NSFileHandle fileHandleWithStandardInput];
NSData *data = [stdin readDataToEndOfFile];
CFDataRef dataRef = (__bridge CFDataRef)data;
CGImageSourceRef source = CGImageSourceCreateWithData(dataRef, nil);
CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, nil);
size_t width = CGImageGetWidth(cgImage);
size_t height = CGImageGetHeight(cgImage);
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(cgImage) & kCGBitmapAlphaInfoMask;
BOOL hasAlpha = NO;
if (alphaInfo == kCGImageAlphaPremultipliedLast ||
alphaInfo == kCGImageAlphaPremultipliedFirst ||
alphaInfo == kCGImageAlphaLast ||
alphaInfo == kCGImageAlphaFirst) {
hasAlpha = YES;
}
CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Host;
bitmapInfo |= hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst;
CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, 0, CGColorSpaceCreateDeviceRGB(), bitmapInfo);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
CGImageRef newImage = CGBitmapContextCreateImage(context);
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
And the compile instructions are as follows:
./afl-clang -fobjc-abi-version=2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -o mainnnn /Users/lilang_wu/Documents/IOS/ios_fuzz/test11.m -framework Foundation -framework UIKit -framework ImageIO
However, the compile results contain many errors:
/var/folders/yv/9dh3cw_976s13hk5t90cyjrw0000gn/T//.afl-78821-1476262885.s:2:2: warning: .ios_version_min should only be used for ios targets
.ios_version_min 10, 0
^
Undefined symbols for architecture x86_64:
"_CGBitmapContextCreate", referenced from:
-[MyDelegate application:didFinishLaunchingWithOptions:] in test11-df485d.o
"_CGBitmapContextCreateImage", referenced from:
-[MyDelegate application:didFinishLaunchingWithOptions:] in test11-df485d.o
"_CGColorSpaceCreateDeviceRGB", referenced from:
-[MyDelegate application:didFinishLaunchingWithOptions:] in test11-df485d.o
"_CGContextDrawImage", referenced from:
-[MyDelegate application:didFinishLaunchingWithOptions:] in test11-df485d.o
"_CGImageGetAlphaInfo", referenced from:
-[MyDelegate application:didFinishLaunchingWithOptions:] in test11-df485d.o
"_CGImageGetHeight", referenced from:
-[MyDelegate application:didFinishLaunchingWithOptions:] in test11-df485d.o
"_CGImageGetWidth", referenced from:
-[MyDelegate application:didFinishLaunchingWithOptions:] in test11-df485d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Could anyone give me some suggestions or any simple examples?