Results 1 to 14 of 14

Thread: Using pointers to edit memory locationa? C++

  1. #1
    Join Date
    Oct 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Using pointers to edit memory locationa? C++

    Hey I started C++ a few weeks ago and I read into memory editing programs. I was like oh hey sounds simple I'd just do something like:

    Code:
    int *ptr;
    ptr=0x22ff77;
    *ptr=23;
    Or at least a version of this to change the value of 0x22ff77 to a number. Is it because its looking in local script memory or what?
    If someone could help me with this it would be appreciated.

    ~Ethien

  2. #2
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It should work, but for game hacking you should hook it first to a game, I think.
    ~Hermen

  3. #3
    Join Date
    Oct 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    When I first started this it wasn't for game hacking but I realize the potential. How would you hook this to a program anyways?

  4. #4
    Join Date
    Oct 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    By the way, I used this to check if the said memory was edited:
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int *first_val;
        int  test;
        test=10;
        int *ptr;
        ptr=&test;
        
        cout<<"Press enter to loop memory adress"<<endl;
        system("PAUSE");
        
        cout<<"You are using the memory adress of  "<<ptr<<" Wich has the  value of "<<*ptr<<" Is this correct?"<<endl;
        system("PAUSE");
        first_val=ptr;
        
        int i;
        for(i=0;i<1;i+=i)
        {
                         if(first_val!=ptr)
                         {
                                           break;
                                           cout<<"Memory was changed to "<<ptr<<endl;
                         }
        }
                         
    }
    and to change it I used:

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    
    int main()
    {
        int changed_val;
       
        int address;
        cout<<"Please type in a memory adress to change..."<<endl;
        
        
        cin>>address;
        *ptr =address;
        
       
        cout<<"What would you like to change this value to?"<<endl;
        
        cin>>changed_val;
        
        cout<<"You are about to change the value of the adress "<<*ptr<<" To "<<changed_val<<endl;
        
        system("PAUSE");
        *ptr=changed_val;
        
        
        
        return 0;
        
    }

  5. #5
    Join Date
    Jul 2008
    Location
    England
    Posts
    763
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Maybe you would need to change the Device Context.
    Last edited by Quickmarch; 04-09-2009 at 07:25 AM.
    lol

  6. #6
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    each program runs in its own address space, so you cant have one program editing memory of another program just like that.

    you need to make a part of your program run in the address space of another program.

    for windows, you may be intrested in dll injection.
    Join the Official SRL IRC channel. Learn how to Here.

  7. #7
    Join Date
    Oct 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    So is dll inject a way of hooking to a program?

  8. #8
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    depends on what you mean by hooking
    Join the Official SRL IRC channel. Learn how to Here.

  9. #9
    Join Date
    Oct 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Alright, so lets say I have a simple program called "holder.exe". It has a variable which is temp=10. Now I have another program that I want to hook to "Holder.exe" so I can change the value of temp.

  10. #10
    Join Date
    Dec 2007
    Location
    Somewhere in Idaho
    Posts
    480
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It is going to vary from OS to OS. Your program is given a virtual memory space. So two programs could have the addresses in them of 0x1000, that address is relative to the program itself.

    The windows API has a call that will return a pointer to data outside of the program (I don't remember what it is at this point). Just know that you are going to have to rely on your os's API in order to change data in another running program. (Unless you do a dll injection like Yakman suggests)

  11. #11
    Join Date
    Oct 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Alright thanks a lot, one last thing. I've tried to change the address of a pointer manually using hex, but this never works. whats the correct syntax?

  12. #12
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    you need to cast it

    Code:
    int* pointer = (int*)0xdeadbeef;
    
    *pointer = 5;
    Join the Official SRL IRC channel. Learn how to Here.

  13. #13
    Join Date
    Oct 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ok so (int*) is telling it that the hex is an address?

  14. #14
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    yes, but it doesnt have to be hex, the hex is just another way of representing a number

    Code:
    int* pointer = (int*)564564564;
    also works
    Join the Official SRL IRC channel. Learn how to Here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •