Skip to content

Commit

Permalink
Reduced module string length less than 10 due to SYSTRACE_COND constr…
Browse files Browse the repository at this point in the history
…aint
  • Loading branch information
syscl committed Oct 6, 2018
1 parent 12c93be commit c0d12d3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
EnableLidWake Changelog
==============
### v4.0.2

- Reduced module string length less than 10 due to ```SYSTRACE_COND``` constraint

### v4.0.1

- Updated framebuffer symbol to more general ```_gPlatformInformationList``` instead of specific symbols (preperation for Mojave)
Expand Down
68 changes: 34 additions & 34 deletions EnableLidWake/EnableLidWake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ uint32_t LWEnabler::getIgPlatformId() const
sect = WIOKit::findEntryByPrefix(sect, tree[i], gIOServicePlane);
if (sect && i+1 == arrsize(tree)) {
if (WIOKit::getOSDataValue(sect, "AAPL,ig-platform-id", platform)) {
DBGLOG(kThisKextID, "found IGPU with ig-platform-id 0x%08x", platform);
DBGLOG(kThisModule, "found IGPU with ig-platform-id 0x%08x", platform);
return platform;
} else {
SYSLOG(kThisKextID, "found IGPU with missing ig-platform-id, assuming old");
SYSLOG(kThisModule, "found IGPU with missing ig-platform-id, assuming old");
}
}
}

DBGLOG(kThisKextID, "failed to find IGPU ig-platform-id");
DBGLOG(kThisModule, "failed to find IGPU ig-platform-id");
return platform;
}

Expand All @@ -61,7 +61,7 @@ bool LWEnabler::init()

if (error != LiluAPI::Error::NoError)
{
SYSLOG(kThisKextID, "failed to register onPatcherLoad method %d", error);
SYSLOG(kThisModule, "failed to register onPatcherLoad method %d", error);
return false;
}

