سلام. از روش زیر استفاده کنید یک مسیر دریافت می کنه و تمام ماژول های آن بررسی میشه و لیست فایل های x86, x64 به صورت مجزا در همان مسیر ذخیره میشه.
import sys
import glob
import os
import platform
import struct
import subprocess
def main():
if len(sys.argv) != 2 :
return
path = sys.argv[1]
if not os.path.exists(path):
return
text_file_64 = os.path.join(path,'result_x64.txt')
text_file_86 = os.path.join(path, 'result_x86.txt')
f_64 = open(text_file_64,'w')
f_86 = open(text_file_86, 'w')
files = glob.glob(os.path.join(path,'*.*'))
for file in files:
filename, file_extension = os.path.splitext(file)
file_extension = file_extension.lower()
if not(file_extension == '.exe' or file_extension == '.dll'):
continue
# str = /HEADERS '+ file+' | findstr machine';
command = [R'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64\dumpbin.exe','/HEADERS',file]
p = subprocess.Popen(command, stdout=subprocess.PIPE)
text = p.stdout.read()
text = text.decode("utf-8")
retcode = p.wait()
list1 = text.split('\n')
for l in list1 :
if l.find('machine (') != -1:
if l.find('(x64)') != -1:
f_64.write(file + '\n')
else :f_86.write(file + '\n')
f_64.close()
f_86.close()
if __name__ == '__main__':
main()