Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //hidend
- #include <windows.h>
- #pragma comment(lib, "detours.lib")
- #include <detours.h>
- #include <iostream>
- DWORD samp_base = 0;
- bool bDetourMyself = false;
- const DWORD OFFSETS[6][2]{
- /*ChatInfo, AddMsg*/
- {0x21A0E4, 0x645A0}, // 037-r1 - 0
- {0x021A0EC, 0x64670}, // 037-r2 - 1
- {0x026E8C8, 0x679F0}, // 037-r3_1 - 2
- {0x026E9F8, 0x68130}, // 037-r4 - 3
- {0x026E9F8, 0x68170}, // 037-r4_2 -4
- {0x026EB80, 0x68170}, // 037-r5_1 - 5
- };
- int get_samp_version_id()
- {
- int version_current = -1;
- if (samp_base)
- {
- int version_id = *reinterpret_cast<int*>((char*)samp_base + 0x128);
- std::cout << "Version1: " << version_id << std::endl;
- switch (version_id) {
- case 0x5542F47A: // R1
- version_current = 0;
- break;
- case 0x59C30C94: // R2
- version_current = 1;
- break;
- default:
- version_id = *reinterpret_cast<int*>((char*)samp_base + 0x120);
- std::cout << "Version877: " << version_id << std::endl;
- switch (version_id) {
- case 0x5C0B4243: // R3
- version_current = 2;
- break;
- case 0x5DD606CD: // R4 - v1
- version_current = 3;
- break;
- case 0x6094ACAB: // R4 - v2
- version_current = 4;
- break;
- case 0x6372C39E: // R5, ni nos interesa pero meh
- version_current = 5;
- break;
- }
- }
- }
- std::cout << "Version2: " << version_current << std::endl;
- return version_current;
- }
- std::string WStringToString(const std::wstring& wstr) {
- if (wstr.empty()) return std::string();
- int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
- std::string strTo(size_needed, 0);
- WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
- return strTo;
- }
- void addMessageToChat(unsigned dwColor, const char* szMsg, ...)
- {
- int version = get_samp_version_id();
- std::cout << "Version3: " << version << std::endl;
- if (version == -1)
- return;
- DWORD chatInfoOffset = OFFSETS[version][0];
- DWORD addMsgOffset = OFFSETS[version][1];
- unsigned char red = static_cast<unsigned char>(rand() % 256);
- unsigned char green = static_cast<unsigned char>(rand() % 256);
- unsigned char blue = static_cast<unsigned char>(rand() % 256);
- // Combine the color components into a single unsigned integer
- unsigned newColor = (red << 16) | (green << 8) | blue;
- auto addMessage = reinterpret_cast<void(__thiscall*)(void* pChat, unsigned color, const char* message)>(samp_base + addMsgOffset);
- addMessage(*reinterpret_cast<void**>(samp_base + chatInfoOffset), newColor, szMsg);
- }
- static HMODULE(WINAPI* TrueLoadLibraryA)(LPCTSTR lpLibFileName) = LoadLibraryA;
- HMODULE WINAPI LoadLibraryA_replacement(_In_ LPCTSTR lpFileName)
- {
- std::cout << "LoadLibraryA_replacement" << std::endl;
- HMODULE res = TrueLoadLibraryA(lpFileName);
- if (strcmp("OPENGL32", lpFileName) != 0 && bDetourMyself)
- {
- addMessageToChat(-1, "LoadLibraryA_replacement!");
- addMessageToChat(-1, lpFileName);
- return res; //devolvemos null y paramos la inyeccion
- }
- return res; //original
- }
- static HMODULE(WINAPI* TrueLoadLibraryW)(LPCWSTR lpLibFileName) = LoadLibraryW;
- HMODULE WINAPI LoadLibraryW_replacement(LPCWSTR lpLibFileName)
- {
- HMODULE res = TrueLoadLibraryW(lpLibFileName);
- if (bDetourMyself) {
- std::cout << "LoadLibraryW_replacement" << std::endl;
- std::string libFileName = WStringToString(lpLibFileName); // Convert std::wstring to std::string
- addMessageToChat(-1, "LoadLibraryW_replacement");
- addMessageToChat(-1, libFileName.c_str());
- return res; //devolvemos null y paramos la inyeccion
- }
- return res; //original
- }
- int init()
- {
- std::cout << "init" << std::endl;
- samp_base = (DWORD)LoadLibraryA("samp.dll");
- bDetourMyself = true;
- while (true)
- {
- addMessageToChat(-1, "Hidend // Shaarawy // <3");
- std::cout << "mensaje!" << std::endl;
- Sleep(5000);
- }
- FreeLibraryAndExitThread(GetModuleHandle(NULL), 0);
- return 0;
- }
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
- {
- if (DetourIsHelperProcess()) {
- return TRUE;
- }
- switch (dwReasonForCall)
- {
- case DLL_PROCESS_ATTACH:
- //AllocConsole();
- //freopen("CONOUT$", "w", stdout);
- //std::cout << "injected" << std::endl;
- CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)init, NULL, NULL, NULL);
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourAttach(&(PVOID&)TrueLoadLibraryW, LoadLibraryW_replacement);
- DetourAttach(&(PVOID&)TrueLoadLibraryA, LoadLibraryA_replacement);
- DetourTransactionCommit();
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- case DLL_PROCESS_DETACH:
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourDetach(&(PVOID&)TrueLoadLibraryW, LoadLibraryW_replacement);
- DetourDetach(&(PVOID&)TrueLoadLibraryA, LoadLibraryA_replacement);
- DetourTransactionCommit();
- break;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement