分析ELF文件Simplesection.o

文件代碼

今天我們來學一下怎樣分析一個ELF文件。xxx.o在Linux裡面的文件格式是屬於可重定位文件(Relocatable File)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* SimpleSection.c */

int printf(const char* format,...);

int global_init_var =84; //
int global_uninit_var;

void func1(int i)
{
printf("%d\n",i);
}
int main(void)
{
static int static_var =85;
static int static_var2;
int a = 1;
int b;
funcl1(static_var + static_var2 + a + b);
}

使用Objdump

Objdump工具可用來查看目標文件的結構和內容。在這裡我會先用-h來看看這個ELF各個段的基本資訊。

輸入objdump -h SimpleSection.o

根據上圖我們可以知道一個ELF的可重定位文件可分為的段如下:

  • .text 代碼段
  • .data 數據段
  • .bss Block Started by Symbol
  • .rodata
  • .comment
  • .note.GNU-stack
  • .eh_frame

未完待續

0%