From 04d76ef804102b8ede802fc6e5c331a36ad6c784 Mon Sep 17 00:00:00 2001 From: Visual Ehrmanntraut <30368284+VisualEhrmanntraut@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:55:59 +0200 Subject: [PATCH] feat: Ensure VBIOS override is valid --- NootedRed/NRed.cpp | 50 +++++++++++++++++++------------ NootedRed/PrivateHeaders/NRed.hpp | 1 + 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/NootedRed/NRed.cpp b/NootedRed/NRed.cpp index c6986e2a..a9bcc66d 100644 --- a/NootedRed/NRed.cpp +++ b/NootedRed/NRed.cpp @@ -100,25 +100,7 @@ void NRed::hwLateInit() { this->iGPU->setMemoryEnable(true); this->iGPU->setBusMasterEnable(true); - auto *atombiosImageProp = OSDynamicCast(OSData, this->iGPU->getProperty("ATY,bin_image")); - if (atombiosImageProp == nullptr) { - if (this->getVBIOSFromVFCT()) { - DBGLOG("NRed", "Got VBIOS from VFCT."); - } else { - SYSLOG("NRed", "Failed to get VBIOS from VFCT, trying to get it from VRAM!"); - if (this->getVBIOSFromVRAM()) { - DBGLOG("NRed", "Got VBIOS from VRAM."); - } else { - SYSLOG("NRed", "Failed to get VBIOS from VRAM, trying to get it from PCI Expansion ROM!"); - PANIC_COND(!this->getVBIOSFromExpansionROM(), "NRed", "Failed to get VBIOS!"); - DBGLOG("NRed", "Got VBIOS from PCI Expansion ROM."); - } - } - - } else { - this->vbiosData = OSData::withData(atombiosImageProp); - SYSLOG("NRed", "!!! VBIOS MANUALLY OVERRIDDEN, MAKE SURE YOU KNOW WHAT YOU'RE DOING !!!"); - } + PANIC_COND(!this->getVBIOS(), "NRed", "Failed to get VBIOS!"); auto len = this->vbiosData->getLength(); if (len < ATOMBIOS_IMAGE_SIZE) { @@ -451,6 +433,36 @@ bool NRed::getVBIOSFromVRAM() { return true; } +bool NRed::getVBIOS() { + auto *biosImageProp = OSDynamicCast(OSData, this->iGPU->getProperty("ATY,bin_image")); + if (biosImageProp != nullptr) { + if (checkAtomBios(static_cast(biosImageProp->getBytesNoCopy()), biosImageProp->getLength())) { + this->vbiosData = OSData::withData(biosImageProp); + SYSLOG("NRed", "Warning: VBIOS manually overridden, make sure you know what you're doing."); + return true; + } else { + SYSLOG("NRed", "Error: VBIOS override is invalid."); + } + } + if (this->getVBIOSFromVFCT()) { + DBGLOG("NRed", "Got VBIOS from VFCT."); + } else { + SYSLOG("NRed", "Error: Failed to get VBIOS from VFCT, trying to get it from VRAM."); + if (this->getVBIOSFromVRAM()) { + DBGLOG("NRed", "Got VBIOS from VRAM."); + } else { + SYSLOG("NRed", "Error: Failed to get VBIOS from VRAM, trying to get it from PCI Expansion ROM!"); + if (this->getVBIOSFromExpansionROM()) { + DBGLOG("NRed", "Got VBIOS from PCI Expansion ROM."); + } else { + SYSLOG("NRed", "Error: Failed to get VBIOS from PCI Expansion ROM!"); + return false; + } + } + } + return true; +} + static const char *getDriverXMLForBundle(const char *bundleIdentifier, size_t *len) { const auto identifierLen = strlen(bundleIdentifier); const auto totalLen = identifierLen + 5; diff --git a/NootedRed/PrivateHeaders/NRed.hpp b/NootedRed/PrivateHeaders/NRed.hpp index d3dff97d..eb4bb7d3 100644 --- a/NootedRed/PrivateHeaders/NRed.hpp +++ b/NootedRed/PrivateHeaders/NRed.hpp @@ -60,6 +60,7 @@ class NRed { bool getVBIOSFromExpansionROM(); bool getVBIOSFromVFCT(); bool getVBIOSFromVRAM(); + bool getVBIOS(); static bool wrapAddDrivers(void *that, OSArray *array, bool doNubMatching); static OSMetaClassBase *wrapSafeMetaCast(const OSMetaClassBase *anObject, const OSMetaClass *toMeta);