Advertisement
Hidend

Untitled

May 9th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. //hidend
  2. #include <windows.h>
  3. #pragma comment(lib, "detours.lib")
  4. #include <detours.h>
  5. #include <iostream>
  6.  
  7. DWORD samp_base = 0;
  8. bool bDetourMyself = false;
  9.  
  10. const DWORD OFFSETS[6][2]{
  11. /*ChatInfo, AddMsg*/
  12. {0x21A0E4, 0x645A0}, // 037-r1 - 0
  13. {0x021A0EC, 0x64670}, // 037-r2 - 1
  14. {0x026E8C8, 0x679F0}, // 037-r3_1 - 2
  15. {0x026E9F8, 0x68130}, // 037-r4 - 3
  16. {0x026E9F8, 0x68170}, // 037-r4_2 -4
  17. {0x026EB80, 0x68170}, // 037-r5_1 - 5
  18. };
  19.  
  20. int get_samp_version_id()
  21. {
  22. int version_current = -1;
  23.  
  24. if (samp_base)
  25. {
  26. int version_id = *reinterpret_cast<int*>((char*)samp_base + 0x128);
  27. std::cout << "Version1: " << version_id << std::endl;
  28. switch (version_id) {
  29. case 0x5542F47A: // R1
  30. version_current = 0;
  31. break;
  32. case 0x59C30C94: // R2
  33. version_current = 1;
  34. break;
  35. default:
  36. version_id = *reinterpret_cast<int*>((char*)samp_base + 0x120);
  37. std::cout << "Version877: " << version_id << std::endl;
  38.  
  39. switch (version_id) {
  40. case 0x5C0B4243: // R3
  41. version_current = 2;
  42. break;
  43. case 0x5DD606CD: // R4 - v1
  44. version_current = 3;
  45. break;
  46. case 0x6094ACAB: // R4 - v2
  47. version_current = 4;
  48. break;
  49. case 0x6372C39E: // R5, ni nos interesa pero meh
  50. version_current = 5;
  51. break;
  52. }
  53. }
  54. }
  55. std::cout << "Version2: " << version_current << std::endl;
  56. return version_current;
  57. }
  58.  
  59. std::string WStringToString(const std::wstring& wstr) {
  60. if (wstr.empty()) return std::string();
  61. int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
  62. std::string strTo(size_needed, 0);
  63. WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
  64. return strTo;
  65. }
  66.  
  67.  
  68. void addMessageToChat(unsigned dwColor, const char* szMsg, ...)
  69. {
  70. int version = get_samp_version_id();
  71. std::cout << "Version3: " << version << std::endl;
  72. if (version == -1)
  73. return;
  74.  
  75. DWORD chatInfoOffset = OFFSETS[version][0];
  76. DWORD addMsgOffset = OFFSETS[version][1];
  77.  
  78. unsigned char red = static_cast<unsigned char>(rand() % 256);
  79. unsigned char green = static_cast<unsigned char>(rand() % 256);
  80. unsigned char blue = static_cast<unsigned char>(rand() % 256);
  81.  
  82. // Combine the color components into a single unsigned integer
  83. unsigned newColor = (red << 16) | (green << 8) | blue;
  84. auto addMessage = reinterpret_cast<void(__thiscall*)(void* pChat, unsigned color, const char* message)>(samp_base + addMsgOffset);
  85. addMessage(*reinterpret_cast<void**>(samp_base + chatInfoOffset), newColor, szMsg);
  86. }
  87.  
  88.  
  89. static HMODULE(WINAPI* TrueLoadLibraryA)(LPCTSTR lpLibFileName) = LoadLibraryA;
  90. HMODULE WINAPI LoadLibraryA_replacement(_In_ LPCTSTR lpFileName)
  91. {
  92. std::cout << "LoadLibraryA_replacement" << std::endl;
  93. HMODULE res = TrueLoadLibraryA(lpFileName);
  94. if (strcmp("OPENGL32", lpFileName) != 0 && bDetourMyself)
  95. {
  96. addMessageToChat(-1, "LoadLibraryA_replacement!");
  97. addMessageToChat(-1, lpFileName);
  98. return res; //devolvemos null y paramos la inyeccion
  99. }
  100. return res; //original
  101. }
  102.  
  103.  
  104. static HMODULE(WINAPI* TrueLoadLibraryW)(LPCWSTR lpLibFileName) = LoadLibraryW;
  105. HMODULE WINAPI LoadLibraryW_replacement(LPCWSTR lpLibFileName)
  106. {
  107. HMODULE res = TrueLoadLibraryW(lpLibFileName);
  108. if (bDetourMyself) {
  109. std::cout << "LoadLibraryW_replacement" << std::endl;
  110. std::string libFileName = WStringToString(lpLibFileName); // Convert std::wstring to std::string
  111. addMessageToChat(-1, "LoadLibraryW_replacement");
  112. addMessageToChat(-1, libFileName.c_str());
  113. return res; //devolvemos null y paramos la inyeccion
  114. }
  115.  
  116. return res; //original
  117. }
  118.  
  119.  
  120. int init()
  121. {
  122. std::cout << "init" << std::endl;
  123. samp_base = (DWORD)LoadLibraryA("samp.dll");
  124. bDetourMyself = true;
  125. while (true)
  126. {
  127. addMessageToChat(-1, "Hidend // Shaarawy // <3");
  128. std::cout << "mensaje!" << std::endl;
  129. Sleep(5000);
  130. }
  131. FreeLibraryAndExitThread(GetModuleHandle(NULL), 0);
  132. return 0;
  133. }
  134.  
  135. BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
  136. {
  137. if (DetourIsHelperProcess()) {
  138. return TRUE;
  139. }
  140. switch (dwReasonForCall)
  141. {
  142. case DLL_PROCESS_ATTACH:
  143. //AllocConsole();
  144. //freopen("CONOUT$", "w", stdout);
  145. //std::cout << "injected" << std::endl;
  146. CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)init, NULL, NULL, NULL);
  147.  
  148. DetourTransactionBegin();
  149. DetourUpdateThread(GetCurrentThread());
  150. DetourAttach(&(PVOID&)TrueLoadLibraryW, LoadLibraryW_replacement);
  151. DetourAttach(&(PVOID&)TrueLoadLibraryA, LoadLibraryA_replacement);
  152. DetourTransactionCommit();
  153. break;
  154. case DLL_THREAD_ATTACH:
  155. break;
  156. case DLL_THREAD_DETACH:
  157. break;
  158. case DLL_PROCESS_DETACH:
  159. DetourTransactionBegin();
  160. DetourUpdateThread(GetCurrentThread());
  161. DetourDetach(&(PVOID&)TrueLoadLibraryW, LoadLibraryW_replacement);
  162. DetourDetach(&(PVOID&)TrueLoadLibraryA, LoadLibraryA_replacement);
  163. DetourTransactionCommit();
  164. break;
  165. }
  166. return TRUE;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement