-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattempt_access.cpp
61 lines (49 loc) · 1.97 KB
/
attempt_access.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// compile with g++ -std=c++11 -IC:\\boost\\include\boost-1_71\\ -o attempt_access.exe attempt_access.cpp
/*************************************
* This process uses a shared_memory_object
* (see boost library "interprocess") called
* "shared_memory" to access an int at a given
* memory location and print it.
*
* The process will crash if "shared_memory"
* does not exist or if there is a segmentation
* fault.
*
*************************************/
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
int main(int argc, char *argv[]){
// Use shared memory (will throw if shared_memory does not exist)
boost::interprocess::shared_memory_object shared_memory(
boost::interprocess::open_only,
"shared_memory",
boost::interprocess::read_write
);
// Map the shared_memory in this process
boost::interprocess::mapped_region region(shared_memory, boost::interprocess::read_write);
// printf("Let's first check out the shared memory\n");
// printf("--------------------------------\n");
// printf("SHARED MEMORY\n");
// printf("Region start: %08x \n", region.get_address());
// printf("Region size: %i \n", region.get_size());
// printf("Memory : Value\n");
// int *mem = static_cast<int*>(region.get_address());
// for(std::size_t i = 0; i < region.get_size()/sizeof(int); ++i){
// printf("%08x: %08x\n", mem, *mem);
// mem++;
// }
// printf("--------------------------------\n \n");
// printf("Now let's try to access the requested location\n");
int * ptr = (int *) atoi(argv[1]);
// printf("Starting at %08x aka %s\n", ptr, argv[1]);
// printf("Memory : Value\n");
// for (int i = 0; i < 10; i++) {
// printf("%08x : %08x\n", ptr, *ptr);
// ptr++;
// }
printf("Memory : Value\n");
printf("%08x : %08x\n", ptr, *ptr);
}