I am trying to read the memory addresses from /proc//maps and I use the following code
for (ptr = NULL; getline(&ptr, &n, file) > 0;) {
if (ptr[0]== ' ') { continue; }
sscanf(ptr, "%lx-%lx", &r0, &r1);
printf("r0: %lx, r1: %lx\n", r0, r1); }
Assume that file points to /proc//maps & ptr is the line pointer. But when you consider a maps file, it doesn't read the file proper. It drops the zero, it does not pick the zeros up. So consider:
00110000-00123000 r-xp 00000000 08:01 129925 /lib/i686/cmov/libnsl-2.11.1.so
After running through my program:
r0: 110000, r1: 123000
How I keep the leading zeros to output something like this:
r0: 00110000, r1: 00123000
Edit: The printf is for debugging.
Here is what I do with r1 later on
mem = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, mem_fd, r1)