Skip to content

Commit

Permalink
Fix Syscall hook in user32 function
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussacana committed May 17, 2019
1 parent b75d4b6 commit a1695b5
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions SRL/Hook/IntroInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ static partial class StringReloader {
static FxHook ShowWindowHook;
static FxHook SetWindowPosHook;
static FxHook MoveWindowHook;

static bool SysCall = true;
static void InstallIntroInjector() {
if (ShowWindowHook != null)
return;
Expand All @@ -34,6 +36,14 @@ static void InstallIntroInjector() {
if (HookCreateWindowEx)
CreateWindowExADel = new CreateWindowExADelegate(hCreateWindowEx);
#endif

SysCall = !CheckLibrary("win32u.dll");

if (SysCall)
{
Log("Intro Injector SysCall Support Enabled", true);
}

ShowWindowDel = new ShowWindowDelegate(hShowWindow);
ShowWindowHook = new FxHook("user32.dll", "ShowWindow", ShowWindowDel);
if (HookShowWindow)
Expand All @@ -54,18 +64,45 @@ static void InstallIntroInjector() {

static bool IntroInitialized = false;
static bool hShowWindow(IntPtr hWnd, int nCmdShow) {
if (SysCall)
{
ShowWindowHook.Uninstall();
bool Rst = ShowWindow(hWnd, nCmdShow);
ShowWindowHook.Install();
ShowIntro(hWnd);
return Rst;
}

bool Result = NtUserShowWindow(hWnd, nCmdShow);
ShowIntro(hWnd);
return Result;
}

static bool hSetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags) {
if (SysCall)
{
SetWindowPosHook.Uninstall();
bool Rst = SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
SetWindowPosHook.Install();
ShowIntro(hWnd);
return Rst;
}

bool Result = NtUserSetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
ShowIntro(hWnd);
return Result;
}

static bool hMoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint) {
if (SysCall)
{
MoveWindowHook.Uninstall();
bool Rst = MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint);
MoveWindowHook.Install();
ShowIntro(hWnd);
return Rst;
}

bool Result = NtUserMoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint);
ShowIntro(hWnd);
return Result;
Expand Down Expand Up @@ -285,6 +322,8 @@ static Bitmap SetBitmapOpacity(Bitmap image, float opacity) {
}
}

static bool CheckLibrary(string fileName) => LoadLibrary(fileName) == IntPtr.Zero;

struct IntroHelper {
public Bitmap[] Fade;
public Color Background;
Expand All @@ -303,6 +342,9 @@ struct IntroHelper {
[DllImport("win32u.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
internal static extern bool NtUserMoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

[DllImport("kernel32", SetLastError = true)]
internal static extern IntPtr LoadLibrary(string lpFileName);


[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]

Expand Down

0 comments on commit a1695b5

Please sign in to comment.