Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Studio Anti-Rich-Header v1.0.3 #1266

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions mods/visual-studio-anti-rich-header.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
// @id visual-studio-anti-rich-header
// @name Visual Studio Anti-Rich-Header
// @description Prevent the Visual Studio linker from embedding the Rich header into new executables
// @version 1.0.2
// @version 1.0.3
// @author m417z
// @github https://github.com/m417z
// @twitter https://twitter.com/m417z
// @homepage https://m417z.com/
// @include link.exe
// ==/WindhawkMod==

// Source code is published under The GNU General Public License v3.0.
//
// For bug reports and feature requests, please open an issue here:
// https://github.com/ramensoftware/windhawk-mods/issues
//
// For pull requests, development takes place here:
// https://github.com/m417z/my-windhawk-mods

// ==WindhawkModReadme==
/*
# Visual Studio Anti-Rich-Header

Prevent the Visual Studio linker from embedding the Rich header into new executables.

![Screenshot](https://i.imgur.com/7ZeEfYK.png) \
*A Rich header example*
*/
// ==/WindhawkModReadme==

Expand All @@ -34,7 +45,7 @@ std::string ReplaceAll(std::string str, const std::string& from, const std::stri
return str;
}

BOOL Wh_ModInit(void)
BOOL Wh_ModInit()
{
Wh_Log(L"Init");

Expand All @@ -50,16 +61,26 @@ BOOL Wh_ModInit(void)
#else
std::string targetRegex =
R"(\x8B\x44\x24.)" // mov eax,dword ptr ss:[esp+??]
R"(\x5F)" // pop edi
R"(\x5E)" // pop esi
R"(()"

// VS 2019
R"(\x5F)" // pop edi
R"(\x5E)" // pop esi
R"(\xC7\x03\x52\x69\x63\x68)" // mov dword ptr ds:[ebx],68636952
R"(\x89\x4B\x04)" // mov dword ptr ds:[ebx+4],ecx
R"(|)"
// VS 2022
R"(\x5F)" // pop edi
R"(\x5E)" // pop esi
R"(\x89\x59\x04)" // mov dword ptr ds:[ecx+4],ebx
R"(\xC7\x01\x52\x69\x63\x68)" // mov dword ptr ds:[ecx],68636952
R"(|)"
// VS 2022 17.12.1
R"(\x89\x7B\x04)" // mov dword ptr ds:[ebx+4],ebx
R"(\x5F)" // pop edi
R"(\x5E)" // pop esi
R"(\xC7\x03\x52\x69\x63\x68)" // mov dword ptr ds:[ebx],68636952

R"())"
R"(\x5B)" // pop ebx
;
Expand All @@ -81,10 +102,10 @@ BOOL Wh_ModInit(void)
if (std::regex_search(search.begin(), search.end(), match, regex)) {
auto pos = from + match.position(0);

DWORD dlOldProtect;
VirtualProtect(pos, targetPatch.size(), PAGE_EXECUTE_READWRITE, &dlOldProtect);
DWORD dwOldProtect;
VirtualProtect(pos, targetPatch.size(), PAGE_EXECUTE_READWRITE, &dwOldProtect);
memcpy(pos, targetPatch.data(), targetPatch.size());
VirtualProtect(pos, targetPatch.size(), dlOldProtect, &dlOldProtect);
VirtualProtect(pos, targetPatch.size(), dwOldProtect, &dwOldProtect);
}
else {
bool proceed = MessageBox(
Expand Down