mirror of
https://github.com/x64dbg/x64dbg.git
synced 2024-11-26 22:30:22 +00:00
Introduce reusable TLS in x64dbg.dll
This commit is contained in:
parent
5ec6023cac
commit
6e976ab67b
@ -5,10 +5,13 @@
|
||||
*/
|
||||
|
||||
#include "debugger.h"
|
||||
#include "threading.h"
|
||||
|
||||
extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||||
{
|
||||
if(fdwReason == DLL_PROCESS_ATTACH)
|
||||
switch(fdwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
hInst = hinstDLL;
|
||||
|
||||
@ -27,9 +30,12 @@ extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
|
||||
szProgramDir[len] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-disablethreadlibrarycalls
|
||||
DisableThreadLibraryCalls(hinstDLL);
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -145,3 +145,48 @@ void SectionLockerGlobal::Deinitialize()
|
||||
|
||||
m_Initialized = false;
|
||||
}
|
||||
|
||||
static DWORD gTlsIndex = TLS_OUT_OF_INDEXES;
|
||||
|
||||
TLSData::TLSData()
|
||||
{
|
||||
moduleHashLower.reserve(MAX_MODULE_SIZE);
|
||||
}
|
||||
|
||||
bool TLSData::notify(DWORD fdwReason)
|
||||
{
|
||||
switch(fdwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
gTlsIndex = TlsAlloc();
|
||||
return gTlsIndex != TLS_OUT_OF_INDEXES;
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
{
|
||||
auto data = (TLSData*)TlsGetValue(gTlsIndex);
|
||||
delete data;
|
||||
}
|
||||
return true;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
auto data = (TLSData*)TlsGetValue(gTlsIndex);
|
||||
delete data;
|
||||
TlsFree(gTlsIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TLSData* TLSData::get()
|
||||
{
|
||||
auto data = (TLSData*)TlsGetValue(gTlsIndex);
|
||||
if(data == nullptr)
|
||||
{
|
||||
data = new TLSData();
|
||||
TlsSetValue(gTlsIndex, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef _THREADING_H
|
||||
#define _THREADING_H
|
||||
#pragma once
|
||||
|
||||
#include "_global.h"
|
||||
|
||||
@ -256,4 +255,14 @@ private:
|
||||
using Internal = SectionLockerGlobal;
|
||||
};
|
||||
|
||||
#endif // _THREADING_H
|
||||
struct TLSData
|
||||
{
|
||||
String moduleHashLower;
|
||||
|
||||
TLSData();
|
||||
TLSData(const TLSData &) = delete;
|
||||
TLSData & operator=(const TLSData &) = delete;
|
||||
|
||||
static bool notify(DWORD fdwReason);
|
||||
static TLSData* get();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user