Patching DLLs in general, and specifically user32.dll to prevent FlashWindow(Ex) on Windows 10?


Recommended Posts

Has anyone patched DLLs in this era where Windows includes anti-malware and other measures to prevent tampering?

My problem is that on Windows 10 the Flashing taskbar buttons appear on all virtual desktops, and interrupts my work on another virtual desktop. https://www.neowin.net/forum/topic/1276378-windows-10-virtual-desktops-and-flashing-taskbar-buttons-on-all-virtual-desktops-still-on-insider-builds/ 

I can't come up a better solution than preventing whole flash window thing happening, I have not yet tried to patch this, I have ran dumpbin for the user32.dll and original code for FlashWindow(Ex) function is following, if I'm not mistaken:

user32.dll
10.0.10240.16384

1776  10C 0004C7F0 FlashWindow
1777  10D 000333C0 FlashWindowEx


Function Table (3186)
         Begin    End      Info     
0000729C 0004C7F0 0004C828 0008F3C4
0000510C 000333C0 000333CB 000951B0

FlashWindow
00000001800333C0: 4C 8B D1           mov         r10,rcx
00000001800333C3: B8 7A 13 00 00     mov         eax,137Ah
00000001800333C8: 0F 05              syscall
00000001800333CA: C3                 ret
  
FlashWindowEx
000000018004C7F0: 48 83 EC 48        sub         rsp,48h
000000018004C7F4: F7 DA              neg         edx
000000018004C7F6: 48 89 4C 24 28     mov         qword ptr [rsp+28h],rcx
000000018004C7FB: 48 8D 4C 24 20     lea         rcx,[rsp+20h]
000000018004C800: C7 44 24 20 20 00  mov         dword ptr [rsp+20h],20h
                  00 00
000000018004C808: 1B C0              sbb         eax,eax
000000018004C80A: C7 44 24 34 01 00  mov         dword ptr [rsp+34h],1
                  00 00
000000018004C812: 83 64 24 38 00     and         dword ptr [rsp+38h],0
000000018004C817: 83 E0 03           and         eax,3
000000018004C81A: 89 44 24 30        mov         dword ptr [rsp+30h],eax
000000018004C81E: E8 9D 6B FE FF     call        00000001800333C0 (FlashWindow)
000000018004C823: 48 83 C4 48        add         rsp,48h
000000018004C827: C3                 ret

 

  On 27/10/2015 at 06:19, Ace said:

Would it be possible to patch the .dll in memory? e.g. via memorpy

 

Thanks, I'll look into this. Though, I don't know what is the program that causes random programs (e.g. Chrome or Gimp or Visual Studio window) to flash a window when I quickly switch between apps or desktops. That is the most common cause for flashes.

I wonder can I memory patch all programs, maybe then it would work on all times?

Edit: Maybe I can memory patch the Virtual Desktop program in the shell directly? Will that cause problems with anti-malware executables? I have not disassembled that, so finding it will be a task in itself.

Truly interesting, microsoft has just added something to the FlashWindowEx in build 10565:

FlashWindowEx (build 10565):
0000000180039210: 4C 8B D1           mov         r10,rcx
0000000180039213: B8 7D 13 00 00     mov         eax,137Dh
0000000180039218: F6 04 25 08 03 FE  test        byte ptr [000000007FFE0308h],1
                  7F 01
0000000180039220: 75 03              jne         0000000180039225
0000000180039222: 0F 05              syscall
0000000180039224: C3                 ret
0000000180039225: CD 2E              int         2Eh
0000000180039227: C3                 ret

 

And in old one: 

FlashWindowEx (build 10240):
00000001800333C0: 4C 8B D1           mov         r10,rcx
00000001800333C3: B8 7A 13 00 00     mov         eax,137Ah
00000001800333C8: 0F 05              syscall
00000001800333CA: C3                 ret

 

I wish it's some registry thing so we could turn the whole damn thing off. Must study this change more.

(Notice that in my parent post I had typed the FlashWindowEx and FlashWindow function names incorrectly.)

Edit: I notice this comparing address 000000007FFE0308h appears in all places where there is a syscall, maybe it's not flashwindowEx specific after all, darn.

Edited by Ciantic
  • 2 months later...

It can quite easily be done with a global AppInit_DLLs hook and some memory patching. Your AV might go crazy but compile for yourself and create an exception if you really want to disable flashing windows.

 

