Class: Uirusu::VTResult

Inherits:
Object
  • Object
show all
Defined in:
lib/uirusu/vtresult.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash, result) ⇒ VTResult

Returns a new instance of VTResult.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/uirusu/vtresult.rb', line 5

def initialize hash, result
	if result == nil
		return
	end

	@results = Array.new

	if result["response_code"] == 0
		res = Hash.new
		res['hash'] = hash
		res['scanner'] = '-'
		res['md5'] = '-'
		res['sha1'] = '-'
		res['sha256'] = '-'
		res['detected'] = '-'
		res['version'] = '-'
		res['result']  = '-'
		res['update'] = '-'
		res['permalink'] = '-'
		res['result'] = result["verbose_msg"]

		@results.push res
	elsif result["response_code"] == 0
		puts "[!] Invalid API KEY! Please correct this! Check ~/.uirusu"
		exit
	else
		permalink = result["permalink"]
		date = result["scan_date"]
		md5 = result["md5"]
		sha1 = result["sha1"]
		sha256 = result["sha256"]
		
		result["scans"].each do |scanner, value|
			if value != ''
				res = Hash.new
				res['hash'] = hash
				res['md5'] = md5
				res['sha1'] = sha1
				res['sha256'] = sha256
				res['scanner'] = scanner
				res['detected'] = value["detected"]
				res['version'] = value["version"]

				if value["result"] == nil
					res['result'] = "Nothing detected"
				else
					res['result']  = value["result"]
				end
				
				res['update'] = value['update']
				res['permalink'] = permalink unless permalink == nil

				@results.push res
			end
		end
	end
	
	#if we didn't have any results let create a fake not found
	if @results.size == 0
		res = Hash.new
		res['hash'] = hash
		res['scanner'] = '-'
		res['md5'] = '-'
		res['sha1'] = '-'
		res['sha256'] = '-'
		res['permalink'] = '-'
		res['detected'] = '-'
		res['version'] = '-'
		res['result']  = '-'
		res['update'] = '-'
		res['result'] = result["verbose_msg"]
		@results.push res				
	end
end

Instance Method Details

#to_stdoutObject



82
83
84
85
86
87
88
89
# File 'lib/uirusu/vtresult.rb', line 82

def to_stdout
	result_string = String.new
	@results.each do |result|				
		result_string << "#{result['hash']}: Scanner: #{result['scanner']} Result: #{result['result']}\n"
	end
	
	print result_string
end

#to_xmlObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/uirusu/vtresult.rb', line 113

def to_xml
	result_string = String.new
	@results.each do |result|
		result_string << "\t<vtresult>\n"
		result_string << "\t\t<hash>#{result['hash']}</hash>\n"
		result_string << "\t\t<md5>#{result['md5']}</md5>\n"
		result_string << "\t\t<sha1>#{result['sha1']}</sha1>\n"
		result_string << "\t\t<sha256>#{result['sha256']}</sha256>\n"
		result_string << "\t\t<scanner>#{result['scanner']}</scanner>\n"
		result_string << "\t\t<detected>#{result['detected']}</detected>\n"
		result_string << "\t\t<date>#{result['date']}</date>\n"
		result_string << "\t\t<permalink>#{result['permalink']}</permalink>\n" unless result['permalink'] == nil
		result_string << "\t\t<result>#{result['result']}</result>\n"
		result_string << "\t</vtresult>\n"
	end
	
	print result_string
end

#to_yamlObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/uirusu/vtresult.rb', line 93

def to_yaml
	result_string = String.new
	@results.each do |result|
		result_string << "vtresult:\n"
		result_string << "  hash: #{result['hash']}\n"
		result_string << "  md5: #{result['md5']}\n"
		result_string << "  sha1: #{result['sha1']}\n"
		result_string << "  sha256: #{result['sha256']}\n"
		result_string << "  scanner: #{result['scanner']}\n"
		result_string << "  detected: #{result['detected']}\n"
		result_string << "  date: #{result['date']}\n"
		result_string << "  permalink: #{result['permalink']}\n" unless result['permalink'] == nil
		result_string << "  result: #{result['result']}\n\n"
	end
	
	print result_string
end