Skip to content

Commit 76ccf2f

Browse files
committed
Merge branch 'master' of github.com:trinitronx/vncpasswd.py
2 parents 8f26d0e + c4b3997 commit 76ccf2f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
*.pyc
2+
.idea/misc.xml
3+
*.xml
4+
*.iml

WindowsRegistry.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import _winreg as wreg
33
import cPickle as pickle
4+
import platform
45

56
class WindowsRegistry:
67
""" A class to simplify read/write access to the Windows Registry """
@@ -58,7 +59,10 @@ def __init__(self, company="RealVNC", project="WinVNC4", create=0):
5859
i=0
5960
while not_opened and i<len(rights)-1:
6061
try:
61-
self.key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, self.keyname,0, rights[i])
62+
if platform.machine().endswith('64') and platform.architecture()[0] == '32bit':
63+
self.key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, self.keyname, 0, rights[i] | wreg.KEY_WOW64_64KEY)
64+
else:
65+
self.key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, self.keyname,0, rights[i])
6266
not_opened = False
6367
self.right = rights[i]
6468
#print "rights = %05x" % rights[i]

vncpasswd.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def main():
125125
if ( args.filename == None and args.passwd == None and (args.registry == False or not platform.system().startswith('Windows')) ):
126126
parser.error('Error: No password file or password passed\n')
127127
if ( args.registry and args.decrypt and platform.system().startswith('Windows')):
128-
reg = wreg.WindowsRegistry("RealVNC", "WinVNC4")
128+
reg = get_realvnc_key()
129129
( args.passwd, key_type) = reg.getval("Password")
130130
elif not platform.system().startswith('Windows'):
131131
print 'Cannot read from Windows Registry on a %s system' % platform.system()
@@ -159,7 +159,7 @@ def main():
159159
if ( args.filename != None and not args.decrypt ):
160160
do_file_out(args.filename, crypted, args.hex)
161161
if ( args.registry and not args.decrypt and platform.system().startswith('Windows')):
162-
reg = wreg.WindowsRegistry("RealVNC", "WinVNC4")
162+
reg = get_realvnc_key()
163163
reg.setval('Password', crypted, wreg.WindowsRegistry.REG_BINARY)
164164
elif not platform.system().startswith('Windows'):
165165
print 'Cannot write to Windows Registry on a %s system' % platform.system()
@@ -168,5 +168,22 @@ def main():
168168
print "%scrypted Bin Pass= '%s'" % ( prefix, crypted )
169169
print "%scrypted Hex Pass= '%s'" % ( prefix, crypted.encode('hex') )
170170

171+
172+
def get_realvnc_key():
173+
reg = None
174+
175+
for k in ['vncserver', 'WinVNC4',]:
176+
try:
177+
reg = wreg.WindowsRegistry('RealVNC', k)
178+
break
179+
except WindowsError as e:
180+
if 'The system cannot find the file specified' in str(e):
181+
pass
182+
else:
183+
raise e
184+
185+
return reg
186+
187+
171188
if __name__ == '__main__':
172189
main()

0 commit comments

Comments
 (0)