PassRefPtr<ArchiveResource> LegacyWebArchive::createResource(CFDictionaryRef dictionary) { ASSERT(dictionary); if (!dictionary) return 0; CFDataRef resourceData = static_cast<CFDataRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceDataKey)); if (resourceData && CFGetTypeID(resourceData) != CFDataGetTypeID()) { LOG(Archives, "LegacyWebArchive - Resource data is not of type CFData, cannot create invalid resource"); return 0; } CFStringRef frameName = static_cast<CFStringRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceFrameNameKey)); if (frameName && CFGetTypeID(frameName) != CFStringGetTypeID()) { LOG(Archives, "LegacyWebArchive - Frame name is not of type CFString, cannot create invalid resource"); return 0; } CFStringRef mimeType = static_cast<CFStringRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceMIMETypeKey)); if (!mimeType || CFGetTypeID(mimeType) != CFStringGetTypeID()) { LOG(Archives, "LegacyWebArchive - MIME type is not of type CFString, cannot create invalid resource"); return 0; } CFStringRef url = static_cast<CFStringRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceURLKey)); if (url && CFGetTypeID(url) != CFStringGetTypeID()) { LOG(Archives, "LegacyWebArchive - URL is not of type CFString, cannot create invalid resource"); return 0; } CFStringRef textEncoding = static_cast<CFStringRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceTextEncodingNameKey)); if (textEncoding && CFGetTypeID(textEncoding) != CFStringGetTypeID()) { LOG(Archives, "LegacyWebArchive - Text encoding is not of type CFString, cannot create invalid resource"); return 0; } ResourceResponse response; CFDataRef resourceResponseData = static_cast<CFDataRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceResponseKey)); if (resourceResponseData) { if (CFGetTypeID(resourceResponseData) != CFDataGetTypeID()) { LOG(Archives, "LegacyWebArchive - Resource response data is not of type CFData, cannot create invalid resource"); return 0; } CFStringRef resourceResponseVersion = static_cast<CFStringRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceResponseVersionKey)); if (resourceResponseVersion && CFGetTypeID(resourceResponseVersion) != CFStringGetTypeID()) { LOG(Archives, "LegacyWebArchive - Resource response version is not of type CFString, cannot create invalid resource"); return 0; } response = createResourceResponseFromPropertyListData(resourceResponseData, resourceResponseVersion); } return ArchiveResource::create(SharedBuffer::wrapCFData(resourceData), KURL(KURL(), url), mimeType, textEncoding, frameName, response); }
CFDictionaryRef bruteforce_system_keybag(int socket, CFDictionaryRef dict) { uint8_t passcodeKey[32]; CFDataRef kbkeys = CFDictionaryGetValue(dict, CFSTR("KeyBagKeys")); if(kbkeys == NULL || CFGetTypeID(kbkeys) != CFDataGetTypeID()) return NULL; char* passcode = bruteforceWithAppleKeyStore(kbkeys, bruteforceProgressCallback, (void*) socket); if (passcode == NULL) return NULL; KeyBag* kb = AppleKeyStore_parseBinaryKeyBag(kbkeys); if (kb == NULL) { printf("FAIL: AppleKeyStore_parseBinaryKeyBag\n"); return NULL; } AppleKeyStore_getPasscodeKey(kb, passcode, strlen(passcode), passcodeKey); free(kb); CFMutableDictionaryRef out = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFStringRef cfpasscode = CFStringCreateWithCString(kCFAllocatorDefault, passcode, kCFStringEncodingASCII); CFDictionaryAddValue(out, CFSTR("passcode"), cfpasscode); CFRelease(cfpasscode); addHexaString(out, CFSTR("passcodeKey"), passcodeKey, 32); return out; }
std::string getIOKitProperty(const CFMutableDictionaryRef& details, const std::string& key) { std::string value; // Get a property from the device. auto cfkey = CFStringCreateWithCString( kCFAllocatorDefault, key.c_str(), kCFStringEncodingUTF8); auto property = CFDictionaryGetValue(details, cfkey); CFRelease(cfkey); // Several supported ways of parsing IOKit-encoded data. if (property) { if (CFGetTypeID(property) == CFNumberGetTypeID()) { value = stringFromCFNumber((CFDataRef)property); } else if (CFGetTypeID(property) == CFStringGetTypeID()) { value = stringFromCFString((CFStringRef)property); } else if (CFGetTypeID(property) == CFDataGetTypeID()) { value = stringFromCFData((CFDataRef)property); } else if (CFGetTypeID(property) == CFBooleanGetTypeID()) { value = (CFBooleanGetValue((CFBooleanRef)property)) ? "1" : "0"; } } return value; }
/* * Given a CFTypeRef passphrase which may be a CFDataRef or a CFStringRef, * return a refcounted CFStringRef suitable for use with the PKCS12 library. * PKCS12 passphrases in CFData format must be UTF8 encoded. */ OSStatus impExpPassphraseToCFString( CFTypeRef passin, CFStringRef *passout) // may be the same as passin, but refcounted { if(CFGetTypeID(passin) == CFStringGetTypeID()) { CFStringRef passInStr = (CFStringRef)passin; CFRetain(passInStr); *passout = passInStr; return errSecSuccess; } else if(CFGetTypeID(passin) == CFDataGetTypeID()) { CFDataRef cfData = (CFDataRef)passin; CFIndex len = CFDataGetLength(cfData); CFStringRef cfStr = CFStringCreateWithBytes(NULL, CFDataGetBytePtr(cfData), len, kCFStringEncodingUTF8, true); if(cfStr == NULL) { SecImpExpDbg("Passphrase not in UTF8 format"); return errSecParam; } *passout = cfStr; return errSecSuccess; } else { SecImpExpDbg("Passphrase not CFData or CFString"); return errSecParam; } }
OSErr XPFIODevice::getRegistryProperty (REG_ENTRY_TYPE entry, char *key, char *value) { value[0] = 0; #ifdef __MACH__ CFStringRef cfKey = CFStringCreateWithCString (NULL, key, kCFStringEncodingASCII); CFTypeRef cfValue = IORegistryEntryCreateCFProperty (entry, cfKey, NULL, 0); if (!cfValue) return -1; if (CFGetTypeID (cfValue) == CFDataGetTypeID ()) { memcpy (value, CFDataGetBytePtr ((CFDataRef) cfValue), CFDataGetLength ((CFDataRef) cfValue)); value [CFDataGetLength ((CFDataRef) cfValue)] = 0; CFRelease (cfValue); } return noErr; #else RegPropertyValueSize propSize; OSErr err = RegistryPropertyGetSize (entry, key, &propSize); if (err == noErr) { RegistryPropertyGet (entry, key, value, &propSize); value[propSize] = '\0'; } return err; #endif }
PassRefPtr<FormData> httpBodyFromRequest(CFURLRequestRef request) { if (RetainPtr<CFDataRef> bodyData = CFURLRequestCopyHTTPRequestBody(request)) return FormData::create(CFDataGetBytePtr(bodyData.get()), CFDataGetLength(bodyData.get())); if (wkCanAccessCFURLRequestHTTPBodyParts()) { if (RetainPtr<CFArrayRef> bodyParts = wkCFURLRequestCopyHTTPRequestBodyParts(request)) { RefPtr<FormData> formData = FormData::create(); CFIndex count = CFArrayGetCount(bodyParts.get()); for (CFIndex i = 0; i < count; i++) { CFTypeRef bodyPart = CFArrayGetValueAtIndex(bodyParts.get(), i); CFTypeID typeID = CFGetTypeID(bodyPart); if (typeID == CFStringGetTypeID()) { String filename = (CFStringRef)bodyPart; formData->appendFile(filename); } else if (typeID == CFDataGetTypeID()) { CFDataRef data = (CFDataRef)bodyPart; formData->appendData(CFDataGetBytePtr(data), CFDataGetLength(data)); } else ASSERT_NOT_REACHED(); } return formData.release(); } } else { if (RetainPtr<CFReadStreamRef> bodyStream = CFURLRequestCopyHTTPRequestBodyStream(request)) return getStreamFormDatas().get(bodyStream.get()); } // FIXME: what to do about arbitrary body streams? return 0; }
static CFType typeFromCFTypeRef(CFTypeRef type) { ASSERT(type); if (type == tokenNullTypeRef()) return Null; CFTypeID typeID = CFGetTypeID(type); if (typeID == CFArrayGetTypeID()) return CFArray; if (typeID == CFBooleanGetTypeID()) return CFBoolean; if (typeID == CFDataGetTypeID()) return CFData; if (typeID == CFDictionaryGetTypeID()) return CFDictionary; if (typeID == CFNullGetTypeID()) return CFNull; if (typeID == CFNumberGetTypeID()) return CFNumber; if (typeID == CFStringGetTypeID()) return CFString; if (typeID == CFURLGetTypeID()) return CFURL; #if PLATFORM(MAC) if (typeID == SecCertificateGetTypeID()) return SecCertificate; #endif ASSERT_NOT_REACHED(); return Unknown; }
PassRefPtr<FormData> httpBodyFromRequest(CFURLRequestRef request) { // RetainPtr<CFDataRef> bodyData(AdoptCF, CFURLRequestCopyHTTPRequestBody(request)); //Ricardo: comentando y cambiando por la linea siguiente. RetainPtr<CFDataRef> bodyData(AdoptCF, 0); if (bodyData) return FormData::create(CFDataGetBytePtr(bodyData.get()), CFDataGetLength(bodyData.get())); RetainPtr<CFArrayRef> bodyParts(AdoptCF, wkCFURLRequestCopyHTTPRequestBodyParts(request)); if (bodyParts) { RefPtr<FormData> formData = FormData::create(); CFIndex count = CFArrayGetCount(bodyParts.get()); for (CFIndex i = 0; i < count; i++) { CFTypeRef bodyPart = CFArrayGetValueAtIndex(bodyParts.get(), i); CFTypeID typeID = CFGetTypeID(bodyPart); if (typeID == CFStringGetTypeID()) { String filename = (CFStringRef)bodyPart; formData->appendFile(filename); } else if (typeID == CFDataGetTypeID()) { CFDataRef data = (CFDataRef)bodyPart; formData->appendData(CFDataGetBytePtr(data), CFDataGetLength(data)); } else ASSERT_NOT_REACHED(); } return formData.release(); } // FIXME: what to do about arbitrary body streams? return 0; }
void CASettingsStorage::CopyDataValue(CFStringRef inKey, CFDataRef& outValue, CFDataRef inDefaultValue) const { // initialize the return value outValue = NULL; // get the raw value CFTypeRef theValue = NULL; CopyCFTypeValue(inKey, theValue, inDefaultValue); // for this type, NULL is a valid value, but requires less work if(theValue != NULL) { // make sure we are dealing with the right kind of CF object if(CFGetTypeID(theValue) == CFDataGetTypeID()) { // set the return value to the CF object we are returning outValue = static_cast<CFDataRef>(theValue); } else { // release the value since we aren't returning it CFRelease(theValue); // set the return value to the default value outValue = inDefaultValue; // and retain it CFRetain(outValue); } } }
std::string genKIDProperty(const CFDataRef& kid) { CFDataRef kid_data = nullptr; CFDictionaryRef kid_dict = nullptr; // Find the key identifier data within the property mess. for (CFIndex i = 0; i < CFArrayGetCount((CFArrayRef)kid); i++) { kid_dict = (CFDictionaryRef)CFArrayGetValueAtIndex((CFArrayRef)kid, i); auto kid_value = (const char*)CFDictionaryGetValue(kid_dict, kSecPropertyKeyValue); if (CFGetTypeID(kid_value) == CFDataGetTypeID()) { kid_data = (CFDataRef)kid_value; break; } } if (kid_data == nullptr) { // No key identifier found. return ""; } // Provide an ASCII-representation of the KID, similar to keychain. std::stringstream ascii_kid; for (CFIndex i = 0; i < CFDataGetLength(kid_data); i++) { int kid_byte = (uint8_t)CFDataGetBytePtr(kid_data)[i]; ascii_kid << std::setfill('0') << std::setw(2) << std::hex << kid_byte; // Then make it easy to read. if (i < CFDataGetLength(kid_data) - 1) { ascii_kid << ""; } } return ascii_kid.str(); }
static void printObj(CFPropertyListRef obj, struct printContext* c) { CFTypeID typeID = CFGetTypeID(obj); if (typeID == _CFKeyedArchiverUIDGetTypeID()) { unsigned uid = _CFKeyedArchiverUIDGetValue(obj); CFPropertyListRef refObj = CFArrayGetValueAtIndex(c->objs, uid); if (CFEqual(refObj, CFSTR("$null"))) printf("nil"); else if (c->refCount[uid] > 1 && isComplexObj(refObj)) printf("{CF$UID = %u;}", uid); else printObj(refObj, c); } else if (typeID == CFArrayGetTypeID()) { printf("(\n"); ++ c->tabs; CFArrayApplyFunction(obj, CFRangeMake(0, CFArrayGetCount(obj)), (CFArrayApplierFunction)&printObjAsArrayEntry, c); -- c->tabs; for (unsigned i = 0; i < c->tabs; ++ i) printf("\t"); printf(")"); } else if (typeID == CFDictionaryGetTypeID()) { CFStringRef className = CFDictionaryGetValue(obj, CFSTR("$classname")); if (className != NULL) printObjAsClassName(className); else { printf("{\n"); ++ c->tabs; CFIndex dictCount = CFDictionaryGetCount(obj); struct dictionarySorterContext sc; sc.keys = malloc(sizeof(CFStringRef)*dictCount); sc.values = malloc(sizeof(CFPropertyListRef)*dictCount); unsigned* mapping = malloc(sizeof(unsigned)*dictCount); for (unsigned i = 0; i < dictCount; ++ i) mapping[i] = i; CFDictionaryGetKeysAndValues(obj, (const void**)sc.keys, sc.values); qsort_r(mapping, dictCount, sizeof(unsigned), &sc, (int(*)(void*,const void*,const void*))&dictionaryComparer); for (unsigned i = 0; i < dictCount; ++ i) printObjAsDictionaryEntry(sc.keys[mapping[i]], sc.values[mapping[i]], c); free(mapping); free(sc.keys); free(sc.values); -- c->tabs; for (unsigned i = 0; i < c->tabs; ++ i) printf("\t"); printf("}"); } } else if (typeID == CFDataGetTypeID()) printObjAsData(obj); else if (typeID == CFNumberGetTypeID()) printObjAsNumber(obj); else if (typeID == CFStringGetTypeID()) printObjAsString(obj); else if (typeID == CFBooleanGetTypeID()) printf(CFBooleanGetValue(obj) ? "true" : "false"); else if (typeID == CFDateGetTypeID()) printf("/*date*/ %0.09g", CFDateGetAbsoluteTime(obj)); }
/* * Obtain signing cert for specified principal. On successful return, * caller must eventually release the cert with krb5_pkinit_release_cert(). */ krb5_error_code krb5_pkinit_get_client_cert( const char *principal, /* full principal string */ krb5_pkinit_signing_cert_t *client_cert) { CFDataRef issuerSerial = NULL; CSSM_DATA issuerSerialData; SecIdentityRef idRef = NULL; OSStatus ortn; CFDictionaryRef theDict = NULL; CFStringRef cfPrinc = NULL; krb5_error_code ourRtn = 0; if(principal == NULL) { return KRB5_PRINC_NOMATCH; } /* Is there a stored preference for PKINIT certs for this user? */ ortn = pkinit_get_pref_dict(&theDict); if(ortn) { return KRB5_PRINC_NOMATCH; } /* Entry in the dictionary for specified principal? */ cfPrinc = CFStringCreateWithCString(NULL, principal, kCFStringEncodingASCII); issuerSerial = (CFDataRef)CFDictionaryGetValue(theDict, cfPrinc); CFRelease(cfPrinc); if(issuerSerial == NULL) { pkiDebug("krb5_pkinit_get_client_cert: no identity found\n"); ourRtn = KRB5_PRINC_NOMATCH; goto errOut; } if(CFGetTypeID(issuerSerial) != CFDataGetTypeID()) { pkiDebug("krb5_pkinit_get_client_cert: bad kPkinitClientCertKey value\n"); ourRtn = KRB5_PRINC_NOMATCH; goto errOut; } issuerSerialData.Data = (uint8 *)CFDataGetBytePtr(issuerSerial); issuerSerialData.Length = CFDataGetLength(issuerSerial); /* find a cert with that issuer/serial number in default search list */ ortn = pkinit_search_ident(NULL, CSSM_KEYUSE_SIGN | CSSM_KEYUSE_ENCRYPT, &issuerSerialData, &idRef); if(ortn) { pkiDebug("krb5_pkinit_get_client_cert: no identity found!\n"); pkiCssmErr("pkinit_search_ident", ortn); ourRtn = KRB5_PRINC_NOMATCH; } else { *client_cert = (krb5_pkinit_signing_cert_t)idRef; } errOut: if(theDict) { CFRelease(theDict); } return ourRtn; }
OSStatus DoWriteDataToFile(COMMAND_PROC_ARGUMENTS) { #pragma unused (auth) #pragma unused (userData) OSStatus retval = noErr; // Pre-conditions // userData may be NULL assert(request != NULL); assert(response != NULL); // asl may be NULL // aslMsg may be NULL // Get data to write and assert that it's a CFDataRef CFDataRef data = CFDictionaryGetValue(request, CFSTR(kData)) ; assert(data != NULL) ; assert(CFGetTypeID(data) == CFDataGetTypeID()) ; // Get path and assert that it's a CFStringRef CFStringRef filePath = CFDictionaryGetValue(request, CFSTR(kPath)) ; assert(filePath != NULL) ; assert(CFGetTypeID(filePath) == CFStringGetTypeID()) ; CFURLRef url = CFURLCreateWithFileSystemPath ( kCFAllocatorDefault, filePath, kCFURLPOSIXPathStyle, false ) ; SInt32 errorCode ; Boolean ok = CFURLWriteDataAndPropertiesToResource ( url, data, NULL, &errorCode ) ; if (!ok) { retval = errorCode ; } asl_log(asl, aslMsg, ASL_LEVEL_DEBUG, "DoWriteDataToFile result ok=%d for %s", ok, CFStringGetCStringPtr( filePath, CFStringGetSystemEncoding() ) ) ; // Clean up CFQRelease(url) ; return retval ; }
__attribute__((constructor)) void Init_TSICTString(void) { kCFDataTypeID = CFDataGetTypeID(); kCFStringTypeID = CFStringGetTypeID(); kCFNumberTypeID = CFNumberGetTypeID(); kCFBooleanTypeID = CFBooleanGetTypeID(); kCFNullTypeID = CFNullGetTypeID(); kCFArrayTypeID = CFArrayGetTypeID(); kCFDictionaryTypeID = CFDictionaryGetTypeID(); }
CFDictionaryRef keybag_get_passcode_key(int socket, CFDictionaryRef dict) { uint8_t passcodeKey[32]; CFDataRef passcode_cfdata = NULL; CFDataRef kbkeys = CFDictionaryGetValue(dict, CFSTR("KeyBagKeys")); if(kbkeys == NULL || CFGetTypeID(kbkeys) != CFDataGetTypeID()) return NULL; KeyBag* kb = AppleKeyStore_parseBinaryKeyBag(kbkeys); if (kb == NULL) return NULL; CFTypeRef cfpasscode = CFDictionaryGetValue(dict, CFSTR("passcode")); if(cfpasscode == NULL) return NULL; if(CFGetTypeID(cfpasscode) == CFDataGetTypeID()) { passcode_cfdata = cfpasscode; } else if(CFGetTypeID(cfpasscode) == CFStringGetTypeID()) { passcode_cfdata = CFStringCreateExternalRepresentation(kCFAllocatorDefault, cfpasscode, kCFStringEncodingUTF8, 0); } else return NULL; AppleKeyStore_getPasscodeKey(kb, CFDataGetBytePtr(passcode_cfdata), CFDataGetLength(passcode_cfdata), passcodeKey); free(kb); if (passcode_cfdata != cfpasscode) CFRelease(passcode_cfdata); CFMutableDictionaryRef out = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionaryAddValue(out, CFSTR("passcode"), cfpasscode); addHexaString(out, CFSTR("passcodeKey"), passcodeKey, 32); return out; }
static long int getIdleTime (void) /* returns mouse and keyboard idle time in TIMER_RESOLUTION seconds; returns -1 on error */ { mach_port_t masterPort = 0; io_iterator_t iter = 0; io_registry_entry_t curObj = 0; CFMutableDictionaryRef properties = NULL; CFTypeRef obj = NULL; CFTypeID type = 0; uint64_t idletime = -1; if (IOMasterPort (MACH_PORT_NULL, &masterPort) != KERN_SUCCESS) { message (LOG_ERR, "can't get IOMasterPort\n"); goto error; } IOServiceGetMatchingServices (masterPort, IOServiceMatching(kIOHIDSystemClass), &iter); if (iter == 0) { message (LOG_ERR, "can't access IOHIDSystem\n"); goto error; } curObj = IOIteratorNext(iter); if (curObj == 0) { message (LOG_ERR, "got empty IOIterator\n"); goto error; } if (IORegistryEntryCreateCFProperties(curObj, &properties, kCFAllocatorDefault, 0) != KERN_SUCCESS || ! properties) { message (LOG_ERR, "can't access HIDIdleTime\n"); goto error; } obj = CFDictionaryGetValue(properties, CFSTR(kIOHIDIdleTimeKey)); CFRetain (obj); type = CFGetTypeID(obj); if (type == CFDataGetTypeID()) CFDataGetBytes ((CFDataRef) obj, CFRangeMake(0, sizeof(idletime)), (UInt8 *) &idletime); else if (type == CFNumberGetTypeID()) CFNumberGetValue ((CFNumberRef) obj, kCFNumberSInt64Type, &idletime); else { message (LOG_ERR, "unsupported idle time data type\n", (int) type); goto error; } idletime /= 1000000000l * TIMER_RESOLUTION; /* transform from 10**-9 to TIMER_RESOLUTION seconds */ error : if (masterPort) mach_port_deallocate (mach_task_self(), masterPort); if (obj) CFRelease(obj); if (curObj) IOObjectRelease (curObj); if (iter) IOObjectRelease (iter); if (properties) CFRelease ((CFTypeRef) properties); return (idletime); }
CFDataRef SFB::Audio::AttachedPicture::GetDataValue(CFStringRef key) const { CFTypeRef value = GetValue(key); if(nullptr == value) return nullptr; if(CFDataGetTypeID() != CFGetTypeID(value)) return nullptr; else return (CFDataRef)value; }
/** * Get the #plist_type of a node. * * @param node the node * @return the type of the node */ plist_type plist_get_node_type(plist_t node) { if (!node) return PLIST_NONE; CFTypeID type = CFGetTypeID(node); if (type == CFArrayGetTypeID()) return PLIST_ARRAY; else if (type == CFDictionaryGetTypeID()) return PLIST_DICT; else if (type == CFStringGetTypeID()) return PLIST_STRING; else if (type == CFDataGetTypeID()) return PLIST_DATA; else if (type == CFBooleanGetTypeID()) return PLIST_BOOLEAN; else if (type == CFDateGetTypeID()) return PLIST_DATE; else if (type == CFNumberGetTypeID()) { CFTypeID numType = CFNumberGetType(node); switch (numType) { case kCFNumberFloat32Type: case kCFNumberFloat64Type: case kCFNumberFloatType: case kCFNumberDoubleType: return PLIST_REAL; break; case kCFNumberSInt8Type: case kCFNumberSInt16Type: case kCFNumberSInt32Type: case kCFNumberSInt64Type: case kCFNumberCharType: case kCFNumberShortType: case kCFNumberIntType: return PLIST_UINT; break; default: return PLIST_NONE; break; } } return PLIST_NONE; }
void copy_device_csr(io_registry_entry_t dev, uint32_t *rom) { // Attempt to extract the "FireWire Device ROM" property CFDictionaryRef romdict = IORegistryEntryCreateCFProperty(dev, CFSTR("FireWire Device ROM"), NULL, 0); memset(rom, '\0', FORENSIC1394_CSR_SZ * sizeof(uint32_t)); // Ensure the ROM dictionary exists if (romdict) { // And that it is really a dictionary if (CFGetTypeID(romdict) == CFDictionaryGetTypeID()) { // The ROM itself is stored in the "Offset 0" key CFDataRef romdata = CFDictionaryGetValue(romdict, CFSTR("Offset 0")); // Ensure the ROM data exists if (romdata) { // And that it is really a data type if (CFGetTypeID(romdata) == CFDataGetTypeID()) { int i; CFRange datarange = CFRangeMake(0, CFDataGetLength(romdata)); // Check the size is not > 1024 bytes assert(datarange.length <= (FORENSIC1394_CSR_SZ * sizeof(uint32_t))); // Copy the data to the buffer CFDataGetBytes(romdata, datarange, (UInt8 *) rom); // Convert from big-endian to CPU-endian (no-op on PPC Macs) for (i = 0; i < (datarange.length / sizeof(uint32_t)); i++) { rom[i] = CSR_HOST_QUADLET(rom[i]); } } // Release the data CFRelease(romdata); } } // Release the dictionary CFRelease(romdict); } }
int IdlePlatform::secondsIdle() { mach_port_t masterPort; io_iterator_t iter; io_registry_entry_t curObj; IOMasterPort(MACH_PORT_NULL, &masterPort); IOServiceGetMatchingServices(masterPort, IOServiceMatching("IOHIDSystem"), &iter); if (iter == 0) return -1; curObj = IOIteratorNext(iter); if (curObj == 0) return -1; CFMutableDictionaryRef properties = 0; CFTypeRef obj; int result = -1; if (IORegistryEntryCreateCFProperties(curObj, &properties, kCFAllocatorDefault, 0) == KERN_SUCCESS && properties != NULL) { obj = CFDictionaryGetValue(properties, CFSTR("HIDIdleTime")); CFRetain(obj); } else obj = NULL; if (obj) { uint64_t tHandle; CFTypeID type = CFGetTypeID(obj); if (type == CFDataGetTypeID()) CFDataGetBytes((CFDataRef) obj, CFRangeMake(0, sizeof(tHandle)), (UInt8*) &tHandle); else if (type == CFNumberGetTypeID()) CFNumberGetValue((CFNumberRef)obj, kCFNumberSInt64Type, &tHandle); else return -1; CFRelease(obj); // essentially divides by 10^9 tHandle >>= 30; result = tHandle; } /* Release our resources */ IOObjectRelease(curObj); IOObjectRelease(iter); CFRelease((CFTypeRef)properties); return result; }
CFStringRef copyStringFromChosen(CFStringRef key) { CFStringRef s = NULL; CFDataRef data = copyDataFromChosen(key); if(data == NULL) return NULL; if(CFGetTypeID(data) == CFDataGetTypeID()) { s = CFStringCreateWithCString(kCFAllocatorDefault, (const char*) CFDataGetBytePtr(data), kCFStringEncodingUTF8); } CFRelease(data); return s; }
bool CACFDictionary::GetData(const CFStringRef inKey, CFDataRef& outValue) const { bool theAnswer = false; CFTypeRef theValue = NULL; if(GetCFType(inKey, theValue)) { if((theValue != NULL) && (CFGetTypeID(theValue) == CFDataGetTypeID())) { outValue = static_cast<CFDataRef>(theValue); theAnswer = true; } } return theAnswer; }
/* * Add an attr during encode. */ void P12BagAttrs::addAttr( const CFDataRef attrOid, const CFArrayRef attrValues) { NSS_Attribute *newAttr = reallocAttrs(numAttrs() + 1); p12CfDataToCssm(attrOid, newAttr->attrType, mCoder); unsigned numVals = CFArrayGetCount(attrValues); newAttr->attrValue = (CSSM_DATA **)p12NssNullArray(numVals, mCoder); for(unsigned dex=0; dex<numVals; dex++) { CSSM_DATA *dstVal = (CSSM_DATA *)mCoder.malloc(sizeof(CSSM_DATA)); newAttr->attrValue[dex] = dstVal; CFDataRef srcVal = (CFDataRef)CFArrayGetValueAtIndex(attrValues, dex); assert(CFGetTypeID(srcVal) == CFDataGetTypeID()); p12CfDataToCssm(srcVal, *dstVal, mCoder); } }
bool CACFArray::GetData(UInt32 inIndex, CFDataRef& outItem) const { bool theAnswer = false; CFTypeRef theItem = NULL; if(GetCFType(inIndex, theItem)) { if((theItem != NULL) && (CFGetTypeID(theItem) == CFDataGetTypeID())) { outItem = static_cast<CFDataRef>(theItem); theAnswer = true; } } return theAnswer; }
// // Process % scan forms. // This delivers the object value, scanf-style, somehow. // bool CFScan::scanformat(CFTypeRef obj) { switch (*++format) { case F_OBJECT: store<CFTypeRef>(obj); return true; case F_ARRAY: // %a* return typescan(obj, CFArrayGetTypeID()) == done; case F_BOOLEAN: if (Typescan rc = typescan(obj, CFBooleanGetTypeID())) return rc == done; switch (*format) { case 'f': // %Bf - two arguments (value, &variable) { unsigned flag = va_arg(args, unsigned); unsigned *value = va_arg(args, unsigned *); if (obj == kCFBooleanTrue && !suppress) *value |= flag; return true; } default: // %b - CFBoolean as int boolean store<int>(obj == kCFBooleanTrue); return true; } case F_DICTIONARY: return typescan(obj, CFDictionaryGetTypeID()) == done; case 'd': // %d - int return scannumber<int>(obj); case F_NUMBER: return typescan(obj, CFNumberGetTypeID()) == done; case F_STRING: case 's': if (Typescan rc = typescan(obj, CFStringGetTypeID())) return rc == done; // %s store<std::string>(cfString(CFStringRef(obj))); return true; case 'u': return scannumber<unsigned int>(obj); case F_DATA: return typescan(obj, CFDataGetTypeID()) == done; default: assert(false); return false; } }
static PyObject *pyidle_get(PyIdle *self, PyObject *args, PyObject *kwargs) { CFMutableDictionaryRef props; CFTypeRef obj; uint64_t idleTime; CFTypeID type; int ret; if ((ret = IORegistryEntryCreateCFProperties(self->regEntry, &props, kCFAllocatorDefault, 0)) != kIOReturnSuccess) { PyErr_Format(PyExc_RuntimeError, "IORegistryEntryCreateCFProperties failed: %d", ret); return NULL; } obj = CFDictionaryGetValue(props, CFSTR("HIDIdleTime")); CFRetain(obj); type = CFGetTypeID(obj); if (type == CFDataGetTypeID()) { CFDataGetBytes((CFDataRef)obj, CFRangeMake(0, sizeof(idleTime)), (UInt8*)&idleTime); } else if (type == CFNumberGetTypeID()) { CFNumberGetValue((CFNumberRef)obj, kCFNumberSInt64Type, &idleTime); } else { PyErr_Format(PyExc_RuntimeError, "Unsupported type: %d", (int)type); CFRelease(obj); CFRelease((CFTypeRef)props); return NULL; } CFRelease(obj); CFRelease(props); return Py_BuildValue("L", idleTime >> 30); }
void genOSXPrefValues(const CFTypeRef& value, const Row& base, QueryData& results, size_t depth) { if (value == nullptr) { return; } // Since we recurse when parsing Arrays/Dicts, monitor stack limits. if (++depth > kPreferenceDepthLimit) { TLOG << "The macOS preference: " << base.at("domain") << " exceeded subkey depth limit: " << kPreferenceDepthLimit; return; } // Emit a string representation for each preference type. Row r = base; if (CFGetTypeID(value) == CFNumberGetTypeID()) { r["value"] = stringFromCFNumber(static_cast<CFDataRef>(value)); } else if (CFGetTypeID(value) == CFStringGetTypeID()) { r["value"] = stringFromCFString(static_cast<CFStringRef>(value)); } else if (CFGetTypeID(value) == CFDateGetTypeID()) { auto unix_time = CFDateGetAbsoluteTime(static_cast<CFDateRef>(value)) + kCFAbsoluteTimeIntervalSince1970; r["value"] = boost::lexical_cast<std::string>(std::llround(unix_time)); } else if (CFGetTypeID(value) == CFBooleanGetTypeID()) { r["value"] = (CFBooleanGetValue(static_cast<CFBooleanRef>(value)) == TRUE) ? "true" : "false"; } else if (CFGetTypeID(value) == CFDataGetTypeID()) { // Do not include data preferences. } else if (CFGetTypeID(value) == CFArrayGetTypeID()) { genOSXListPref(static_cast<CFArrayRef>(value), base, results, depth); return; } else if (CFGetTypeID(value) == CFDictionaryGetTypeID()) { // Generate a row for each hash key. TRowResults trow(base, results, depth); CFDictionaryApplyFunction( static_cast<CFDictionaryRef>(value), &genOSXHashPref, &trow); return; } results.push_back(std::move(r)); }
static void cf_hash_to_rb_hash(const void *raw_key, const void * raw_value, void *ctx){ CFTypeRef value = (CFTypeRef)raw_value; CFStringRef key = (CFStringRef)raw_key; VALUE rubyValue = Qnil; VALUE hash = (VALUE)ctx; if(CFStringGetTypeID() == CFGetTypeID(value)){ rubyValue = cfstring_to_rb_string((CFStringRef)value); } else if(CFDataGetTypeID() == CFGetTypeID(value)){ CFDataRef data = (CFDataRef)value; rubyValue = rb_enc_str_new((const char*)CFDataGetBytePtr(data),CFDataGetLength(data), rb_ascii8bit_encoding()); } else if(CFBooleanGetTypeID() == CFGetTypeID(value)){ Boolean booleanValue = CFBooleanGetValue(value); rubyValue = booleanValue ? Qtrue : Qfalse; } else if(CFNumberGetTypeID() == CFGetTypeID(value)){ if(CFNumberIsFloatType(value)) { double doubleValue; CFNumberGetValue(value, kCFNumberDoubleType, &doubleValue); rubyValue = rb_float_new(doubleValue); }else{ long long longValue; CFNumberGetValue(value, kCFNumberLongLongType, &longValue); rubyValue = LL2NUM(longValue); } } else if (CFDateGetTypeID() == CFGetTypeID(value)){ CFDateRef date = (CFDateRef) value; CFAbsoluteTime abs_time = CFDateGetAbsoluteTime(date); double secondsSinceUnixEpoch = abs_time + kCFAbsoluteTimeIntervalSince1970; time_t seconds = (time_t)secondsSinceUnixEpoch; long usec = (secondsSinceUnixEpoch - seconds) * 1000000; rubyValue = rb_time_new((time_t)secondsSinceUnixEpoch, usec); } if(!NIL_P(rubyValue)){ rb_hash_aset(hash, cfstring_to_rb_string(key), rubyValue); } }
CFNumberRef copyNumberFromChosen(CFStringRef key) { CFNumberRef num = NULL; CFDataRef data = copyDataFromChosen(key); if(data == NULL) return NULL; if(CFGetTypeID(data) == CFDataGetTypeID()) { int len = CFDataGetLength(data); num = CFNumberCreate(kCFAllocatorDefault, len == 4 ? kCFNumberSInt32Type : kCFNumberSInt64Type, CFDataGetBytePtr(data) ); } CFRelease(data); return num; }
io_registry_entry_t lookService(uint32_t segment, uint32_t bus, uint32_t device, uint32_t function) { kern_return_t status; io_iterator_t iter; io_service_t service; IOPCIAddressSpace space; space.bits = 0; space.es.busNum = bus; space.es.deviceNum = device; space.es.functionNum = function; status = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching("IOPCIDevice"), &iter); assert(kIOReturnSuccess == status); while ((service = IOIteratorNext(iter))) { CFDataRef reg; UInt32 bits; reg = IORegistryEntryCreateCFProperty(service, CFSTR("reg"), kCFAllocatorDefault, kNilOptions); bits = 0; if (reg) { if (CFDataGetTypeID() == CFGetTypeID(reg)) bits = ((UInt32 *)CFDataGetBytePtr(reg))[0]; CFRelease(reg); } if (bits == space.bits) { IOObjectRetain(service); break; } } IOObjectRelease(iter); return (service); }