Expand All @@ -82,11 +82,11 @@ void LWEnabler::configIgPlatform()
case 0x0a2e000a:
case 0x59260002: {
lilu_os_memcpy(reinterpret_cast<uint32_t *>(rIgPlatformId), &gIgPlatformId, sizeof(uint32_t));
DBGLOG(kThisKextID, "reverse order of ig-platform-id: 0x%02x, 0x%02x, 0x%02x, 0x%02x", *rIgPlatformId, *(rIgPlatformId+1), *(rIgPlatformId+2), *(rIgPlatformId+3));
DBGLOG(kThisModule, "reverse order of ig-platform-id: 0x%02x, 0x%02x, 0x%02x, 0x%02x", *rIgPlatformId, *(rIgPlatformId+1), *(rIgPlatformId+2), *(rIgPlatformId+3));
break;
}
default: {
SYSLOG(kThisKextID, "0x%08x is not fixable, abort.", gIgPlatformId);
SYSLOG(kThisModule, "0x%08x is not fixable, abort.", gIgPlatformId);
isFixablePlatform = false;
break;
}
Expand All @@ -111,11 +111,11 @@ void LWEnabler::frameBufferPatch(KernelPatcher& patcher, size_t index, mach_vm_a
// Enable lid wake for Haswell (Azul) platform
if (!(progressState & ProcessingState::EverythingDone) &&
memcmp(kextList[i].id, kextHSWFbId, strlen(kextHSWFbId)) == 0) {
SYSLOG(kThisKextID, "found %s", kextList[i].id);
SYSLOG(kThisModule, "found %s", kextList[i].id);

mach_vm_address_t address = patcher.solveSymbol(index, "_gPlatformInformationList");
if (address) {
SYSLOG(kThisKextID, "obtained _gPlatformInformationList");
SYSLOG(kThisModule, "obtained _gPlatformInformationList");
patcher.clearError();

// Lookup the ig-platform-id specific framebuffer data
Expand All @@ -130,53 +130,53 @@ void LWEnabler::frameBufferPatch(KernelPatcher& patcher, size_t index, mach_vm_a
curOff++;
// verify search
if (curOff < endOff) {
DBGLOG(kThisKextID, "found platform-id (0x%08x) at framebuffer info data segment", gIgPlatformId);
DBGLOG(kThisModule, "found platform-id (0x%08x) at framebuffer info data segment", gIgPlatformId);
// now let's generate the patch for it
// target offset should @ +88
curOff += 88;
uint8_t repl[MaxReplSize] {};
lilu_os_memcpy(repl, curOff, MaxReplSize);
DBGLOG(kThisKextID, "%u, %u, %u, %u, %u", *curOff, *(curOff+1), *(curOff+2), *(curOff+3), *(curOff+4));
DBGLOG(kThisModule, "%u, %u, %u, %u, %u", *curOff, *(curOff+1), *(curOff+2), *(curOff+3), *(curOff+4));
// apply platform specific patch pattern
// 0x0a2e0008 and 0x0d26000f use 0x1f
// 0x0a2e000a and 0x0a26000a use 0x1e
memset(repl, (gIgPlatformId == 0x0a2e0008 || gIgPlatformId == 0x0d26000f) ? 0x1f : 0x1e, MaxReplSize);
if (memcmp(repl, curOff, MaxReplSize) == 0) {
// already patch due to the kext has been
// patched in the cache? we should stop here
SYSLOG(kThisKextID, "already enabled internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
SYSLOG(kThisModule, "already enabled internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
return;
}
SYSLOG(kThisKextID, "binary patches for internal display have been generated.");
SYSLOG(kThisKextID, "attempting to copy back...");
SYSLOG(kThisModule, "binary patches for internal display have been generated.");
SYSLOG(kThisModule, "attempting to copy back...");
// a more nature way to fix the lid wake issue by
// copying back to the framebuffer in memory instead of
// invoking the applyLookupPatch()
// note: we didn't require to check kernel version
// due to the fact that we don't care about which
// version of kext will be loaded
lilu_os_memcpy(curOff, repl, MaxReplSize);
SYSLOG(kThisKextID, "enable internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
SYSLOG(kThisModule, "enable internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
progressState |= ProcessingState::EverythingDone;
break;
} else {
SYSLOG(kThisKextID, "cannot find platform-id at %s", *kextHSWFb);
SYSLOG(kThisModule, "cannot find platform-id at %s", *kextHSWFb);
return;
}
} else {
SYSLOG(kThisKextID, "cannot find _gPlatformInformationList");
SYSLOG(kThisModule, "cannot find _gPlatformInformationList");
return;
}
}

// Enable lid wake for Skylake (skl) platform
if (!(progressState & ProcessingState::EverythingDone) &&
memcmp(kextList[i].id, kextSKLFbId, strlen(kextSKLFbId)) == 0) {
SYSLOG(kThisKextID, "found %s", kextList[i].id);
SYSLOG(kThisModule, "found %s", kextList[i].id);
// it must be 0x19260004 due to the previous configPlatform's check
mach_vm_address_t address = patcher.solveSymbol(index, "_gPlatformInformationList");
if (address) {
SYSLOG(kThisKextID, "obtained _gPlatformInformationList");
SYSLOG(kThisModule, "obtained _gPlatformInformationList");
patcher.clearError();
// Lookup the ig-platform-id specific framebuffer data
auto curOff = reinterpret_cast<uint8_t *>(address);
Expand All @@ -190,51 +190,51 @@ void LWEnabler::frameBufferPatch(KernelPatcher& patcher, size_t index, mach_vm_a
curOff++;
// verify search
if (curOff < endOff) {
DBGLOG(kThisKextID, "found platform-id (0x%08x) at framebuffer info data segment", gIgPlatformId);
DBGLOG(kThisModule, "found platform-id (0x%08x) at framebuffer info data segment", gIgPlatformId);
// now let's generate the patch for it
// target offset should @ +97
curOff += 97;
uint8_t repl[MaxReplSize] {};
lilu_os_memcpy(repl, curOff, MaxReplSize);
DBGLOG(kThisKextID, "%u, %u, %u, %u, %u", *curOff, *(curOff+1), *(curOff+2), *(curOff+3), *(curOff+4));
DBGLOG(kThisModule, "%u, %u, %u, %u, %u", *curOff, *(curOff+1), *(curOff+2), *(curOff+3), *(curOff+4));
// apply platform specific patch pattern
// 0x19260004 uses 0x0f
memset(repl, 0x0f, MaxReplSize);
if (memcmp(repl, curOff, MaxReplSize) == 0) {
// already patch due to the kext has been
// patched in the cache? we should stop here
SYSLOG(kThisKextID, "already enabled internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
SYSLOG(kThisModule, "already enabled internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
return;
}
SYSLOG(kThisKextID, "binary patches for internal display have been generated.");
SYSLOG(kThisModule, "binary patches for internal display have been generated.");
// a more nature way to fix the lid wake issue by
// copying back to the framebuffer in memory instead of
// invoking the applyLookupPatch()
// note: we didn't require to check kernel version
// due to the fact that we don't care about which
// version of kext will be loaded
lilu_os_memcpy(curOff, repl, MaxReplSize);
SYSLOG(kThisKextID, "enable internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
SYSLOG(kThisModule, "enable internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
progressState |= ProcessingState::EverythingDone;
break;
} else {
SYSLOG(kThisKextID, "cannot find platform-id at %s", *kextHSWFb);
SYSLOG(kThisModule, "cannot find platform-id at %s", *kextHSWFb);
return;
}
} else {
SYSLOG(kThisKextID, "cannot find _gPlatformInformationList");
SYSLOG(kThisModule, "cannot find _gPlatformInformationList");
return;
}
}

// Enable lid wake for KabyLake (kbl) platform
if (!(progressState & ProcessingState::EverythingDone) &&
memcmp(kextList[i].id, kextKBLFbId, strlen(kextKBLFbId)) == 0) {
SYSLOG(kThisKextID, "found %s", kextList[i].id);
SYSLOG(kThisModule, "found %s", kextList[i].id);
// it must be 0x59260002 due to the previous configPlatform's check
mach_vm_address_t address = patcher.solveSymbol(index, "_gPlatformInformationList");
if (address) {
SYSLOG(kThisKextID, "obtained _gPlatformInformationList");
SYSLOG(kThisModule, "obtained _gPlatformInformationList");
patcher.clearError();
// Lookup the ig-platform-id specific framebuffer data
auto curOff = reinterpret_cast<uint8_t *>(address);
Expand All @@ -248,39 +248,39 @@ void LWEnabler::frameBufferPatch(KernelPatcher& patcher, size_t index, mach_vm_a
curOff++;
// verify search
if (curOff < endOff) {
DBGLOG(kThisKextID, "found platform-id (0x%08x) at framebuffer info data segment", gIgPlatformId);
DBGLOG(kThisModule, "found platform-id (0x%08x) at framebuffer info data segment", gIgPlatformId);
// now let's generate the patch for it
// target offset should @ +97
curOff += 97;
uint8_t repl[MaxReplSize] {};
lilu_os_memcpy(repl, curOff, MaxReplSize);
DBGLOG(kThisKextID, "%u, %u, %u, %u, %u", *curOff, *(curOff+1), *(curOff+2), *(curOff+3), *(curOff+4));
DBGLOG(kThisModule, "%u, %u, %u, %u, %u", *curOff, *(curOff+1), *(curOff+2), *(curOff+3), *(curOff+4));
// apply platform specific patch pattern
// 0x19260004 uses 0x0f
memset(repl, 0x0f, MaxReplSize);
if (memcmp(repl, curOff, MaxReplSize) == 0) {
// already patch due to the kext has been
// patched in the cache? we should stop here
SYSLOG(kThisKextID, "already enabled internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
SYSLOG(kThisModule, "already enabled internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
return;
}
SYSLOG(kThisKextID, "binary patches for internal display have been generated.");
SYSLOG(kThisModule, "binary patches for internal display have been generated.");
// a more nature way to fix the lid wake issue by
// copying back to the framebuffer in memory instead of
// invoking the applyLookupPatch()
// note: we didn't require to check kernel version
// due to the fact that we don't care about which
// version of kext will be loaded
lilu_os_memcpy(curOff, repl, MaxReplSize);
SYSLOG(kThisKextID, "enable internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
SYSLOG(kThisModule, "enable internal display after sleep for ig-platform-id: 0x%08x", gIgPlatformId);
progressState |= ProcessingState::EverythingDone;
break;
} else {
SYSLOG(kThisKextID, "cannot find platform-id at %s", *kextHSWFb);
SYSLOG(kThisModule, "cannot find platform-id at %s", *kextHSWFb);
return;
}
} else {
SYSLOG(kThisKextID, "cannot find _gPlatformInformationList");
SYSLOG(kThisModule, "cannot find _gPlatformInformationList");
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion EnableLidWake/EnableLidWake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <Headers/kern_patcher.hpp>

#define kThisKextID "org.syscl.EnableLidWake"
#define kThisModule "elw"

class LWEnabler
{
Expand Down
4 changes: 2 additions & 2 deletions EnableLidWake/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>4.0.1</string>
<string>4.0.2</string>
<key>CFBundleVersion</key>
<string>4.0.1</string>
<string>4.0.2</string>
<key>IOKitPersonalities</key>
<dict>
<key>EnableLidWake</key>
Expand Down

0 comments on commit c0d12d3

Please sign in to comment.