Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // test.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <windows.h>
- #include <tchar.h>
- #include <stdio.h>
- #include <psapi.h>
- #include <TlHelp32.h>
- #include <iostream>
- #include <cstring>
- #include <tchar.h>
- using namespace std;
- // To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
- // and compile with -DPSAPI_VERSION=1
- TCHAR* PrintModules( DWORD processID, DWORD TibianicPID )
- {
- 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 0;
- // 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.
- if (processID == TibianicPID){
- _tprintf( TEXT("\t%s (0x%08X)\n"), szModName, hMods[i] );
- return szModName;
- }
- }
- }
- }
- // Release the handle to the process.
- CloseHandle( hProcess );
- return 0;
- }
- int main( void )
- {
- DWORD pAddress1;
- DWORD pAddress2; // This will store our value we read.
- DWORD pAddress3 = 0x00400000; // This will store our value we read.
- DWORD ModuleBase;
- DWORD offset0 = 0xF3090;
- DWORD offset1 = 0x378;
- DWORD offset2 = 0x218;
- DWORD offset3 = 0x10C;
- DWORD offset4 = 0x1C0;
- DWORD offset5 = 0x78;
- HWND hWnd = FindWindow( NULL , _T("Tibianic Client") );
- DWORD TibianicPID; //This will store our Process ID, used to read/write into the memory
- GetWindowThreadProcessId(hWnd, &TibianicPID); //Get the process id and place it in pid
- DWORD aProcesses[1024];
- DWORD cbNeeded;
- DWORD cProcesses;
- unsigned int i;
- // Get the list of process identifiers.
- if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
- return 1;
- // Calculate how many process identifiers were returned.
- cProcesses = cbNeeded / sizeof(DWORD);
- // Print the names of the modules for each process.
- for ( i = 0; i < cProcesses; i++ )
- {
- pAddress1 = (DWORD)PrintModules( aProcesses[i], TibianicPID );
- if(pAddress1 != 0)
- ModuleBase = pAddress1; // Get base address from pAddress1 here
- }
- cout << "pAddress1: " << pAddress1 << endl;
- cout << "pAddress3: " << pAddress3 << endl;
- /* Reading Memory & Opening process */
- HANDLE phandle = OpenProcess(PROCESS_VM_READ,0, TibianicPID); // Get permission to read
- if(!phandle){ // Once again, if it fails, tell us
- cout <<"Error message: " << GetLastError() << " Dvs Access denied" << endl;
- cin.get();
- return 0;
- }
- cout << "Base address is: " << pAddress3 << endl;
- ReadProcessMemory(phandle,(void*)(pAddress3+offset0),&pAddress3,sizeof(pAddress3),0);
- cout << "Value read is: " << pAddress3 << endl;
- ReadProcessMemory(phandle,(void*)(pAddress3+offset1),&pAddress3,sizeof(pAddress3),0);
- cout << "Value read is: " << pAddress3 << endl;
- ReadProcessMemory(phandle,(void*)(pAddress3+offset2),&pAddress3,sizeof(pAddress3),0);
- cout << "Value read is: " << pAddress3 << endl;
- ReadProcessMemory(phandle,(void*)(pAddress3+offset3),&pAddress3,sizeof(pAddress3),0);
- cout << "Value read is: " << pAddress3 << endl;
- ReadProcessMemory(phandle,(void*)(pAddress3+offset4),&pAddress3,sizeof(pAddress3),0);
- cout << "Value read is: " << pAddress3 << endl;
- ReadProcessMemory(phandle,(void*)(pAddress3+offset5),&pAddress3,sizeof(pAddress3),0);
- cout << "Value read is: " << pAddress3 << endl;
- ReadProcessMemory(phandle,(void*)(pAddress3),&pAddress3,sizeof(pAddress3),0);
- cout << "Value read is: " << pAddress3 << endl;
- ReadProcessMemory(phandle,(void*)(0x00A57830),&pAddress2,sizeof(pAddress2),0);
- cout << "Real value read is: " << pAddress2 << endl;
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment