Skip to content

Commit

Permalink
fix: check if an ELF is static
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Jul 12, 2023
1 parent 177eaa2 commit d574330
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/lib/agent/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,19 @@ func FixELF(elf_path string) (err error) {
func IsStaticELF(file_path string) bool {
f, err := elf.Open(file_path)
if err != nil {
return false
fmt.Println("Error opening ELF file:", err)
os.Exit(1)

}
defer f.Close()

// Check if the ELF file is statically linked
return f.Type == elf.ET_EXEC || f.Type == elf.ET_DYN
isStaticallyLinked := true
for _, phdr := range f.Progs {
if phdr.Type == elf.PT_DYNAMIC {
isStaticallyLinked = false
break
}
}
return isStaticallyLinked
}

0 comments on commit d574330

Please sign in to comment.