SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
程式設計師的自我修養
Chapter 3.4 ELF檔結構描述

      Shu-Yu Fu
ELF結構
檔頭
                                       常量 值      含义
                                       ET_REL    1 可重定位文件,一般 为.o文件
typedef struct {                       ET_EXEC   2 可执行文件
                                       ET_DYN    3 共享目标文件,一般为.so文件
  unsigned char e_ident[16];
  Elf32_Half e_type;
  Elf32_Half e_machine;
  Elf32_Word e_version;
  Elf32_Addr e_entry;
  Elf32_Off e_phoff;                             常量      值 含义
                                                 EM_M32      1 AT&T WE 32100
  Elf32_Off e_shoff;
           Magic:       7f 45 4c 46 01 01 01 00 00 00 00 00 00 00SPARC
                                                 EM_SPARC 2       00 00
  Elf32_Word e_flags; ELF32
           Class:                                EM_386      3 Intel x86
  Elf32_Half e_ehsize; complement, little endian
           Data:        2's                      EM_68K      4 Motorola
           Version:     1 (current)
  Elf32_Half e_phentsize;- System V
           OS/ABI:      UNIX
                                                 68000
                                                 EM_88K      5 Motorola
  Elf32_Half e_phnum; 0
           ABI Version:
                                                 88000
  Elf32_Half e_shentsize;                        EM_860      6 Intel 80860
  Elf32_Half e_shnum;
  Elf32_Half e_shstrndx;
} Elf32_Ehdr;
段頭表【Section Header Table】

● 描述了ELF各個區段的資
  訊
● 是Elf32_Shdr陣列
● 第一個是無效的段述項
  【Section Descriptor】
● 編譯器、連結器和載入器
  都是依靠段頭表來定位和
  存取各個區段的屬性
● 段頭表在ELF檔案中的位
  置由ELF檔頭的e_shoff成
  員決定
段頭表【續】                       區段名稱是個字串,
                             它位於一個叫做.
                             shstrtab的字串表。
typedef struct {             sh_name是區段名稱
  Elf32_Word sh_name;        字串在.shstrtab中的
  Elf32_Word sh_type;        偏移
  Elf32_Word sh_flags;
  Elf32_Addr sh_addr;
  Elf32_Off sh_offset;
  Elf32_Word sh_size;
                             區段類型和區段旗標
  Elf32_Word sh_link;        位元決定區段屬性
  Elf32_Word sh_info;        我們接下來會看到
  Elf32_Word sh_addralign;   SHT_REL和
  Elf32_Word sh_entsize;     SHT_STRTAB
} Elf32_Shdr;
重定表【Relocation Table】

● 一個重定表同時也是ELF的一個區段
  ○ 它的sh_type為SHT_REL
  ○ sh_link表示符號表的索引
  ○ sh_info表示它作用的區段
● 細節可參考4.2.2節【重定表】
字串表

● 把ELF檔中用到的字串集中起來存放
● 一般常見的區段名稱為.strtab或.shstrtab
  ○ 字串表【String Table】用來保存普通字串
  ○ 段頭字串表【Section Header String Table】用來保存段
     頭表中用到的字串
● ELF檔頭中的e_shstrndx表示.shstrtab在段頭表
  中的索引
作業

● 平常我們在程式裡用的const char *是存在那
  個section?
● 用sh_name去查找在.shstrtab對應的字串

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

程式設計師的自我修養 Chapter 3.4

  • 3. 檔頭 常量 值 含义 ET_REL 1 可重定位文件,一般 为.o文件 typedef struct { ET_EXEC 2 可执行文件 ET_DYN 3 共享目标文件,一般为.so文件 unsigned char e_ident[16]; Elf32_Half e_type; Elf32_Half e_machine; Elf32_Word e_version; Elf32_Addr e_entry; Elf32_Off e_phoff; 常量 值 含义 EM_M32 1 AT&T WE 32100 Elf32_Off e_shoff; Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00SPARC EM_SPARC 2 00 00 Elf32_Word e_flags; ELF32 Class: EM_386 3 Intel x86 Elf32_Half e_ehsize; complement, little endian Data: 2's EM_68K 4 Motorola Version: 1 (current) Elf32_Half e_phentsize;- System V OS/ABI: UNIX 68000 EM_88K 5 Motorola Elf32_Half e_phnum; 0 ABI Version: 88000 Elf32_Half e_shentsize; EM_860 6 Intel 80860 Elf32_Half e_shnum; Elf32_Half e_shstrndx; } Elf32_Ehdr;
  • 4. 段頭表【Section Header Table】 ● 描述了ELF各個區段的資 訊 ● 是Elf32_Shdr陣列 ● 第一個是無效的段述項 【Section Descriptor】 ● 編譯器、連結器和載入器 都是依靠段頭表來定位和 存取各個區段的屬性 ● 段頭表在ELF檔案中的位 置由ELF檔頭的e_shoff成 員決定
  • 5. 段頭表【續】 區段名稱是個字串, 它位於一個叫做. shstrtab的字串表。 typedef struct { sh_name是區段名稱 Elf32_Word sh_name; 字串在.shstrtab中的 Elf32_Word sh_type; 偏移 Elf32_Word sh_flags; Elf32_Addr sh_addr; Elf32_Off sh_offset; Elf32_Word sh_size; 區段類型和區段旗標 Elf32_Word sh_link; 位元決定區段屬性 Elf32_Word sh_info; 我們接下來會看到 Elf32_Word sh_addralign; SHT_REL和 Elf32_Word sh_entsize; SHT_STRTAB } Elf32_Shdr;
  • 6. 重定表【Relocation Table】 ● 一個重定表同時也是ELF的一個區段 ○ 它的sh_type為SHT_REL ○ sh_link表示符號表的索引 ○ sh_info表示它作用的區段 ● 細節可參考4.2.2節【重定表】
  • 7. 字串表 ● 把ELF檔中用到的字串集中起來存放 ● 一般常見的區段名稱為.strtab或.shstrtab ○ 字串表【String Table】用來保存普通字串 ○ 段頭字串表【Section Header String Table】用來保存段 頭表中用到的字串 ● ELF檔頭中的e_shstrndx表示.shstrtab在段頭表 中的索引
  • 8. 作業 ● 平常我們在程式裡用的const char *是存在那 個section? ● 用sh_name去查找在.shstrtab對應的字串