From c118951863c2524302a893729a48abb3d92ad7c4 Mon Sep 17 00:00:00 2001 From: Peter Babka Date: Tue, 18 Aug 2020 17:52:56 +0200 Subject: [PATCH] Added support for elf --- filetype/types/__init__.py | 1 + filetype/types/archive.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/filetype/types/__init__.py b/filetype/types/__init__.py index 87d95b8..d6607c0 100644 --- a/filetype/types/__init__.py +++ b/filetype/types/__init__.py @@ -77,6 +77,7 @@ archive.Ar(), archive.Z(), archive.Lz(), + archive.Elf(), ) # Expose supported type matchers diff --git a/filetype/types/archive.py b/filetype/types/archive.py index 5cde4b3..0346666 100644 --- a/filetype/types/archive.py +++ b/filetype/types/archive.py @@ -513,3 +513,24 @@ def match(self, buf): buf[1] == 0x5A and buf[2] == 0x49 and buf[3] == 0x50) + + +class Elf(Type): + """ + Implements the Elf archive type matcher + """ + MIME = 'application/x-executable' + EXTENSION = 'elf' + + def __init__(self): + super(Elf, self).__init__( + mime=Elf.MIME, + extension=Elf.EXTENSION + ) + + def match(self, buf): + return (len(buf) > 52 and + buf[0] == 0x7F and + buf[1] == 0x45 and + buf[2] == 0x4C and + buf[3] == 0x46)