From 53891376af83d32737242e3ad67e4fd8ad91e07d Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Sat, 3 Dec 2022 19:47:58 +0100 Subject: [PATCH] Small cleanup --- src/client/loader/loader.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/client/loader/loader.cpp b/src/client/loader/loader.cpp index dc402eb4..950eeff2 100644 --- a/src/client/loader/loader.cpp +++ b/src/client/loader/loader.cpp @@ -144,8 +144,10 @@ namespace loader get_optional_header() ->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress); + auto* tls_start = PVOID(source_tls->StartAddressOfRawData); const auto tls_size = source_tls->EndAddressOfRawData - source_tls->StartAddressOfRawData; const auto tls_index = *reinterpret_cast(target_tls->AddressOfIndex); + utils::hook::set(source_tls->AddressOfIndex, tls_index); if (target_tls->AddressOfCallBacks) @@ -154,14 +156,11 @@ namespace loader } DWORD old_protect; - VirtualProtect(PVOID(target_tls->StartAddressOfRawData), - source_tls->EndAddressOfRawData - source_tls->StartAddressOfRawData, PAGE_READWRITE, - &old_protect); + VirtualProtect(tls_start, tls_size, PAGE_READWRITE, &old_protect); auto* const tls_base = *reinterpret_cast(__readgsqword(0x58) + 8ull * tls_index); - std::memmove(tls_base, PVOID(source_tls->StartAddressOfRawData), tls_size); - std::memmove(PVOID(target_tls->StartAddressOfRawData), PVOID(source_tls->StartAddressOfRawData), - tls_size); + std::memmove(tls_base, tls_start, tls_size); + std::memmove(PVOID(target_tls->StartAddressOfRawData), tls_start, tls_size); VirtualProtect(target_tls, sizeof(*target_tls), PAGE_READWRITE, &old_protect); *target_tls = *source_tls;