Read plt section of ELF binary and print function virtual address
Asked Answered
G

1

6

I want to read .plt section of an ELF binary and get all the virtual addresses of external functions.

Disassembly of section .plt:

0000000000400400 <puts@plt-0x10>:
  400400:       ff 35 02 0c 20 00       pushq  0x200c02(%rip)        # 601008 <_GLOBAL_OFFSET_TABLE_+0x8>
  400406:       ff 25 04 0c 20 00       jmpq   *0x200c04(%rip)        # 601010 <_GLOBAL_OFFSET_TABLE_+0x10>
  40040c:       0f 1f 40 00             nopl   0x0(%rax)

0000000000400410 <puts@plt>:
  400410:       ff 25 02 0c 20 00       jmpq   *0x200c02(%rip)        # 601018 <_GLOBAL_OFFSET_TABLE_+0x18>
  400416:       68 00 00 00 00          pushq  $0x0
  40041b:       e9 e0 ff ff ff          jmpq   400400 <_init+0x20>

0000000000400420 <__libc_start_main@plt>:
  400420:       ff 25 fa 0b 20 00       jmpq   *0x200bfa(%rip)        # 601020 <_GLOBAL_OFFSET_TABLE_+0x20>
  400426:       68 01 00 00 00          pushq  $0x1
  40042b:       e9 d0 ff ff ff          jmpq   400400 <_init+0x20>

0000000000400430 <__gmon_start__@plt>:
  400430:       ff 25 f2 0b 20 00       jmpq   *0x200bf2(%rip)        # 601028 <_GLOBAL_OFFSET_TABLE_+0x28>
  400436:       68 02 00 00 00          pushq  $0x2
  40043b:       e9 c0 ff ff ff          jmpq   400400 <_init+0x20>

For example, 0x400410 and the function name puts@plt and so on. I've tried to read REL_PLT section of ELF binary. But I get the address 0x601108 for PLT entry 0x400410 which is from Global Offset Table. How can I get the virtual addresses of plt entries?

EDIT: It turned out I'm reading got.plt section. How can I read just .plt section using readelf?

Garygarza answered 3/6, 2015 at 19:35 Comment(0)
F
-1

Uhmm, If I've understood what your question is correctly then you can't.... ASLR - Adress Space Layout Randomization, Every SO gets loaded into some Random address, and during load-time or run-time (dependant on the symbol's binding - Lazy or not ) the GOT is changed to the actual virtual address of the loaded external symbol, When calling some external function you are basically jumping to some pre defined offset (into the GOT) and call the function out of the address that would be stored within that offset. It is the goal of ld or the OS loader to change that address into the address you should jump into during runtime

Forepaw answered 14/1, 2017 at 23:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.