python 判斷Dll是32位還是64位

2021-06-07 19:00:17 字數 4367 閱讀 7736

#_*_coding:gb2312_*_

########################

#writer:write by lhsbqb#

#date:2012-07-16 #

########################

import sys

class getdllbit:

def __init__(self, dll_name=""):

if len(sys.argv) == 2: #獲取dll軟體名

#print sys.argv[1].decode('gb2312')

self.dll_name = sys.argv[1]

self.oper()

elif dll_name:

self.dll_name = dll_name

self.oper()

else:

print "error, please input only one dll file name."

def oper(self): #總操作 獲取pe標誌 找到pe入口

f = open(self.dll_name, "rb").read(80)

s1 = f[60:61] #低位

s2 = f[61:62] #高位

self.checkdll(self.convert(hex(ord(s1))),self.convert_h(hex(ord(s2))))

def checkdll(self, one, two): #判斷dll是多少位

res_num = int(one) + int(two) + 6

f = open(self.dll_name, "rb").read(res_num)

for c in f[res_num-2:res_num-1]:

#print("f[res_num-2:res_num-1]",hex(ord(c)))

s_1 = hex(ord(c))

for c in f[res_num-1:res_num]:

#print("f[res_num-1:res_num]",hex(ord(c)))

s_2 = hex(ord(c))

if s_1 == "0x4c" and s_2 == "0x1":

print("this program run in 32bit system!")

elif s_1 == "0x64" and s_2 == "0x86":

print("this program run in 64bit system!")

else:

print("error!"+s_1+s_2)

#print("res_num",res_num)

def convert(self, ss): #低位 進行編碼轉換

if len(ss) == 3:

if ss[-1] == "a" or ss[-1] == "a":

ss = 10

elif ss[-1] == "b" or ss[-1] == "b":

ss = 11

elif ss[-1] == "c" or ss[-1] == "c":

ss = 12

elif ss[-1] == "d" or ss[-1] == "d":

ss = 13

elif ss[-1] == "e" or ss[-1] == "e":

ss = 14

elif ss[-1] == "f" or ss[-1] == "f":

ss = 15

else:

ss = int(ss[-1])

elif len(ss) == 4:

if ss[-1] == "a" or ss[-1] == "a":

ss1 = 10

elif ss[-1] == "b" or ss[-1] == "b":

ss1 = 11

elif ss[-1] == "c" or ss[-1] == "c":

ss1 = 12

elif ss[-1] == "d" or ss[-1] == "d":

ss1 = 13

elif ss[-1] == "e" or ss[-1] == "e":

ss1 = 14

elif ss[-1] == "f" or ss[-1] == "f":

ss1 = 15

else:

ss1 = int(ss[-1])

if ss[-2:-1] == "a" or ss[-2:-1] == "a":

ss2 = 10*16

elif ss[-2:-1] == "b" or ss[-2:-1] == "b":

ss2 = 11*16

elif ss[-2:-1] == "c" or ss[-2:-1] == "c":

ss2 = 12*16

elif ss[-2:-1] == "d" or ss[-2:-1] == "d":

ss2 = 13*16

elif ss[-2:-1] == "e" or ss[-2:-1] == "e":

ss2 = 14*16

elif ss[-2:-1] == "f" or ss[-2:-1] == "f":

ss2 = 15*16

else:

ss2 = int(ss[-2:-1])*16

ss = ss1 + ss2

return ss

def convert_h(self, ss): #高位 進行編碼轉換

if len(ss) == 3:

if ss[-1] == "a" or ss[-1] == "a":

ss = 10*16*16

elif ss[-1] == "b" or ss[-1] == "b":

ss = 11*16*16

elif ss[-1] == "c" or ss[-1] == "c":

ss = 12*16*16

elif ss[-1] == "d" or ss[-1] == "d":

ss = 13*16*16

elif ss[-1] == "e" or ss[-1] == "e":

ss = 14*16*16

elif ss[-1] == "f" or ss[-1] == "f":

ss = 15*16*16

else:

ss = int(ss[-1])*16*16

elif len(ss) == 4:

if ss[-1] == "a" or ss[-1] == "a":

ss1 = 10*16*16

elif ss[-1] == "b" or ss[-1] == "b":

ss1 = 11*16*16

elif ss[-1] == "c" or ss[-1] == "c":

ss1 = 12*16*16

elif ss[-1] == "d" or ss[-1] == "d":

ss1 = 13*16*16

elif ss[-1] == "e" or ss[-1] == "e":

ss1 = 14*16*16

elif ss[-1] == "f" or ss[-1] == "f":

ss1 = 15*16*16

else:

ss1 = int(ss[-1])*16*16

if ss[-2:-1] == "a" or ss[-2:-1] == "a":

ss2 = 10*16*16*16

elif ss[-2:-1] == "b" or ss[-2:-1] == "b":

ss2 = 11*16*16*16

elif ss[-2:-1] == "c" or ss[-2:-1] == "c":

ss2 = 12*16*16*16

elif ss[-2:-1] == "d" or ss[-2:-1] == "d":

ss2 = 13*16*16*16

elif ss[-2:-1] == "e" or ss[-2:-1] == "e":

ss2 = 14*16*16*16

elif ss[-2:-1] == "f" or ss[-2:-1] == "f":

ss2 = 15*16*16*16

else:

ss2 = int(ss[-2:-1])*16*16*16

ss = ss1 + ss2

return ss

if __name__ == "__main__":

gdb = getdllbit("32.dll")

判斷機器 程式是32位還是64位

一 linux上如何知道自己的作業系統 計算機 是32位還是 64位的?linux users should type the uname command.depending on the platform,you may see linux gaylord.stata.com 2.6.11 1.2...

如何判斷Linux是32位還是64位

方法一 getconf long bit 在linux終端輸入getconf long bit命令 如果是32位機器,則結果為32 linux root localhost getconf long bit 32 如果是64位機器,則結果為64 linux root localhost getcon...

golang 判斷平台是32位還是64位

在strconv包中有個常量 const intsize 32 uint 0 63 const intsize intsize 在32位平台這個值為32 在64位平台,這個值為64 因此可以通過這個來判斷平台的位數.原理 在32平台系統 1.uint 0 在平台底層是0x00000000 2.uin...