class Allsum::Client::Complicator

Public Class Methods

calculate_checksums(file) click to toggle source
# File lib/allsum/client/complicator.rb, line 32
def self.calculate_checksums(file)
  begin
    puts "Filename: #{@filename}"
    puts "[x]calculating checksums" if @debug || @verbose
    #md5
    @md5digest = Digest::MD5.hexdigest(File.read(file))
    puts "  MD5 checksum: #{@md5digest}" if @debug || @verbose
    #sha1
    @sha1digest = Digest::SHA1.hexdigest(File.read(file))
    puts "  SHA1 checksum: #{@sha1digest}" if @debug || @verbose
    #sha256
    @sha256digest = Digest::SHA256.hexdigest(File.read(file))
    puts "  SHA256 checksum: #{@sha256digest}" if @debug || @verbose
        #fuzzy hash
        @fuzzyhash = Ssdeep::FuzzyHash.from_file(file)
        puts "  Fuzzy hash: #{@fuzzyhash}" if @debug || @verbose
  rescue Errno::EACCESS
    puts "Perrmission denied when attempting to read #{@filename}" if @debug || @verbose
  end
end
file_size(path) click to toggle source
# File lib/allsum/client/complicator.rb, line 58
def self.file_size(path)
  puts "[x]checking file size" if @debug || @verbose
      @filesize = File.size?(path)

      puts "Filesize: #{@filesize}" if @debug || @verbose
  @filepath = path
end
file_type(path) click to toggle source
# File lib/allsum/client/complicator.rb, line 53
def self.file_type(path)
  puts "[x]checking file type" if @debug || @verbose
      @filetype = File.basename(path.downcase).split(".").last
end
filename(path) click to toggle source
# File lib/allsum/client/complicator.rb, line 13
def self.filename(path)
    @filename = Pathname.new(path).basename
end
log_to_db(file) click to toggle source
# File lib/allsum/client/complicator.rb, line 66
def self.log_to_db(file)
  # schema:  uid | file name | size | file type | product | version info | modification date | ms bulletin | build | md5 | sha1  | sha256 | comment(?)
      puts "[x]logging to database" if @debug || @verbose

      Allsum::Client::Logger.paper(@filename, @filetype, @md5digest, @sha1digest, @sha256digest, @filepath, @fuzzyhash,
        @fileversion, @filesize)
  end
version_info(file) click to toggle source
# File lib/allsum/client/complicator.rb, line 17
def self.version_info(file)
  vsize=Win32API.new('version.dll', 'GetFileVersionInfoSize', ['P', 'P'], 'L').call(file, "") # "" was s
  #p vsize if @debug
  if (vsize > 0)
    result = ' '*vsize
    Win32API.new('version.dll', 'GetFileVersionInfo', ['P', 'L', 'L', 'P'], 'L').call(file, 0, vsize, result)
    rstring = result.unpack('v*').map{|s| s.chr if s<256}*''
    r = /FileVersion..(.*?)\000/.match(rstring)
    puts "FileVersion = #{r ? r[1] : '??' }" if @verbose || @debug
    @fileversion = r ? r[1] : '??'
  else
    puts "No Version Info"  if @verbose || @debug
  end
end