一个Python写的小工具,计算文件的MD5和SHA1,目前对指定文件进行计算,稍微修改,就可以为作为发布版本.
程序代码
#file md5
#!/usr/bin/env python
import sys;
import hashlib;
import os.path;
def GetFileMd5(strFile):
file = None;
bRet = False;
strMd5 = "";
strSha1 = "";
try:
file = open(strFile, "rb");
md5 = hashlib.md5();
sha1 = hashlib.sha1();
strRead = "";
while True:
strRead = file.read(8096);
if not strRead:
break;
else:
md5.update(strRead);
sha1.update(strRead);
#read file finish
bRet = True;
strMd5 = md5.hexdigest();
strSha1 = sha1.hexdigest();
except:
bRet = False;
finally:
if file:
file.close()
return [bRet, strMd5, strSha1];
def writFile(strInfo):
file = None;
file = open("E:\\1.txt", 'w+');
file.write(strInfo);
file.write("\n");
if file:
file.close();
if "__main__" == __name__:
bOK , md5str1, sha1str1 = GetFileMd5("E:\\Nativelayer\\NLayer\\platform\\android\\libs\\armeabi\\libNLayer.so");
print(md5str1);
md5All = md5str1 + "\t" + sha1str1;
md5All += "\n";
bOK , md5str2, sha1str2 = GetFileMd5("E:\\Nativelayer\\NLayer\\platform\\android\\libs\\armeabi-v7a\\libNLayer.so");
print(md5str2);
writFile(md5str2 + "\t" +sha1str2);
md5All += (md5str2 + "\t" + sha1str2);
md5All += "\n";
bOK , md5str3, sha1str3 = GetFileMd5("E:\\Nativelayer\\NLayer\\platform\\android\\libs\\x86\\libNLayer.so");
print(md5str3);
writFile(md5str3 + "\t" +sha1str3);
md5All += (md5str2 + "\t" + sha1str3);
md5All += "\n";
writFile(md5All);