|
-
May 13th, 2009, 08:34 AM
#16
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 ^^
-
May 13th, 2009, 08:58 AM
#17
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.
-
May 13th, 2009, 09:21 AM
#18
Re: how to read memory address and get its value
 Originally Posted by S__B
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.
-
May 13th, 2009, 11:57 AM
#19
Re: how to read memory address and get its value
 Originally Posted by Owyn
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
-
May 13th, 2009, 12:04 PM
#20
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
-
May 13th, 2009, 12:06 PM
#21
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.
-
May 13th, 2009, 12:09 PM
#22
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
-
May 13th, 2009, 12:18 PM
#23
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.
-
May 13th, 2009, 12:24 PM
#24
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
-
May 13th, 2009, 12:45 PM
#25
Re: how to read memory address and get its value
 Originally Posted by Owyn
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:
p is a pointer (we don't have a clue what it should point to).
This casts it to a "pointer to int" meaning (on 32 bit machines) the memory at that address occupies 4 bytes.
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.
-
May 13th, 2009, 01:10 PM
#26
Re: how to read memory address and get its value
 Originally Posted by hoxsiew
S__B has shown you everything you need to know. I'll break it down for you:
p is a pointer (we don't have a clue what it should point to).
This casts it to a "pointer to int" meaning (on 32 bit machines) the memory at that address occupies 4 bytes.
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.
-
May 13th, 2009, 01:46 PM
#27
Re: how to read memory address and get its value
 Originally Posted by Owyn
Code:
void* myPtr;
myPtr = (void*)0x336288; // for example
int x = *reinterpret_cast<int*>(myPtr);
-
May 13th, 2009, 01:55 PM
#28
Re: how to read memory address and get its value
 Originally Posted by Amleto
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.
-
May 13th, 2009, 02:23 PM
#29
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.
-
June 23rd, 2015, 02:57 AM
#30
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??
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|