Magic
A Ruby C extension (and gem) for the libmagic library and database used by the file(1) command.
BUILD
The standard C extension build process is used:
bash# ruby extconf.rb bash# make
Note that the Ruby headers must be installed. On Ubuntu, these are in the ruby-dev or ruby1.9-dev package.
The gem is built using the standard gem build command:
bash# gem build Magic.gemspec
The top-level Makefile supports each of these builds with the commands ‘make’ and ‘make gem’.
bash# make # builds C extension bash# make gem # builds the gem
EXAMPLES
Extended examples are provided in the ‘examples’ directory. The following code snippets give a brief overview of using the BFD and Opcodes extensions together.
require ‘Magic’ File.open( ‘/tmp/a.out’ ) { |f| puts Magic::identify(f) }
File.open( ‘/tmp/a.out’ ) { |f| puts Magic::identify(f, => true) }
Magic.identify( ‘<html></html>’ )
Magic.identify( [0x7f, 0x45, 0x4c, 0x00] )