#_*_coding:gb2312_*_#########################Writer:Write by lhsbqb##Date:2012-07-16 #########################import sysclass 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")