fork download
  1. bool LoadPE_DirectoryExists(LoadPE_CONTEXT* ctx, unsigned long id)
  2. {
  3. return (ctx->pPeHdr->OptionalHeader.NumberOfRvaAndSizes - 1) >= id
  4. && ctx->pPeHdr->OptionalHeader.DataDirectory[id].VirtualAddress;
  5. }
  6.  
  7. bool LoadPE_HasTLS(LoadPE_CONTEXT* ctx)
  8. {
  9. return LoadPE_DirectoryExists(ctx, IMAGE_DIRECTORY_ENTRY_TLS);
  10. }
  11.  
  12. DWORD LoadPE_GetTLS(LoadPE_CONTEXT* ctx)
  13. {
  14. return ctx->pPeHdr->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress;
  15. }
  16.  
  17. void LoadPE_ProcessTLS(LoadPE_CONTEXT* ctx)
  18. {
  19. if (LoadPE_HasTLS(ctx))
  20. {
  21. PIMAGE_TLS_DIRECTORY32 tls = PIMAGE_TLS_DIRECTORY32(ctx->pbRealImageBase + LoadPE_GetTLS(ctx));
  22. std::cout << "Callbacks: " << std::endl;
  23. PIMAGE_TLS_CALLBACK* cb_addr = (PIMAGE_TLS_CALLBACK *)(tls->AddressOfCallBacks);
  24. while (*cb_addr++)
  25. {
  26. std::cout << cb_addr << std::endl;
  27. }
  28.  
  29. PTEB teb = (PTEB)__readfsdword(0x18);
  30. teb->ThreadLocalStoragePointer = HeapAlloc(
  31. GetProcessHeap(),
  32. HEAP_ZERO_MEMORY,
  33. tls->EndAddressOfRawData - tls->StartAddressOfRawData
  34. );
  35.  
  36. auto data_begin = tls->StartAddressOfRawData;
  37. auto data_end = tls->EndAddressOfRawData;
  38. while (data_begin != data_end)
  39. {
  40. std::cout << *(DWORD*)data_begin << " at " << data_begin << std::endl;
  41. ((DWORD *)teb->ThreadLocalStoragePointer)[0] = data_begin;
  42. data_begin += 4;
  43. }
  44. }
  45. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:29: error: ‘LoadPE_CONTEXT’ was not declared in this scope
 bool LoadPE_DirectoryExists(LoadPE_CONTEXT* ctx, unsigned long id)
                             ^~~~~~~~~~~~~~
prog.cpp:1:45: error: ‘ctx’ was not declared in this scope
 bool LoadPE_DirectoryExists(LoadPE_CONTEXT* ctx, unsigned long id)
                                             ^~~
prog.cpp:1:50: error: expected primary-expression before ‘unsigned’
 bool LoadPE_DirectoryExists(LoadPE_CONTEXT* ctx, unsigned long id)
                                                  ^~~~~~~~
prog.cpp:1:66: error: expression list treated as compound expression in initializer [-fpermissive]
 bool LoadPE_DirectoryExists(LoadPE_CONTEXT* ctx, unsigned long id)
                                                                  ^
prog.cpp:7:20: error: ‘LoadPE_CONTEXT’ was not declared in this scope
 bool LoadPE_HasTLS(LoadPE_CONTEXT* ctx)
                    ^~~~~~~~~~~~~~
prog.cpp:7:36: error: ‘ctx’ was not declared in this scope
 bool LoadPE_HasTLS(LoadPE_CONTEXT* ctx)
                                    ^~~
prog.cpp:12:1: error: ‘DWORD’ does not name a type
 DWORD LoadPE_GetTLS(LoadPE_CONTEXT* ctx)
 ^~~~~
prog.cpp:17:24: error: variable or field ‘LoadPE_ProcessTLS’ declared void
 void LoadPE_ProcessTLS(LoadPE_CONTEXT* ctx)
                        ^~~~~~~~~~~~~~
prog.cpp:17:24: error: ‘LoadPE_CONTEXT’ was not declared in this scope
prog.cpp:17:40: error: ‘ctx’ was not declared in this scope
 void LoadPE_ProcessTLS(LoadPE_CONTEXT* ctx)
                                        ^~~
stdout
Standard output is empty