So i've mapped a section of code utilizing the mmap() call.
Code:
size_t pSize = getpagesize();
printf("Page Size: %zu\n", pSize);
int dh = open("/dev/mem", O_RDWR | O_SYNC); // Open /dev/mem which represents the whole physical memory
unsignedint *addr = mmap(NULL, pSize, PROT_READ, MAP_SHARED, dh, 0x4000000); // Memory map source address
Now I have two different functions that are reading the memory at what I believe to be the same address.
Code:
voidcapture(void *addr, intbyteCnt)
{
unsigned int *p = addr;
int offset;
for (offset = 0; offset < byteCnt; offset++) {
printf("%02X", p[offset]);
if (offset % 4 == 3) {
printf(" ");
}
}
printf("\n");
}
and
Code:
voidmemCapture(void *addr, intbyteCnt)
{
unsigned int a;
char *p = addr;
memcpy(&a, p, byteCnt);
printf("%X\n", a);
}
Why am i seeing two different values when I run both functions back to back.
If I attempt to capture four bytes from both I get values such as
587eb357
57b3e758