CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 32
  1. #16
    Join Date
    May 2009
    Posts
    140

    Re: how to read memory address and get its value

    if i was trying to cheat i'd just use chatengine and edit values or download a cheat, i'm writing an anticheat with some extenstion feautures for the game, yes i'm missing some simple C++ concepts or more than some, i work like i try to get and understand thing by thing i need in process, hope you help me a little ^^

  2. #17
    Join Date
    Feb 2008
    Posts
    22

    Re: how to read memory address and get its value

    Use typecasting:

    If "char* p" is the character pointer, then something like

    Code:
    int n = *( (int *) p );
    is what you should be looking at.

  3. #18
    Join Date
    May 2009
    Posts
    140

    Re: how to read memory address and get its value

    Quote Originally Posted by S__B View Post
    Use typecasting:

    If "char* p" is the character pointer, then something like

    Code:
    int n = *( (int *) p );
    is what you should be looking at.
    thx it works)

    but now i need to write data back to memory and have problems writing int into memory =\
    how can i write int value into memory? i think that can be done with WriteProcessMemory but is it a good way?
    Last edited by Owyn; May 13th, 2009 at 10:39 AM.

  4. #19
    Join Date
    Apr 1999
    Posts
    27,449

    Re: how to read memory address and get its value

    Quote Originally Posted by Owyn View Post
    if i was trying to cheat i'd just use chatengine and edit values or download a cheat, i'm writing an anticheat with some extenstion feautures for the game, yes i'm missing some simple C++ concepts or more than some, i work like i try to get and understand thing by thing i need in process, hope you help me a little ^^
    Here is the problem with all of this:

    I've noticed that in every thread for the past few years, anyone who wants to try and read and write to a specific memory address are newcomers to CodeGuru (less than 40 posts), and always know very little, if any, C or C++. Why is that? Similarly, why have none of the persons who have been here for a while ever ask these kind of questions you're asking?

    That's why what you're asking for will always lead to suspicion. Writing to certain hard-coded memory addresses is how games are cheated, applications compromised, etc. Unless you have a hardware device, and you are writing a driver for it,

    1) You would have specified the device you're writing to, or at least make an attempt to give more detail.

    2) Even so, writing a device driver requires a prerequisite knowledge of C or C++. In other words, a programmer who wants to do what you want already knows how to do it.

    Many here are developers of commercial applications and games. The last thing we want to do is give advice that either compromises one of our own programs, or someone elses. Writing to certain, hardcoded memory locations sets off red flags (at least to me) that something suspicious is going on, as Lindley stated, doing so is very rarely done.

    Regards,

    Paul McKenzie

  5. #20
    Join Date
    May 2009
    Posts
    140

    Re: how to read memory address and get its value

    ok, so how'd i dehardcode it? mb that'd would be better and faster and more stable i dunno

  6. #21
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: how to read memory address and get its value

    Typically you'd query some function or existing pointer in the program to get the address you needed.

  7. #22
    Join Date
    May 2009
    Posts
    140

    Re: how to read memory address and get its value

    it's not really a function it's an value for checking string length, i need to enlarge it cuz utf-8 characters takes x2 more space than ASCII ones

  8. #23
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: how to read memory address and get its value

    UTF-8 strings can take anywhere from 1x to 4x the size of an ASCII string of equivalent length, actually. It's variable. Besides, if the program isn't built from the ground-up to support UTF-8, I very much doubt changing one variable will make it work.

  9. #24
    Join Date
    May 2009
    Posts
    140

    Re: how to read memory address and get its value

    that's not the deal, program wasn't made to use utf-8 but it can display it, problem is chat system that counts letters, hooking one letter being inputted and replacing it with utf-8 one works fine until 2nd letter is entered, letter counter counts just one byte while letter takes two and tries to write new letter on the top of an old one, all i need to do is add 1 to counter every time letter is entered but i can't figure out how to write int value to 4 byte value of memory address containing the counter data

  10. #25
    Join Date
    Feb 2005
    Posts
    2,160

    Re: how to read memory address and get its value

    Quote Originally Posted by Owyn View Post
    thx it works)

    but now i need to write data back to memory and have problems writing int into memory =\
    how can i write int value into memory? i think that can be done with WriteProcessMemory but is it a good way?
    S__B has shown you everything you need to know. I'll break it down for you:
    Code:
    void *p;
    p is a pointer (we don't have a clue what it should point to).

    Code:
    (int *)p;
    This casts it to a "pointer to int" meaning (on 32 bit machines) the memory at that address occupies 4 bytes.

    Code:
    *((int *)p);
    This dereferences the pointer meaning that instead of the address, we want the actual value stored at that address. At his point, the whole expression is identical to int and can be used interchangeably as such:

    Code:
    int a = *((int *)p);  //copy it's value to another int
    
    int b=100;
    
    *((int *)p) = b;  //copy the value of b to our dereferenced pointer
    
    *((int *)p) = 100;  //cut out the middle-man
    As Paul explained though, none of this should be necessary. You're going about it from the wrong perspective. There's certainly an easier, safer, more understandable way to achieve whatever it is you're trying to achieve. We won't know how to help you without more details.

  11. #26
    Join Date
    May 2009
    Posts
    140

    Re: how to read memory address and get its value

    Quote Originally Posted by hoxsiew View Post
    S__B has shown you everything you need to know. I'll break it down for you:
    Code:
    void *p;
    p is a pointer (we don't have a clue what it should point to).

    Code:
    (int *)p;
    This casts it to a "pointer to int" meaning (on 32 bit machines) the memory at that address occupies 4 bytes.

    Code:
    *((int *)p);
    This dereferences the pointer meaning that instead of the address, we want the actual value stored at that address. At his point, the whole expression is identical to int and can be used interchangeably as such:

    Code:
    int a = *((int *)p);  //copy it's value to another int
    
    int b=100;
    
    *((int *)p) = b;  //copy the value of b to our dereferenced pointer
    
    *((int *)p) = 100;  //cut out the middle-man
    As Paul explained though, none of this should be necessary. You're going about it from the wrong perspective. There's certainly an easier, safer, more understandable way to achieve whatever it is you're trying to achieve. We won't know how to help you without more details.
    ok, now i know what pointers are and how to use them and i have read http://www.cplusplus.com/doc/tutorial/pointers/ but still.... how to specify memory address to which pointer points?
    Last edited by Owyn; May 13th, 2009 at 01:17 PM.

  12. #27
    Join Date
    Apr 2008
    Posts
    725

    Re: how to read memory address and get its value

    Quote Originally Posted by Owyn View Post
    ok, now i know what pointers are and how to use them and i have read http://www.cplusplus.com/doc/tutorial/pointers/ but still.... how to specify memory address to which pointer points?
    Code:
    void* myPtr;
    
    myPtr = (void*)0x336288; // for example
    
    int x = *reinterpret_cast<int*>(myPtr);

  13. #28
    Join Date
    May 2009
    Posts
    140

    Re: how to read memory address and get its value

    Quote Originally Posted by Amleto View Post
    Code:
    void* myPtr;
    
    myPtr = (void*)0x336288; // for example
    
    int x = *reinterpret_cast<int*>(myPtr);
    omg that really did it xD thx thx thx thx thx and now i can allocate pointers to addresses i read from, that would be better than reading them everytime yes?
    Last edited by Owyn; May 13th, 2009 at 01:59 PM.

  14. #29
    Join Date
    Apr 2008
    Posts
    725

    Re: how to read memory address and get its value

    every time you 'read from a pointer' you read the memory location pointed at. if the data that the memory contains is changed between different 'read from pointer' times, then you will get different answers back.

  15. #30
    Join Date
    Jun 2015
    Posts
    1

    Re: how to read memory address and get its value

    memcpy (txt, (char*)(0xfeafe000), sizeof(txt));

    i have used it and got a segmentation fault.

    *******************************
    progarm recieved signal SIGSEV,segmentaion fault.
    **********************************

    why this happens??

Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured