Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Byte from memory address?

I'm still learning c++ and have spent hours trying to figure out a way to get a byte stored at a certain memory address, in my case ALL (well, almost all) memory addresses aren't dynamic - so addresses pointing to, for example variables will not change.

So I'm trying to retrieve a single byte stored at a known memory address. For example let's say: 0x20000

the byte i'm trying to retrieve is, for example, let's say 0xEF.

Now how would i retrieve the byte without using the dereference operator? So basically i need to get 0xEF without having to declare what type of data type it is, like literally just physically get the byte 0xEF. Hopefully this makes sense, I'm quite a noob :/

like image 949
C0d1ng Avatar asked Dec 25 '22 04:12

C0d1ng


1 Answers

Now how would i retrieve the byte without using the dereference operator?

You cannot do this without dereferencing the accessed address. The smallest data type you can address is a char. For bytes there's usually a typedef unsigned char uint8_t used.

So you have to access the memory address using a reinterpret_cast<uint8_t*>(addr) and dereference to get the value.

like image 197
πάντα ῥεῖ Avatar answered Dec 29 '22 11:12

πάντα ῥεῖ