本文整理匯總了C++中CFDataGetBytePtr函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFDataGetBytePtr函數的具體用法?C++ CFDataGetBytePtr怎麽用?C++ CFDataGetBytePtr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFDataGetBytePtr函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: isom_write_avcc
bool PrivateDecoderVDA::Init(const QString &decoder,
PlayerFlags flags,
AVCodecContext *avctx)
{
if ((decoder != "vda") || (avctx->codec_id != CODEC_ID_H264) ||
!(flags & kDecodeAllowEXT) || !avctx)
return false;
m_lib = VDALibrary::GetVDALibrary();
if (!m_lib)
return false;
uint8_t *extradata = avctx->extradata;
int extrasize = avctx->extradata_size;
if (!extradata || extrasize < 7)
return false;
CFDataRef avc_cdata = NULL;
if (extradata[0] != 1)
{
if (extradata[0] == 0 && extradata[1] == 0 && extradata[2] == 0 &&
extradata[3] == 1)
{
// video content is from x264 or from bytestream h264 (AnnexB format)
// NAL reformating to bitstream format needed
AVIOContext *pb;
if (avio_open_dyn_buf(&pb) < 0)
{
return false;
}
m_annexb = true;
isom_write_avcc(pb, extradata, extrasize);
// unhook from ffmpeg's extradata
extradata = NULL;
// extract the avcC atom data into extradata then write it into avcCData for VDADecoder
extrasize = avio_close_dyn_buf(pb, &extradata);
// CFDataCreate makes a copy of extradata contents
avc_cdata = CFDataCreate(kCFAllocatorDefault,
(const uint8_t*)extradata, extrasize);
// done with the converted extradata, we MUST free using av_free
av_free(extradata);
}
else
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Invalid avcC atom data");
return false;
}
}
else
{
if (extradata[4] == 0xFE)
{
// video content is from so silly encoder that think 3 byte NAL sizes
// are valid, setup to convert 3 byte NAL sizes to 4 byte.
extradata[4] = 0xFF;
m_convert_3byteTo4byteNALSize = true;
}
// CFDataCreate makes a copy of extradata contents
avc_cdata = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)extradata,
extrasize);
}
OSType format = 'avc1';
// check the avcC atom's sps for number of reference frames and
// bail if interlaced, VDA does not handle interlaced h264.
uint32_t avcc_len = CFDataGetLength(avc_cdata);
if (avcc_len < 8)
{
// avcc atoms with length less than 8 are borked.
CFRelease(avc_cdata);
return false;
}
bool interlaced = false;
uint8_t *spc = (uint8_t*)CFDataGetBytePtr(avc_cdata) + 6;
uint32_t sps_size = VDA_RB16(spc);
if (sps_size)
{
H264Parser *h264_parser = new H264Parser();
h264_parser->parse_SPS(spc+3, sps_size-1,
interlaced, m_max_ref_frames);
delete h264_parser;
}
else
{
m_max_ref_frames = avctx->refs;
}
if (interlaced)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Possible interlaced content. Aborting");
CFRelease(avc_cdata);
return false;
}
if (m_max_ref_frames == 0)
{
m_max_ref_frames = 2;
}
if (avctx->profile == FF_PROFILE_H264_MAIN && avctx->level == 32 &&
//.........這裏部分代碼省略.........
示例2: _ServerCreateAndRegisterNetService
/* static */ Boolean
_ServerCreateAndRegisterNetService(Server* server) {
do {
UInt32 port = server->_port;
Boolean didSet, didRegister;
CFNetServiceClientContext netSvcCtxt = {0,
server,
(CFAllocatorRetainCallBack)&CFRetain,
(CFAllocatorReleaseCallBack)&CFRelease,
(CFAllocatorCopyDescriptionCallBack)&CFCopyDescription};
// If the port was unspecified, get the port from the socket.
if (port == 0) {
// Get the local address
CFDataRef addr = CFSocketCopyAddress(server->_sockets[0]);
struct sockaddr_in* nativeAddr = (struct sockaddr_in*)CFDataGetBytePtr(addr);
CFRelease(addr);
port = ntohs(nativeAddr->sin_port);
}
// Create the service for registration.
server->_service = CFNetServiceCreate(CFGetAllocator((_CFServerRef)server),
_kCFServerEmptyString,
server->_type,
server->_name,
port);
// Require the service for the socket.
if (server->_service == NULL)
break;
// Try setting the client on the service.
didSet = CFNetServiceSetClient(server->_service,
(CFNetServiceClientCallBack)&_NetServiceCallBack,
&netSvcCtxt);
// Check to make sure it set before registering.
if (!didSet)
break;
// Schedule the service on the run loop.
CFNetServiceScheduleWithRunLoop(server->_service, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
// Start the registration.
didRegister = CFNetServiceRegisterWithOptions(server->_service, 0, NULL);
// If registration failed, die.
if (!didRegister)
break;
return TRUE;
} while (0);
// Failed to set up the service, so clean up anything that succeeded.
_ServerReleaseNetService(server);
return FALSE;
}
示例3: getActiveModifiers
KeyButton
COSXKeyState::mapKeyFromEvent(CKeyIDs& ids,
KeyModifierMask* maskOut, CGEventRef event) const
{
ids.clear();
// map modifier key
if (maskOut != NULL) {
KeyModifierMask activeMask = getActiveModifiers();
activeMask &= ~KeyModifierAltGr;
*maskOut = activeMask;
}
// get virtual key
UInt32 vkCode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
// handle up events
UInt32 eventKind = CGEventGetType(event);
if (eventKind == kCGEventKeyUp) {
// the id isn't used. we just need the same button we used on
// the key press. note that we don't use or reset the dead key
// state; up events should not affect the dead key state.
ids.push_back(kKeyNone);
return mapVirtualKeyToKeyButton(vkCode);
}
// check for special keys
CVirtualKeyMap::const_iterator i = m_virtualKeyMap.find(vkCode);
if (i != m_virtualKeyMap.end()) {
m_deadKeyState = 0;
ids.push_back(i->second);
return mapVirtualKeyToKeyButton(vkCode);
}
// get keyboard info
#if defined(MAC_OS_X_VERSION_10_5)
TISInputSourceRef currentKeyboardLayout = TISCopyCurrentKeyboardLayoutInputSource();
#else
KeyboardLayoutRef currentKeyboardLayout;
OSStatus status = KLGetCurrentKeyboardLayout(¤tKeyboardLayout);
#endif
if (currentKeyboardLayout == NULL) {
return kKeyNone;
}
// get the event modifiers and remove the command and control
// keys. note if we used them though.
// UCKeyTranslate expects old-style Carbon modifiers, so convert.
UInt32 modifiers;
modifiers = mapModifiersToCarbon(CGEventGetFlags(event));
static const UInt32 s_commandModifiers =
cmdKey | controlKey | rightControlKey;
bool isCommand = ((modifiers & s_commandModifiers) != 0);
modifiers &= ~s_commandModifiers;
// if we've used a command key then we want the glyph produced without
// the option key (i.e. the base glyph).
//if (isCommand) {
modifiers &= ~optionKey;
//}
// choose action
UInt16 action;
if(eventKind==kCGEventKeyDown) {
action = kUCKeyActionDown;
}
else if(CGEventGetIntegerValueField(event, kCGKeyboardEventAutorepeat)==1) {
action = kUCKeyActionAutoKey;
}
else {
return 0;
}
// translate via uchr resource
#if defined(MAC_OS_X_VERSION_10_5)
CFDataRef ref = (CFDataRef) TISGetInputSourceProperty(currentKeyboardLayout,
kTISPropertyUnicodeKeyLayoutData);
const UCKeyboardLayout* layout = (const UCKeyboardLayout*) CFDataGetBytePtr(ref);
const bool layoutValid = (layout != NULL);
#else
const void* resource;
int err = KLGetKeyboardLayoutProperty(currentKeyboardLayout, kKLuchrData, &resource);
const bool layoutValid = (err == noErr);
const UCKeyboardLayout* layout = (const UCKeyboardLayout*)resource;
#endif
if (layoutValid) {
// translate key
UniCharCount count;
UniChar chars[2];
LOG((CLOG_DEBUG2 "modifiers: %08x", modifiers & 0xffu));
OSStatus status = UCKeyTranslate(layout,
vkCode & 0xffu, action,
(modifiers >> 8) & 0xffu,
LMGetKbdType(), 0, &m_deadKeyState,
sizeof(chars) / sizeof(chars[0]), &count, chars);
// get the characters
if (status == 0) {
//.........這裏部分代碼省略.........
示例4: RTDECL
RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
{
AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
*pszBuf = '\0';
AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
CFStringRef PropStringRef = NULL;
switch (enmString)
{
case RTSYSDMISTR_PRODUCT_NAME: PropStringRef = CFSTR(PROP_PRODUCT_NAME); break;
case RTSYSDMISTR_PRODUCT_VERSION: PropStringRef = CFSTR(PROP_PRODUCT_VERSION); break;
case RTSYSDMISTR_PRODUCT_SERIAL: PropStringRef = CFSTR(PROP_PRODUCT_SERIAL); break;
case RTSYSDMISTR_PRODUCT_UUID: PropStringRef = CFSTR(PROP_PRODUCT_UUID); break;
case RTSYSDMISTR_MANUFACTURER: PropStringRef = CFSTR(PROP_MANUFACTURER); break;
default:
return VERR_NOT_SUPPORTED;
}
mach_port_t MasterPort;
kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &MasterPort);
if (kr != kIOReturnSuccess)
{
if (kr == KERN_NO_ACCESS)
return VERR_ACCESS_DENIED;
return RTErrConvertFromDarwinIO(kr);
}
CFDictionaryRef ClassToMatch = IOServiceMatching(IOCLASS_PLATFORMEXPERTDEVICE);
if (!ClassToMatch)
return VERR_NOT_SUPPORTED;
/* IOServiceGetMatchingServices will always consume ClassToMatch. */
io_iterator_t Iterator;
kr = IOServiceGetMatchingServices(MasterPort, ClassToMatch, &Iterator);
if (kr != kIOReturnSuccess)
return RTErrConvertFromDarwinIO(kr);
int rc = VERR_NOT_SUPPORTED;
io_service_t ServiceObject;
while ((ServiceObject = IOIteratorNext(Iterator)))
{
if ( enmString == RTSYSDMISTR_PRODUCT_NAME
|| enmString == RTSYSDMISTR_PRODUCT_VERSION
|| enmString == RTSYSDMISTR_MANUFACTURER
)
{
CFDataRef DataRef = (CFDataRef)IORegistryEntryCreateCFProperty(ServiceObject, PropStringRef,
kCFAllocatorDefault, kNilOptions);
if (DataRef)
{
size_t cbData = CFDataGetLength(DataRef);
const char *pchData = (const char *)CFDataGetBytePtr(DataRef);
rc = RTStrCopyEx(pszBuf, cbBuf, pchData, cbData);
CFRelease(DataRef);
break;
}
}
else
{
CFStringRef StringRef = (CFStringRef)IORegistryEntryCreateCFProperty(ServiceObject, PropStringRef,
kCFAllocatorDefault, kNilOptions);
if (StringRef)
{
Boolean fRc = CFStringGetCString(StringRef, pszBuf, cbBuf, kCFStringEncodingUTF8);
if (fRc)
rc = VINF_SUCCESS;
else
{
CFIndex cwc = CFStringGetLength(StringRef);
size_t cbTmp = cwc + 1;
char *pszTmp = (char *)RTMemTmpAlloc(cbTmp);
int cTries = 1;
while ( pszTmp
&& (fRc = CFStringGetCString(StringRef, pszTmp, cbTmp, kCFStringEncodingUTF8)) == FALSE
&& cTries++ < 4)
{
RTMemTmpFree(pszTmp);
cbTmp *= 2;
pszTmp = (char *)RTMemTmpAlloc(cbTmp);
}
if (fRc)
rc = RTStrCopy(pszBuf, cbBuf, pszTmp);
else if (!pszTmp)
rc = VERR_NO_TMP_MEMORY;
else
rc = VERR_ACCESS_DENIED;
RTMemFree(pszTmp);
}
CFRelease(StringRef);
break;
}
}
}
IOObjectRelease(ServiceObject);
IOObjectRelease(Iterator);
return rc;
}
示例5: GetFormatCount
bool wxDataObject::GetFromPasteboard( void * pb )
{
PasteboardRef pasteboard = (PasteboardRef) pb;
size_t formatcount = GetFormatCount(wxDataObject::Set);
wxDataFormat *array = new wxDataFormat[ formatcount ];
GetAllFormats(array, wxDataObject::Set);
ItemCount itemCount = 0;
wxString filenamesPassed;
bool transferred = false;
bool pastelocationset = false;
// we synchronize here once again, so we don't mind which flags get returned
PasteboardSynchronize( pasteboard );
OSStatus err = PasteboardGetItemCount( pasteboard, &itemCount );
if ( err == noErr )
{
for (size_t i = 0; !transferred && i < formatcount; i++)
{
// go through the data in our order of preference
wxDataFormat dataFormat = array[ i ];
for( UInt32 itemIndex = 1; itemIndex <= itemCount && transferred == false ; itemIndex++ )
{
PasteboardItemID itemID = 0;
CFArrayRef flavorTypeArray = NULL;
CFIndex flavorCount = 0;
err = PasteboardGetItemIdentifier( pasteboard, itemIndex, &itemID );
if ( err != noErr )
continue;
err = PasteboardCopyItemFlavors( pasteboard, itemID, &flavorTypeArray );
if ( err != noErr )
continue;
flavorCount = CFArrayGetCount( flavorTypeArray );
for( CFIndex flavorIndex = 0; !transferred && flavorIndex < flavorCount ; flavorIndex++ )
{
CFStringRef flavorType;
CFDataRef flavorData;
CFIndex flavorDataSize;
flavorType = (CFStringRef)CFArrayGetValueAtIndex( flavorTypeArray,
flavorIndex );
wxDataFormat flavorFormat( (wxDataFormat::NativeFormat) flavorType );
if ( dataFormat == flavorFormat )
{
if ( UTTypeConformsTo( (CFStringRef)flavorType, kPasteboardTypeFileURLPromise) )
{
if ( !pastelocationset )
{
wxString tempdir = wxFileName::GetTempDir() + wxFILE_SEP_PATH + "wxtemp.XXXXXX";
char* result = mkdtemp((char*)tempdir.fn_str().data());
if (!result)
continue;
wxCFRef<CFURLRef> dest(CFURLCreateFromFileSystemRepresentation(NULL,(const UInt8*)result,strlen(result),true));
PasteboardSetPasteLocation(pasteboard, dest);
pastelocationset = true;
}
}
else if ( flavorFormat.GetType() != wxDF_PRIVATE )
{
// indicate the expected format for the type, benefiting from native conversions eg utf8 -> utf16
flavorType = (CFStringRef) wxDataFormat( flavorFormat.GetType()).GetFormatId();
}
err = PasteboardCopyItemFlavorData( pasteboard, itemID, flavorType , &flavorData );
if ( err == noErr )
{
flavorDataSize = CFDataGetLength( flavorData );
if (dataFormat.GetType() == wxDF_FILENAME )
{
// revert the translation and decomposition to arrive at a proper utf8 string again
CFURLRef url = CFURLCreateWithBytes( kCFAllocatorDefault, CFDataGetBytePtr( flavorData ), flavorDataSize, kCFStringEncodingUTF8, NULL );
CFStringRef cfString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
CFRelease( url );
CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString);
CFRelease( cfString );
CFStringNormalize(cfMutableString,kCFStringNormalizationFormC);
wxString path = wxCFStringRef(cfMutableString).AsString();
if (!path.empty())
filenamesPassed += path + wxT("\n");
}
else
{
// because some data implementation expect trailing a trailing NUL, we add some headroom
void *buf = malloc( flavorDataSize + 4 );
if ( buf )
{
memset( buf, 0, flavorDataSize + 4 );
memcpy( buf, CFDataGetBytePtr( flavorData ), flavorDataSize );
//.........這裏部分代碼省略.........
示例6: S_set
static int
S_set(mach_port_t server, int argc, char * argv[])
{
CFDataRef data = NULL;
CFDictionaryRef dict = NULL;
const char * method_name;
if_name_t if_name;
kern_return_t kret;
ipconfig_status_t status = ipconfig_status_success_e;
void * xml_data_ptr = NULL;
int xml_data_len = 0;
strlcpy(if_name, argv[0], sizeof(if_name));
method_name = argv[1];
argv += 2;
argc -= 2;
if (strcasecmp(method_name, "NONE") == 0) {
/* nothing to do, NONE implies NULL method data */
}
else if (strcasecmp(method_name, "NONE-V6") == 0
|| strcasecmp(method_name, "NONE-V4") == 0) {
CFDictionaryRef empty_dict;
CFStringRef ip_key;
/* NONE-V{4,6} is represented as an empty IPv{4,6} dictionary */
empty_dict = CFDictionaryCreate(NULL,
NULL, NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (strcasecmp(method_name, "NONE-V6") == 0) {
ip_key = kSCEntNetIPv6;
}
else {
ip_key = kSCEntNetIPv4;
}
dict = CFDictionaryCreate(NULL,
(const void * *)&ip_key,
(const void * *)&empty_dict, 1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFRelease(empty_dict);
}
else {
dict = ConfigDictCreate(if_name, argc, argv, command_name, method_name,
TRUE);
if (dict == NULL) {
return (1);
}
}
if (dict != NULL) {
data = CFPropertyListCreateData(NULL,
dict,
kCFPropertyListBinaryFormat_v1_0,
0,
NULL);
if (data == NULL) {
CFRelease(dict);
fprintf(stderr, "failed to allocate memory\n");
return (1);
}
xml_data_ptr = (void *)CFDataGetBytePtr(data);
xml_data_len = (int)CFDataGetLength(data);
}
kret = ipconfig_set(server, if_name, xml_data_ptr, xml_data_len, &status);
my_CFRelease(&dict);
my_CFRelease(&data);
if (kret != KERN_SUCCESS) {
mach_error("ipconfig_set failed", kret);
return (1);
}
if (status != ipconfig_status_success_e) {
fprintf(stderr, "ipconfig_set %s %s failed: %s\n",
if_name, method_name, ipconfig_status_string(status));
return (1);
}
return (0);
}
示例7: _inputStreamAtEOF
__private_extern__ Boolean _inputStreamAtEOF(_CFXMLInputStream *stream) {
if (!(stream->flags & STREAM_OPEN)) return false;
if (stream->currentChar) return false;
if (stream->currentByte - CFDataGetBytePtr(stream->data) < CFDataGetLength(stream->data)) return false;
return true;
}
示例8: determineEncoding
/* Utility functions used in parsing */
static Boolean determineEncoding(_CFXMLInputStream *stream) {
const uint8_t *bytes = (uint8_t *)CFDataGetBytePtr(stream->data);
UInt32 length = CFDataGetLength(stream->data);
const uint8_t *idx = 0L, *end = 0L;
const uint8_t *base = 0L;
char quote = ' ';
Boolean useUTF8 = false;
// Check for the byte order mark first
if (length > 2) {
// This clause checks for the unicode byte order mark, or a Unicode sequence lacking the BOM; technically an error, but this check is recommended by the XML spec
if ((*bytes == 0xFF && *(bytes+1) == 0xFE) ||*(bytes+1) == 0x00) {
#if __BIG_ENDIAN__
stream->flags |= ENCODING_IS_UNICODE_SWAPPED;
#else
stream->flags |= ENCODING_IS_UNICODE_NATURAL;
#endif
if (*bytes == 0xFF) {
stream->currentByte = bytes + 2;
}
stream->encoding = kCFStringEncodingUnicode;
return true;
} else if ((*bytes == 0xFE && *(bytes+1) == 0xFF) || *bytes == 0x00) {
#if __BIG_ENDIAN__
stream->flags |= ENCODING_IS_UNICODE_NATURAL;
#else
stream->flags |= ENCODING_IS_UNICODE_SWAPPED;
#endif
if (*bytes == 0xFE) {
stream->currentByte = bytes + 2;
}
stream->encoding = kCFStringEncodingUnicode;
return true;
} else if(*bytes == 0xEF && *(bytes+1) == 0xBB && *(bytes+2) == 0xBF) {
if(*bytes == 0xEF) {
stream->currentByte = bytes + 3;
}
stream->encoding = kCFStringEncodingUTF8;
stream->flags |= ENCODING_MATCHES_ASCII;
return true;
}
}
// Scan for the <?xml.... ?> opening
if (length < 5 || strncmp((char const *) bytes, "<?xml", 5) != 0) {
useUTF8 = true;
}
if (!useUTF8) {
idx = bytes + 5;
end = bytes + length;
// Found "<?xml"; now we scan for "encoding"
while (idx < end) {
uint8_t ch = *idx;
const uint8_t *scan;
if ( ch == '?' || ch == '>') {
useUTF8 = true;
break;
}
idx ++;
scan = idx;
if (ch == 'e' && *scan++ == 'n' && *scan++ == 'c' && *scan++ == 'o' && *scan++ == 'd' && *scan++ == 'i' && *scan++ == 'n' && *scan++ == 'g' && *scan++ == '=') {
idx = scan;
break;
}
}
if (!useUTF8 && idx >= end) {
useUTF8 = true;
}
}
if (!useUTF8) {
// Found "encoding="; see if we've got an honest-to-goodness encoding name
quote = *idx;
if (quote != '\'' && quote != '\"') {
useUTF8 = true;
}
}
if (!useUTF8) {
base = idx + 1; // Move past the quote character
idx ++;
while (idx < end && *idx != quote) idx ++;
if (idx >= end) {
useUTF8 = true;
}
}
if (!useUTF8) {
UInt32 len = idx - base;
if (len == 5 && (*base == 'u' || *base == 'U') && (base[1] == 't' || base[1] == 'T') && (base[2] == 'f' || base[2] == 'F') && (base[3] == '-') && (base[4] == '8')) {
useUTF8 = true;
} else {
CFStringRef encodingName = CFStringCreateWithBytes(stream->allocator, base, len, kCFStringEncodingISOLatin1, false);
stream->encoding = CFStringConvertIANACharSetNameToEncoding(encodingName);
CFRelease(encodingName);
}
}
if (useUTF8) {
stream->encoding = kCFStringEncodingUTF8;
stream->flags |= ENCODING_MATCHES_ASCII;
return true;
} else if (stream->encoding == kCFStringEncodingInvalidId) {
return false;
//.........這裏部分代碼省略.........
示例9: CFDataCreateCopy
CFDataRef
CFDataCreateCopy (CFAllocatorRef allocator, CFDataRef d)
{
return CFDataCreate_internal (allocator, CFDataGetBytePtr(d),
CFDataGetLength(d), NULL, true);
}
示例10: createMkext1ForArch
CFDataRef createMkext1ForArch(const NXArchInfo * arch, CFArrayRef archiveKexts,
boolean_t compress)
{
CFMutableDataRef result = NULL;
CFMutableDictionaryRef kextsByIdentifier = NULL;
Mkext1Context context;
mkext1_header * mkextHeader = NULL; // do not free
const uint8_t * adler_point = 0;
CFIndex count, i;
result = CFDataCreateMutable(kCFAllocatorDefault, /* capaacity */ 0);
if (!result || !createCFMutableDictionary(&kextsByIdentifier)) {
OSKextLogMemError();
goto finish;
}
/* mkext1 can only contain 1 kext for a given bundle identifier, so we
* have to pick out the most recent versions.
*/
count = CFArrayGetCount(archiveKexts);
for (i = 0; i < count; i++) {
OSKextRef theKext = (OSKextRef)CFArrayGetValueAtIndex(archiveKexts, i);
CFStringRef bundleIdentifier = OSKextGetIdentifier(theKext);
OSKextRef savedKext = (OSKextRef)CFDictionaryGetValue(kextsByIdentifier,
bundleIdentifier);
OSKextVersion thisVersion, savedVersion;
if (!OSKextSupportsArchitecture(theKext, arch)) {
continue;
}
if (!savedKext) {
CFDictionarySetValue(kextsByIdentifier, bundleIdentifier, theKext);
continue;
}
thisVersion = OSKextGetVersion(theKext);
savedVersion = OSKextGetVersion(savedKext);
if (thisVersion > savedVersion) {
CFDictionarySetValue(kextsByIdentifier, bundleIdentifier, theKext);
}
}
/* Add room for the mkext header and kext descriptors.
*/
CFDataSetLength(result, sizeof(mkext1_header) +
CFDictionaryGetCount(kextsByIdentifier) * sizeof(mkext_kext));
context.mkext = result;
context.kextIndex = 0;
context.compressOffset = (uint32_t)CFDataGetLength(result);
context.arch = arch;
context.fatal = false;
context.compress = compress;
CFDictionaryApplyFunction(kextsByIdentifier, addToMkext1, &context);
if (context.fatal) {
SAFE_RELEASE_NULL(result);
goto finish;
}
mkextHeader = (mkext1_header *)CFDataGetBytePtr(result);
mkextHeader->magic = OSSwapHostToBigInt32(MKEXT_MAGIC);
mkextHeader->signature = OSSwapHostToBigInt32(MKEXT_SIGN);
mkextHeader->version = OSSwapHostToBigInt32(0x01008000); // 'vers' 1.0.0
mkextHeader->numkexts =
OSSwapHostToBigInt32(CFDictionaryGetCount(kextsByIdentifier));
mkextHeader->cputype = OSSwapHostToBigInt32(arch->cputype);
mkextHeader->cpusubtype = OSSwapHostToBigInt32(arch->cpusubtype);
mkextHeader->length = OSSwapHostToBigInt32(CFDataGetLength(result));
adler_point = (UInt8 *)&mkextHeader->version;
mkextHeader->adler32 = OSSwapHostToBigInt32(local_adler32(
(UInt8 *)&mkextHeader->version,
(int)(CFDataGetLength(result) - (adler_point - (uint8_t *)mkextHeader))));
OSKextLog(/* kext */ NULL, kOSKextLogProgressLevel | kOSKextLogArchiveFlag,
"Created mkext for %s containing %lu kexts.",
arch->name,
CFDictionaryGetCount(kextsByIdentifier));
finish:
SAFE_RELEASE(kextsByIdentifier);
return result;
}
示例11: keychain_iter_start
static int
keychain_iter_start(hx509_context context,
hx509_certs certs, void *data, void **cursor)
{
#ifndef __APPLE_TARGET_EMBEDDED__
struct ks_keychain *ctx = data;
#endif
struct iter *iter;
iter = calloc(1, sizeof(*iter));
if (iter == NULL) {
hx509_set_error_string(context, 0, ENOMEM, "out of memory");
return ENOMEM;
}
#ifndef __APPLE_TARGET_EMBEDDED__
if (ctx->anchors) {
CFArrayRef anchors;
int ret;
int i;
ret = hx509_certs_init(context, "MEMORY:ks-file-create",
0, NULL, &iter->certs);
if (ret) {
free(iter);
return ret;
}
ret = SecTrustCopyAnchorCertificates(&anchors);
if (ret != 0) {
hx509_certs_free(&iter->certs);
free(iter);
hx509_set_error_string(context, 0, ENOMEM,
"Can't get trust anchors from Keychain");
return ENOMEM;
}
for (i = 0; i < CFArrayGetCount(anchors); i++) {
SecCertificateRef cr;
hx509_cert cert;
CFDataRef dataref;
cr = (SecCertificateRef)CFArrayGetValueAtIndex(anchors, i);
dataref = SecCertificateCopyData(cr);
if (dataref == NULL)
continue;
ret = hx509_cert_init_data(context, CFDataGetBytePtr(dataref), CFDataGetLength(dataref), &cert);
CFRelease(dataref);
if (ret)
continue;
ret = hx509_certs_add(context, iter->certs, cert);
hx509_cert_free(cert);
}
CFRelease(anchors);
if (ret != 0) {
hx509_certs_free(&iter->certs);
free(iter);
hx509_set_error_string(context, 0, ret,
"Failed to add cert");
return ret;
}
}
if (iter->certs) {
int ret;
ret = hx509_certs_start_seq(context, iter->certs, &iter->cursor);
if (ret) {
hx509_certs_free(&iter->certs);
free(iter);
return ret;
}
} else
#endif
{
OSStatus ret;
const void *keys[] = {
kSecClass,
kSecReturnRef,
kSecMatchLimit
};
const void *values[] = {
kSecClassCertificate,
kCFBooleanTrue,
kSecMatchLimitAll
};
CFDictionaryRef secQuery;
secQuery = CFDictionaryCreate(NULL, keys, values,
sizeof(keys) / sizeof(*keys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
ret = SecItemCopyMatching(secQuery, (CFTypeRef *)&iter->search);
CFRelease(secQuery);
if (ret) {
free(iter);
return ENOMEM;
//.........這裏部分代碼省略.........
示例12: q_toVariant
static QVariant q_toVariant(const CFTypeRef &obj)
{
const CFTypeID typeId = CFGetTypeID(obj);
if (typeId == CFStringGetTypeID())
return QVariant(q_toString(static_cast<const CFStringRef>(obj)));
if (typeId == CFNumberGetTypeID()) {
const CFNumberRef num = static_cast<const CFNumberRef>(obj);
const CFNumberType type = CFNumberGetType(num);
switch (type) {
case kCFNumberSInt8Type:
return qVariantFromValue(convertCFNumber<char>(num, type));
case kCFNumberSInt16Type:
return qVariantFromValue(convertCFNumber<qint16>(num, type));
case kCFNumberSInt32Type:
return qVariantFromValue(convertCFNumber<qint32>(num, type));
case kCFNumberSInt64Type:
return qVariantFromValue(convertCFNumber<qint64>(num, type));
case kCFNumberCharType:
return qVariantFromValue(convertCFNumber<uchar>(num, type));
case kCFNumberShortType:
return qVariantFromValue(convertCFNumber<short>(num, type));
case kCFNumberIntType:
return qVariantFromValue(convertCFNumber<int>(num, type));
case kCFNumberLongType:
return qVariantFromValue(convertCFNumber<long>(num, type));
case kCFNumberLongLongType:
return qVariantFromValue(convertCFNumber<long long>(num, type));
case kCFNumberFloatType:
return qVariantFromValue(convertCFNumber<float>(num, type));
case kCFNumberDoubleType:
return qVariantFromValue(convertCFNumber<double>(num, type));
default:
if (CFNumberIsFloatType(num))
return qVariantFromValue(convertCFNumber<double>(num, kCFNumberDoubleType));
return qVariantFromValue(convertCFNumber<quint64>(num, kCFNumberLongLongType));
}
}
if (typeId == CFDateGetTypeID()) {
QDateTime dt;
dt.setTime_t(uint(kCFAbsoluteTimeIntervalSince1970));
return dt.addSecs(int(CFDateGetAbsoluteTime(static_cast<const CFDateRef>(obj))));
}
if (typeId == CFDataGetTypeID()) {
const CFDataRef cfdata = static_cast<const CFDataRef>(obj);
return QByteArray(reinterpret_cast<const char *>(CFDataGetBytePtr(cfdata)),
CFDataGetLength(cfdata));
}
if (typeId == CFBooleanGetTypeID())
return QVariant(bool(CFBooleanGetValue(static_cast<const CFBooleanRef>(obj))));
if (typeId == CFArrayGetTypeID()) {
const CFArrayRef cfarray = static_cast<const CFArrayRef>(obj);
QList<QVariant> list;
CFIndex size = CFArrayGetCount(cfarray);
bool metNonString = false;
for (CFIndex i = 0; i < size; ++i) {
QVariant value = q_toVariant(CFArrayGetValueAtIndex(cfarray, i));
if (value.type() != QVariant::String)
metNonString = true;
list << value;
}
if (metNonString)
return list;
else
return QVariant(list).toStringList();
}
if (typeId == CFDictionaryGetTypeID()) {
const CFDictionaryRef cfdict = static_cast<const CFDictionaryRef>(obj);
const CFTypeID arrayTypeId = CFArrayGetTypeID();
int size = int(CFDictionaryGetCount(cfdict));
QVarLengthArray<CFPropertyListRef> keys(size);
QVarLengthArray<CFPropertyListRef> values(size);
CFDictionaryGetKeysAndValues(cfdict, keys.data(), values.data());
QMultiMap<QString, QVariant> map;
for (int i = 0; i < size; ++i) {
QString key = q_toString(static_cast<const CFStringRef>(keys[i]));
if (CFGetTypeID(values[i]) == arrayTypeId) {
const CFArrayRef cfarray = static_cast<const CFArrayRef>(values[i]);
CFIndex arraySize = CFArrayGetCount(cfarray);
for (CFIndex j = arraySize - 1; j >= 0; --j)
map.insert(key, q_toVariant(CFArrayGetValueAtIndex(cfarray, j)));
} else {
map.insert(key, q_toVariant(values[i]));
}
}
return map;
}
return QVariant();
}
示例13: RunAppOnDeviceWithIdentifier
void RunAppOnDeviceWithIdentifier(char *udid, char *identifier, bool waitForDebugger)
{
SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid);
if (device) {
sdmmd_return_t result = SDMMD_AMDeviceConnect(device);
if (SDM_MD_CallSuccessful(result)) {
result = SDMMD_AMDeviceStartSession(device);
if (SDM_MD_CallSuccessful(result)) {
CFDictionaryRef response;
CFArrayRef lookupValues = SDMMD_ApplicationLookupDictionary();
CFMutableDictionaryRef optionsDict = SDMMD_create_dict();
CFDictionarySetValue(optionsDict, CFSTR("ReturnAttributes"), lookupValues);
result = SDMMD_AMDeviceLookupApplications(device, optionsDict, &response);
if (SDM_MD_CallSuccessful(result)) {
CFStringRef bundleIdentifier = CFStringCreateWithCString(kCFAllocatorDefault, identifier, kCFStringEncodingUTF8);
CFDictionaryRef details = NULL;
if (CFDictionaryContainsKey(response, bundleIdentifier)) {
details = CFDictionaryGetValue(response, bundleIdentifier);
}
CFSafeRelease(bundleIdentifier);
if (details) {
SDMMD_AMDeviceStopSession(device);
SDMMD_AMDeviceDisconnect(device);
SDMMD_AMDebugConnectionRef dconn = SDMMD_AMDebugConnectionCreateForDevice(device);
sdmmd_return_t result = SDMMD_AMDebugConnectionStart(dconn);
bool launchSuccess = false;
if (SDM_MD_CallSuccessful(result)) {
// setting max packet size
CFMutableArrayRef maxPacketArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
CFArrayAppendValue(maxPacketArgs, CFSTR("1024"));
DebuggerCommandRef maxPacket = SDMMD_CreateDebuggingCommand(kDebugQSetMaxPacketSize, NULL, maxPacketArgs);
CFSafeRelease(maxPacketArgs);
CFDataRef maxPacketResponse = NULL;
result = SDMMD_DebuggingSend(dconn, maxPacket, &maxPacketResponse);
CFSafeRelease(maxPacketResponse);
SDMMD_DebuggingCommandRelease(maxPacket);
// setting the working directory
CFStringRef path = CFDictionaryGetValue(details, CFSTR("Path"));
CFStringRef container = CFDictionaryGetValue(details, CFSTR("Container"));
if (!container) {
CFURLRef pathURL = CFURLCreateWithString(kCFAllocatorDefault, path, NULL);
CFURLRef containerURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, pathURL);
container = CFURLGetString(containerURL);
CFSafeRelease(pathURL);
}
CFMutableArrayRef containerPathArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
CFArrayAppendValue(containerPathArgs, container);
DebuggerCommandRef containerPath = SDMMD_CreateDebuggingCommand(kDebugQSetWorkingDir, NULL, containerPathArgs);
CFSafeRelease(containerPathArgs);
CFDataRef containerPathResponse = NULL;
result = SDMMD_DebuggingSend(dconn, containerPath, &containerPathResponse);
CFSafeRelease(containerPathResponse);
SDMMD_DebuggingCommandRelease(containerPath);
// setting launch args
CFStringRef commandFormat = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("A%d,0,"), (uint32_t)CFStringGetLength(path) * 0x2);
CFMutableArrayRef setLaunchArgsArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
CFArrayAppendValue(setLaunchArgsArgs, path);
DebuggerCommandRef setLaunchArgs = SDMMD_CreateDebuggingCommand(kDebugCUSTOMCOMMAND, commandFormat, setLaunchArgsArgs);
CFSafeRelease(setLaunchArgsArgs);
CFSafeRelease(commandFormat);
CFDataRef setLaunchArgsResponse = NULL;
result = SDMMD_DebuggingSend(dconn, setLaunchArgs, &setLaunchArgsResponse);
CFSafeRelease(setLaunchArgsResponse);
SDMMD_DebuggingCommandRelease(setLaunchArgs);
// Check for launch success
CFMutableArrayRef launchSuccessArgs = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks);
DebuggerCommandRef launchSuccessCommand = SDMMD_CreateDebuggingCommand(kDebugqLaunchSuccess, NULL, launchSuccessArgs);
CFSafeRelease(launchSuccessArgs);
CFDataRef launchSuccessResponse = NULL;
result = SDMMD_DebuggingSend(dconn, launchSuccessCommand, &launchSuccessResponse);
if (launchSuccessResponse) {
char *launchSuccessResponseAsString = (char *)CFDataGetBytePtr(launchSuccessResponse);
launchSuccess = !strncmp(launchSuccessResponseAsString, "OK", 2);
if (!launchSuccess) {
printf("Launch failure: %s\n", launchSuccessResponseAsString);
}
}
CFSafeRelease(launchSuccessResponse);
SDMMD_DebuggingCommandRelease(launchSuccessCommand);
if (launchSuccess) {
printf("Launch success\n");
if (!waitForDebugger) {
printf("Continuing with execution...\n");
// setting thread to attach
//.........這裏部分代碼省略.........
示例14: ct_font_descriptor_get_coverage
static PangoCoverage *
ct_font_descriptor_get_coverage (CTFontDescriptorRef desc)
{
CFCharacterSetRef charset;
CFIndex i, length;
CFDataRef bitmap;
const UInt8 *ptr, *plane_ptr;
const UInt32 plane_size = 8192;
PangoCoverage *coverage;
coverage = pango_coverage_new ();
charset = CTFontDescriptorCopyAttribute (desc, kCTFontCharacterSetAttribute);
if (!charset)
/* Return an empty coverage */
return coverage;
bitmap = CFCharacterSetCreateBitmapRepresentation (kCFAllocatorDefault,
charset);
ptr = CFDataGetBytePtr (bitmap);
/* First handle the BMP plane. */
length = MIN (CFDataGetLength (bitmap), plane_size);
/* FIXME: can and should this be done more efficiently? */
for (i = 0; i < length; i++)
{
int j;
for (j = 0; j < 8; j++)
if ((ptr[i] & (1 << j)) == (1 << j))
pango_coverage_set (coverage, i * 8 + j, PANGO_COVERAGE_EXACT);
}
/* Next, handle the other planes. The plane number is encoded first as
* a single byte. In the following 8192 bytes that plane's coverage bitmap
* is stored.
*/
plane_ptr = ptr + plane_size;
while (plane_ptr - ptr < CFDataGetLength (bitmap))
{
const UInt8 plane_number = *plane_ptr;
plane_ptr++;
for (i = 0; i < plane_size; i++)
{
int j;
for (j = 0; j < 8; j++)
if ((plane_ptr[i] & (1 << j)) == (1 << j))
pango_coverage_set (coverage, (plane_number * plane_size + i) * 8 + j,
PANGO_COVERAGE_EXACT);
}
plane_ptr += plane_size;
}
CFRelease (bitmap);
CFRelease (charset);
return coverage;
}
示例15: _inputStreamReturnCharacter
__private_extern__ Boolean _inputStreamReturnCharacter(_CFXMLInputStream *stream, UniChar ch) {
Boolean decrementLineNum = false;
if (ch == '\n') {
decrementLineNum = true;
} else if (ch == '\r') {
UniChar nextChar;
if (!_inputStreamPeekCharacter(stream, &nextChar) || nextChar != '\n') {
decrementLineNum = true;
}
}
if (!(stream->flags & STREAM_OPEN)) {
return false;
} else if (stream->currentChar) {
if (stream->currentChar != stream->charBuffer) {
stream->currentChar --;
} else {
// Yuck; we're unlucky and are returning a character _before_ the first character in charBuffer
if (stream->bufferLength >= stream->bufferCapacity) {
growCharacterBuffer(stream);
}
memmove(stream->charBuffer + 1, stream->charBuffer, stream->bufferLength * sizeof(UniChar));
*stream->charBuffer = ch;
stream->bufferLength ++;
if (stream->mark) {
stream->mark ++;
}
if (stream->parserMark) {
stream->parserMark ++;
}
}
} else if ((stream->mark || stream->parserMark) && stream->bufferLength) {
// We've been collecting characters in charBuffer; the only reason stream->currentChar is NULL is that we've processed the last character thusfar translated from data. That last character is the one being returned.
stream->currentChar = stream->charBuffer + stream->bufferLength - 1;
} else if (stream->charBuffer) {
// We have processed all the meaningful characters from charBuffer and have no reason to preserve them. We use charBuffer to hold this one character that has been returned to us.
*stream->charBuffer = ch;
stream->currentChar = stream->charBuffer;
stream->bufferLength = 1;
if (stream->mark) {
stream->mark ++;
}
if (stream->parserMark) {
stream->parserMark ++;
}
} else if (stream->currentByte > CFDataGetBytePtr(stream->data)) {
// We have no character buffer available, so that means one of two things - either we've never needed a character buffer because all the characters could come directly out of the byte stream, or we've not yet processed the first character. The former means we can just back up the byte pointer; the latter means Bad Things have happened.
if (stream->flags & ENCODING_MATCHES_ASCII) {
stream->currentByte --;
} else { // Must be Unicode
stream->currentByte -= 2;
}
} else {
return false;
}
stream->charIndex --;
if (decrementLineNum) {
stream->lineNum --;
}
return true;
}