Skip to content

Commit

Permalink
Support boot-arg -dbgenhiolog to redirect IOLog output to kernel vp…
Browse files Browse the repository at this point in the history
…rintf
  • Loading branch information
lvs1974 committed Dec 6, 2021
1 parent b4813da commit 1b50f48
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
18 changes: 16 additions & 2 deletions DebugEnhancer/kern_dbgenhancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions DebugEnhancer/kern_dbgenhancer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ 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
*/

mach_vm_address_t orgIOHibernateSystemSleep {};
mach_vm_address_t org_hibernate_write_image {};
mach_vm_address_t orgIOLog {};

/**
* Original method
Expand Down
2 changes: 1 addition & 1 deletion DebugEnhancer/kern_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
static DBGENH dbgenh;

static const char *bootargOff[] {
"-dbgenhxoff"
"-dbgenhoff"
};

static const char *bootargDebug[] {
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1b50f48

Please sign in to comment.