Skip to content

Commit

Permalink
Add changes
Browse files Browse the repository at this point in the history
  • Loading branch information
J P committed Jan 11, 2020
1 parent 6d37985 commit f9c160f
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,12 @@
"$(inherited)",
"$(PROJECT_DIR)/Lilu.kext/Contents/Resources/Library",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MODULE_NAME = fish.goldfish64.SystemProfilerMemoryFixup;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = fish.goldfish64.SystemProfilerMemoryFixup;
PRODUCT_BUNDLE_IDENTIFIER = meow.IOIIIO.MacProMemoryNotificationDisabler;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = kext;
};
Expand All @@ -404,11 +405,12 @@
"$(inherited)",
"$(PROJECT_DIR)/Lilu.kext/Contents/Resources/Library",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MODULE_NAME = fish.goldfish64.SystemProfilerMemoryFixup;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = fish.goldfish64.SystemProfilerMemoryFixup;
PRODUCT_BUNDLE_IDENTIFIER = meow.IOIIIO.MacProMemoryNotificationDisabler;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = kext;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<string>$(MODULE_VERSION)</string>
<key>IOKitPersonalities</key>
<dict>
<key>SystemProfilerMemoryFixup</key>
<key>MacProMemoryNotificationDisabler</key>
<dict>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
Expand All @@ -34,10 +34,10 @@
<string>IOKit</string>
</dict>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 IOIIIO. All rights reserved.</string>
<key>OSBundleCompatibleVersion</key>
<string>1.0</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018-2019 Goldfish64. All rights reserved.</string>
<key>OSBundleLibraries</key>
<dict>
<key>as.vit9696.Lilu</key>
Expand Down
138 changes: 138 additions & 0 deletions MacProMemoryNotificationDisabler/kern_start.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2018-2019 John Davis
* Copyright (c) 2020 IOIIIO
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <Headers/plugin_start.hpp>
#include <Headers/kern_api.hpp>
#include <Headers/kern_file.hpp>

// Path to binary.
static const char *binPathMemorySlotNotification = "/System/Library/CoreServices/MemorySlotNotification";

static const uint32_t SectionActive = 1;

// Find: 74 xx 4C 89 F7 E8 xx xx xx xx
// Replace: 90 90 4C 89 F7 90 90 90 90 90
static const size_t patchBytesCount = 10;
static const uint8_t replaceBytes[patchBytesCount] = { 0x90, 0x90, 0x4C, 0x89, 0xF7, 0x90, 0x90, 0x90, 0x90, 0x90 };

// Patching info for MemorySlotNotification binary.
static uint8_t findBytesMemorySlotNotification[patchBytesCount] = { };
static UserPatcher::BinaryModPatch patchBytesMemorySlotNotification {
CPU_TYPE_X86_64,
0,
findBytesMemorySlotNotification,
replaceBytes,
patchBytesCount,
0,
1,
UserPatcher::FileSegment::SegmentTextText,
SectionActive
};

// BinaryModInfo array containing all patches required.
static UserPatcher::BinaryModInfo binaryPatchesCatalina[] {
{ binPathMemorySlotNotification, &patchBytesMemorySlotNotification, 1},
};

static void buildPatch(KernelPatcher &patcher, const char *path, uint8_t *findBuffer) {
DBGLOG("MacProMemoryNotificationDisabler", "buildPatches() start");

// Get contents of binary.
size_t outSize;
uint8_t *buffer = FileIO::readFileToBuffer(path, outSize);
if (buffer == NULL) {
DBGLOG("MacProMemoryNotificationDisabler", "Failed to read binary: %s\n", path);
procInfo.section = procInfo.SectionDisabled;
procInfoCatalina.section = procInfoCatalina.SectionDisabled;
return;
}

// Find where the notification is called.
off_t index = 0;
for (off_t i = 0; i < outSize; i++) {
if (buffer[i] == 0x74 && buffer[i+2] == 0x4C && buffer[i+3] == 0x89
&& buffer[i+4] == 0xF7 && buffer[i+5] == 0xE8) {
index = i;
break;
}
}

// If we found no match, we can't go on.
if (index == 0)
panic("MacProMemoryNotificationDisabler: Failed to get index into binary: %s\n", path);

// Build find pattern.
uint8_t *bufferOffset = buffer + index;
for (uint32_t i = 0; i < patchBytesCount; i++)
findBuffer[i] = bufferOffset[i];

// Free buffer.
Buffer::deleter(buffer);
}

static void buildPatchesCatalina(void *user, KernelPatcher &patcher) {
// Build patches for binaries.
buildPatch(patcher, binPathMemorySlotNotification, findBytesMemorySlotNotification);
}

// Main function.
static void mpmndStart() {
DBGLOG("MacProMemoryNotificationDisabler", "start");

// Are we on 10.15 or above?
if (getKernelVersion() >= KernelVersion::Catalina) {
// Load callback so we can determine patterns to search for.
lilu.onPatcherLoad(buildPatchesCatalina);

// Load patches into Lilu for 10.15+.
lilu.onProcLoadForce(&procInfoCatalina, 1, nullptr, nullptr, binaryPatchesCatalina, arrsize(binaryPatchesCatalina));
}
}

// Boot args.
static const char *bootargOff[] {
"-mpmndoff"
};
static const char *bootargDebug[] {
"-mpmnddbg"
};
static const char *bootargBeta[] {
"-mpmndbeta"
};

// Plugin configuration.
PluginConfiguration ADDPR(config) {
xStringify(PRODUCT_NAME),
parseModuleVersion(xStringify(MODULE_VERSION)),
LiluAPI::AllowNormal,
bootargOff,
arrsize(bootargOff),
bootargDebug,
arrsize(bootargDebug),
bootargBeta,
arrsize(bootargBeta),
KernelVersion::Catalina,
[]() {
mpmndStart();
}
};
208 changes: 0 additions & 208 deletions SystemProfilerMemoryFixup/kern_start.cpp

This file was deleted.

0 comments on commit f9c160f

Please sign in to comment.