mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
Add support for reading ELF package notes with section header (#2939)
* add support for reading ELF package notes with section header Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add systemd elf package fields to json schema Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"debug/elf"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
@@ -154,11 +156,42 @@ func getELFNotes(r file.LocationReadCloser) (*elfBinaryPackageNotes, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var metadata elfBinaryPackageNotes
|
||||
if err := json.Unmarshal(notes, &metadata); err != nil {
|
||||
log.WithFields("file", r.Location.Path(), "error", err).Trace("unable to unmarshal ELF package notes as JSON")
|
||||
if len(notes) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &metadata, err
|
||||
{
|
||||
var metadata elfBinaryPackageNotes
|
||||
if err := json.Unmarshal(notes, &metadata); err == nil {
|
||||
return &metadata, nil
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var header elf64SectionHeader
|
||||
headerSize := binary.Size(header) / 4
|
||||
if len(notes) > headerSize {
|
||||
var metadata elfBinaryPackageNotes
|
||||
newPayload := bytes.TrimRight(notes[headerSize:], "\x00")
|
||||
if err := json.Unmarshal(newPayload, &metadata); err == nil {
|
||||
return &metadata, nil
|
||||
}
|
||||
log.WithFields("file", r.Location.Path(), "error", err).Trace("unable to unmarshal ELF package notes as JSON")
|
||||
}
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
type elf64SectionHeader struct {
|
||||
ShName uint32
|
||||
ShType uint32
|
||||
ShFlags uint64
|
||||
ShAddr uint64
|
||||
ShOffset uint64
|
||||
ShSize uint64
|
||||
ShLink uint32
|
||||
ShInfo uint32
|
||||
ShAddralign uint64
|
||||
ShEntsize uint64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user