Skip to content

Instantly share code, notes, and snippets.

@merces
Last active February 27, 2024 04:44
Show Gist options
  • Save merces/1336cd4739cb1368efed to your computer and use it in GitHub Desktop.
Save merces/1336cd4739cb1368efed to your computer and use it in GitHub Desktop.
TLS callback implementation in C
#include <stdio.h>
#include <windows.h>
void NTAPI tls_callback(void* DllHandle, DWORD Reason, void* Reserved)
{
if (Reason == DLL_PROCESS_ATTACH)
{
//MessageBox(0, L"Cheguei primeiro! ^^", L"Exemplo de TLS callback", MB_ICONEXCLAMATION);
HWND hnd;
ShellExecute(hnd, NULL, L"calc.exe", NULL, NULL, SW_SHOWNORMAL);
Sleep(1000);
}
}
#pragma comment (linker, "/INCLUDE:__tls_used")
#pragma comment (linker, "/INCLUDE:__xl_b")
#pragma data_seg(".CRT$XLB")
EXTERN_C
PIMAGE_TLS_CALLBACK _xl_b = tls_callback;
#pragma data_seg()
int main(void)
{
printf("Eu sou a main! O.o\nwww.mentebinaria.com.br\nPressione ENTER para continuar...");
(void) getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment