Giriş
elf dosyasının veya .o dosyasının sembollerine
objdump ile bakılabilir. Komutun bir çok seçeneği var.
Diğer Araçlar
Bu araç ile ilgili diğer araçların açıklaması
şöyle.
ar: creates static libraries.
objdump: this is the most important binary tool; it can be used to display all the information in an object binary file.
strings: list all the printable strings in a binary file.
nm: lists the symbols defined in the symbol table of an object file.
ldd: lists the shared libraries on which the object binary is dependent.
strip: deletes the symbol table information.
-d disassamble seçeneği
Assembly kodunu çıkartır.
Örnek
Şöyle
yaparız.
objdump -d a.o
veya şöyle
yaparız
objdump -d foo.exe
Örnek
Şöyle derlenmiş bir .o dosyası
olsun
gcc -c test.c
Bu dosyanın tamamına şöyle
bakarız.
objdump -D test.o
Çıktı olarak şuna benzer bir şey
görürüz.
0: 14 00 adc $0x0,%al
--disassembler-options seçeneği
Üretilen assembly kodunun att veya intel formatında olmasını sağlar. Bu seçenek sanırım -M intel ile aynı. Şöyle
yaparız.
$ objdump -d --disassembler-options=att code.c
...
080483c4 :
80483c4: 8d 4c 24 04 lea 0x4(%esp),%ecx
80483c8: 83 e4 f0 and $0xfffffff0,%esp
80483cb: ff 71 fc pushl -0x4(%ecx)
80483ce: 55 push %ebp
80483cf: 89 e5 mov %esp,%ebp
80483d1: 51 push %ecx
80483d2: 83 ec 04 sub $0x4,%esp
80483d5: c7 04 24 b0 84 04 08 movl $0x80484b0,(%esp)
80483dc: e8 13 ff ff ff call 80482f4
80483e1: b8 00 00 00 00 mov $0x0,%eax
80483e6: 83 c4 04 add $0x4,%esp
80483e9: 59 pop %ecx
80483ea: 5d pop %ebp
80483eb: 8d 61 fc lea -0x4(%ecx),%esp
80483ee: c3 ret
80483ef: 90 nop
veya şöyle
yaparız.
$ objdump -d --disassembler-options=intel code.c
...
080483c4 :
80483c4: 8d 4c 24 04 lea ecx,[esp+0x4]
80483c8: 83 e4 f0 and esp,0xfffffff0
80483cb: ff 71 fc push DWORD PTR [ecx-0x4]
80483ce: 55 push ebp
80483cf: 89 e5 mov ebp,esp
80483d1: 51 push ecx
80483d2: 83 ec 04 sub esp,0x4
80483d5: c7 04 24 b0 84 04 08 mov DWORD PTR [esp],0x80484b0
80483dc: e8 13 ff ff ff call 80482f4
80483e1: b8 00 00 00 00 mov eax,0x0
80483e6: 83 c4 04 add esp,0x4
80483e9: 59 pop ecx
80483ea: 5d pop ebp
80483eb: 8d 61 fc lea esp,[ecx-0x4]
80483ee: c3 ret
80483ef: 90 nop
-f seçeneği - file-headers
.so dosyasının hangi ABI türünü kullandığını
gösterir.
% objdump -f /lib/ld-linux.so.2
/lib64/ld-linux-x86-64.so.2
/libx32/ld-linux-x32.so.2
/lib/ld-linux.so.2: file format elf32-i386
architecture: i386, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x00000a90
/lib64/ld-linux-x86-64.so.2: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x0000000000000c90
/libx32/ld-linux-x32.so.2: file format elf32-x86-64
architecture: i386:x64-32, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x00000960
-S seçeneği
Açıklaması
şöyle. -d seçeği ile birlikte kullanılır
>objdump --help
[...]
-S, --source Intermix source code with disassembly
-l, --line-numbers Include line numbers and filenames in output
Örnek
Şöyle
yaparız.
> objdump -d -M intel -S test.o
test.o: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include <stdio.h>
int main(void)
{
0: 55 push ebp
1: 89 e5 mov ebp,esp
3: 83 e4 f0 and esp,0xfffffff0
6: 83 ec 10 sub esp,0x10
puts("test");
9: c7 04 24 00 00 00 00 mov DWORD PTR [esp],0x0
10: e8 fc ff ff ff call 11 <main+0x11>
return 0;
15: b8 00 00 00 00 mov eax,0x0
}
1a: c9 leave
1b: c3 ret
-t seçeneği
Sembolleri gösterir
Örnek
Şöyle yaparız
objdump -t x.sm
Örnek
Elimizde şöyle bir kod
olsun.
#include <stdio.h>
int g_a;
int g_b;
int g_c;
int main()
{
printf("Hello world\n");
return 0;
}
Şöyle
yaparız.
objdump -t myapp
Çıktı olarak şunu
alırız.
00004020 g_b
00004024 g_a
00004028 g_c
Örnek
Sembollerin hangi elf bölümüne geldiği görmek için şöyle
yaparız.
.text ve
.rodata bölümlerinde tanımlı semboller görülebilir.
$ objdump -T /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 | grep "chrono"
00080828 g DF .text 0000002a GLIBCXX_3.4.11 _ZNSt6chrono12system_clock3nowEv
0008ae38 g DO .rodata 00000001 GLIBCXX_3.4.11 _ZNSt6chrono12system_clock12
Örnek
Eğer bir sembol yoksa undefined olarak
belirtilir.
$ objdump -T myapp | grep "GLIBCXX_3.4.19"
00000000 DF *UND* 00000000 GLIBCXX_3.4.19 _ZNSt6chrono3_V212system_clock3n
-x seçeneği
Elimizde şöyle bir kod
olsun.
// main.c
extern int x;
static int *y = &x;
int main() {
return *y;
}
Şöyle
yaparız
objdump -x main.o
Çıktı olarak şunu
alırız.
RELOCATION RECORDS FOR [.data]:
OFFSET TYPE VALUE
0000000000000000 R_X86_64_64 x