diff --git a/CPUFriend.xcodeproj/project.pbxproj b/CPUFriend.xcodeproj/project.pbxproj index 56bf88b..69f0531 100755 --- a/CPUFriend.xcodeproj/project.pbxproj +++ b/CPUFriend.xcodeproj/project.pbxproj @@ -10,8 +10,8 @@ 1C748C2D1C21952C0024EED2 /* kern_start.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C748C2C1C21952C0024EED2 /* kern_start.cpp */; }; CE405EC91E49DD9700AA0B3D /* libkmod.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE405EC71E49DD7100AA0B3D /* libkmod.a */; }; CE405ED91E4A080700AA0B3D /* plugin_start.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE405ED81E4A080700AA0B3D /* plugin_start.cpp */; }; - CEBD8C191F372A4600BBCB85 /* kern_cpuf.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEBD8C171F372A4600BBCB85 /* kern_cpuf.cpp */; }; - CEBD8C1A1F372A4600BBCB85 /* kern_cpuf.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CEBD8C181F372A4600BBCB85 /* kern_cpuf.hpp */; }; + CEBD8C191F372A4600BBCB85 /* CPUFriend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEBD8C171F372A4600BBCB85 /* CPUFriend.cpp */; }; + CEBD8C1A1F372A4600BBCB85 /* CPUFriend.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CEBD8C181F372A4600BBCB85 /* CPUFriend.hpp */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -32,7 +32,7 @@ 1C748C2E1C21952C0024EED2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 1CF01C901C8CF97F002DCEA3 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 1CF01C921C8CF997002DCEA3 /* Changelog.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Changelog.md; sourceTree = ""; }; - 1CF01C931C8DF02E002DCEA3 /* LICENSE.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE.txt; sourceTree = ""; }; + 1CF01C931C8DF02E002DCEA3 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 83023F381F3747EC00850499 /* Instructions.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Instructions.md; sourceTree = ""; }; CE2DC5071F7626EC004FAC48 /* ResourceConverter.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ResourceConverter.sh; sourceTree = ""; }; CE405EBA1E49DD7100AA0B3D /* kern_compression.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_compression.hpp; sourceTree = ""; }; @@ -50,8 +50,9 @@ CE405ED21E49F9FC00AA0B3D /* kern_api.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_api.hpp; sourceTree = ""; }; CE405ED81E4A080700AA0B3D /* plugin_start.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = plugin_start.cpp; sourceTree = ""; }; CE405EDA1E4A080F00AA0B3D /* plugin_start.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = plugin_start.hpp; sourceTree = ""; }; - CEBD8C171F372A4600BBCB85 /* kern_cpuf.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = kern_cpuf.cpp; sourceTree = ""; }; - CEBD8C181F372A4600BBCB85 /* kern_cpuf.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = kern_cpuf.hpp; sourceTree = ""; }; + CEB1294E1F99F986004BA715 /* build.command */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.command; sourceTree = ""; }; + CEBD8C171F372A4600BBCB85 /* CPUFriend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPUFriend.cpp; sourceTree = ""; }; + CEBD8C181F372A4600BBCB85 /* CPUFriend.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CPUFriend.hpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -71,6 +72,7 @@ children = ( 1CF01C911C8CF982002DCEA3 /* Docs */, CE405EC81E49DD7B00AA0B3D /* SDK */, + CEB1294D1F99F986004BA715 /* Tools */, CE2DC5061F7626EC004FAC48 /* ResourceConverter */, 1C748C291C21952C0024EED2 /* CPUFriend */, 1C748C281C21952C0024EED2 /* Products */, @@ -97,7 +99,7 @@ 1CF01C911C8CF982002DCEA3 /* Docs */ = { isa = PBXGroup; children = ( - 1CF01C931C8DF02E002DCEA3 /* LICENSE.txt */, + 1CF01C931C8DF02E002DCEA3 /* LICENSE */, 1CF01C921C8CF997002DCEA3 /* Changelog.md */, 83023F381F3747EC00850499 /* Instructions.md */, 1CF01C901C8CF97F002DCEA3 /* README.md */, @@ -109,8 +111,8 @@ isa = PBXGroup; children = ( 1C748C2C1C21952C0024EED2 /* kern_start.cpp */, - CEBD8C181F372A4600BBCB85 /* kern_cpuf.hpp */, - CEBD8C171F372A4600BBCB85 /* kern_cpuf.cpp */, + CEBD8C181F372A4600BBCB85 /* CPUFriend.hpp */, + CEBD8C171F372A4600BBCB85 /* CPUFriend.cpp */, ); name = Source; sourceTree = ""; @@ -171,6 +173,14 @@ name = SDK; sourceTree = ""; }; + CEB1294D1F99F986004BA715 /* Tools */ = { + isa = PBXGroup; + children = ( + CEB1294E1F99F986004BA715 /* build.command */, + ); + path = Tools; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -178,7 +188,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - CEBD8C1A1F372A4600BBCB85 /* kern_cpuf.hpp in Headers */, + CEBD8C1A1F372A4600BBCB85 /* CPUFriend.hpp in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -239,7 +249,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CEBD8C191F372A4600BBCB85 /* kern_cpuf.cpp in Sources */, + CEBD8C191F372A4600BBCB85 /* CPUFriend.cpp in Sources */, CE405ED91E4A080700AA0B3D /* plugin_start.cpp in Sources */, 1C748C2D1C21952C0024EED2 /* kern_start.cpp in Sources */, ); @@ -357,7 +367,7 @@ MODULE_NAME = org.vanilla.driver.CPUFriend; MODULE_START = "$(PRODUCT_NAME)_kern_start"; MODULE_STOP = "$(PRODUCT_NAME)_kern_stop"; - MODULE_VERSION = 1.1.0; + MODULE_VERSION = 1.1.1; OTHER_CFLAGS = ( "-mmmx", "-msse", @@ -402,7 +412,7 @@ MODULE_NAME = org.vanilla.driver.CPUFriend; MODULE_START = "$(PRODUCT_NAME)_kern_start"; MODULE_STOP = "$(PRODUCT_NAME)_kern_stop"; - MODULE_VERSION = 1.1.0; + MODULE_VERSION = 1.1.1; OTHER_CFLAGS = ( "-mmmx", "-msse", diff --git a/CPUFriend/CPUFriend.cpp b/CPUFriend/CPUFriend.cpp new file mode 100755 index 0000000..c4f7293 --- /dev/null +++ b/CPUFriend/CPUFriend.cpp @@ -0,0 +1,130 @@ +// +// CPUFriend.cpp +// CPUFriend +// +// Copyright © 2017 Vanilla. All rights reserved. +// + +#include + +#include "CPUFriend.hpp" + +static const char * binList[] { + "/System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/X86PlatformPlugin.kext/Contents/MacOS/X86PlatformPlugin" +}; + +static const char * idList[] { + "com.apple.driver.X86PlatformPlugin" +}; + +static const char * symbolList[] { + "__ZN17X86PlatformPlugin22configResourceCallbackEjiPKvjPv" +}; + +static KernelPatcher::KextInfo kextList[] { + { idList[0], & binList[0], arrsize(binList), { false, false }, {}, KernelPatcher::KextInfo::Unloaded } +}; + +static constexpr size_t kextListSize = arrsize(kextList); + +static CPUFriendPlugin * callbackCpuf = nullptr; + +OSDefineMetaClassAndStructors(CPUFriendPlatform, IOService) + +IOService * CPUFriendPlatform::probe(IOService * provider, SInt32 * score) { + if (provider) { + if (callbackCpuf) { + if (! callbackCpuf->frequencyData) { + auto name = provider->getName(); + if (! name) + name = "(null)"; + DBGLOG("probe", "looking for cf-frequency-data in %s", name); + + auto data = OSDynamicCast(OSData, provider->getProperty("cf-frequency-data")); + if (! data) { + auto cpu = provider->getParentEntry(gIOServicePlane); + if (cpu) { + name = cpu->getName(); + if (! name) + name = "(null)"; + DBGLOG("probe", "looking for cf-frequency-data in %s", name); + data = OSDynamicCast(OSData, cpu->getProperty("cf-frequency-data")); + } else { + SYSLOG("probe", "unable to access cpu parent"); + } + } + + if (data) { + callbackCpuf->frequencyDataSize = data->getLength(); + callbackCpuf->frequencyData = data->getBytesNoCopy(); + } else { + SYSLOG("probe", "failed to obtain cf-frequency-data"); + } + } + } else + SYSLOG("probe", "missing storage instance"); + } + + return nullptr; +} + +bool CPUFriendPlugin::init() { + callbackCpuf = this; + + LiluAPI::Error error = lilu.onKextLoad(kextList, kextListSize, [](void * user, KernelPatcher & patcher, size_t index, mach_vm_address_t address, size_t size) { + static_cast(user)->processKext(patcher, index, address, size); + }, this); + + if (error != LiluAPI::Error::NoError) { + SYSLOG("init", "failed to register onKextLoad method %d", error); + return false; + } + + return true; +} + +void CPUFriendPlugin::myConfigResourceCallback(uint32_t requestTag, kern_return_t result, const void * resourceData, uint32_t resourceDataLength, void * context) { + if (callbackCpuf && callbackCpuf->orgConfigLoadCallback) { + auto data = callbackCpuf->frequencyData; + auto sz = callbackCpuf->frequencyDataSize; + if (data && sz > 0) { + DBGLOG("myConfigResourceCallback", "feeding frequency data %u", sz); + resourceData = data; + resourceDataLength = sz; + result = kOSReturnSuccess; + } else { + SYSLOG("myConfigResourceCallback", "failed to feed cpu data (%u, %d)", sz, data != nullptr); + } + callbackCpuf->orgConfigLoadCallback(requestTag, result, resourceData, resourceDataLength, context); + } else { + SYSLOG("myConfigResourceCallback", "config callback arrived at nowhere"); + } +} + +void CPUFriendPlugin::processKext(KernelPatcher & patcher, size_t index, mach_vm_address_t address, size_t size) { + if (progressState != ProcessingState::EverythingDone) { + for (size_t i = 0; i < kextListSize; i++) { + if (kextList[i].loadIndex == index) { + DBGLOG("processKext", "current kext is %s progressState %d", kextList[i].id, progressState); + // clear error from the very beginning just in case + patcher.clearError(); + if (! strcmp(kextList[i].id, idList[0])) { + auto callback = patcher.solveSymbol(index, symbolList[0]); + if (callback) { + orgConfigLoadCallback = reinterpret_cast(patcher.routeFunction(callback, reinterpret_cast(myConfigResourceCallback), true)); + if (patcher.getError() == KernelPatcher::Error::NoError) { + DBGLOG("processKext", "routed %s", symbolList[0]); + } else { + SYSLOG("processKext", "failed to route %s", symbolList[0]); + } + } else { + SYSLOG("processKext", "failed to find %s", symbolList[0]); + } + progressState |= ProcessingState::CallbackRouted; + } + } + } + } + // Ignore all the errors for other processors + patcher.clearError(); +} diff --git a/CPUFriend/CPUFriend.hpp b/CPUFriend/CPUFriend.hpp new file mode 100755 index 0000000..e6f2ff5 --- /dev/null +++ b/CPUFriend/CPUFriend.hpp @@ -0,0 +1,73 @@ +// +// CPUFriend.hpp +// CPUFriend +// +// Copyright © 2017 Vanilla. All rights reserved. +// + +#ifndef kern_cpuf_hpp +#define kern_cpuf_hpp + +#include +#include + +class EXPORT CPUFriendPlatform : public IOService { + OSDeclareDefaultStructors(CPUFriendPlatform) +public: + IOService * probe(IOService * provider, SInt32 *score) override; +}; + +class CPUFriendPlugin { + public: + bool init(); + + /** + * ResourceLoad callback type + */ + using t_callback = void (*)(uint32_t, kern_return_t, const void *, uint32_t, void *); + + /** + * Trampolines for original resource load callback + */ + t_callback orgConfigLoadCallback = nullptr; + + /** + * Loaded user-specified frequency data + */ + const void * frequencyData = nullptr; + + /** + * Loaded user-specified frequency data size + */ + uint32_t frequencyDataSize = 0; + + private: + /** + * Hooked ResourceLoad callback returning user-specified platform data + */ + static void myConfigResourceCallback(uint32_t requestTag, kern_return_t result, const void * resourceData, uint32_t resourceDataLength, void * context); + + /** + * Patch kext if needed and prepare other patches + * + * @param patcher KernelPatcher instance + * @param index kinfo handle + * @param address kinfo load address + * @param size kinfo memory size + */ + void processKext(KernelPatcher & patcher, size_t index, mach_vm_address_t address, size_t size); + + /** + * Current progress mask + */ + struct ProcessingState { + enum : uint32_t { + NothingReady = 0, + CallbackRouted = 1, + EverythingDone = CallbackRouted + }; + }; + uint32_t progressState = ProcessingState::NothingReady; +}; + +#endif /* kern_cpuf_hpp */ diff --git a/CPUFriend/kern_cpuf.cpp b/CPUFriend/kern_cpuf.cpp deleted file mode 100755 index 45974d4..0000000 --- a/CPUFriend/kern_cpuf.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// -// kern_cpuf.cpp -// CPUFriend -// -// Copyright © 2017 Vanilla. All rights reserved. -// - -#include -#include "kern_cpuf.hpp" - -static const char *binList[] { - "/System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/X86PlatformPlugin.kext/Contents/MacOS/X86PlatformPlugin" -}; - -static const char *idList[] { - "com.apple.driver.X86PlatformPlugin" -}; - -static const char *symbolList[] { - "__ZN17X86PlatformPlugin22configResourceCallbackEjiPKvjPv" -}; - -static KernelPatcher::KextInfo kextList[] { - { idList[0], &binList[0], arrsize(binList), {false, false}, {}, KernelPatcher::KextInfo::Unloaded } -}; - -static constexpr size_t kextListSize {arrsize(kextList)}; - -static CPUFriendPlugin *callbackCpuf {nullptr}; - -OSDefineMetaClassAndStructors(CPUFriendPlatform, IOService) - -IOService *CPUFriendPlatform::probe(IOService *provider, SInt32 *score) { - if (provider) { - if (callbackCpuf) { - if (!callbackCpuf->frequencyData) { - auto name = provider->getName(); - if (!name) - name = "(null)"; - DBGLOG("probing", "looking for cf-frequency-data in %s", name); - - auto data = OSDynamicCast(OSData, provider->getProperty("cf-frequency-data")); - if (!data) { - auto cpu = provider->getParentEntry(gIOServicePlane); - if (cpu) { - name = cpu->getName(); - if (!name) - name = "(null)"; - DBGLOG("probing", "looking for cf-frequency-data in %s", name); - - data = OSDynamicCast(OSData, cpu->getProperty("cf-frequency-data")); - } else { - SYSLOG("probing", "unable to access cpu parent"); - } - } - - if (data) { - callbackCpuf->frequencyDataSize = data->getLength(); - callbackCpuf->frequencyData = data->getBytesNoCopy(); - } else { - SYSLOG("probing", "failed to obtain cf-frequency-data"); - } - } - } else { - SYSLOG("probing", "missing storage instance"); - } - } - - return nullptr; -} - -bool CPUFriendPlugin::init() { - callbackCpuf = this; - - LiluAPI::Error error = lilu.onKextLoad(kextList, kextListSize, - [](void *user, KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) { - static_cast(user)->processKext(patcher, index, address, size); - }, this); - - if (error != LiluAPI::Error::NoError) { - SYSLOG("init", "failed to register onKextLoad method %d", error); - return false; - } - - return true; -} - -void CPUFriendPlugin::myConfigResourceCallback(uint32_t requestTag, kern_return_t result, const void *resourceData, uint32_t resourceDataLength, void *context) { - if (callbackCpuf && callbackCpuf->orgConfigLoadCallback) { - auto data = callbackCpuf->frequencyData; - auto sz = callbackCpuf->frequencyDataSize; - if (data && sz > 0) { - DBGLOG("myConfigResourceCallback", "feeding frequency data %u", sz); - resourceData = data; - resourceDataLength = sz; - result = kOSReturnSuccess; - } else { - SYSLOG("myConfigResourceCallback", "failed to feed cpu data (%u, %d)", sz, data != nullptr); - } - callbackCpuf->orgConfigLoadCallback(requestTag, result, resourceData, resourceDataLength, context); - } else { - SYSLOG("myConfigResourceCallback", "config callback arrived at nowhere"); - } -} - -void CPUFriendPlugin::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) { - if (progressState != cpufessingState::EverythingDone) { - for (size_t i = 0; i < kextListSize; i++) { - if (kextList[i].loadIndex == index) { - DBGLOG("processKext", "current kext is %s progressState %d", kextList[i].id, progressState); - // clear error from the very beginning just in case - patcher.clearError(); - if (!strcmp(kextList[i].id, idList[0])) { - auto callback = patcher.solveSymbol(index, symbolList[0]); - if (callback) { - orgConfigLoadCallback = reinterpret_cast(patcher.routeFunction(callback, reinterpret_cast(myConfigResourceCallback), true)); - if (patcher.getError() == KernelPatcher::Error::NoError) { - DBGLOG("processKext", "routed %s", symbolList[0]); - } else { - SYSLOG("processKext", "failed to route %s", symbolList[0]); - } - } else { - SYSLOG("processKext", "failed to find %s", symbolList[0]); - } - progressState |= cpufessingState::CallbackRouted; - } - - // Ignore all the errors for other processors - patcher.clearError(); - break; - } - } - } -} diff --git a/CPUFriend/kern_cpuf.hpp b/CPUFriend/kern_cpuf.hpp deleted file mode 100755 index 776cb9f..0000000 --- a/CPUFriend/kern_cpuf.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// -// kern_cpuf.hpp -// CPUFriend -// -// Copyright © 2017 Vanilla. All rights reserved. -// - -#ifndef kern_cpuf_hpp -#define kern_cpuf_hpp - -#include -#include - -class EXPORT CPUFriendPlatform : public IOService { - OSDeclareDefaultStructors(CPUFriendPlatform) -public: - IOService *probe(IOService *provider, SInt32 *score) override; -}; - -class CPUFriendPlugin { -public: - bool init(); - void deinit(); - - /** - * ResourceLoad callback type - */ - using t_callback = void (*)(uint32_t, kern_return_t, const void *, uint32_t, void *); - - /** - * Trampolines for original resource load callback - */ - t_callback orgConfigLoadCallback {nullptr}; - - /** - * Loaded user-specified frequency data - */ - const void *frequencyData {nullptr}; - - /** - * Loaded user-specified frequency data size - */ - uint32_t frequencyDataSize {0}; - -private: - /** - * Hooked ResourceLoad callback returning user-specified platform data - */ - static void myConfigResourceCallback(uint32_t requestTag, kern_return_t result, const void *resourceData, uint32_t resourceDataLength, void *context); - - /** - * Patch kext if needed and prepare other patches - * - * @param patcher KernelPatcher instance - * @param index kinfo handle - * @param address kinfo load address - * @param size kinfo memory size - */ - void processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size); - - /** - * Current progress mask - */ - struct cpufessingState { - enum : uint32_t { - NothingReady = 0, - CallbackRouted = 1, - EverythingDone = CallbackRouted - }; - }; - uint32_t progressState {cpufessingState::NothingReady}; - -}; - -#endif /* kern_cpuf_hpp */ diff --git a/CPUFriend/kern_start.cpp b/CPUFriend/kern_start.cpp index dc340eb..ad97b86 100755 --- a/CPUFriend/kern_start.cpp +++ b/CPUFriend/kern_start.cpp @@ -8,35 +8,35 @@ #include #include -#include "kern_cpuf.hpp" +#include "CPUFriend.hpp" static CPUFriendPlugin cpuf; static const char *bootargOff[] { - "-cpufoff" + "-cpufoff" }; static const char *bootargDebug[] { - "-cpufdbg" + "-cpufdbg" }; static const char *bootargBeta[] { - "-cpufbeta" + "-cpufbeta" }; PluginConfiguration ADDPR(config) { - xStringify(PRODUCT_NAME), - parseModuleVersion(xStringify(MODULE_VERSION)), - LiluAPI::AllowNormal | LiluAPI::AllowInstallerRecovery | LiluAPI::AllowSafeMode, - bootargOff, - arrsize(bootargOff), - bootargDebug, - arrsize(bootargDebug), - bootargBeta, - arrsize(bootargBeta), - KernelVersion::MountainLion, - KernelVersion::HighSierra, - []() { - cpuf.init(); - } + xStringify(PRODUCT_NAME), + parseModuleVersion(xStringify(MODULE_VERSION)), + LiluAPI::AllowNormal | LiluAPI::AllowInstallerRecovery | LiluAPI::AllowSafeMode, + bootargOff, + arrsize(bootargOff), + bootargDebug, + arrsize(bootargDebug), + bootargBeta, + arrsize(bootargBeta), + KernelVersion::MountainLion, + KernelVersion::HighSierra, + []() { + cpuf.init(); + } }; diff --git a/Changelog.md b/Changelog.md index 3077556..3ae224e 100755 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ CPUFriend Changelog =================== +#### v1.1.1 +- Various typo fixes + #### v1.1.0 - Requires Lilu 1.2.0 or higher diff --git a/Instructions.md b/Instructions.md index 3cc2507..b1a7dd2 100755 --- a/Instructions.md +++ b/Instructions.md @@ -6,6 +6,7 @@ CPUFriend needs macOS ***v10.8*** or greater. #### Installation It's highly recommended to let the bootloader inject CPUFriend, otherwise you'll need [LiluFriend](https://github.com/PMheart/LiluFriend) to ensure CPUFriend will work properly. +Also, theoretically X86PlatformPlugin.kext should be untouched. You'd better use the original kext. #### Available kernel flags Add `-cpufdbg` to enable debug logging (ONLY available in DEBUG binaries). @@ -34,29 +35,29 @@ NOTE: 2. Open your SSDT generated by [ssdtPRGen.sh](https://github.com/Piker-Alpha/ssdtPRGen.sh), and search for `Method (_DSM, 4, NotSerialized)` in your editor. 3. Paste `"cf-frequency-data"` entry from `ssdt_data.dsl` to the SSDT generated by [ssdtPRGen.sh](https://github.com/Piker-Alpha/ssdtPRGen.sh). It will look like this if everything is done. ``` - // - // Context of the SSDT generated by ssdtPRGen.sh - // - Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method + // + // Context of the SSDT generated by ssdtPRGen.sh + // + Method (_DSM, 4, NotSerialized) { If (LEqual (Arg2, Zero)) { Return (Buffer (One) { - 0x03 + 0x03 }) } - Return (Package () // Removed size + Return (Package () // size removed, just let the compiler fill it up { "plugin-type",                One, - // - // Paste it from ssdt_data.dsl - // - "cf-frequency-data", - Buffer () // Removed size + // + // Paste it from ssdt_data.dsl + // + "cf-frequency-data", + Buffer () // size removed, just let the compiler fill it up {                    // Data from ssdt_data.dsl                } diff --git a/LICENSE.txt b/LICENSE similarity index 98% rename from LICENSE.txt rename to LICENSE index 67b858f..d493a26 100755 --- a/LICENSE.txt +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2017, Angel Wu +Copyright (c) 2017, Vanilla All rights reserved. diff --git a/README.md b/README.md index 8579c90..719c969 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ CPUFriend ========= -A [Lilu](https://github.com/vit9696/Lilu) plug-in kernel extension which injects power management data dynamically. +A [Lilu](https://github.com/vit9696/Lilu) plug-in for dynamic power management data injection. #### Notes This repository should be compiled with [Lilu](https://github.com/vit9696/Lilu) ***v1.2.0*** and greater, otherwise the compilation will be failed! diff --git a/ResourceConverter/ResourceConverter.sh b/ResourceConverter/ResourceConverter.sh index 04e0c52..8e136d0 100755 --- a/ResourceConverter/ResourceConverter.sh +++ b/ResourceConverter/ResourceConverter.sh @@ -4,127 +4,145 @@ function main() { - case "${1}" in - --kext ) - shift - if [[ -e "${1}" ]]; then - gData2Base64="$(cat "${1}" | base64)" - - # generate a new customised CPUFriendDataProvider.kext - if [[ -d CPUFriendDataProvider.kext ]]; then - rm -r CPUFriendDataProvider.kext - fi - - mkdir -p CPUFriendDataProvider.kext/Contents && cd CPUFriendDataProvider.kext/Contents - - gPlistContent=`cat < - CFBundleIdentifier - org.vanilla.driver.CPUFriendDataProvider - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - CPUFriendDataProvider - CFBundlePackageType - KEXT - CFBundleShortVersionString - 1.0.0 - CFBundleVersion - 1.0.0 - IOKitPersonalities - - CPUFriendDataProvider - - CFBundleIdentifier - com.apple.driver.AppleACPIPlatform - IOClass - AppleACPICPU - IONameMatch - processor - IOProbeScore - 1100 - IOProviderClass - IOACPIPlatformDevice - cf-frequency-data - ${gData2Base64} - - - NSHumanReadableCopyright - Copyright © 2017 Vanilla. All rights reserved. - OSBundleRequired - Root + CFBundleIdentifier + org.vanilla.driver.CPUFriendDataProvider + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + CPUFriendDataProvider + CFBundlePackageType + KEXT + CFBundleShortVersionString + 1.0.0 + CFBundleVersion + 1.0.0 + IOKitPersonalities + + CPUFriendDataProvider + + CFBundleIdentifier + com.apple.driver.AppleACPIPlatform + IOClass + AppleACPICPU + IONameMatch + processor + IOProbeScore + 1100 + IOProviderClass + IOACPIPlatformDevice + cf-frequency-data + ${gData2Base64} + + + NSHumanReadableCopyright + Copyright © 2017 Vanilla. All rights reserved. + OSBundleRequired + Root ` - - echo "${gPlistContent}" > Info.plist - else - echo "${1} does not exist, failed to convert hex" - exit 1 - fi - ;; - - --acpi ) - shift - if [[ -e "${1}" ]]; then - gCPUName="$(ioreg -p IODeviceTree -c IOACPIPlatformDevice -k cpu-type -k clock-frequency | egrep name | sed -e 's/ *[-|="]//g')" - gCPURealName="$(echo ${gCPUName[0]} | awk '{print $1}')" - gDataContent="$(xxd -pr -u "${1}" | tr -d '\n' | sed 's/.\{2\}/\0x&, /g')" - gSSDTContent=`cat < Info.plist + else + echo "${1} does not exist, failed to convert hex" + exit 1 + fi + ;; + + --acpi ) + shift + if [[ -e "${1}" ]]; then + gCPUName="$(ioreg -p IODeviceTree -c IOACPIPlatformDevice -k cpu-type -k clock-frequency | egrep name | sed -e 's/ *[-|="]//g')" + gCPURealName="$(echo ${gCPUName[0]} | awk '{print $1}')" + gDataContent="$(xxd -pr -u "${1}" | tr -d '\n' | sed 's/.\{2\}/\0x&, /g')" + gSSDTContent=`cat < ssdt_data.dsl # will override the old one - else - echo "${1} does not exist, failed to convert hex" - exit 2 - fi - ;; - - * ) - echo "Invalid option" - exit 3 - ;; - esac + if [[ -f ssdt_data.dsl ]]; then + read -p "ssdt_data.dsl already exists, still continue? (y/n) " askforNewDsl + case "${askforNewPlist}" in + y|Y ) + ;; + + * ) + exit + ;; + esac + fi + echo "${gSSDTContent}" > ssdt_data.dsl # will override the old one + else + echo "${1} does not exist, failed to convert hex" + exit 2 + fi + ;; + + * ) + echo "Invalid option" + exit 3 + ;; + esac } main "$@" diff --git a/Tools/build.command b/Tools/build.command index c4033ab..e3575a8 100755 --- a/Tools/build.command +++ b/Tools/build.command @@ -8,19 +8,19 @@ cd "$(dirname "$0")"/.. if [[ ! -d Lilu.kext ]]; then - echo "Lilu.kext not found at repo dir, trying desktop" - if [[ -d ~/Desktop/Lilu.kext ]]; then - mv ~/Desktop/Lilu.kext Lilu.kext - else - echo "Lilu.kext still not found, exiting..." - exit 1 - fi + echo "Lilu.kext not found at repo dir, trying desktop" + if [[ -d ~/Desktop/Lilu.kext ]]; then + mv ~/Desktop/Lilu.kext Lilu.kext + else + echo "Lilu.kext still not found, exiting..." + exit 1 + fi fi TARGET=("Debug" "Release") for build in "${TARGET[@]}"; do - xcodebuild build -configuration "${build}" + xcodebuild build -configuration "${build}" done VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" build/Debug/CPUFriend.kext/Contents/Info.plist)