تشخیص x64 و x86 در پایتون - هفت خط کد انجمن پرسش و پاسخ برنامه نویسی

تشخیص x64 و x86 در پایتون

0 امتیاز

سلام .من از روش زیر برای تشخیص x64و x86 استفاده کردم ولی خروجی درست نیست.

import sys
import glob
import os
import platform


def main():
    if len(sys.argv) != 2 :
        return

    path = sys.argv[1]
    files = glob.glob(os.path.join(path,'*.*'))
    for file in files:
        print(platform.architecture(), file)


if __name__ == '__main__':
    main()

 

سوال شده آذر 5, 1397  بوسیله ی همایون (امتیاز 220)   10 38 43
دوباره تگ گذاری شد آذر 5, 1397 بوسیله ی مصطفی ساتکی

1 پاسخ

+1 امتیاز
 
بهترین پاسخ

سلام. از روش زیر استفاده کنید یک مسیر دریافت می کنه و تمام ماژول های آن بررسی میشه و لیست فایل های 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()

 

پاسخ داده شده آذر 5, 1397 بوسیله ی مصطفی ساتکی (امتیاز 21,998)   24 34 75
انتخاب شد آذر 5, 1397 بوسیله ی همایون
...