flying-anvil/fileinfo

Get information about files. Focused on exotic file types.

0.2.0 2021-03-30 18:10 UTC

README

Get information about files. Focused on exotic file types.

Supported Filetypes

extensiondescription
Application
Dev Tools
diffOutput of the diff command (and git diff)
patchOutput of the diff command (and git diff)
Games
lvlxSMBX2 Level
gmaGMod Mod
d2sDiablo 2 savegame
ROMs
rpxWii U Application
spcSPC700 Dump
smcSNES Rom
sfcSuper Famicom Rom
z64Nintendo 64 Rom
ndsNintendo DS Rom
gbaNintendo GameBoy Advance Rom
gbNintendo GameBoy Rom
nesNES ROM
Archive
zipLossless compressed archive
jarJava Archivce
Media
Audio
xmExtended Module Audio File
modModule Audio File
wavUncompressed Wave audio
Video
bikBink Video/Audio Container
bik2Bink Video/Audio Container
bk2Bink Video/Audio Container
Image
pngPortable Network Graphic
bmpBitmap
gifGraphics Interchange Format
jpgJoint Photographic (Experts) Group
jpegJoint Photographic Experts Group
jfifJPEG File Interchange Format
asepriteAseprite project file
Geometry
objWavefront OBJ
Misc
urlWindows shortcuts that point to a webstite

Restore Extension From Content

Can scan files to try to recognize the type and its file extension. Works for a ton of types.

CLI Usage

This package contains a script (fileinfo) that can be run from the CLI.
Usage: fileinfo [options] <file> [<file>...] [options]
See fileinfo --help for more information

List of supported options:

shortlongdescription
hhelpPrints help text
vversionPrints version text
aallShow all possible information
fullSame as all
eextensionOverride extension
ccontextUse context instead of extension
rreconstructTry to reconstruct extension for file by content
fformatFormat of the output
ddebugThrow Exceptions (if not specified, print the message)

Does work with multiple input files (fileinfo samples/*), however, the output differs and might not be considered stable when multiple files are shown.

Development Notes

Adding a new FileInfoExtractor

  1. Create a new class in src/InfoExtractor/Extractor/[…]
  2. Implement InfoExtractor
    • Try to use keys from InfoCommonKeys
  3. Create a new KnownExtension and Context
  4. Register it in DefaultDefinition

Adding a new ExtensionReader

For simple, non-offset magic bytes, add an entry to FileExtensionMagicByteSupplier::DEFAULT_SIMPLE_MAGIC.

For more complex ones:

  1. Create a new class in src/FileExtension/Reader/[…]
  2. Implement FileExtensionMagicByteReader
  3. Register it in FileExtensionMagicByteSupplier::DEFAULT_READERS

Acquiring sample files

Run the following command and give it an extension: bin/download-samples.php $extension
--all can be used to download all available samples.

Note that not all extensions have samples to download, due to practical or copyright reasons.

Local docker testing

dcd run --rm php bin/fileinfo ./samples/$file