volatile int kmod_start(void) { libkern_init0(); OSString* one = OSString::withCString("Anal sex"); OSString* two = OSString::withCString("Cunnilingus"); OSArray* sexthings = OSArray::withCapacity(2); sexthings->setObject(one); sexthings->setObject(two); printk("Hello from IOKit!\n"); printk("Put: %p %p\n", one, two); printk("OSArray: %p\n", sexthings); printk("Get: %p %p\n", sexthings->getObject(0), sexthings->getObject(1)); OSSerialize* ser = OSSerialize::withCapacity(1024); sexthings->serialize(ser); printk("Serialized: %s \n", ser->text()); return 0; }
OSObject * FileNVRAM::getProperty(const OSSymbol *aKey) const { OSObject* value = IOService::getProperty(aKey); if (value) { OSSerialize *s = OSSerialize::withCapacity(1000); if (value->serialize(s)) { LOG(INFO, "getProperty(%s) = %s called\n", aKey->getCStringNoCopy(), s->text()); } else { LOG(INFO, "getProperty(%s) = %p called\n", aKey->getCStringNoCopy(), value); } s->release(); } else { // Ignore BSD Name for now in logs, it pollutes if (!aKey->isEqualTo("BSD Name")) { LOG(INFO, "getProperty(%s) = %p called\n", aKey->getCStringNoCopy(), (void*)NULL); } } return value; }
bool FileNVRAM::setProperty(const OSSymbol *aKey, OSObject *anObject) { // Verify permissions. if (IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator) != kIOReturnSuccess) { // Not priveleged! return false; } // Check for SIP configuration variables. if ((strncmp("csr-data", aKey->getCStringNoCopy(), 8) == 0) || (strncmp("csr-active-config", aKey->getCStringNoCopy(), 17) == 0)) { // We have a match so first verify the entitlements. if (IOUserClient::copyClientEntitlement(current_task(), "com.apple.private.iokit.nvram-csr") == NULL) { LOG(INFO, "setProperty(%s, (%s) %p) failed (not entitled)\n", aKey->getCStringNoCopy(), anObject->getMetaClass()->getClassName(), anObject); // Not entitled! return false; } } OSSerialize *s = OSSerialize::withCapacity(1000); if (anObject->serialize(s)) { LOG(INFO, "setProperty(%s, (%s) %s) called\n", aKey->getCStringNoCopy(), anObject->getMetaClass()->getClassName(), s->text()); } else { LOG(INFO, "setProperty(%s, (%s) %p) called\n", aKey->getCStringNoCopy(), anObject->getMetaClass()->getClassName(), anObject); } s->release(); // Check for special FileNVRAM properties: if (strncmp(FILE_NVRAM_GUID ":", aKey->getCStringNoCopy(), MIN(aKey->getLength(), strlen(FILE_NVRAM_GUID ":"))) == 0) { unsigned long bytes = aKey->getLength() - strlen(FILE_NVRAM_GUID ":") + 1; // Found GUID char* newKey = (char*)IOMalloc(bytes); snprintf(newKey, bytes+1, "%s", &(aKey->getCStringNoCopy()[strlen(FILE_NVRAM_GUID ":")])); // Send d OSString* str = OSString::withCString(newKey); handleSetting(str, anObject, this); str->release(); IOFree(newKey, bytes); } bool stat = IOService::setProperty(aKey, cast(aKey, anObject)); if (mInitComplete) { sync(); } return stat; }
OSSerialize *OSSerialize::withCapacity(unsigned int inCapacity) { OSSerialize *me = new OSSerialize; if (me && !me->initWithCapacity(inCapacity)) { me->release(); return 0; } return me; }
UInt32 FakeSMCDevice::loadKeysFromNVRAM() { UInt32 count = 0; // Find driver and load keys from NVRAM if (OSDictionary *matching = serviceMatching("IODTNVRAM")) { if (IODTNVRAM *nvram = OSDynamicCast(IODTNVRAM, waitForMatchingService(matching, 1000000000ULL * 15))) { useNVRAM = true; if ((genericNVRAM = (0 == strncmp(nvram->getName(), "AppleNVRAM", sizeof("AppleNVRAM"))))) HWSensorsInfoLog("fallback to generic NVRAM methods"); OSSerialize *s = OSSerialize::withCapacity(0); // Workaround for IODTNVRAM->getPropertyTable returns IOKitPersonalities instead of NVRAM properties dictionary if (nvram->serializeProperties(s)) { if (OSDictionary *props = OSDynamicCast(OSDictionary, OSUnserializeXML(s->text()))) { if (OSCollectionIterator *iterator = OSCollectionIterator::withCollection(props)) { size_t prefix_length = strlen(kFakeSMCKeyPropertyPrefix); char name[5]; name[4] = 0; char type[5]; type[4] = 0; while (OSString *property = OSDynamicCast(OSString, iterator->getNextObject())) { const char *buffer = static_cast<const char *>(property->getCStringNoCopy()); if (property->getLength() >= prefix_length + 1 + 4 + 1 + 0 && 0 == strncmp(buffer, kFakeSMCKeyPropertyPrefix, prefix_length)) { if (OSData *data = OSDynamicCast(OSData, props->getObject(property))) { strncpy(name, buffer + prefix_length + 1, 4); // fakesmc-key-???? -> strncpy(type, buffer + prefix_length + 1 + 4 + 1, 4); // fakesmc-key-xxxx-???? -> if (addKeyWithValue(name, type, data->getLength(), data->getBytesNoCopy())) { HWSensorsDebugLog("key %s of type %s loaded from NVRAM", name, type); count++; } } } } OSSafeRelease(iterator); } OSSafeRelease(props); } } OSSafeRelease(s); OSSafeRelease(nvram); } else { HWSensorsWarningLog("NVRAM is unavailable"); } OSSafeRelease(matching); } return count; }
void OWCDumpIORegistry::dumpIORegistry (void *argument) { IOSleep (DUMP_DELAY_SECONDS * 1000); IORegistryIterator *iter = IORegistryIterator::iterateOver (gIOServicePlane, kIORegistryIterateRecursively); if (iter == NULL) return; int maxBufferSize = 2048; char *buffer = (char *) IOMalloc (maxBufferSize); if (buffer == NULL) return; OSSerialize *s = OSSerialize::withCapacity (maxBufferSize); if (s == NULL) return; IORegistryEntry *object = iter->getCurrentEntry (); while (object) { s->clearText (); int busyState = 0; IOService *ios = OSDynamicCast (IOService, object); if (ios) busyState = ios->getBusyState (); int pathSize = maxBufferSize; object->getPath (buffer, &pathSize, gIOServicePlane); kprintf ("\n--> %s <%s> (%d, %d)\n", buffer, object->getMetaClass ()->getClassName (), object->getRetainCount (), busyState); if (object->serializeProperties (s)) { kprintf ("%s\n", s->text ()); } else { kprintf ("serializeProperties failed\n"); } object = iter->getNextObject (); } IOFree (buffer, maxBufferSize); s->release (); iter->release (); }
void AppleALC::getBootArguments() { OSSerialize *s = IOUtil::retrieveBootArguments(); if (s) { bool disabled {false}; disabled |= strstr(s->text(), booatargOff, strlen(booatargOff)) != nullptr; disabled |= strstr(s->text(), "-s", strlen("-s")) != nullptr; disabled |= strstr(s->text(), "-x", strlen("-x")) != nullptr; isEnabled = !disabled; debugEnabled = strstr(s->text(), booatargDebug, strlen(booatargDebug)); DBGLOG("init @ boot arguments value is %s (enabled %d, debug %d)", s->text(), isEnabled, debugEnabled); s->release(); } else { DBGLOG("init @ no boot arguments available"); } }
void FileNVRAM::doSync(void) { LOG(NOTICE, "doSync() called\n"); /* if (!mFilePath) { return; } */ if (!mSafeToSync) { return; } LOG(NOTICE, "doSync() running\n"); //create the output Dictionary OSDictionary * outputDict = OSDictionary::withCapacity(1); //going to have to spin over ourselves.. OSDictionary * inputDict = dictionaryWithProperties(); OSCollectionIterator *iter = OSCollectionIterator::withCollection(inputDict); if (iter == 0) { LOG(ERROR, "FAILURE!. No iterator on input dictionary (myself)\n"); return; } OSSymbol * key = NULL; OSObject * value = NULL; while ((key = OSDynamicCast(OSSymbol,iter->getNextObject()))) { //just get the value now anyway value = inputDict->getObject(key); //if the key conmektains :, look to see if it's in the map already, cause we'll add a child pair to it //otherwise we just slam the key/val pair in const char * keyChar = key->getCStringNoCopy(); const char * guidValueStr = NULL; if (( guidValueStr = strstr(keyChar , NVRAM_SEPERATOR)) != NULL) { //we have a GUID child to deal with //now substring out the GUID cause thats going to be a DICT itself on the new outputDict //guidValueStr points to the : size_t guidCutOff = guidValueStr - keyChar; //allocate buffer //we ar ereally accounting for + sizeof('\0') //thats always 1. so 1. char guidStr[guidCutOff+1]; strlcpy(guidStr, keyChar, guidCutOff+1); //in theory we have a guid and a value //LOG("sync() -> Located GUIDStr as %s\n",guidStr); //check for ?OSDictionary? from the dictionary OSDictionary * guidDict = OSDynamicCast(OSDictionary, outputDict->getObject(guidStr)); if (!guidDict) { guidDict = OSDictionary::withCapacity(1); outputDict->setObject(guidStr,guidDict); } //now we have a dict for the guid no matter what (mapping GUID | DICT) guidDict->setObject(OSString::withCString(guidValueStr+strlen(NVRAM_SEPERATOR)), value); } else { //we are boring. outputDict->setObject(key,value); } }//end while //serialize and write this out OSSerialize *s = OSSerialize::withCapacity(10000); s->addString(NVRAM_FILE_HEADER); outputDict->serialize(s); s->addString(NVRAM_FILE_FOOTER); int error = write_buffer(s->text(), mCtx); if (error) { LOG(ERROR, "Unable to write to %s, errno %d\n", mFilePath->getCStringNoCopy(), error); } //now free the dictionaries && iter iter->release(); outputDict->release(); s->release(); }