hi, i want to read memory at adress 02804C20 and get its value, this should be simple but i'm a little new at this ^^
it should be something like
char txt[512];
txt = value.from.memory.at(02804C20);
Printable View
hi, i want to read memory at adress 02804C20 and get its value, this should be simple but i'm a little new at this ^^
it should be something like
char txt[512];
txt = value.from.memory.at(02804C20);
Why do you want to read something from a static memory address ?Code:memcpy (txt, (char*)(02804C20), sizeof(txt));
i thougt i'd need a pointer at first too, but address was fully static
Memory addresses change every time you run your program... that's why I asked.Quote:
i thougt i'd need a pointer at first too, but address was fully static
oops.. my bad...
Code:memcpy (txt, (char*)(0x02804C20), sizeof(txt));
thx) works
btw sizeof(text) returns real size of text or its maxsize? or maxsize was maxsizeof(txt) ?
sizeof(txt) is 512. It returns 512 * sizeof(char).Code:char txt[512];
plus, how do i get value from 4 bytes address into an int ?
ps-how do i get the real size? like if char = '12345" so it'd be 5 or 6
strlenQuote:
like if char = '12345" so it'd be 5 or 6
thx, but what about int value? i have an adress 4 bytes which has a number, i need this number to count thingsQuote:
strlen
Unless you're working with very specialized hardware, there's almost no reason ever to hard-code a particular address.
If you have a pointer, you can just dereference it (assuming you know what kind of data it is pointing at). I think you're missing some simple C++ concept here (or you're trying to cheat at the game).
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 ^^
Use typecasting:
If "char* p" is the character pointer, then something like
is what you should be looking at.Code:int n = *( (int *) p );
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
ok, so how'd i dehardcode it? mb that'd would be better and faster and more stable i dunno
Typically you'd query some function or existing pointer in the program to get the address you needed.
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
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.
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
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).Code:void *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 *)p);
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.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
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?
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.
memcpy (txt, (char*)(0xfeafe000), sizeof(txt));
i have used it and got a segmentation fault.
*******************************
progarm recieved signal SIGSEV,segmentaion fault.
**********************************
why this happens??
Is the address 0xfeafe000 valid for read? of what type is txt? How is the address of txt set?
Rather than posting to this old thread that has nothing to do with your problem you should have better googled for this error message in Web... Then you would find among the first tree items this one:
https://en.wikipedia.org/wiki/Segmentation_fault