#recover all infected .ZMX file
import os
count=0 # Global 变量
os.system(r'attrib -s -h *.zmx /s') #所有感染文件感染后的属性是系统文件和隐藏文件
#括号内的参数实际上是windows的shell命令,其作用为修改感染文件属性为为普通属性
cwd=os.getcwd()#获得当前文件夹
#core函数是一个递归函数,将所有感染的ZMX文件后缀改回到.exe
def core(n_dir):
global count
print 'now in'+n_dir
os.chdir(n_dir)
li=os.listdir(n_dir)
lifile=[x for x in li if '.ZMX' in x]
if len(lifile)!=0:
print lifile
for f in lifile:
os.rename(f,f.replace('.ZMX','.exe'))
print 'file'+f+'is cured successfully!'
count+=1
lidir=[x for x in li if os.path.isdir(x)]
if len(lidir)==0:
return
print lidir #just for debug
for d in lidir:
core(n_dir+'\\'+d)
if __name__ == "__main__":
core(cwd)
print "congratulations!!"+str(count)+" infected files r found in"+cwd+' and they r all successfully cured!!!'
raw_input("Press any key to end program") #该语句可以避免命令行窗口自动关闭