From 1b50f48dacd0db47cb7f4c10e9bd0380337b9f75 Mon Sep 17 00:00:00 2001 From: lvs1974 Date: Mon, 6 Dec 2021 08:33:06 +0100 Subject: [PATCH] Support boot-arg `-dbgenhiolog` to redirect IOLog output to kernel vprintf --- Changelog.md | 3 +++ DebugEnhancer/kern_dbgenhancer.cpp | 18 ++++++++++++++++-- DebugEnhancer/kern_dbgenhancer.hpp | 2 ++ DebugEnhancer/kern_start.cpp | 2 +- README.md | 6 ++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index f997743..97b7392 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ DebugEnhancer Changelog ============================ +#### v1.0.5 +- Support boot-arg `-dbgenhiolog` to redirect IOLog output to kernel vprintf + #### v1.0.4 - Use method routeMultipleLong instead of routeMultiple in order to avoid conflict with HibernationFixup diff --git a/DebugEnhancer/kern_dbgenhancer.cpp b/DebugEnhancer/kern_dbgenhancer.cpp index 85a70a3..2a7d575 100644 --- a/DebugEnhancer/kern_dbgenhancer.cpp +++ b/DebugEnhancer/kern_dbgenhancer.cpp @@ -88,6 +88,16 @@ uint32_t DBGENH::hibernate_write_image(void) //============================================================================== +void DBGENH::IOLog(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + callbackDBGENH->kern_vprintf(fmt, ap); + va_end(ap); +} + +//============================================================================== + void DBGENH::processKernel(KernelPatcher &patcher) { if (!(progressState & ProcessingState::KernelRouted)) @@ -111,9 +121,13 @@ void DBGENH::processKernel(KernelPatcher &patcher) {"_kdb_printf", kdb_printf}, {"_kprintf", kprintf}, {"_hibernate_write_image", hibernate_write_image, org_hibernate_write_image}, - {"_IOHibernateSystemSleep", IOHibernateSystemSleep, orgIOHibernateSystemSleep} + {"_IOHibernateSystemSleep", IOHibernateSystemSleep, orgIOHibernateSystemSleep}, + {"_IOLog", IOLog, orgIOLog} }; - if (!patcher.routeMultipleLong(KernelPatcher::KernelID, requests, arrsize(requests))) + + bool route_iolog = checkKernelArgument("-dbgenhiolog"); + size_t size = arrsize(requests) - (route_iolog ? 0 : 1); + if (!patcher.routeMultipleLong(KernelPatcher::KernelID, requests, size)) SYSLOG("DBGENH", "patcher.routeMultiple for %s is failed with error %d", requests[0].symbol, patcher.getError()); } else SYSLOG("DBGENH", "Symbol _vprintf cannot be resolved with error %d", patcher.getError()); diff --git a/DebugEnhancer/kern_dbgenhancer.hpp b/DebugEnhancer/kern_dbgenhancer.hpp index 75c8941..26e72a4 100644 --- a/DebugEnhancer/kern_dbgenhancer.hpp +++ b/DebugEnhancer/kern_dbgenhancer.hpp @@ -30,6 +30,7 @@ class DBGENH { static void kprintf(const char *fmt, ...); static IOReturn IOHibernateSystemSleep(void); static uint32_t hibernate_write_image(void); + static void IOLog(const char *fmt, ...); /** * Trampolines for original method invocations @@ -37,6 +38,7 @@ class DBGENH { mach_vm_address_t orgIOHibernateSystemSleep {}; mach_vm_address_t org_hibernate_write_image {}; + mach_vm_address_t orgIOLog {}; /** * Original method diff --git a/DebugEnhancer/kern_start.cpp b/DebugEnhancer/kern_start.cpp index 9fea04e..ae02c11 100644 --- a/DebugEnhancer/kern_start.cpp +++ b/DebugEnhancer/kern_start.cpp @@ -13,7 +13,7 @@ static DBGENH dbgenh; static const char *bootargOff[] { - "-dbgenhxoff" + "-dbgenhoff" }; static const char *bootargDebug[] { diff --git a/README.md b/README.md index de3682b..8aca654 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,9 @@ DebugEnhancer A Lilu plugin intended to enable debug output in the macOS kernel, the original idea belongs to Piker-Alpha, see https://github.com/Piker-Alpha/debugMachKernel.sh for more details. + +#### Boot-args +- `-dbgenhdbg` turns on debugging output +- `-dbgenhbeta` enables loading on unsupported osx +- `-dbgenhoff` disables kext loading +- `-dbgenhiolog` redirect IOLog output to kernel vprintf (the same as for kdb_printf and kprintf)