我正在使用
我一直在尝试使用
有没有办法做到这一点?如何做?
谢谢。
编辑:样例代码:
CFDictionaryGetValue
从 CFDictionaryRef
中获取一个 CFStringRef
。我一直在尝试使用
CFStringGetCString
或 CFStringGetCStringPtr
将 CFStringRef
转换为 char*
,但它们要么返回 NULL,要么崩溃。有没有办法做到这一点?如何做?
谢谢。
编辑:样例代码:
SecStaticCodeRef staticCode;
CFDictionaryRef information;
SecCSFlags flags = kSecCSInternalInformation
| kSecCSSigningInformation
| kSecCSRequirementInformation
| kSecCSInternalInformation;
CFURLRef pathURL = NULL;
CFStringRef pathStr = NULL;
CFStringRef uniqueid;
char* str = NULL;
CFIndex length;
pathStr = CFStringCreateWithCString(kCFAllocatorDefault,
filename, kCFStringEncodingUTF8);
pathURL = CFURLCreateWithString(kCFAllocatorDefault, pathStr, NULL);
SecStaticCodeCreateWithPath(pathURL, kSecCSDefaultFlags, &staticCode);
SecCodeCopySigningInformation(staticCode, flags, &information);
uniqueid = (CFStringRef) CFDictionaryGetValue(information, kSecCodeInfoUnique);
// how do I convert it here to char *?
length = CFStringGetLength(uniqueid);
str = (char *)malloc( length + 1 );
CFStringGetCString(uniqueid, str, length, kCFStringEncodingUTF8);
printf("hash of signature is %s\n", str);
CFRelease(information);
CFRelease(staticCode);
CFStringGetCString()
崩溃代码是什么样子的?你有查看过这个指南吗? - Georg Fritzsche__bridge NSString*
强制转换,NSString* ns = (__bridge NSString*)cfStr ; char* regStr=[ns UTF8String] );
- bobobobo