-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from LordNoteworthy/Noteworthy
add TLS callback trick
- Loading branch information
Showing
7 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "TLS_callbacks.h" | ||
|
||
// The Tread Local Storage (TLS) callback is called before the execution of the EntryPoint of the application | ||
// Malware takes advantages to perform anti-debug and anti-vm checks. | ||
// Their could be more than one callback, and sometimes, inside one call back, one can create one in the fly. | ||
|
||
VOID WINAPI tls_callback(PVOID hModule, DWORD dwReason, PVOID pContext) | ||
{ | ||
if (dwReason == DLL_THREAD_ATTACH) | ||
{ | ||
// This will be loaded in each DLL thread attach | ||
// MessageBox(0, _T("I am running from a TLS callbacks, did you see that?"), _T("DLL_THREAD_ATTACH"), 0); | ||
} | ||
|
||
if (dwReason == DLL_PROCESS_ATTACH) | ||
{ | ||
MessageBox(0, _T("I am running from a TLS callbacks, did you see that?"), _T("DLL_PROCESS_ATTACH"), 0); | ||
} | ||
} | ||
|
||
#ifdef _WIN64 | ||
#pragma comment (linker, "/INCLUDE:_tls_used") | ||
#pragma comment (linker, "/INCLUDE:tls_callback_func") | ||
#else | ||
#pragma comment (linker, "/INCLUDE:__tls_used") | ||
#pragma comment (linker, "/INCLUDE:_tls_callback_func") | ||
#endif | ||
|
||
|
||
#ifdef _WIN64 | ||
#pragma const_seg(".CRT$XLF") | ||
EXTERN_C const | ||
#else | ||
#pragma data_seg(".CRT$XLF") | ||
EXTERN_C | ||
#endif | ||
|
||
PIMAGE_TLS_CALLBACK tls_callback_func = tls_callback; | ||
|
||
#ifdef _WIN64 | ||
#pragma const_seg() | ||
#else | ||
#pragma data_seg() | ||
#endif //_WIN64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include <Windows.h> | ||
#include <tchar.h> | ||
|
||
VOID WINAPI tls_callback(PVOID hModule, DWORD dwReason, PVOID pContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters