(filePath string)
| 14 | } |
| 15 | |
| 16 | func Detected(filePath string) (*BinProps, error) { |
| 17 | binFile, err := elf.Open(filePath) |
| 18 | if err == nil { |
| 19 | binProps := &BinProps{ |
| 20 | IsBin: true, |
| 21 | } |
| 22 | |
| 23 | switch binFile.Type { |
| 24 | case elf.ET_EXEC: |
| 25 | binProps.IsExe = true |
| 26 | case elf.ET_DYN: |
| 27 | binProps.IsSO = true |
| 28 | } |
| 29 | |
| 30 | binFile.Close() |
| 31 | return binProps, nil |
| 32 | } |
| 33 | |
| 34 | log.Debugf("binfile.Detected(%v) - elf.Open error: %v", filePath, err) |
| 35 | |
| 36 | if elfErr, ok := err.(*elf.FormatError); ok { |
| 37 | if strings.Contains(elfErr.Error(), "bad magic number") { |
| 38 | return nil, nil |
| 39 | } |
| 40 | |
| 41 | log.Debugf("binfile.Detected(%v) - malformed binary file", filePath) |
| 42 | return nil, err |
| 43 | } |
| 44 | |
| 45 | return nil, err |
| 46 | } |
no test coverage detected