/** * \brief Retrieves the values from the context. * * \param context the context * \param receiver the receiving object which will be signaled when the * notification is clicked. May be NULL. * \param clicked_slot the slot to be signaled when the notification is clicked. * \param timeout_slot the slot to be signaled when the notification isn't clicked. * \param context the context which will be passed back to the slot * May be NULL. */ void getContext( CFPropertyListRef context, GrowlNotifierSignaler** signaler, const QObject** receiver, const char** clicked_slot, const char** timeout_slot, void** qcontext/*, pid_t* pid*/) { CFDataRef data; if (signaler) { data = (CFDataRef) CFArrayGetValueAtIndex((CFArrayRef) context, 0); CFDataGetBytes(data, CFRangeMake(0,CFDataGetLength(data)), (UInt8*) signaler); } if (receiver){ data = (CFDataRef) CFArrayGetValueAtIndex((CFArrayRef) context, 1); CFDataGetBytes(data, CFRangeMake(0,CFDataGetLength(data)), (UInt8*) receiver); } if (clicked_slot) { data = (CFDataRef) CFArrayGetValueAtIndex((CFArrayRef) context, 2); CFDataGetBytes(data, CFRangeMake(0,CFDataGetLength(data)), (UInt8*) clicked_slot); } if (timeout_slot) { data = (CFDataRef) CFArrayGetValueAtIndex((CFArrayRef) context, 3); CFDataGetBytes(data, CFRangeMake(0,CFDataGetLength(data)), (UInt8*) timeout_slot); } if (qcontext) { data = (CFDataRef) CFArrayGetValueAtIndex((CFArrayRef) context, 4); CFDataGetBytes(data, CFRangeMake(0,CFDataGetLength(data)), (UInt8*) qcontext); } //if (pid) { // data = (CFDataRef) CFArrayGetValueAtIndex((CFArrayRef) context, 5); // CFDataGetBytes(data, CFRangeMake(0,CFDataGetLength(data)), (UInt8*) pid); //} }
void __CFWriteStreamClientCallBack(CFWriteStreamRef stream, CFStreamEventType eventType, void *clientCallBackInfo) { // Extract the context tnet_transport_t *transport = (tnet_transport_t *) clientCallBackInfo; transport_context_t *context = transport->context; /* lock context */ tsk_safeobj_lock(context); // Extract the native socket CFDataRef data = CFWriteStreamCopyProperty(stream, kCFStreamPropertySocketNativeHandle); CFSocketNativeHandle fd; CFDataGetBytes(data, CFRangeMake(0, sizeof(CFSocketNativeHandle)), (UInt8*) &fd); CFRelease(data); transport_socket_t *sock = (transport_socket_t *) getSocket(context, fd); switch(eventType) { case kCFStreamEventOpenCompleted: { TSK_DEBUG_INFO("__CFWriteStreamClientCallBack --> kCFStreamEventOpenCompleted"); if (TNET_SOCKET_TYPE_IS_SECURE(sock->type)) { #if !TARGET_OS_IPHONE SSLContextRef sslContext = NULL; data = CFWriteStreamCopyProperty(stream, kCFStreamPropertySocketSSLContext); CFDataGetBytes(data, CFRangeMake(0, sizeof(SSLContextRef)), (UInt8*) &sslContext); CFRelease(data); // TODO: Set the client certificates #endif } break; } case kCFStreamEventEndEncountered: case kCFStreamEventErrorOccurred: { // Get the error code CFErrorRef error = CFWriteStreamCopyError(stream); CFIndex index = CFErrorGetCode(error); CFRelease(error); TSK_DEBUG_INFO("__CFWriteStreamClientCallBack --> Error %lu", index); TSK_RUNNABLE_ENQUEUE(transport, event_error, transport->callback_data, sock->fd); removeSocket(sock, context); break; } default: { // Not Implemented assert(42 == 0); break; } } /* unlock context */ tsk_safeobj_unlock(context); }
unsigned char * CGImageLuminanceSource::getMatrix() { int size = width_ * height_; unsigned char* result = new unsigned char[size]; if (left_ == 0 && top_ == 0 && dataWidth_ == width_ && dataHeight_ == height_) { CFDataGetBytes(data_, CFRangeMake(0, size), result); } else { for (int row = 0; row < height_; row++) { CFRange dataRange = CFRangeMake((top_ + row) * dataWidth_ + left_, width_); CFDataGetBytes(data_, dataRange, result + row * width_); } } return result; }
// // We've already read the data into a dataRef. // Just spoon it out to the caller as they ask for it. // unsigned int URLAccessCFBinInputStream::readBytes(XMLByte* const toFill , const unsigned int maxToRead) { // If we don't have a dataRef, we can't return any data if (!mDataRef) return 0; // Get the length of the data we've fetched CFIndex dataLength = CFDataGetLength(mDataRef); // Calculate how much to return based on how much // we've already returned, and how much the user wants CFIndex n = dataLength - mBytesProcessed; // Amount remaining CFIndex desired = maxToRead & 0x7fffffff; // CFIndex is signed if (n > desired) // Amount desired n = desired; // Read the appropriate bytes into the user buffer CFRange range = CFRangeMake(mBytesProcessed, n); CFDataGetBytes(mDataRef, range, reinterpret_cast<UInt8*>(toFill)); // Update bytes processed mBytesProcessed += n; // Return the number of bytes delivered return n; }
void Blob::getBytes(Range range, UInt8 *outBuffer) { gfx_assert_param(outBuffer); gfx_assert(range.location < length() && range.max() < length(), str("out of bounds range")); CFDataGetBytes(getStorage(), range, outBuffer); }
Status genUid(id_t& uid, uuid_string_t& uuid_str) { CFDataRef uuid = nullptr; if (!genUnlockIdent(uuid).ok()) { if (uuid != nullptr) { CFRelease(uuid); } return Status(1, "Could not get unlock ident"); } CFDataGetBytes(uuid, CFRangeMake(0, CFDataGetLength(uuid)), (UInt8*)uuid_str); if (uuid != nullptr) { CFRelease(uuid); } uuid_t uuidT = {0}; if (uuid_parse(uuid_str, uuidT) != 0) { return Status(1, "Could not parse UUID"); } // id_type >=0 are all valid id types int id_type = -1; if (mbr_uuid_to_id(uuidT, &uid, &id_type) != 0 && id_type != ID_TYPE_UID) { return Status(1, "Could not get uid from uuid"); } return Status(0, "ok"); }
//----------------------------------------------------------------------------- bool IPlatformBitmap::createMemoryPNGRepresentation (IPlatformBitmap* bitmap, void** ptr, uint32_t& size) { bool result = false; #if !TARGET_OS_IPHONE CGBitmap* cgBitmap = dynamic_cast<CGBitmap*> (bitmap); if (cgBitmap) { CGImageRef image = cgBitmap->getCGImage (); if (image) { CFMutableDataRef data = CFDataCreateMutable (NULL, 0); if (data) { CGImageDestinationRef dest = CGImageDestinationCreateWithData (data, kUTTypePNG, 1, 0); if (dest) { CGImageDestinationAddImage (dest, image, 0); if (CGImageDestinationFinalize (dest)) { size = (uint32_t)CFDataGetLength (data); *ptr = malloc (size); CFDataGetBytes (data, CFRangeMake (0, size), (UInt8*)*ptr); result = true; } CFRelease (dest); } CFRelease (data); } } } #endif return result; }
static CFStringRef CreateStringFromData(CFDataRef data) // Some IOKit strings are encoded in CFDataRefs; extract as a CFStringRef. // Also remove any trailing null characters, which can lurk in the // I/O Registry strings. { CFIndex len; assert(data != NULL); // Decrement len until to eliminate any trailing null characters. len = CFDataGetLength(data); do { char ch; if (len < 1) { break; } CFDataGetBytes(data, CFRangeMake(len - 1, 1), (UInt8 *) &ch); if (ch != 0) { break; } len -= 1; } while (true); return CFStringCreateWithBytes(NULL, CFDataGetBytePtr(data), len, kCFStringEncodingMacRoman, false ); }
static int mailstream_low_cfstream_get_fd(mailstream_low * s) { struct mailstream_cfstream_data * cfstream_data = NULL; CFDataRef native_handle_data = NULL; CFSocketNativeHandle native_handle_value = -1; CFIndex native_data_len = 0; CFIndex native_value_len = 0; if (!s) return -1; cfstream_data = (struct mailstream_cfstream_data *) s->data; if (!cfstream_data->readStream) return -1; native_handle_data = (CFDataRef)CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySocketNativeHandle); if (!native_handle_data) return -1; native_data_len = CFDataGetLength(native_handle_data); native_value_len = (CFIndex)sizeof(native_handle_value); if (native_data_len != native_value_len) { CFRelease(native_handle_data); return -1; } CFDataGetBytes(native_handle_data, CFRangeMake(0, MIN(native_data_len, native_value_len)), (UInt8 *)&native_handle_value); CFRelease(native_handle_data); return native_handle_value; }
std::string stringFromCFData(const CFDataRef& cf_data) { CFRange range = CFRangeMake(0, CFDataGetLength(cf_data)); char* buffer = (char*)malloc(range.length + 1); if (buffer == nullptr) { return ""; } memset(buffer, 0, range.length + 1); std::stringstream result; uint8_t byte; CFDataGetBytes(cf_data, range, (UInt8*)buffer); for (CFIndex i = 0; i < range.length; ++i) { byte = buffer[i]; if (isprint(byte)) { result << byte; } else if (buffer[i] == 0) { result << ' '; } else { result << '%' << std::setfill('0') << std::setw(2) << std::hex << (int)byte; } } // Cleanup allocations. free(buffer); return result.str(); }
std::wstring MacUtils::CFStringRefToWString(CFStringRef aString) { if (aString == NULL) { return L""; } if (!aString) return false; CFDataRef cfData = CFStringCreateExternalRepresentation(kCFAllocatorDefault, aString, kCFStringEncodingUTF32, 0); CFRelease(aString); if (!cfData) return false; int out_byte_len = CFDataGetLength(cfData); out_byte_len -= sizeof(wchar_t); // don't count the 32 bit BOM char at start int out_len = out_byte_len / sizeof(wchar_t); wchar_t *tmp = new wchar_t[out_len + 1]; // start after the BOM, hence sizeof(wchar_t) CFDataGetBytes(cfData, CFRangeMake(sizeof(wchar_t), out_byte_len), (UInt8*)tmp); CFRelease(cfData); tmp[out_len] = 0; std::wstring result = tmp; delete[] tmp; return result; }
static cairo_int_status_t _cairo_quartz_load_truetype_table (void *abstract_font, unsigned long tag, long offset, unsigned char *buffer, unsigned long *length) { cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face (abstract_font); CFDataRef data = NULL; if (likely (CGFontCopyTableForTagPtr)) data = CGFontCopyTableForTagPtr (font_face->cgFont, tag); if (!data) return CAIRO_INT_STATUS_UNSUPPORTED; if (buffer == NULL) { *length = CFDataGetLength (data); CFRelease (data); return CAIRO_STATUS_SUCCESS; } if (CFDataGetLength (data) < offset + (long) *length) { CFRelease (data); return CAIRO_INT_STATUS_UNSUPPORTED; } CFDataGetBytes (data, CFRangeMake (offset, *length), buffer); CFRelease (data); return CAIRO_STATUS_SUCCESS; }
CFStringRef lookup_mac_address(const char* serviceName) { unsigned char macaddrBytes[6]; CFStringRef res = NULL; io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceNameMatching(serviceName)); if(service) { CFDataRef macData = IORegistryEntryCreateCFProperty(service, CFSTR("local-mac-address"), kCFAllocatorDefault, 0); if(macData != NULL) { CFDataGetBytes(macData, CFRangeMake(0,6), macaddrBytes); res = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%02x:%02x:%02x:%02x:%02x:%02x"), macaddrBytes[0], macaddrBytes[1], macaddrBytes[2], macaddrBytes[3], macaddrBytes[4], macaddrBytes[5]); CFRelease(macData); } IOObjectRelease(service); } return res; }
CFStringRef copy_bluetooth_mac_address() { io_service_t service; CFDataRef macaddrData; CFStringRef macaddr; unsigned char macaddrBytes[6]; service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceNameMatching("bluetooth")); if(!service) { printf("unable to find bluetooth service\n"); return NULL; } macaddrData= IORegistryEntryCreateCFProperty(service, CFSTR("local-mac-address"), kCFAllocatorDefault, 0); if(macaddrData == NULL) { printf("bluetooth local-mac-address not found\n"); IOObjectRelease(service); return NULL; } CFDataGetBytes(macaddrData, CFRangeMake(0,6), macaddrBytes); macaddr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%02x:%02x:%02x:%02x:%02x:%02x"), macaddrBytes[0], macaddrBytes[1], macaddrBytes[2], macaddrBytes[3], macaddrBytes[4], macaddrBytes[5]); return macaddr; }
static PyObject *AE_CopyScriptingDefinition(PyObject* self, PyObject* args) { PyObject *res; FSRef fsRef; CFDataRef sdef; CFIndex dataSize; char *data; OSAError err; if (!PyArg_ParseTuple(args, "O&", AE_GetFSRef, &fsRef)) return NULL; err = OSACopyScriptingDefinition(&fsRef, 0, &sdef); if (err) return AE_MacOSError(err); dataSize = CFDataGetLength(sdef); data = (char *)CFDataGetBytePtr(sdef); if (data != NULL) { res = PyBytes_FromStringAndSize(data, dataSize); } else { data = malloc(dataSize); CFDataGetBytes(sdef, CFRangeMake(0, dataSize), (UInt8 *)data); res = PyBytes_FromStringAndSize(data, dataSize); free(data); } CFRelease(sdef); return res; }
static CFStringRef CreateMACFromData(CFDataRef data) // Extracts a MAC address as a colon delimited string from // a CFDataRef extracted from I/O Registry. { // mac addresses are 6 bytes long, which translates to 18 chars. UInt8 bytes[6]; UInt8 *p = &bytes[0]; char s [19]; char *cp = &s[0]; CFIndex len; assert(data != NULL); len = CFDataGetLength( data ); // make sure it's valid if ( len != 6 ) return NULL; CFDataGetBytes( data, CFRangeMake( 0, 6 ), &bytes[0] ); // add digits in pairs with colon separators while ( len-- ) cp += sprintf( cp, "%2.2x:", *p++ ); // terminate string s[17] = '\0'; return CFStringCreateWithCString( NULL, s, kCFStringEncodingMacRoman ); }
static gboolean gst_vtenc_negotiate_downstream (GstVTEnc * self, CMSampleBufferRef sbuf) { gboolean result; GstCaps *caps; GstStructure *s; if (self->caps_width == self->negotiated_width && self->caps_height == self->negotiated_height && self->caps_fps_n == self->negotiated_fps_n && self->caps_fps_d == self->negotiated_fps_d) { return TRUE; } caps = gst_pad_get_pad_template_caps (self->srcpad); caps = gst_caps_make_writable (caps); s = gst_caps_get_structure (caps, 0); gst_structure_set (s, "width", G_TYPE_INT, self->negotiated_width, "height", G_TYPE_INT, self->negotiated_height, "framerate", GST_TYPE_FRACTION, self->negotiated_fps_n, self->negotiated_fps_d, NULL); if (self->details->format_id == kVTFormatH264) { CMFormatDescriptionRef fmt; CFDictionaryRef atoms; CFStringRef avccKey; CFDataRef avcc; gpointer codec_data; gsize codec_data_size; GstBuffer *codec_data_buf; fmt = CMSampleBufferGetFormatDescription (sbuf); atoms = CMFormatDescriptionGetExtension (fmt, kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms); avccKey = CFStringCreateWithCString (NULL, "avcC", kCFStringEncodingUTF8); avcc = CFDictionaryGetValue (atoms, avccKey); CFRelease (avccKey); codec_data_size = CFDataGetLength (avcc); codec_data = g_malloc (codec_data_size); CFDataGetBytes (avcc, CFRangeMake (0, codec_data_size), codec_data); codec_data_buf = gst_buffer_new_wrapped (codec_data, codec_data_size); gst_structure_set (s, "codec_data", GST_TYPE_BUFFER, codec_data_buf, NULL); gst_buffer_unref (codec_data_buf); } result = gst_pad_push_event (self->srcpad, gst_event_new_caps (caps)); gst_caps_unref (caps); self->caps_width = self->negotiated_width; self->caps_height = self->negotiated_height; self->caps_fps_n = self->negotiated_fps_n; self->caps_fps_d = self->negotiated_fps_d; return result; }
static gboolean gst_vtenc_negotiate_downstream (GstVTEnc * self, CMSampleBufferRef sbuf) { gboolean result; GstCMApi *cm = self->ctx->cm; GstCaps *caps; GstStructure *s; if (self->caps_width == self->negotiated_width && self->caps_height == self->negotiated_height && self->caps_fps_n == self->negotiated_fps_n && self->caps_fps_d == self->negotiated_fps_d) { return TRUE; } caps = gst_caps_copy (gst_pad_get_pad_template_caps (self->srcpad)); s = gst_caps_get_structure (caps, 0); gst_structure_set (s, "width", G_TYPE_INT, self->negotiated_width, "height", G_TYPE_INT, self->negotiated_height, "framerate", GST_TYPE_FRACTION, self->negotiated_fps_n, self->negotiated_fps_d, NULL); if (self->details->format_id == kVTFormatH264) { CMFormatDescriptionRef fmt; CFDictionaryRef atoms; CFStringRef avccKey; CFDataRef avcc; GstBuffer *codec_data; fmt = cm->CMSampleBufferGetFormatDescription (sbuf); atoms = cm->CMFormatDescriptionGetExtension (fmt, *(cm->kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms)); avccKey = CFStringCreateWithCString (NULL, "avcC", kCFStringEncodingUTF8); avcc = CFDictionaryGetValue (atoms, avccKey); CFRelease (avccKey); codec_data = gst_buffer_new_and_alloc (CFDataGetLength (avcc)); CFDataGetBytes (avcc, CFRangeMake (0, CFDataGetLength (avcc)), GST_BUFFER_DATA (codec_data)); gst_structure_set (s, "codec_data", GST_TYPE_BUFFER, codec_data, NULL); gst_buffer_unref (codec_data); } result = gst_pad_set_caps (self->srcpad, caps); gst_caps_unref (caps); self->caps_width = self->negotiated_width; self->caps_height = self->negotiated_height; self->caps_fps_n = self->negotiated_fps_n; self->caps_fps_d = self->negotiated_fps_d; return result; }
// Given an iterator across a set of Ethernet interfaces, return the MAC address of the last one. // If no interfaces are found the MAC address is set to an empty string. // In this sample the iterator should contain just the primary interface. static kern_return_t GetMACAddress(io_iterator_t intfIterator, UInt8 *MACAddress, UInt8 bufferSize) { io_object_t intfService; io_object_t controllerService; kern_return_t kernResult = KERN_FAILURE; // Make sure the caller provided enough buffer space. Protect against buffer overflow problems. if (bufferSize < kIOEthernetAddressSize) { return kernResult; } // Initialize the returned address bzero(MACAddress, bufferSize); // IOIteratorNext retains the returned object, so release it when we're done with it. while (intfService = IOIteratorNext(intfIterator)) { CFTypeRef MACAddressAsCFData; // IONetworkControllers can't be found directly by the IOServiceGetMatchingServices call, // since they are hardware nubs and do not participate in driver matching. In other words, // registerService() is never called on them. So we've found the IONetworkInterface and will // get its parent controller by asking for it specifically. // IORegistryEntryGetParentEntry retains the returned object, so release it when we're done with it. kernResult = IORegistryEntryGetParentEntry(intfService, kIOServicePlane, &controllerService); if (KERN_SUCCESS != kernResult) { printf("IORegistryEntryGetParentEntry returned 0x%08x\n", kernResult); } else { // Retrieve the MAC address property from the I/O Registry in the form of a CFData MACAddressAsCFData = IORegistryEntryCreateCFProperty(controllerService, CFSTR(kIOMACAddress), kCFAllocatorDefault, 0); if (MACAddressAsCFData) { // CFShow(MACAddressAsCFData); // for display purposes only; output goes to stderr // Get the raw bytes of the MAC address from the CFData CFDataGetBytes(MACAddressAsCFData, CFRangeMake(0, kIOEthernetAddressSize), MACAddress); CFRelease(MACAddressAsCFData); } // Done with the parent Ethernet controller object so we release it. (void) IOObjectRelease(controllerService); } // Done with the Ethernet interface object so we release it. (void) IOObjectRelease(intfService); } return kernResult; }
static SInt32 _CFUserNotificationSendRequest(CFAllocatorRef allocator, CFStringRef sessionID, mach_port_t replyPort, SInt32 token, CFTimeInterval timeout, CFOptionFlags flags, CFDictionaryRef dictionary) { CFDictionaryRef modifiedDictionary = NULL; SInt32 retval = ERR_SUCCESS, itimeout = (timeout > 0.0 && timeout < INT_MAX) ? (SInt32)timeout : 0; CFDataRef data; mach_msg_base_t *msg = NULL; mach_port_t bootstrapPort = MACH_PORT_NULL, serverPort = MACH_PORT_NULL; CFIndex size; char namebuffer[MAX_PORT_NAME_LENGTH + 1]; strlcpy(namebuffer, NOTIFICATION_PORT_NAME, sizeof(namebuffer)); if (sessionID) { char sessionid[MAX_PORT_NAME_LENGTH + 1]; CFIndex len = MAX_PORT_NAME_LENGTH - sizeof(NOTIFICATION_PORT_NAME) - sizeof(NOTIFICATION_PORT_NAME_SUFFIX); CFStringGetBytes(sessionID, CFRangeMake(0, CFStringGetLength(sessionID)), kCFStringEncodingUTF8, 0, false, (uint8_t *)sessionid, len, &size); sessionid[len - 1] = '\0'; strlcat(namebuffer, NOTIFICATION_PORT_NAME_SUFFIX, sizeof(namebuffer)); strlcat(namebuffer, sessionid, sizeof(namebuffer)); } retval = task_get_bootstrap_port(mach_task_self(), &bootstrapPort); if (ERR_SUCCESS == retval && MACH_PORT_NULL != bootstrapPort) retval = bootstrap_look_up2(bootstrapPort, namebuffer, &serverPort, 0, 0); if (ERR_SUCCESS == retval && MACH_PORT_NULL != serverPort) { modifiedDictionary = _CFUserNotificationModifiedDictionary(allocator, dictionary, token, itimeout, _CFProcessNameString()); if (modifiedDictionary) { data = CFPropertyListCreateXMLData(allocator, modifiedDictionary); if (data) { size = sizeof(mach_msg_base_t) + ((CFDataGetLength(data) + 3) & (~0x3)); msg = (mach_msg_base_t *)CFAllocatorAllocate(kCFAllocatorSystemDefault, size, 0); if (__CFOASafe) __CFSetLastAllocationEventName(msg, "CFUserNotification (temp)"); if (msg) { memset(msg, 0, size); msg->header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE); msg->header.msgh_size = size; msg->header.msgh_remote_port = serverPort; msg->header.msgh_local_port = replyPort; msg->header.msgh_id = flags; msg->body.msgh_descriptor_count = 0; CFDataGetBytes(data, CFRangeMake(0, CFDataGetLength(data)), (uint8_t *)msg + sizeof(mach_msg_base_t)); //CFShow(CFStringCreateWithBytes(kCFAllocatorSystemDefault, (UInt8 *)msg + sizeof(mach_msg_base_t), CFDataGetLength(data), kCFStringEncodingUTF8, false)); retval = mach_msg((mach_msg_header_t *)msg, MACH_SEND_MSG|MACH_SEND_TIMEOUT, size, 0, MACH_PORT_NULL, MESSAGE_TIMEOUT, MACH_PORT_NULL); CFAllocatorDeallocate(kCFAllocatorSystemDefault, msg); } else { retval = unix_err(ENOMEM); } CFRelease(data); } else { retval = unix_err(ENOMEM); } CFRelease(modifiedDictionary); } else { retval = unix_err(ENOMEM); } } return retval; }
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); }
STATIC void cga_prepare_set(struct in6_cga_prepare * cga_prep, CFDataRef modifier, uint8_t security_level) { CFDataGetBytes(modifier, CFRangeMake(0, CFDataGetLength(modifier)), cga_prep->cga_modifier.octets); cga_prep->cga_security_level = security_level; bzero(cga_prep->reserved_A, sizeof(cga_prep->reserved_A)); return; }
STATIC bool cga_parameters_set(CFDataRef priv, CFDataRef pub, CFDataRef modifier, uint8_t security_level) { UInt8 buf[CGA_PARAMETERS_MAX_SIZE]; uint16_t key_len; UInt8 * offset; offset = buf; /* cga_prepare */ cga_prepare_set((struct in6_cga_prepare *)offset, modifier, security_level); offset += sizeof(struct in6_cga_prepare); /* private key length (uint16_t) */ key_len = CFDataGetLength(priv); bcopy(&key_len, offset, sizeof(key_len)); offset += sizeof(key_len); /* private key */ CFDataGetBytes(priv, CFRangeMake(0, key_len), offset); offset += key_len; /* public key length (uint16_t) */ key_len = CFDataGetLength(pub); bcopy(&key_len, offset, sizeof(key_len)); offset += sizeof(key_len); /* public key */ CFDataGetBytes(pub, CFRangeMake(0, key_len), offset); offset += key_len; if (sysctlbyname(knet_inet6_send_cga_parameters, NULL, NULL, buf, (offset - buf)) != 0) { my_log_fl(LOG_NOTICE, "sysctl(%s) failed, %s", knet_inet6_send_cga_parameters, strerror(errno)); return (FALSE); } return (TRUE); }
kern_return_t SMCOpen(void) { kern_return_t result; mach_port_t masterPort; io_iterator_t iterator; io_object_t device; result = IOMasterPort(MACH_PORT_NULL, &masterPort); CFMutableDictionaryRef matchingDictionary = IOServiceMatching("AppleSMC"); result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator); if (result != kIOReturnSuccess) { printf("Error: IOServiceGetMatchingServices() = %08x\n", result); return 1; } device = IOIteratorNext(iterator); IOObjectRelease(iterator); if (device == 0) { printf("Error: no SMC found\n"); return 1; } result = IOServiceOpen(device, mach_task_self(), 0, &conn); IOObjectRelease(device); if (result != kIOReturnSuccess) { printf("Error: IOServiceOpen() = %08x\n", result); return 1; } io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); if (platformExpert) { CFTypeRef CFProductData = IORegistryEntryCreateCFProperty(platformExpert, CFSTR("product-name"), kCFAllocatorDefault, 0); if (CFProductData) { CFIndex length = CFDataGetLength((CFDataRef)CFProductData); char buffer[length]; CFDataGetBytes((CFDataRef) CFProductData, CFRangeMake(0,length), (UInt8*)buffer); CFRelease(CFProductData); modelNo = *new std::string(buffer); } IOObjectRelease(platformExpert); } return kIOReturnSuccess; }
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; }
RefPtr<API::Data> encodeLegacySessionState(const SessionState& sessionState) { auto sessionHistoryDictionary = encodeSessionHistory(sessionState.backForwardListState); auto provisionalURLString = sessionState.provisionalURL.isNull() ? nullptr : sessionState.provisionalURL.string().createCFString(); RetainPtr<CFNumberRef> renderTreeSizeNumber(adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &sessionState.renderTreeSize))); RetainPtr<CFDictionaryRef> stateDictionary; if (provisionalURLString) { stateDictionary = createDictionary({ { sessionHistoryKey, sessionHistoryDictionary.get() }, { provisionalURLKey, provisionalURLString.get() }, { renderTreeSizeKey, renderTreeSizeNumber.get() } }); } else { stateDictionary = createDictionary({ { sessionHistoryKey, sessionHistoryDictionary.get() }, { renderTreeSizeKey, renderTreeSizeNumber.get() } }); } auto writeStream = adoptCF(CFWriteStreamCreateWithAllocatedBuffers(kCFAllocatorDefault, nullptr)); if (!writeStream) return nullptr; if (!CFWriteStreamOpen(writeStream.get())) return nullptr; if (!CFPropertyListWrite(stateDictionary.get(), writeStream.get(), kCFPropertyListBinaryFormat_v1_0, 0, nullptr)) return nullptr; auto data = adoptCF(static_cast<CFDataRef>(CFWriteStreamCopyProperty(writeStream.get(), kCFStreamPropertyDataWritten))); CFIndex length = CFDataGetLength(data.get()); size_t bufferSize = length + sizeof(uint32_t); auto buffer = MallocPtr<uint8_t>::malloc(bufferSize); // Put the session state version number at the start of the buffer buffer.get()[0] = (sessionStateDataVersion & 0xff000000) >> 24; buffer.get()[1] = (sessionStateDataVersion & 0x00ff0000) >> 16; buffer.get()[2] = (sessionStateDataVersion & 0x0000ff00) >> 8; buffer.get()[3] = (sessionStateDataVersion & 0x000000ff); // Copy in the actual session state data CFDataGetBytes(data.get(), CFRangeMake(0, length), buffer.get() + sizeof(uint32_t)); return API::Data::createWithoutCopying(buffer.leakPtr(), bufferSize, [] (unsigned char* buffer, const void* context) { fastFree(buffer); }, nullptr); }
void LoadPrefs (void) { CFMutableStringRef mref; CFStringRef sref; CFDataRef data; for (unsigned int i = 0; i < kPrefListSize; i++) { mref = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, CFSTR("Preferences_")); if (mref) { sref = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8 *) &(prefList[i].itemName), sizeof(OSType), kCFStringEncodingMacRoman, false); if (sref) { CFStringAppend(mref, sref); data = (CFDataRef) CFPreferencesCopyAppValue(mref, kCFPreferencesCurrentApplication); if (data) { if (CFDataGetLength(data) == prefList[i].size) CFDataGetBytes(data, CFRangeMake(0, prefList[i].size), (UInt8 *) prefList[i].itemPointer); CFRelease(data); } CFRelease(sref); } CFRelease(mref); } } mref = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, CFSTR("Preferences_SaveFolder")); if (mref) { sref = (CFStringRef) CFPreferencesCopyAppValue(mref, kCFPreferencesCurrentApplication); if (sref) saveFolderPath = sref; CFRelease(mref); } sref = (CFStringRef) CFPreferencesCopyAppValue(CFSTR("LastVersionUsed"), kCFPreferencesCurrentApplication); if (!sref) { Settings.SoundInputRate = 31950; macSoundBuffer_ms = 80; } else CFRelease(sref); }
static void MacQTOpenVideoComponent(ComponentInstance *rci) { OSStatus err; ComponentInstance ci; ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType); CheckError((ci == nil), 01); CFDataRef data; data = (CFDataRef) CFPreferencesCopyAppValue(CFSTR("QTVideoSetting"), kCFPreferencesCurrentApplication); if (data) { CFIndex len; Handle hdl; len = CFDataGetLength(data); hdl = NewHandleClear((Size) len); if (MemError() == noErr) { HLock(hdl); CFDataGetBytes(data, CFRangeMake(0, len), (unsigned char *) *hdl); err = SCSetInfo(ci, scSettingsStateType, &hdl); DisposeHandle(hdl); } CFRelease(data); } else { SCSpatialSettings ss; SCTemporalSettings ts; ss.codecType = kAnimationCodecType; ss.codec = 0; ss.depth = 16; ss.spatialQuality = codecMaxQuality; err = SCSetInfo(ci, scSpatialSettingsType, &ss); ts.frameRate = FixRatio(Memory.ROMFramesPerSecond, 1); ts.keyFrameRate = Memory.ROMFramesPerSecond; ts.temporalQuality = codecMaxQuality; err = SCSetInfo(ci, scTemporalSettingsType, &ts); } *rci = ci; }
/** * Retrieve the stored data specified by the given 'app' and data 'name'. Requires * 'buffer' be pre-allocated and contains enough space to hold the data. Pass in * the size of 'buffer' with 'buffersize'. * * @returns 0 on success, -1 on error */ int RudeRegistryCF::QueryByte(const TCHAR *app, const TCHAR *name, void *buffer, int *buffersize) { CFStringRef key = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII); CFPropertyListRef value = CFPreferencesCopyAppValue(key, kCFPreferencesCurrentApplication); if(value == 0) return -1; if(CFDataGetLength((CFDataRef) value) != *buffersize) return -1; CFRange range = CFRangeMake(0, *buffersize); CFDataGetBytes((CFDataRef) value, range, (UInt8 *) buffer); return 0; }