Code:

#include <windows.h>

static void DisableFlashWindow()
{
    HINSTANCE hUser32 = GetModuleHandleW(L"user32.dll");
    if (!hUser32)
    {
        OutputDebugStringW(L"[NoFlashWindow] GetModuleHandleW failed for user32.dll...");
        return;
    }

    PVOID pFlashWindow = (PVOID)GetProcAddress(hUser32, "FlashWindow");
    if (pFlashWindow)
    {
        BYTE ret4[] = { 0xC2, 0x04, 0x00 };
        if (WriteProcessMemory(GetCurrentProcess(), pFlashWindow, ret4, sizeof(ret4), NULL))
            OutputDebugStringW(L"[NoFlashWindow] FlashWindow disabled!");
        else
            OutputDebugStringW(L"[NoFlashWindow] WriteProcessMemory failed for FlashWindow...");
    }
    else
        OutputDebugStringW(L"[NoFlashWindow] GetProcAddress failed for FlashWindow...");

    PVOID pFlashWindowEx = (PVOID)GetProcAddress(hUser32, "FlashWindowEx");
    if (pFlashWindowEx)
    {
        BYTE ret8[] = { 0xC2, 0x08, 0x00 };
        if (WriteProcessMemory(GetCurrentProcess(), pFlashWindowEx, ret8, sizeof(ret8), NULL))
            OutputDebugStringW(L"[NoFlashWindow] FlashWindowEx disabled!");
        else
            OutputDebugStringW(L"[NoFlashWindow] WriteProcessMemory failed for FlashWindowEx...");
    }
    else
        OutputDebugStringW(L"[NoFlashWindow] GetProcAddress failed for FlashWindowEx...");
}

extern "C" __declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        DisableFlashWindow();
        break;
    }
    return TRUE; // succesful
}

GitHub:

https://github.com/mrexodia/NoFlashWindow/releases

 

Duncan

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Oh man! I can't wait! 😁
    • slowness that result in unproductive, when something was easy fast one click now its basically 2 or 3 clicks and more mouse movement not the end of the world sure but forcing changes for the sake of it for no good reason its one reason why people dont like 11.
    • WhatsApp for Android expands chat themes with 18 new colors by Paul Hill The WhatsApp Beta for Android has just been updated to version 2.25.19.2 (via WABetaInfo) bringing with it 18 new color options, expanding the selection from 20 to 38 colors. This update brings the Android app up to parity with the iOS version, which got this beta update at the start of the month. The expansion of colors will give users greater personalization options for their WhatsApp chats. You can pick the new colors individually per chat or from the settings for every chat, complementing the existing support for various custom backgrounds. How the new chat themes work To set the new colors for individual chats, just open the chat you want to theme, press the three dot menu in the top right and go to themes and change the chat color. To change the theme color across the whole of the app, just go to settings and then select chats and change the chat theme. The new colors are compatible with both light and dark modes and affect the message bubbles. Unlike Messenger where theme changes can be seen by your contact, theme changes in WhatsApp are only visible to the user who applies it. User reception and future outlook Most people running WhatsApp are using the stable version, so you won’t see these new theme colors yet, we will have to wait a bit longer for that. Even if you’re on the beta, the feature may not be available yet as it’s being rolled out. While not a massive change, lots of people like to theme their WhatsApp messages so this change will be welcomed by those that do that. The messaging app scene is very competitive, so this will help Meta retain users on WhatsApp by boosting satisfaction. If you have had a chance to try out the new themes, let us know in the comments what you think!
    • Yup, that thing. Thank you. I found it invaluable for workflow.
    • Windows 11 finally gets a small, but long-requested Windows 10 taskbar feature — and it is not the ability to use small taskbar buttons.
  • Recent Achievements

    • Explorer
      Legend20 went up a rank
      Explorer
    • One Month Later
      jezzzy earned a badge
      One Month Later
    • First Post
      CSpera earned a badge
      First Post
    • One Month Later
      MIR JOHNNY BLAZE earned a badge
      One Month Later
    • Apprentice
      Wireless wookie went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      618
    2. 2
      ATLien_0
      278
    3. 3
      +FloatingFatMan
      178
    4. 4
      Michael Scrip
      150
    5. 5
      Steven P.
      115
  • Tell a friend

    Love Neowin? Tell a friend!