【发布时间】:2021-12-10 15:08:22
【问题描述】:
我正在编写一个将校验和和目录作为输入的脚本。 在没有太多背景的情况下,我正在可执行文件目录中寻找“恶意软件”(即标志)。我得到了“恶意软件”的 SHA512 总和。我已经让它工作了(我找到了标志),但是在为不同的加密协议、编码和单个文件而不是目录概括了函数后,我遇到了输出问题:
FileNotFoundError: [Errno 2] No such file or directory : 'lessecho'
目录中确实有一个文件lessecho,并且碰巧接近返回实际标志的文件。大概是巧合吧。大概吧。
下面是我的 Python 脚本:
#!/usr/bin/python3
import hashlib, sys, os
"""
### TO DO ###
Add other encryption techniques
Include file read functionality
"""
def main(to_check = sys.argv[1:]):
dir_to_check = to_check[0]
hash_to_check = to_check[1]
BUF_SIZE = 65536
for f in os.listdir(dir_to_check):
sha256 = hashlib.sha256()
with open(f, 'br') as f: <--- line where the issue occurs
while True:
data = f.read(BUF_SIZE)
if not data:
break
sha256.update(data)
f.close()
if sha256.hexdigest() == hash_to_check:
return f
if __name__ == '__main__':
k = main()
print(k)
感谢 Randall 的回答 here
这里有一些来自我家乡的不起眼的小饰品,以换取你的智慧。
【问题讨论】:
-
出现错误的行是什么?
-
谢谢。刚刚更新了markdown。
标签: python-3.x file-not-found python-os