diff --git a/Changelog.md b/Changelog.md index 7b79c7abbe57b0c4861a20042cdcc72c7e452df6..f57e1ce3f4f12386ca263e8796e71f07306cf0b1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ OpenCore Changelog - Fixed intro animation getting stuck in OpenCanopy if an entry which returns to menu is selected before animation ends - Modified OpenCanopy to require presence of label images only when used due to `OC_ATTR_USE_GENERIC_LABEL_IMAGE` - Provided `OC_ATTR_REDUCE_MOTION` to optionally disable non-required OpenCanopy menu animations +- Modified NVRAM logout hook to handle XML entities in string vars #### v0.9.7 - Updated recovery_urls.txt diff --git a/Utilities/LogoutHook/nvramdump.c b/Utilities/LogoutHook/nvramdump.c index 5176cfc2c970de5b96236764d76c73ca47419f9c..236e4d1a25defa3e35343a2ee27b223f56e6c434 100644 --- a/Utilities/LogoutHook/nvramdump.c +++ b/Utilities/LogoutHook/nvramdump.c @@ -40,9 +40,30 @@ static kern_return_t GetOFVariable(char *name, CFStringRef *nameRef, *valueRef = IORegistryEntryCreateCFProperty(gOptionsRef, *nameRef, 0, 0); if (*valueRef == 0) return kIOReturnNotFound; + if (CFGetTypeID(*valueRef) == CFStringGetTypeID()) { + CFTypeRef oldValue = *valueRef; + *valueRef = CFStringCreateExternalRepresentation(kCFAllocatorDefault, *valueRef, kCFStringEncodingUTF8, 0); + CFRelease(oldValue); + if (*valueRef == 0) return kIOReturnNotFound; + } + return KERN_SUCCESS; } +static CFMutableDictionaryRef dict4; + +static void ConvertStringValues (const void* key, const void* value, void* context) { + if (CFGetTypeID(value) == CFStringGetTypeID()) { + CFDataRef dataValue = CFStringCreateExternalRepresentation(kCFAllocatorDefault, value, kCFStringEncodingUTF8, 0); + if (dataValue != NULL) { + CFDictionaryAddValue(dict4, key, dataValue); + } + } else { + CFDictionaryAddValue(dict4, key, value); + } +} + + CFDictionaryRef CreateMyDictionary(void) { char *guid; @@ -69,8 +90,17 @@ CFDictionaryRef CreateMyDictionary(void) { if (result != KERN_SUCCESS) { errx(1, "Error getting the firmware variables: %s", mach_error_string(result)); } - CFDictionarySetValue(dict0, CFSTR("7C436110-AB2A-4BBB-A880-FE41995C9F82"), dict1); + + // To work round limitations of OpenCore XML parser (i.e. XML entities not + // automatically processed), force all string values to save as data. + dict4 = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + CFDictionaryApplyFunction(dict1, ConvertStringValues, NULL); + + CFDictionarySetValue(dict0, CFSTR("7C436110-AB2A-4BBB-A880-FE41995C9F82"), dict4); CFRelease(dict1); + CFRelease(dict4); CFMutableDictionaryRef dict2 = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);