Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Simple trainer for dota. Can currently only change HP of abaddon.
- * Code is based of the C++ trainer code from Fleep
- * Download the original code from: http://guidedhacking.com/attachment.php?attachmentid=3473&d=1445714125
- * Link to the tutorial: http://guidedhacking.com/showthread.php?3-C-HOW-TO-HACK-any-game-TUTORIAL-Trainer-amp-DLL-Injection-DIFFICULTY-2-10
- */
- #include <iostream>
- #include <Windows.h>
- #include <string>
- #include <ctime> // needed for our timer clock
- #include <windows.h>
- #include <tchar.h>
- #include <stdio.h>
- #include <psapi.h>
- #include <string.h>
- void WriteToMemory(HANDLE hProcHandle);
- DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress);
- //CREATES the string used to determine the name of our target window e.g. Calculator
- std::string GameName = "Dota 2";
- LPCWSTR LGameWindow = L"Dota 2"; //<- MAKE SURE it matches the window name
- std::string GameStatus;
- //FUNCTION PROTOTYPES
- bool IsGameAvail;
- bool UpdateOnNextRun; //used to update the display menu only when something changed
- //-------HP VARS--------
- //number we are going to overwrite the current hp with in bytes
- bool HPStatus; // used to DEFine wether HP is on or not
- BYTE HPValue[] = {0x28,0xA,0x0,0x0}; // writing bytes into memory. This value here corresponds to 2600
- DWORD HPBaseAddress = {0x23CF62E0}; // should be server.dll+14E62E0 , this is just an example value
- DWORD HPOffsets[] = {0x0, 0xBC}; //3 LEVEL pointer
- bool addedOffset; //used to check if the 14E62E0 is already added to the adress of server.dll and stored in HPBaseAddress
- //original function from https://msdn.microsoft.com/en-us/library/ms682621%28v=vs.85%29.aspx
- int PrintModules( DWORD processID )
- {
- HMODULE hMods[1024];
- HANDLE hProcess;
- DWORD cbNeeded;
- unsigned int i;
- // Print the process identifier.
- printf( "\nProcess ID: %u\n", processID );
- // Get a handle to the process.
- hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
- PROCESS_VM_READ,
- FALSE, processID );
- if (NULL == hProcess)
- return 1;
- // Get a list of all the modules in this process.
- if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
- {
- for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
- {
- TCHAR szModName[MAX_PATH];
- // Get the full path to the module's file.
- if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
- sizeof(szModName) / sizeof(TCHAR)))
- {
- // Print the module name and handle value.
- std::wstring getDLLstr(szModName);
- if( getDLLstr.find(L"server.dll") != std::wstring::npos){ //we need the server.dll memory adresss
- _tprintf( TEXT("\t%s (0x%08X)\n"), szModName, hMods[i] );
- std::cout << hMods[i] << std::endl;
- HMODULE addtoThis = HMODULE(0x14E62E0);
- std::cout << (int)hMods[i] + 0x14E62E0 << std::endl;
- if( addedOffset == false){
- addedOffset = true;
- std::cout << "before extra offset:" << HPBaseAddress << std::endl;
- //add 0x14E62E0 to the server.dll memory adress to get the abaddon hp memory adress
- HPBaseAddress = (DWORD)((int)hMods[i] + 0x14E62E0);
- }
- std::cout << "after extra offset:" << HPBaseAddress << std::endl;
- //char getHex = ( "(0x%08X)" , hMods[i] );
- }
- }
- }
- }
- // Release the handle to the process.
- CloseHandle( hProcess );
- return 0;
- }
- int main()
- {
- addedOffset = false;
- //Declare our handles as NULL to avoid crashes when closing if they were unused e.g. player starts trainer and closes it before doing any cheats
- HWND hGameWindow = NULL;
- int timeSinceLastUpdate = clock(); //forces status update every x seconds
- int GameAvailTMR = clock();
- int OnePressTMR;//used to limit keys input to only one per x ms
- DWORD dwProcId = NULL;
- HANDLE hProcHandle = NULL;
- UpdateOnNextRun = true;
- std::string sHPStatus;
- sHPStatus = "OFF";
- OnePressTMR = clock();
- while(!GetAsyncKeyState(VK_INSERT)) //Key is not = 'INSERT'
- {
- //Does a series of checks every x ms and
- //checks that the game is available and capable of being
- //written to, if thats the case we write declare it available
- //otherwise we report where it went wrong
- //e.g. if game is closed we make things unavailable, or if its opened
- //we make options available again
- if(clock() - GameAvailTMR > 100)
- {
- GameAvailTMR = clock();
- //Declare game unavailable by default
- //if it is available then it will change immediately
- IsGameAvail = false;
- //Check a valid window is available
- // Get Window Handle
- hGameWindow = FindWindow( NULL, LGameWindow);
- if(hGameWindow)
- {
- GetWindowThreadProcessId( hGameWindow, &dwProcId );
- //If it is a valid id we continue to try and open the process
- if( dwProcId != 0 )
- {
- // Get Process Handle
- hProcHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwProcId );
- if( hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL )
- {
- GameStatus = "Failed to open process for valid handle";
- }
- else
- {
- GameStatus = "Dota 2 Ready to hack";
- IsGameAvail = true;
- }
- }
- else GameStatus = "Failed to obtain process id";
- }
- else GameStatus = "Dota 2 NOT FOUND";
- //if UpdateNextRun is called or a number of seconds without updates have gone by an auto update is done
- //to make sure game is available etc.
- if(UpdateOnNextRun || clock() - timeSinceLastUpdate > 5000)
- {
- system("cls");
- std::cout << "----------------------------------------------------" << std::endl;
- std::cout << " Example Dota 2 trainer" << std::endl;
- std::cout << "----------------------------------------------------" << std::endl << std::endl;
- std::cout << "GAME STATUS:"<< GameStatus <<" " << std::endl << std::endl;
- std::cout << "[F1] Abaddon always 2600 hp -> "<< sHPStatus <<" <-" << std::endl<< std::endl;
- //std::cout << "[F2] Unlimited Health and armor ->" << sHealthStatus << "<-" << std::endl<< std::endl;
- std::cout << "[INSERT] Exit" << std::endl;
- PrintModules( dwProcId );
- UpdateOnNextRun = false;
- timeSinceLastUpdate = clock();
- }
- if(IsGameAvail)
- {
- WriteToMemory(hProcHandle);
- }
- }
- //Stops Keys from being spammed e.g. only allow them to be pressed every x milliseconds
- if(clock() - OnePressTMR > 400)
- {
- if(IsGameAvail)
- {
- //DETECTS WHICH KEYS HAVE BEEN PRESSED IN order to turn cheats on and off
- if(GetAsyncKeyState(VK_F1))
- {
- OnePressTMR = clock();
- //Reverts the HP status e.g. from true to false and vice versa
- HPStatus = !HPStatus;
- UpdateOnNextRun = true;
- //changes the text to update on next display
- if(HPStatus)sHPStatus = "ON";
- else sHPStatus = "OFF";
- }
- }
- }
- }
- //Close any handles once the program is over
- CloseHandle( hProcHandle );
- CloseHandle(hGameWindow);
- //Returns that action was completed successfuly
- return ERROR_SUCCESS;
- }
- //Handles Dynamic memory allocation
- //Receives how high the pointer level is e.g. 4 levels and from that calculates the initial address
- //the offset values and the memory addresses for those offsets
- DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
- {
- //DECLARE BASE ADDRESS
- DWORD pointer = BaseAddress; // Declare a pointer of DWORD
- //USED TO output the contents in the pointer
- DWORD pTemp;
- DWORD pointerAddr;
- for(int i = 0; i < PointerLevel; i ++)
- {
- if(i == 0)
- {
- ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, 4, NULL);
- }
- //add first offset to that address
- pointerAddr = pTemp + Offsets[i]; // Set p1 to content of p + offset
- //Read memory one more time and exit the loop
- ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, 4, NULL);
- }
- return pointerAddr;
- }
- void WriteToMemory(HANDLE hProcHandle)
- {
- if(HPStatus)
- {
- DWORD HPAddressToWrite = FindDmaAddy(2, hProcHandle, HPOffsets, HPBaseAddress);
- WriteProcessMemory( hProcHandle, (BYTE*)HPAddressToWrite, &HPValue, sizeof(HPValue), NULL);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement