import
os, sys
from
signify.authenticode
import
*
target_dir
=
sys.argv[
1
]
file_processed
=
0
file_failed
=
0
for
root, dirs, files
in
os.walk(target_dir):
for
file
in
files:
filename
=
os.path.join(root,
file
)
try
:
total_count
=
0
vaild_count
=
0
with
open
(filename,
'rb'
) as f:
signed_pe
=
SignedPEFile(f)
for
sig
in
signed_pe.signed_datas:
isvaild
=
sig.explain_verify()
if
isvaild[
0
]
=
=
AuthenticodeVerificationResult.OK:
vaild_count
+
=
1
total_count
+
=
1
if
total_count >
1
and
vaild_count < total_count:
print
(filename)
file_processed
+
=
1
except
Exception as e:
print
(
'处理文件 %s 时失败,错误信息: %s'
%
(filename, e),
file
=
sys.stderr)
file_failed
+
=
1
print
(
'成功处理 %d 个文件,处理失败 %d 个文件'
%
(file_processed, file_failed),
file
=
sys.stderr)