Hooch
Hooch

Reputation: 29693

byte array at specyfic addres c++

I want to map some part of process memory as byte array. How to do it?

I have byte array:

byte AmmoBytes[3]

And I want this array to start at address 0xXXXXXXX; How to do it?

Upvotes: 1

Views: 208

Answers (5)

Thomas Matthews
Thomas Matthews

Reputation: 57749

I would declare the memory using a constant pointer:

byte * const AmmoBytes = (byte * const) 0xFFFF000;

Declaring the pointer as constant helps the compiler detect errors such as mistakenly changing the pointer value instead of the value pointed to by the pointer.

Upvotes: 0

Mark B
Mark B

Reputation: 96291

Generally speaking you can't reliably do this.

If 0xXXXXXXX represents hardware address(es) then you'll need to write a device driver to gain kernel access to the memory.

If it's a normal memory address then there's no guarantee that it maps to a valid memory location and you're quite likely to crash your program.

What are you really trying to do here?

Upvotes: 0

wilx
wilx

Reputation: 18248

byte (& a)[3] = *reinterpret_cast<byte (*)[3]>(0xDEADBEEF);

Upvotes: 5

ThomasMcLeod
ThomasMcLeod

Reputation: 7779

This is unsafe, but you can say

byte * AmmoBytes = (byte *) 0xXXXXXXXX

Upvotes: 2

Erik
Erik

Reputation: 91320

byte * AmmoBytes = (byte *) 0xXXXXXXXX;

Upvotes: 3

Related Questions