0

I'm trying to find the pointer's memory address of a global variable on my C program.
It looks something like that:

int target;

int main(){
    return 0;
}

I tried to use objdump -t on the binary code and I got got:

0000000000004014 g     O .bss   0000000000000004              target

Does 0000000000004014 is the actual pointer address? When I ran

printf("%p",&target);

the pointer value kept changing each time. Am I missing something?
Any help will be great ;)

Y_Z
  • 71
  • 6
  • 1
    The library loader will typically relocate stuff during the loading of your program. The `&target` is the actual pointer to the place where the integer value is stored. No need to hard-code memory locations. – Cheatah Oct 28 '22 at 21:00
  • "I'm trying to find" Why? What are you going to do with it? – n. m. could be an AI Oct 28 '22 at 21:09
  • You may have discovered [ASLR](https://en.m.wikipedia.org/wiki/Address_space_layout_randomization) – Useless Oct 28 '22 at 21:13
  • 4014 (hexadecimal) is the address of `target` relative to some base address (for the section/segment/something; you are using a somewhat different tool than I am). When the program is loaded, the program loader picks an address for that program segment and loads it there, so the final address of `target` in the virtual memory of the running process is the chosen start address plus the relative address of `target` within the segment. – Eric Postpischil Oct 28 '22 at 21:20
  • 1
    In modern general-purpose operating systems, the program loaders choose random addresses for program segments to foil attackers who might be able to take advantage of known addresses. That makes it impossible for you to predict the final address in the process from the relative address in the executable file. That randomization can be turned off for debugging. Methods to do so depend on your operating system. (It may be a default behavior of the debugger; if you run the program in the debugger, you may see the same address every time.) – Eric Postpischil Oct 28 '22 at 21:22

0 Answers0