Commit 0ca1403f authored by Chris Lamb's avatar Chris Lamb 💬

Add human-readable yet machine-parsable descriptions to comparators where appropriate.

parent 075d9446
......@@ -80,6 +80,7 @@ class AndroidBootImgContainer(Archive):
class AndroidBootImgFile(File):
DESCRIPTION = "Android boot images"
FILE_TYPE_RE = re.compile(r'^Android bootimg\b')
CONTAINER_CLASS = AndroidBootImgContainer
......
......@@ -152,6 +152,7 @@ class ApkContainer(Archive):
class ApkFile(File):
DESCRIPTION = "Android APK files"
FILE_TYPE_HEADER_PREFIX = b"PK\x03\x04"
FILE_TYPE_RE = re.compile(r'^(Java|Zip) archive data.*\b')
FILE_EXTENSION_SUFFIX = '.apk'
......
......@@ -57,6 +57,7 @@ class ArSymbolTableDumper(Command):
class ArFile(File):
DESCRIPTION = "ar(1) archives"
CONTAINER_CLASS = ArContainer
FILE_TYPE_RE = re.compile(r'\bar archive\b')
......
......@@ -42,6 +42,7 @@ class DbDump(Command):
class BerkeleyDBFile(File):
DESCRIPTION = "Berkeley DB database files"
FILE_TYPE_RE = re.compile(r'^Berkeley DB ')
def compare_details(self, other, source=None):
......
......@@ -51,5 +51,6 @@ class Bzip2Container(Archive):
class Bzip2File(File):
DESCRIPTION = "bzip2 archives"
CONTAINER_CLASS = Bzip2Container
FILE_TYPE_RE = re.compile(r'^bzip2 compressed data\b')
......@@ -99,6 +99,7 @@ def is_header_valid(buf, size, offset=0):
class CbfsFile(File):
DESCRIPTION = "Coreboot CBFS filesystem images"
CONTAINER_CLASS = CbfsContainer
@classmethod
......
......@@ -27,6 +27,7 @@ from .utils.libarchive import LibarchiveContainer, list_libarchive
class CpioFile(File):
DESCRIPTION = "cpio archives"
CONTAINER_CLASS = LibarchiveContainer
FILE_TYPE_RE = re.compile(r'\bcpio archive\b')
......
......@@ -161,6 +161,7 @@ class DebControlFile(File):
class DotChangesFile(DebControlFile):
DESCRIPTION = "Debian .changes files"
FILE_EXTENSION_SUFFIX = '.changes'
@classmethod
......@@ -202,6 +203,7 @@ class DotChangesFile(DebControlFile):
class DotDscFile(DebControlFile):
DESCRIPTION = "Debian source packages (.dsc)"
FILE_EXTENSION_SUFFIX = '.dsc'
@classmethod
......@@ -254,6 +256,7 @@ class DotBuildinfoContainer(DebControlContainer):
class DotBuildinfoFile(DebControlFile):
DESCRIPTION = "Debian .buildinfo files"
CONTAINER_CLASS = DotBuildinfoContainer
FILE_EXTENSION_SUFFIX = '.buildinfo'
......
......@@ -31,6 +31,8 @@ logger = logging.getLogger(__name__)
class Device(File):
DESCRIPTION = "character/block devices"
@classmethod
def recognizes(cls, file):
return file.is_device()
......
......@@ -54,5 +54,6 @@ class DexContainer(Archive):
class DexFile(File):
DESCRIPTION = "Dalvik .dex files"
FILE_TYPE_RE = re.compile(r'^Dalvik dex file .*\b')
CONTAINER_CLASS = DexContainer
......@@ -175,6 +175,8 @@ def compare_directories(path1, path2, source=None):
class Directory(object):
DESCRIPTION = "directories"
@classmethod
def recognizes(cls, file):
return file.is_directory()
......
......@@ -37,6 +37,7 @@ class Docx2txt(Command):
class DocxFile(File):
DESCRIPTION = "Microsoft Word .docx files"
FILE_TYPE_RE = re.compile(r'^Microsoft Word 2007+\b')
def compare_details(self, other, source=None):
......
......@@ -34,6 +34,7 @@ class DeviceTreeContents(Command):
class DeviceTreeFile(File):
DESCRIPTION = "Device Tree Compiler blob files"
FILE_TYPE_RE = re.compile(r'^Device Tree Blob')
def compare_details(self, other, source=None):
......
......@@ -558,6 +558,7 @@ class ElfContainer(Container):
class ElfFile(File):
DESCRIPTION = "ELF binaries"
CONTAINER_CLASS = ElfContainer
FILE_TYPE_RE = re.compile(r'^ELF ')
......@@ -566,6 +567,7 @@ class ElfFile(File):
class StaticLibFile(File):
DESCRIPTION = "statically-linked binaries"
CONTAINER_CLASS = ElfContainer
FILE_TYPE_RE = re.compile(r'\bar archive\b')
FILE_EXTENSION_SUFFIX = '.a'
......
......@@ -25,6 +25,7 @@ from .utils.file import File
class FontconfigCacheFile(File):
DESCRIPTION = "FreeDesktop Fontconfig cache files"
FILE_TYPE_HEADER_PREFIX = struct.pack('<H', 0xFC04)
FILE_EXTENSION_SUFFIX = '-le64.cache-4'
......
......@@ -36,6 +36,7 @@ class Showttf(Command):
class TtfFile(File):
DESCRIPTION = "TrueType font files"
FILE_TYPE_RE = re.compile(r'^(TrueType|OpenType) font data', re.IGNORECASE)
def compare_details(self, other, source=None):
......
......@@ -77,6 +77,7 @@ class FsImageContainer(Archive):
class FsImageFile(File):
DESCRIPTION = "ext2/ext3/ext4/btrfs filesystems"
CONTAINER_CLASS = FsImageContainer
FILE_TYPE_RE = re.compile(r'^(Linux.*filesystem data|BTRFS Filesystem).*')
......
......@@ -61,6 +61,7 @@ class Msgunfmt(Command):
class MoFile(File):
DESCRIPTION = "Gettext message catalogues"
FILE_TYPE_RE = re.compile(r'^GNU message catalog\b')
def compare_details(self, other, source=None):
......
......@@ -67,6 +67,7 @@ def can_compose_gif_images(image1, image2):
class GifFile(File):
DESCRIPTION = "GIF image files"
FILE_TYPE_RE = re.compile(r'^GIF image data\b')
def compare_details(self, other, source=None):
......
......@@ -28,6 +28,7 @@ from .utils.file import File
class GitIndexFile(File):
DESCRIPTION = "Git repositories"
FILE_TYPE_RE = re.compile(r'^Git index')
def compare_details(self, other, source=None):
......
......@@ -29,6 +29,7 @@ from .missing_file import MissingFile
class GnumericFile(File):
DESCRIPTION = "Gnumeric spreadsheets"
FILE_EXTENSION_SUFFIX = '.gnumeric'
@tool_required('ssconvert')
......
......@@ -52,6 +52,7 @@ class GzipContainer(Archive):
class GzipFile(File):
DESCRIPTION = "Gzipped files"
CONTAINER_CLASS = GzipContainer
FILE_TYPE_RE = re.compile(r'^gzip compressed data\b')
......
......@@ -69,6 +69,7 @@ class HiFile(File):
So the version of this file has 4 characters, and it's 7103. Note how all
this information is stored as big endian.
"""
DESCRIPTION = "GHC Haskell .hi files"
RE_FILE_EXTENSION = re.compile(r'\.(p_|dyn_)?hi$')
@classmethod
......
......@@ -33,6 +33,7 @@ class Iccdump(Command):
class IccFile(File):
DESCRIPTION = "ColorSync colour profiles (.icc)"
FILE_TYPE_RE = re.compile(r'\bColorSync (ICC|color) [Pp]rofile')
def compare_details(self, other, source=None):
......
......@@ -144,6 +144,7 @@ def same_size(image1, image2):
class JPEGImageFile(File):
DESCRIPTION = "JPEG images"
FILE_TYPE_RE = re.compile(r'\bJPEG image data\b')
def compare_details(self, other, source=None):
......@@ -179,6 +180,7 @@ class JPEGImageFile(File):
class ICOImageFile(File):
DESCRIPTION = "Microsoft Windows icon files"
FILE_TYPE_RE = re.compile(r'\bMS Windows icon resource\b')
def compare_details(self, other, source=None):
......
......@@ -22,4 +22,5 @@ from .gzip import GzipFile
class IpkFile(GzipFile):
DESCRIPTION = "OpenWRT package archives (.ipk)"
FILE_EXTENSION_SUFFIX = '.ipk'
......@@ -68,6 +68,7 @@ class ISO9660Listing(Command):
class Iso9660File(File):
DESCRIPTION = "ISO 9660 CD images"
CONTAINER_CLASS = LibarchiveContainer
FILE_TYPE_RE = re.compile(r'\bISO 9660\b')
......
......@@ -74,6 +74,7 @@ class Javap(Command):
class ClassFile(File):
DESCRIPTION = "Java .class files"
FILE_TYPE_RE = re.compile(r'^compiled Java class data\b')
decompilers = [ProcyonDecompiler, Javap]
......
......@@ -31,6 +31,7 @@ class JavaScriptBeautify(Command):
class JavaScriptFile(File):
DESCRIPTION = "JavaScript files"
FILE_EXTENSION_SUFFIX = '.js'
def compare_details(self, other, source=None):
......
......@@ -31,6 +31,8 @@ except ImportError: # noqa
class JSONFile(File):
DESCRIPTION = "JSON files"
@classmethod
def recognizes(cls, file):
with open(file.path, 'rb') as f:
......
......@@ -43,6 +43,7 @@ class LlvmBcDisassembler(Command):
class LlvmBitCodeFile(File):
DESCRIPTION = "LLVM IR bitcode files"
FILE_TYPE_RE = re.compile(r'^LLVM IR bitcode')
def compare_details(self, other, source=None):
......
......@@ -70,6 +70,7 @@ class OtoolDisassembleInternal(Otool):
class MachoFile(File):
DESCRIPTION = "MacOS binaries"
FILE_TYPE_RE = re.compile(r'^Mach-O ')
RE_EXTRACT_ARCHS = re.compile(r'^(?:Architectures in the fat file: .* are|Non-fat file: .* is architecture): (.*)$')
......
......@@ -34,6 +34,7 @@ class Pedump(Command):
class MonoExeFile(File):
DESCRIPTION = "Mono 'Portable Executable' files"
FILE_TYPE_RE = re.compile(r'\bPE[0-9]+\b.*\bMono\b')
def compare_details(self, other, source=None):
......
......@@ -37,6 +37,7 @@ class Odt2txt(Command):
class OdtFile(File):
DESCRIPTION = "OpenOffice .odt files"
FILE_TYPE_RE = re.compile(r'^OpenDocument Text\b')
def compare_details(self, other, source=None):
......
......@@ -33,6 +33,7 @@ class OggDump(Command):
class OggFile(File):
DESCRIPTION = "Ogg Vorbis audio files"
FILE_TYPE_RE = re.compile(r'^Ogg data')
def compare_details(self, other, source=None):
......
......@@ -33,6 +33,7 @@ class SSHKeyList(Command):
class PublicKeyFile(File):
DESCRIPTION = "OpenSSH public keys"
FILE_TYPE_RE = re.compile(r'^OpenSSH \S+ public key')
def compare_details(self, other, source=None):
......
......@@ -39,6 +39,7 @@ class Tcpdump(Command):
class PcapFile(File):
DESCRIPTION = "tcpdump capture files (.pcap)"
FILE_TYPE_RE = re.compile(r'^tcpdump capture file\b')
def compare_details(self, other, source=None):
......
......@@ -42,6 +42,7 @@ class Pdftk(Command):
class PdfFile(File):
DESCRIPTION = "PDF documents"
FILE_TYPE_RE = re.compile(r'^PDF document\b')
def compare_details(self, other, source=None):
......
......@@ -41,6 +41,7 @@ class Pgpdump(Command):
class PgpFile(File):
DESCRIPTION = "PGP signed/encrypted messages"
FILE_TYPE_RE = re.compile(r'^PGP message\b')
def compare_details(self, other, source=None):
......
......@@ -42,6 +42,7 @@ class Sng(Command):
class PngFile(File):
DESCRIPTION = "PNG images"
FILE_TYPE_RE = re.compile(r'^PNG image data\b')
def compare_details(self, other, source=None):
......
......@@ -58,6 +58,7 @@ class Ppudump(Command):
class PpuFile(File):
DESCRIPTION = "FreePascal files (.ppu)"
FILE_EXTENSION_SUFFIX = '.ppu'
@classmethod
......
......@@ -37,6 +37,7 @@ class Pstotext(Command):
class PsFile(TextFile):
DESCRIPTION = "PostScript documents"
FILE_TYPE_RE = re.compile(r'^PostScript document\b')
def compare(self, other, *args, **kwargs):
......
......@@ -68,6 +68,8 @@ class RdsReader(Command):
class RdsFile(File):
DESCRIPTION = "GNU R Rscript files (.rds)"
@classmethod
def recognizes(cls, file):
if check_rds_extension(file) or \
......@@ -87,6 +89,7 @@ class RdbReader(Command):
class RdbFile(File):
DESCRIPTION = "GNU R database files (.rdb)"
FILE_EXTENSION_SUFFIX = '.rdb'
def compare_details(self, other, source=None):
......
......@@ -104,6 +104,7 @@ class RpmContainer(Archive):
class RpmFile(AbstractRpmFile):
DESCRIPTION = "RPM archives"
CONTAINER_CLASS = RpmContainer
def compare_details(self, other, source=None):
......
......@@ -57,6 +57,7 @@ class RustObjectContainer(Archive):
class RustObjectFile(File):
DESCRIPTION = "Rust object files (.deflate)"
CONTAINER_CLASS = RustObjectContainer
FILE_TYPE_HEADER_PREFIX = b'RUST_OBJECT\x01\x00\x00\x00'
FILE_EXTENSION_SUFFIX = '.deflate'
......
......@@ -33,6 +33,7 @@ class Sqlite3Dump(Command):
class Sqlite3Database(File):
DESCRIPTION = "SQLite databases"
FILE_TYPE_RE = re.compile(r'^SQLite 3.x database')
def compare_details(self, other, source=None):
......
......@@ -299,6 +299,7 @@ class SquashfsContainer(Archive):
class SquashfsFile(File):
DESCRIPTION = "SquashFS filesystems"
CONTAINER_CLASS = SquashfsContainer
FILE_TYPE_RE = re.compile(r'^Squashfs filesystem\b')
......
......@@ -29,6 +29,8 @@ logger = logging.getLogger(__name__)
class Symlink(File):
DESCRIPTION = "symlinks"
@classmethod
def recognizes(cls, file):
return file.is_symlink()
......
......@@ -30,6 +30,7 @@ class TarContainer(LibarchiveContainer):
class TarFile(File):
DESCRIPTION = "tape archives (.tar)"
CONTAINER_CLASS = TarContainer
FILE_TYPE_RE = re.compile(r'\btar archive\b')
......
......@@ -36,6 +36,7 @@ def order_only_difference(unified_diff):
class TextFile(File):
DESCRIPTION = "text files"
FILE_TYPE_RE = re.compile(r'\btext\b')
@property
......
......@@ -71,6 +71,8 @@ class XMLFile(File):
Attributes:
FILE_EXTENSION_SUFFIX (str): xml file extension suffix
"""
DESCRIPTION = "XML files"
FILE_EXTENSION_SUFFIX = '.xml'
@classmethod
......
......@@ -36,6 +36,7 @@ class Dumpxsb(Command):
class XsbFile(File):
DESCRIPTION = "XML binary schemas (.xsb)"
FILE_EXTENSION_SUFFIX = '.xsb'
def compare_details(self, other, source=None):
......
......@@ -52,6 +52,7 @@ class XzContainer(Archive):
class XzFile(File):
DESCRIPTION = "XZ compressed files"
CONTAINER_CLASS = XzContainer
FILE_TYPE_RE = re.compile(r'^XZ compressed data$')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment