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

    • LibreOffice narrows gap with Microsoft Office in 25.8 Beta 1 by David Uzondu The Document Foundation has released LibreOffice 25.8 Beta 1 for public testing on Linux, macOS, and Windows. This is the second pre-release for the 25.8 cycle and the foundation says that the final, stable version of LibreOffice 25.8 is expected to land at the end of August 2025. Starting off with Writer, LibreOffice's Word, the developers have finally addressed some long-standing annoyances, including a new command to easily insert a paragraph break right before a table. This beta also introduces a useful privacy feature in its Auto-Redact tool, letting you strip all images from a document with a single option. To use it, go to Tools and select the Auto-Redact option: The application has improved its ability to handle different languages for punctuation, preventing mix-ups in multilingual documents. Other notable improvements have also been made. A new hyphenation rule lets you choose to prevent a word from splitting at the end of a page, moving the whole line to the next page instead. Microsoft Word has had this feature for years now. The Navigator now displays a handy tooltip with word and character counts for headings and their sub-outlines. Scrolling behavior when selecting text has been improved, making it less erratic. A new command with a keyboard shortcut was added for converting fields into plain text. Calc gets a lot of new functions that bring it closer to its competitors like Excel, including TEXTSPLIT, VSTACK, and WRAPROWS. Impress now properly supports embedded fonts in PPTX files, which should reduce headaches when sharing presentations with PowerPoint users. Alongside these additions, the project is also cleaning house; support for Windows 7, 8, and 8.1 has been completely dropped. There are also smaller UI tweaks across the suite, like allowing a single click to enter rotation mode for objects in Writer and Calc. macOS users get better integration, with proper support for native full screen mode and new window management features from the Sequoia update. In terms of performance, the team has optimized everything from loading huge DOC files and XLSX spreadsheets with tons of conditional formatting to simply switching between sheets in Calc. These improvements should be noticeable, especially when working with complex documents. A new application-wide "Viewer mode" has also been implemented, which opens all files in a read-only state for quick, safe viewing. On a related note, The Document Foundation has joined efforts by the likes of KDE to encourage Windows 10 users to switch to Linux. Also, you might have heard that Denmark, in a bid to lessen its reliance on Microsoft, has decided to make a full switch to LibreOffice, with plans to begin phasing out Office 365 in certain ministries as early as next month. If you're interested in this release, you can read the full release notes and download the binaries for your platform: Windows, macOS (Intel | Apple Silicon), or Linux (DEB | RPM). You can also get the latest stable version from our software stories page.
    • Until it can be used 100% offline (ie: PST file support or equiv) not even considering it. I'll jump to Thunderbird first which has gotten a LOT better since the last time I looked at it.
  • Recent Achievements

    • Explorer
      Case_f went up a rank
      Explorer
    • Conversation Starter
      Jamie Smith earned a badge
      Conversation Starter
    • First Post
      NeoToad777 earned a badge
      First Post
    • Week One Done
      JoeV earned a badge
      Week One Done
    • One Month Later
      VAT Services in UAE earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      545
    2. 2
      ATLien_0
      227
    3. 3
      +FloatingFatMan
      159
    4. 4
      Michael Scrip
      113
    5. 5
      +Edouard
      105
  • Tell a friend

    Love Neowin? Tell a friend!