Skip to content

Commit

Permalink
Debugger Logs: Also support unicode logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MeFisto94 committed Nov 26, 2023
1 parent 5c0474e commit 6e5d6be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions Native/Kernel32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class Kernel32

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern void OutputDebugStringW(string str);
public delegate void DelegateOutputDebugStringW([MarshalAs(UnmanagedType.LPWStr)] string str);

[DllImport("kernel32.dll")]
public static extern bool IsDebuggerPresent();
Expand Down
14 changes: 14 additions & 0 deletions Util/DebuggerOutputLoggingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class DebuggerOutputLoggingManager : IManager
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private Hook<Kernel32.DelegateOutputDebugString> _odsAHook;
private Hook<Kernel32.DelegateOutputDebugStringW> _odsWHook;
public Kernel32.DelegateOutputDebugString LoggingDelegate = DefaultLogger;
public bool Swallow = false;

Expand All @@ -25,6 +26,17 @@ public void Load()
}
}, this);
_odsAHook.Activate();

_odsWHook = new Hook<Kernel32.DelegateOutputDebugStringW>(
LocalHook.GetProcAddress("kernel32.dll", "OutputDebugStringW"), str =>
{
LoggingDelegate.Invoke(str);
if (!Swallow)
{
_odsWHook.Original(str);
}
}, this);
_odsWHook.Activate();
}

public bool Enabled
Expand All @@ -35,10 +47,12 @@ public bool Enabled
if (value)
{
_odsAHook.Activate();
_odsWHook.Activate();
}
else
{
_odsAHook.Deactivate();
_odsWHook.Deactivate();
}
}
}
Expand Down

0 comments on commit 6e5d6be

Please sign in to comment.