查看: 252|回复: 1

[闲聊灌水] 论自我折磨

[复制链接]

1

技术

14

魅力

1

原创

退休版主

Rank: 8Rank: 8

积分
8187
人气
416
分享
59

论坛元老活跃会员灌水之王荣誉管理

发表于 2023-8-18 22:09:24 | 显示全部楼层 |阅读模式
[Ruby] 纯文本查看 复制代码
# frozen_string_literal: true
require 'digest'
class Srr
  @@sample_path, @@antivir_name, @@notes = nil, nil, nil
  @@deleted, @@fixed, @@missed, @@total = 0, 0, 0, 0
  @@SampleHash =  Hash.new
  def initializer(sample_path, antivir_name, notes)
    if sample_path == nil || antivir_name == nil
      raise "Error: sample_path or antivirus name is nil"
    else
      unless Dir.exist?(sample_path)
        raise "Error: sample_path is not a directory"
      end
    @@sample_path = sample_path
    @@antivir_name = antivir_name
    @@notes = notes
  end
  def ready()
    sample_list = Dir.entries(@@sample_path)
    puts sample_list
    sample_list.each do |sample|
      if sample != "." && sample != ".."
        @@total += 1
        puts(sample)
        data = File.read(@@sample_path + "\\" + sample)
        sample_hash = Digest::MD5.hexdigest(data)
        @@SampleHash[sample] = sample_hash
      end
    end
  end
    def check()
      sample_list = Dir.entries(@@sample_path)
      sample_list.each do |sample|
        if sample != "." && sample != ".."

        data = File.read(@@sample_path + "\\" + sample)
        sample_hash = Digest::MD5.hexdigest(data)
        if @@SampleHash[sample] != sample_hash
          @@fixed += 1
        else if @@SampleHash[sample] == sample_hash
               @@missed  += 1
             end
        end
        end
      end
      @@deleted = @@total - @@fixed - @@missed
      return "Deleted: "+ (@@deleted).to_s() +"\nFixed: "+ (@@fixed).to_s() +"\nMissed: "+ (@@missed).to_s() +"\nTotal: "+ (@@total).to_s() +"\nDetection rate: "+ ((@@total - @@missed) / @@total).to_s()
    end
  end
end

puts("Srr in Ruby v0.1.0 A demo for practising Ruby\n")
puts("Enter the path to the sample: ")
sample_path = gets.chomp
puts("Enter the name of the antivirus: ")
antivir_name = gets.chomp
puts("Enter the notes (Press enter to ignore): ")
notes = gets.chomp
srr = Srr.new
srr.initializer(sample_path, antivir_name, notes)
start_time = Time.now
srr.ready
end_time = Time.now
float = end_time - start_time
print("Finished. Used time: "+ (float).to_s() +" Press enter to check the sample: ")
gets.chomp
start_time2 = Time.now
rrr = srr.check()
end_time2 = Time.now
puts("Finished." + rrr + "Used time: "+ (end_time2 - start_time2).to_s() +"\nPress enter to exit: ")



花15分钟实现了个Ruby的Srr的Demo。但是调Bug调了10分钟。相比之下我竟然不知道写1个小时但是几乎不用改非代码逻辑性Bug的Rust和Ruby哪个是自我折磨。。

一个敢写不敢跑,一个敢跑不敢写

0

技术

5

魅力

0

原创

略有小成

禁止IP

Rank: 4

积分
2649
人气
21
分享
74
发表于 2023-8-19 14:02:47 | 显示全部楼层
az……
我都要吐血了,就差几天赶上招募……
不说了,肝作业去了……
Windows魔改爱好者一枚
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表