GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Sep-2008, 10:19
astropirit astropirit is offline
New Member
 
Join Date: Aug 2008
Posts: 8
astropirit is on a distinguished road

Changing a value using a pointer.


Hi all
i have been having this annoying problem. I can change the value of an memory address. the problem is that the memory address changes every time the application restarts. Now i figured i would need to use a pointer. So i found a pointer that points to this address, but it has an offset.

lets say the address is: "04A96990"
and the offset is: "A0"
and lets say this points to...:"07b96964" // this is the address i want to modify.

How might one change this code to make it take advantage of the pointer and find the address and be able to modify it.

CPP / C++ / C Code:
#include <windows.h>
#include <tlhelp32.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>

bool ChangeMemVal(const char * ProcessName, LPVOID MemAddress, int NewVal, int size);

int main()
{
     printf("=== Pinball Trainer Example. Made by <your name here> ===\n\n");
     if(ChangeMemVal("PINBALL.EXE", (void*) 0xA90C62, 100000000, 4))
          printf("The score has been edited successfully.\n");
     else
          printf("An error occured while attempting edit the score.\n");
     system("PAUSE");
     return 0;
}


/* This function modifys a memory address according to its arguments.
   Arguments :
             ProcessName - the process we want to modify
             MemAddress - the memory address we want to modify
             NewVal - the value we want to change the memory address to
             size - the size of the memory address
   Returns :
           the success of the edit.
   */


bool ChangeMemVal(const char * ProcessName, LPVOID MemAddress, int NewVal, int size)
{
     HANDLE hProcessSnap;
     HANDLE hProcess = NULL;
     PROCESSENTRY32 pe32;    
     hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
     pe32.dwSize = sizeof( PROCESSENTRY32 );
     Process32First(hProcessSnap, &pe32);
     do
     {          
          if(!strcmp(pe32.szExeFile, ProcessName))
          {
               hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
               break;
          }
     }
     while(Process32Next(hProcessSnap, &pe32));
     CloseHandle( hProcessSnap );
     if(hProcess != NULL)
     {
          WriteProcessMemory(hProcess, MemAddress, &NewVal, size, NULL);     // write the value          
          CloseHandle(hProcess);    
          return true;
     }    
     return false;
}

Help would be greately apreciated.


Astro
Last edited by admin : 19-Sep-2008 at 22:58. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 20-Sep-2008, 11:54
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Changing a value using a pointer.


Did you ever get the "number of players' successfully changed in that last thread? gidforums.com/t-19030.html
Where did you get the values you stated above?
The statements you make about offset don't seem right to me.
Code:
Some math on the values given in the post show: 0x04A96990 + 0xA0 = 0x04a96a30 and NOT 0x07b96964 The 'offset' between those two addresses would be: 0x07b96964 - 0x04A96990 = 0x030fffd4
Am I confused? (yes)
If you really want to learn some C or C++ , here's is how I computed those values:
CPP / C++ / C Code:
#include <iostream> 
#include <iomanip>
using namespace std;

int main(void)
{
  cout <<"\nSome math on the values given in the post show: \n";

  cout <<"0x04A96990 + 0xA0 = 0x"<< setfill ('0') << setw (8) << hex
       << (0x04A96990 + 0xA0) << " and NOT 0x07b96964\n";
  cout <<"\nThe 'offset' between those two addresses would be: \n" <<
         "0x07b96964 - 0x04A96990 = 0x" << setfill ('0') << setw (8) << hex 
       << (0x07b96964 - 0x04A96990)
          << endl << endl;
  return 0;
}
  #3  
Old 23-Sep-2008, 12:53
astropirit astropirit is offline
New Member
 
Join Date: Aug 2008
Posts: 8
astropirit is on a distinguished road

Re: Changing a value using a pointer.


yes i figured out how to do the thing in the last post.
and i know those dont add up right, should have mentioned those. those are arbitory values, i do not have th real values with me, i wrote this in school. and my values are at my personal computer.
  #4  
Old 24-Sep-2008, 00:40
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Changing a value using a pointer.


well, if you could change the value in the last post try to do the same thing for this new address.
Do the math before or within the call to ChangeMemVal()
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MACRO to detect big / little endian ahbi82 C Programming Language 14 26-Aug-2007 11:33
Query on displaying pointers emanresu C Programming Language 6 06-Dec-2006 12:01
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 18:36
Pointer values changing unexpectedly spudtheimpaler C Programming Language 11 04-Mar-2004 17:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:52.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.