-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented
unfairgva
device property for MP5,1
- Loading branch information
Showing
9 changed files
with
257 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// | ||
// kern_unfair.cpp | ||
// WhateverGreen | ||
// | ||
// Copyright © 2021 vit9696. All rights reserved. | ||
// | ||
|
||
#include "kern_unfair.hpp" | ||
#include "kern_weg.hpp" | ||
|
||
#include <IOKit/IOService.h> | ||
#include <Headers/plugin_start.hpp> | ||
#include <Headers/kern_api.hpp> | ||
#include <Headers/kern_cpu.hpp> | ||
#include <Headers/kern_devinfo.hpp> | ||
#include <Headers/kern_file.hpp> | ||
#include <Headers/kern_iokit.hpp> | ||
#include <Headers/kern_user.hpp> | ||
#include <IOKit/IODeviceTreeSupport.h> | ||
|
||
UNFAIR *UNFAIR::callbackUNFAIR; | ||
|
||
void UNFAIR::init() { | ||
callbackUNFAIR = this; | ||
|
||
disableUnfair = !(lilu.getRunMode() & LiluAPI::RunningNormal); | ||
disableUnfair |= checkKernelArgument("-unfairoff"); | ||
|
||
if (disableUnfair) | ||
return; | ||
|
||
sharedCachePath = UserPatcher::getSharedCachePath(); | ||
DBGLOG("unfair", "chosen shared cache path is %s", sharedCachePath); | ||
} | ||
|
||
void UNFAIR::deinit() { | ||
|
||
} | ||
|
||
void UNFAIR::csValidatePage(vnode *vp, memory_object_t pager, memory_object_offset_t page_offset, const void *data, int *validated_p, int *tainted_p, int *nx_p) { | ||
FunctionCast(csValidatePage, callbackUNFAIR->orgCsValidatePage)(vp, pager, page_offset, data, validated_p, tainted_p, nx_p); | ||
|
||
char path[PATH_MAX]; | ||
int pathlen = PATH_MAX; | ||
if (vn_getpath(vp, path, &pathlen) == 0) { | ||
//DBGLOG("unfair", "csValidatePage %s", path); | ||
|
||
if ((callbackUNFAIR->unfairGva & UnfairDyldSharedCache) != 0 && UNLIKELY(strcmp(path, callbackUNFAIR->sharedCachePath) == 0)) { | ||
if ((callbackUNFAIR->unfairGva & UnfairRelaxHdcpRequirements) != 0) { | ||
static const uint8_t find[29] = { | ||
0x4D, 0x61, 0x63, 0x50, 0x72, 0x6F, 0x35, 0x2C, 0x31, 0x00, 0x4D, 0x61, 0x63, 0x50, 0x72, 0x6F, | ||
0x36, 0x2C, 0x31, 0x00, 0x49, 0x4F, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65 | ||
}; | ||
if (UNLIKELY(KernelPatcher::findAndReplace(const_cast<void *>(data), PAGE_SIZE, find, sizeof(find), BaseDeviceInfo::get().modelIdentifier, 20))) | ||
DBGLOG("unfair", "patched relaxed drm model"); | ||
} | ||
|
||
if ((callbackUNFAIR->unfairGva & UnfairCustomAppleGvaBoardId) != 0) { | ||
static const uint8_t find[18] = { | ||
0x62, 0x6F, 0x61, 0x72, 0x64, 0x2D, 0x69, 0x64, 0x00, 0x68, 0x77, 0x2E, 0x6D, 0x6F, 0x64, 0x65, | ||
0x6C | ||
}; | ||
static const uint8_t repl[5] = { | ||
0x68, 0x77, 0x67, 0x76, 0x61 | ||
}; | ||
if (UNLIKELY(KernelPatcher::findAndReplace(const_cast<void *>(data), PAGE_SIZE, find, sizeof(find), repl, sizeof(repl)))) | ||
DBGLOG("unfair", "patched board-id -> hwgva-id"); | ||
} | ||
|
||
} else if ((callbackUNFAIR->unfairGva & UnfairAllowHardwareDrmStreamDecoderOnOldCpuid) != 0 && | ||
(UNLIKELY(strcmp(path, "/System/Library/PrivateFrameworks/CoreLSKDMSE.framework/Versions/A/CoreLSKDMSE") == 0) || | ||
UNLIKELY(strcmp(path, "/System/Library/PrivateFrameworks/CoreLSKD.framework/Versions/A/CoreLSKD") == 0))) { | ||
static const uint8_t find[] = {0xC7, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x0F, 0xA2}; | ||
static const uint8_t repl[] = {0xC7, 0xC0, 0xC3, 0x06, 0x03, 0x00, 0x90, 0x90}; | ||
if (UNLIKELY(KernelPatcher::findAndReplace(const_cast<void *>(data), PAGE_SIZE, find, sizeof(find), repl, sizeof(repl)))) | ||
DBGLOG("unfair", "patched streaming cpuid to haswell"); | ||
} | ||
} | ||
} | ||
|
||
void UNFAIR::processKernel(KernelPatcher &patcher, DeviceInfo *info) { | ||
if (disableUnfair) | ||
return; | ||
|
||
WEG::getVideoArgument(info, "unfairgva", &unfairGva, sizeof(unfairGva)); | ||
if (unfairGva == 0) { | ||
DBGLOG("unfair", "disabling unfair gva due to missing boot argument"); | ||
disableUnfair = true; | ||
return; | ||
} | ||
|
||
DBGLOG("unfair", "activating with %d bitmask", unfairGva); | ||
|
||
if ((unfairGva & UnfairCustomAppleGvaBoardId) != 0) { | ||
auto entry = IORegistryEntry::fromPath("/", gIODTPlane); | ||
if (entry) { | ||
DBGLOG("unfair", "setting hwgva-id to iMacPro1,1"); | ||
entry->setProperty("hwgva-id", const_cast<char *>("Mac-7BA5B2D9E42DDD94"), static_cast<uint32_t>(sizeof("Mac-7BA5B2D9E42DDD94"))); | ||
entry->release(); | ||
} else { | ||
SYSLOG("shiki", "failed to obtain iodt tree"); | ||
unfairGva &= ~UnfairCustomAppleGvaBoardId; | ||
} | ||
} | ||
|
||
KernelPatcher::RouteRequest csRoute("_cs_validate_page", csValidatePage, orgCsValidatePage); | ||
if (!patcher.routeMultipleLong(KernelPatcher::KernelID, &csRoute, 1)) { | ||
SYSLOG("unfair", "failed to route cs validation pages"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// kern_unfair.hpp | ||
// WhateverGreen | ||
// | ||
// Copyright © 2021 vit9696. All rights reserved. | ||
// | ||
|
||
#ifndef kern_unfair_hpp | ||
#define kern_unfair_hpp | ||
|
||
#include <Headers/kern_patcher.hpp> | ||
#include <Headers/kern_devinfo.hpp> | ||
#include <Headers/kern_cpu.hpp> | ||
#include <Headers/kern_user.hpp> | ||
|
||
class UNFAIR { | ||
public: | ||
void init(); | ||
void deinit(); | ||
|
||
/** | ||
* Property patching routine | ||
* | ||
* @param patcher KernelPatcher instance | ||
* @param info device info | ||
*/ | ||
void processKernel(KernelPatcher &patcher, DeviceInfo *info); | ||
|
||
private: | ||
/** | ||
* Private self instance for callbacks | ||
*/ | ||
static UNFAIR *callbackUNFAIR; | ||
|
||
/** | ||
* Disable unfair, based on mode | ||
*/ | ||
bool disableUnfair {false}; | ||
|
||
/** | ||
* GVA bitmask as specified in unfairgva boot argument / property. | ||
*/ | ||
enum : uint32_t { | ||
UnfairAllowHardwareDrmStreamDecoderOnOldCpuid = 1, | ||
UnfairRelaxHdcpRequirements = 2, | ||
UnfairCustomAppleGvaBoardId = 4, | ||
UnfairDyldSharedCache = UnfairRelaxHdcpRequirements | UnfairCustomAppleGvaBoardId, | ||
}; | ||
|
||
/** | ||
* Patch rule bitmask (0 means none). | ||
*/ | ||
uint32_t unfairGva {0}; | ||
|
||
/** | ||
* Codesign page validation wrapper used for userspace patching | ||
*/ | ||
static void csValidatePage(vnode *vp, memory_object_t pager, memory_object_offset_t page_offset, const void *data, int *validated_p, int *tainted_p, int *nx_p); | ||
|
||
/** | ||
* Original codesign page validation pointer. | ||
*/ | ||
mach_vm_address_t orgCsValidatePage {0}; | ||
|
||
/** | ||
* Cyrrent shared cache. | ||
*/ | ||
const char *sharedCachePath {nullptr}; | ||
}; | ||
|
||
#endif /* kern_unfair_hpp */ |
Oops, something went wrong.