Skip to content

Commit

Permalink
Merge pull request h2non#90 from mikewiacek/macho
Browse files Browse the repository at this point in the history
Add Mach-O binary support
  • Loading branch information
h2non authored Aug 6, 2020
2 parents dc94c69 + 4350ba0 commit 29039c2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions matchers/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
TypeElf = newType("elf", "application/x-executable")
TypeDcm = newType("dcm", "application/dicom")
TypeIso = newType("iso", "application/x-iso9660-image")
TypeMachO = newType("macho", "application/x-mach-binary") // Mach-O binaries have no common extension.
)

var Archive = Map{
Expand Down Expand Up @@ -56,6 +57,7 @@ var Archive = Map{
TypeElf: Elf,
TypeDcm: Dcm,
TypeIso: Iso,
TypeMachO: MachO,
}

func Epub(buf []byte) bool {
Expand Down Expand Up @@ -232,3 +234,13 @@ func Iso(buf []byte) bool {
buf[32771] == 0x30 && buf[32772] == 0x30 &&
buf[32773] == 0x31
}

func MachO(buf []byte) bool {
return len(buf) > 3 && ((buf[0] == 0xFE && buf[1] == 0xED && buf[2] == 0xFA && buf[3] == 0xCF) ||
(buf[0] == 0xFE && buf[1] == 0xED && buf[2] == 0xFA && buf[3] == 0xCE) ||
(buf[0] == 0xBE && buf[1] == 0xBA && buf[2] == 0xFE && buf[3] == 0xCA) ||
// Big endian versions below here...
(buf[0] == 0xCF && buf[1] == 0xFA && buf[2] == 0xED && buf[3] == 0xFE) ||
(buf[0] == 0xCE && buf[1] == 0xFA && buf[2] == 0xED && buf[3] == 0xFE) ||
(buf[0] == 0xCA && buf[1] == 0xFE && buf[2] == 0xBA && buf[3] == 0xBE))
}

0 comments on commit 29039c2

Please sign in to comment.