ClamAV bindings for Crystal.
You'll need ClamAV installed.
On OS X:
$> brew update
$> brew install clamav
TODO: Installation instructions for other operation systems.
Add this to your application's shard.yml
:
dependencies:
crystal_av:
github: kofno/crystal_av
Before you can use ClamAV, you'll need to run the freshclam
utility. This
installs (or updates) the ClamAV database.
require "crystal_av"
You can scan a file (or many files) using the Engine class.
CrystalAV::Engine.load do |engine|
infected_file = File.expand_path(
"./fixtures/virus.txt",
File.dirname(__FILE__)
)
results = engine.scan(infected_file)
puts results.virus? #=> true
puts results.virus_name #=> Eicar-Test-Signature
end
Or you can use the low level bindings directly.
include CrystalAV
puts LibClamAV.cl_init(0)
engine = LibClamAV.cl_engine_new
puts engine
puts typeof(engine)
dbpath = LibClamAV.cl_retdbdir
puts String.new(dbpath)
signo = 0
signo_ptr = pointerof(signo)
puts LibClamAV.cl_load(dbpath, engine, signo_ptr, LibClamAV::CL_DB_STDOPT)
puts LibClamAV.cl_engine_compile(engine)
puts LibClamAV.cl_scanfile(
"/Users/you/Downloads/clamdoc.pdf",
out not_a_virus,
nil,
engine,
LibClamAV::CL_SCAN_STDOPT
)
puts LibClamAV.cl_scanfile(
"/Users/you/Downloads/example_virus.txt",
out virname,
nil,
engine,
LibClamAV::CL_SCAN_STDOPT
)
puts String.new(virname)
puts LibClamAV.cl_engine_free(engine)
TODO: Document bindings wrapper.
- Fork it ( https://github.com/kofno/crystal_av/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- kofno Ryan L. Bell - creator, maintainer