https://github.com/yalue/elf_reader
A Go library for reading and parsing ELF files
https://github.com/yalue/elf_reader
elf elf-binaries elf-files elf-format elf-header elf-parser elf64 golang
Last synced: 9 months ago
JSON representation
A Go library for reading and parsing ELF files
- Host: GitHub
- URL: https://github.com/yalue/elf_reader
- Owner: yalue
- License: mit
- Created: 2016-11-04T16:31:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-03-21T14:44:55.000Z (almost 2 years ago)
- Last Synced: 2025-04-19T17:57:56.495Z (10 months ago)
- Topics: elf, elf-binaries, elf-files, elf-format, elf-header, elf-parser, elf64, golang
- Language: Go
- Homepage:
- Size: 961 KB
- Stars: 30
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ELF Reader
==========
About
-----
This library is for reading ELF files using the Go programming language. Go's
standard library already includes ELF-related functions, but these do not
include some useful functionality for displaying or accessing some aspects of
ELF files out-of-the-box.
This library supports both big and little-endian 32- and 64-bit ELF files. You
can specifically read 32-bit files by calling `ParseELF32File(...)`, or 64-bit
files by `ParseELF64File(...)`, or either type of file using
`ParseELFFile(...)`. If you use the generic `ParseELFFile(...)` function, then
you can either use the returned `ELFFile` interface directly, or use type
assertions to retrieve a 32-bit `*ELF32File` or a 64-bit `*ELF64File`.
Usage
-----
The following example shows how this library can be used to output section
names to standard output. For a more complete example of how to read
information from an ELF file, see the command-line tool at
`elf_view/elf_view.go`.
```go
import (
"fmt"
"github.com/yalue/elf_reader"
"os"
)
func main() {
// Print the section names in /bin/bash. This code will work on both 32-bit
// and 64-bit systems.
raw, e := os.ReadFile("/bin/bash")
if e != nil {
fmt.Printf("Failed reading /bin/bash: %s\n", e)
return
}
elf, e := elf_reader.ParseELFFile(raw)
if e != nil {
fmt.Printf("Failed parsing ELF file: %s\n", e)
return
}
count := elf.GetSectionCount()
for i := uint16(0); i < count; i++ {
if i == 0 {
fmt.Printf("Section 0: NULL section (no name)\n")
continue
}
name, e := elf.GetSectionName(uint16(i))
if e != nil {
fmt.Printf("Failed getting section %d name: %s\n", i, e)
continue
}
fmt.Printf("Section %d name: %s\n", i, name)
}
}
```