Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung.
- #include "windows.h"
- #include <stdio.h>
- #include "Tribes.h"
- void patch_hook();
- void patch_jump1();
- void patch_jump2();
- //EXTERN_C BOOL WINAPI _DllMainCRTStartup(
- // HINSTANCE hInstDll, // handle to the DLL module
- // DWORD fdwReason, // reason for calling function
- // LPVOID lpvReserved // reserved
- //)
- BOOL APIENTRY DllMain( HMODULE hModule,
- DWORD fdwReason,
- LPVOID lpReserved
- )
- {
- switch (fdwReason)
- {
- case DLL_PROCESS_ATTACH:
- {
- patch_hook(); //the prinf function is hooked, gives us the letter and the text
- patch_jump1();
- patch_jump2();
- break;
- }
- case DLL_THREAD_ATTACH:
- {
- break;
- }
- case DLL_THREAD_DETACH:
- {
- break;
- }
- case DLL_PROCESS_DETACH:
- {
- break;
- }
- }
- return TRUE;
- }
- /* internal, get the correct target adress */
- unsigned int translateJMP(void * patchadress, void * targetadress)
- {
- unsigned int jmp = (char*)targetadress - (char*)patchadress - 5;
- return jmp;
- }
- void intercept()
- {
- Tribes::SetVariable("ChatMenu::visibleItem","");
- _asm
- {
- pop eax
- mov eax, 0x004517FB //where the jump would usually end
- jmp eax
- }
- }
- static const int __printf = 0x5AA747;
- int letter;
- char * strt;
- int lastmenu = 0;
- int currentmenu = 0;
- char** more;
- //bool addnext = true;
- //bool addnext = true;
- //void addMenuEntry()
- //{
- // _asm {
- // pushad
- // mov letter, eax;
- // mov strt, edx;
- // mov currentmenu, edi;
- // mov more, esi
- // }
- // if(*((((char*)(more))+7)))
- // Tribes::Echo("%s",more);
- // else
- // {
- // Tribes::Echo("%s","------------");
- // }
- void addMenuEntry()
- {
- _asm {
- pushad
- mov letter, eax;
- mov strt, edx;
- mov currentmenu, edi;
- mov more, esi
- }
- if(*((((char*)(more))+0x28)) | *((((char*)(more))+0x29)) | *((((char*)(more))+0x2A )) | *((((char*)(more))+0x2B)))
- {
- sprintf_s(Tribes::sprintBuffer, 32768, "%c,%s", letter, strt);
- Tribes::Echo("%s",Tribes::sprintBuffer);
- }
- else
- {
- sprintf_s(Tribes::sprintBuffer, 32768, "%c,%s", letter, strt);
- Tribes::Echo("%s",Tribes::sprintBuffer);
- Tribes::Echo("%s","------------");
- }
- //clear on new menu and add item
- if(currentmenu != lastmenu)
- {
- Tribes::Echo("%s","NewMenu");
- Tribes::SetVariable("ChatMenu::visibleItem","");
- sprintf_s(Tribes::sprintBuffer, 32768, "%s,%c,%s", Tribes::GetVariable("ChatMenu::visibleItem"), letter, strt);
- Tribes::SetVariable("ChatMenu::visibleItem",Tribes::sprintBuffer);
- lastmenu = currentmenu; //update currentmenu
- }
- _asm {
- popad
- }
- return;
- }
- void patch_hook()
- {
- //patch our interception hook
- void* address = (void*) 0x004517A5;
- unsigned int jmp = translateJMP(address,(void*)&addMenuEntry);
- char ptr[5];
- ptr[0] = 0xE8;
- ptr[1] = ((char*)&jmp)[0];
- ptr[2] = ((char*)&jmp)[1];
- ptr[3] = ((char*)&jmp)[2];
- ptr[4] = ((char*)&jmp)[3];
- DWORD dwOldProtect;
- if (!VirtualProtect ((LPVOID)address,
- 5,
- PAGE_READWRITE,
- &dwOldProtect
- ))
- {
- }
- else
- {
- //copy patch in
- memcpy(address, (void*)ptr, 5);
- //reset the protection
- VirtualProtect((LPVOID)address,5,dwOldProtect,NULL);
- }
- }
- void patch_jump1()
- {
- //patch our interception hook
- void* address = (void*) 0x00451638;
- unsigned int jmp = translateJMP(address,(void*)&intercept);
- jmp -= 1;
- char ptr[6];
- ptr[0] = 0x0F; //JE
- ptr[1] = 0x84; //JE
- ptr[2] = ((char*)&jmp)[0];
- ptr[3] = ((char*)&jmp)[1];
- ptr[4] = ((char*)&jmp)[2];
- ptr[5] = ((char*)&jmp)[3];
- DWORD dwOldProtect;
- if (!VirtualProtect ((LPVOID)address,
- 6,
- PAGE_READWRITE,
- &dwOldProtect
- ))
- {
- }
- else
- {
- //copy patch in
- memcpy(address, (void*)ptr, 6);
- //reset the protection
- VirtualProtect((LPVOID)address,6,dwOldProtect,NULL);
- }
- }
- void patch_jump2()
- {
- //patch our interception hook
- void* address = (void*) 0x00451642;
- unsigned int jmp = translateJMP(address,(void*)&intercept);
- jmp -= 1;
- char ptr[6];
- ptr[0] = 0x0F; //JE
- ptr[1] = 0x84; //JE
- ptr[2] = ((char*)&jmp)[0];
- ptr[3] = ((char*)&jmp)[1];
- ptr[4] = ((char*)&jmp)[2];
- ptr[5] = ((char*)&jmp)[3];
- DWORD dwOldProtect;
- if (!VirtualProtect ((LPVOID)address,
- 6,
- PAGE_READWRITE,
- &dwOldProtect
- ))
- {
- }
- else
- {
- //copy patch in
- memcpy(address, (void*)ptr, 6);
- //reset the protection
- VirtualProtect((LPVOID)address,6,dwOldProtect,NULL);
- }
- }
- //00451638 |. /0F84 BD010000 JE 004517FB
- //00451642 |. |0F84 B3010000 JE 004517FB
Add Comment
Please, Sign In to add comment