Module: FFI::Ssdeep
- Extended by:
- Library
- Defined in:
- lib/ffi/ssdeep.rb
Defined Under Namespace
Classes: HashError
Constant Summary
- SPAMSUM_LENGTH =
64- FUZZY_MAX_RESULT =
(SPAMSUM_LENGTH + (SPAMSUM_LENGTH/2 + 20))
Class Method Summary (collapse)
-
+ (Object) compare(sig1, sig2)
Compare two hashes.
-
+ (Object) from_file(filename)
Create a fuzzy hash from a file.
-
+ (Object) from_fileno(fileno)
Create a fuzzy hash from a file descriptor fileno.
-
+ (Object) from_string(buf)
Create a fuzzy hash from a ruby string.
Class Method Details
+ (Object) compare(sig1, sig2)
Compare two hashes
100 101 102 103 104 105 |
# File 'lib/ffi/ssdeep.rb', line 100 def self.compare(sig1, sig2) psig1 = FFI::MemoryPointer.from_string(sig1) psig2 = FFI::MemoryPointer.from_string(sig2) return fuzzy_compare(psig1, psig2) end |
+ (Object) from_file(filename)
Create a fuzzy hash from a file
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ffi/ssdeep.rb', line 81 def self.from_file(filename) File.stat(filename) out = FFI::MemoryPointer.new(FUZZY_MAX_RESULT) if (ret=fuzzy_hash_filename(filename, out)) == 0 return out.read_string else raise(HashError, "An error occurred hashing the file: #{filename} -- ret=#{ret}"); end end |
+ (Object) from_fileno(fileno)
Create a fuzzy hash from a file descriptor fileno
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ffi/ssdeep.rb', line 59 def self.from_fileno(fileno) if (not fileno.kind_of?(Integer)) or (file=fdopen(fileno, "r")).null? raise(HashError, "Unable to open file descriptor: #{fileno}") end out = FFI::MemoryPointer.new(FUZZY_MAX_RESULT) if (ret=fuzzy_hash_file(file, out)) == 0 return out.read_string else raise(HashError, "An error occurred hashing the file descriptor: #{fileno} -- ret=#{ret}") end end |
+ (Object) from_string(buf)
Create a fuzzy hash from a ruby string
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ffi/ssdeep.rb', line 38 def self.from_string(buf) bufp = FFI::MemoryPointer.new(buf.size) bufp.write_string(buf) out = FFI::MemoryPointer.new(FUZZY_MAX_RESULT) if (ret=fuzzy_hash_buf(bufp, bufp.size, out)) == 0 return out.read_string else raise(HashError, "An error occurred hashing a string: ret=#{ret}") end end |