Skip to content

Commit

Permalink
another fix for the TlsSetValue hook
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 13, 2011
1 parent 6cbfd84 commit 4cdfc33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/wintasee/hooks/modulehooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ HOOKFUNC BOOL WINAPI MyFlsSetValue(DWORD dwFlsIndex, LPVOID lpFlsData) {
FlsRecursing = TRUE;
if (fseeds.find(dwFlsIndex) == fseeds.end()) {
_ptiddata ptd = (_ptiddata)FlsGetValue(dwFlsIndex);
debugprintf("FlsSetValue(%d,lpFlsData), set _tiddata structure at %08X",dwFlsIndex,ptd);
debuglog(LCF_THREAD,"FlsSetValue(%d,lpFlsData), set _tiddata structure at %08X",dwFlsIndex,ptd);
cmdprintf("WATCH: %08X,d,u,AutoRandSeed_Fiber_%d",&(ptd->_holdrand),dwFlsIndex);
fseeds[dwFlsIndex] = &(ptd->_holdrand);
}
Expand All @@ -841,7 +841,7 @@ HOOKFUNC BOOL WINAPI MyTlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) {
TlsRecursing = TRUE;
if (tseeds.find(dwTlsIndex) == tseeds.end()) {
_ptiddata ptd = (_ptiddata)TlsGetValue(dwTlsIndex);
debugprintf("TlsSetValue(%d,lpTlsValue), set _tiddata structure at %08X",dwTlsIndex,ptd);
debuglog(LCF_THREAD,"TlsSetValue(%d,lpTlsValue), set _tiddata structure at %08X",dwTlsIndex,ptd);
cmdprintf("WATCH: %08X,d,u,AutoRandSeed_Thread_%d",&(ptd->_holdrand),dwTlsIndex);
tseeds[dwTlsIndex] = &(ptd->_holdrand);
}
Expand Down
15 changes: 12 additions & 3 deletions src/wintasee/tramps/moduletramps.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,22 @@ TRAMPFUNC VOID WINAPI ExitProcess(DWORD dwExitCode) TRAMPOLINE_DEF_VOID
////#define DllGetClassObject TrampDllGetClassObject
//TRAMPFUNC HRESULT STDAPICALLTYPE TrampDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) TRAMPOLINE_DEF

#ifdef TlsSetValue
#error this shouldn't happen (TlsSetValue already defined)
#endif

// hack: because we need to call TlsSetValue/TlsGetValue potentially very early in the startup process,
// let the TlsSetValue/TlsGetValue macros act like trampolines both before and after their respective functions have been hooked.
// this might seem universally safer, but the reason we usually avoid this way of defining trampolines is because:
// if the function doesn't exist in the DLL, it will cause the game to immediately crash on startup.
// for example, it's not safe to do this for FlsSetValue/FlsGetValue because those don't exist on Windows XP.
TRAMPFUNC BOOL WINAPI TrampTlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) TRAMPOLINE_DEF_CUSTOM(return TlsSetValue(dwTlsIndex,lpTlsValue))
#define TlsSetValue TrampTlsSetValue
TRAMPFUNC BOOL WINAPI TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) TRAMPOLINE_DEF
TRAMPFUNC LPVOID WINAPI TrampTlsGetValue(DWORD dwTlsIndex) TRAMPOLINE_DEF_CUSTOM(return TlsGetValue(dwTlsIndex))
#define TlsGetValue TrampTlsGetValue

#define FlsSetValue TrampFlsSetValue
TRAMPFUNC BOOL WINAPI FlsSetValue(DWORD dwFlsIndex, LPVOID lpFlsData) TRAMPOLINE_DEF
#define TlsGetValue TrampTlsGetValue
TRAMPFUNC LPVOID WINAPI TlsGetValue(DWORD dwTlsIndex) TRAMPOLINE_DEF
#define FlsGetValue TrampFlsGetValue
TRAMPFUNC PVOID WINAPI FlsGetValue(DWORD dwFlsIndex) TRAMPOLINE_DEF

Expand Down

0 comments on commit 4cdfc33

Please sign in to comment.