Small cleanup
This commit is contained in:
parent
fc65e498bb
commit
53891376af
@ -144,8 +144,10 @@ namespace loader
|
|||||||
get_optional_header()
|
get_optional_header()
|
||||||
->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress);
|
->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_size = source_tls->EndAddressOfRawData - source_tls->StartAddressOfRawData;
|
||||||
const auto tls_index = *reinterpret_cast<DWORD*>(target_tls->AddressOfIndex);
|
const auto tls_index = *reinterpret_cast<DWORD*>(target_tls->AddressOfIndex);
|
||||||
|
|
||||||
utils::hook::set<DWORD>(source_tls->AddressOfIndex, tls_index);
|
utils::hook::set<DWORD>(source_tls->AddressOfIndex, tls_index);
|
||||||
|
|
||||||
if (target_tls->AddressOfCallBacks)
|
if (target_tls->AddressOfCallBacks)
|
||||||
@ -154,14 +156,11 @@ namespace loader
|
|||||||
}
|
}
|
||||||
|
|
||||||
DWORD old_protect;
|
DWORD old_protect;
|
||||||
VirtualProtect(PVOID(target_tls->StartAddressOfRawData),
|
VirtualProtect(tls_start, tls_size, PAGE_READWRITE, &old_protect);
|
||||||
source_tls->EndAddressOfRawData - source_tls->StartAddressOfRawData, PAGE_READWRITE,
|
|
||||||
&old_protect);
|
|
||||||
|
|
||||||
auto* const tls_base = *reinterpret_cast<LPVOID*>(__readgsqword(0x58) + 8ull * tls_index);
|
auto* const tls_base = *reinterpret_cast<LPVOID*>(__readgsqword(0x58) + 8ull * tls_index);
|
||||||
std::memmove(tls_base, PVOID(source_tls->StartAddressOfRawData), tls_size);
|
std::memmove(tls_base, tls_start, tls_size);
|
||||||
std::memmove(PVOID(target_tls->StartAddressOfRawData), PVOID(source_tls->StartAddressOfRawData),
|
std::memmove(PVOID(target_tls->StartAddressOfRawData), tls_start, tls_size);
|
||||||
tls_size);
|
|
||||||
|
|
||||||
VirtualProtect(target_tls, sizeof(*target_tls), PAGE_READWRITE, &old_protect);
|
VirtualProtect(target_tls, sizeof(*target_tls), PAGE_READWRITE, &old_protect);
|
||||||
*target_tls = *source_tls;
|
*target_tls = *source_tls;
|
||||||
|
Loading…
Reference in New Issue
Block a user