def reg_openkey_noredir(key, sub_key, sam=_winreg.KEY_READ, create_if_missing=False): """Open the registry key\subkey with access rights sam Returns a key handle for reg_getvalue and reg_set_value key : HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER ... sub_key : string like "software\\microsoft\\windows\\currentversion" sam : a boolean comination of KEY_READ | KEY_WRITE create_if_missing : True to create the sub_key if not exists, access rights will include KEY_WRITE """ try: if platform.machine() == 'AMD64': return _winreg.OpenKey(key, sub_key, 0, sam | _winreg.KEY_WOW64_64KEY) else: return _winreg.OpenKey(key, sub_key, 0, sam) except WindowsError as e: if e.errno == 2: if create_if_missing: if platform.machine() == 'AMD64': return _winreg.CreateKeyEx( key, sub_key, 0, sam | _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY | _winreg.KEY_WRITE) else: return _winreg.CreateKeyEx( key, sub_key, 0, sam | _winreg.KEY_READ | _winreg.KEY_WRITE) else: raise WindowsError(e.errno, 'The key %s can not be opened' % sub_key)
def install_gedit_pecf_support (self): # If gedit installed, install pecf syntax os.chdir (path.join (eiffel_loop_home_dir, r'tool\toolkit')) edit_cmd = None gedit_dir = gedit_home_dir () if gedit_dir: print gedit_dir for gtk_ver in range (2, 4): specs_dir = path.join (gedit_dir, r'share\gtksourceview-%s.0\language-specs' % gtk_ver) if path.exists (specs_dir): dir_util.copy_tree ('language-specs', specs_dir) gedit_exe_path = path.join (gedit_dir, r'bin\gedit.exe') if path.exists (gedit_exe_path): edit_cmd = '"%s" "%%1"' % gedit_exe_path else: print 'It is recommended to install the gedit Text editor for editing .pecf files.' print 'Download and install from https://wiki.gnome.org/Apps/Gedit.' print "Then run 'setup.bat' again." r = raw_input ("Press <return> to continue") py_icon_path = path.join (python_home_dir, 'DLLs', 'py.ico') estudio_logo_path = r'"%ISE_EIFFEL%\contrib\examples\web\ewf\upload_image\htdocs\favicon.ico"' conversion_cmd = 'cmd /C el_toolkit -pyxis_to_xml -ask_user_to_quit -in "%1"' open_with_estudio_cmd = '"%s" "%%1"' % path.join (python_home_dir, "launch_estudio.bat") pecf_extension_cmds = {'open' : open_with_estudio_cmd, 'Convert To ECF' : conversion_cmd } pyx_extension_cmds = {'Convert To XML' : conversion_cmd } if edit_cmd: pecf_extension_cmds ['edit'] = edit_cmd pyx_extension_cmds ['open'] = edit_cmd pyx_extension_cmds ['edit'] = edit_cmd mime_types = [ ('.pecf', 'Pyxis.ECF.File', 'Pyxis Eiffel Configuration File', estudio_logo_path, pecf_extension_cmds), ('.pyx', 'Pyxis.File', 'Pyxis Data File', py_icon_path, pyx_extension_cmds) ] for extension_name, pyxis_key_name, description, icon_path, extension_cmds in mime_types: key = _winreg.CreateKeyEx (_winreg.HKEY_CLASSES_ROOT, extension_name, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValue (key, '', _winreg.REG_SZ, pyxis_key_name) pyxis_shell_path = path.join (pyxis_key_name, 'shell') for command_name, command in extension_cmds.iteritems(): command_path = path.join (pyxis_shell_path, command_name, 'command') print 'Setting:', command_path, 'to', command key = _winreg.CreateKeyEx (_winreg.HKEY_CLASSES_ROOT, command_path, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValue (key, '', _winreg.REG_SZ, command) key = _winreg.CreateKeyEx (_winreg.HKEY_CLASSES_ROOT, pyxis_key_name, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValue (key, '', _winreg.REG_SZ, description) key = _winreg.CreateKeyEx (_winreg.HKEY_CLASSES_ROOT, path.join (pyxis_key_name, 'DefaultIcon'), 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValue (key, '', _winreg.REG_SZ, icon_path)
def set_registry_value(key, value): reg_key = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, "Software\\OPE\\OPELMS\\student", 0, winreg.KEY_WOW64_64KEY | winreg.KEY_WRITE) winreg.SetValueEx(reg_key, key, 0, winreg.REG_SZ, value)
def register(root, key, subkey, value, regtype=winreg.REG_SZ): reg = winreg.CreateKeyEx(root, key, 0, winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_32KEY) if subkey == '@': winreg.SetValue(reg, None, regtype, value) else: winreg.SetValueEx(reg, subkey, 0, regtype, value) winreg.CloseKey(reg) reg = winreg.CreateKeyEx(root, key, 0, winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY) if subkey == '@': winreg.SetValue(reg, None, regtype, value) else: winreg.SetValueEx(reg, subkey, 0, regtype, value) winreg.CloseKey(reg)
def _set_dpi_mode(enabled): """ """ try: import _winreg as winreg # Python 2 except ImportError: import winreg # Python 3 try: dpi_support = winreg.OpenKey( winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers', 0, winreg.KEY_ALL_ACCESS) except WindowsError: dpi_support = winreg.CreateKeyEx( winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers', 0, winreg.KEY_ALL_ACCESS) try: subprocess_path = os.path.join(sys._MEIPASS, 'subprocess.exe') except: subprocess_path = os.path.join(os.path.dirname(cef.__file__), 'subprocess.exe') if enabled: winreg.SetValueEx(dpi_support, subprocess_path, 0, winreg.REG_SZ, '~HIGHDPIAWARE') else: winreg.DeleteValue(dpi_support, subprocess_path) winreg.CloseKey(dpi_support)
def update_registry_version(version): # updatethe registry with _winreg.CreateKeyEx(HKEY_LOCAL_MACHINE,r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WAPT_is1',\ 0, _winreg.KEY_READ| _winreg.KEY_WRITE ) as waptis: reg_setvalue(waptis,"DisplayName","WAPT %s" % version) reg_setvalue(waptis,"DisplayVersion","%s" % version) reg_setvalue(waptis,"InstallDate",currentdate())
def register(self): key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, r'Folder\shell') newKey = _winreg.CreateKeyEx(key, 'cmdPrompt', 0, KEY_ALL_ACCESS) subKey = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, r'Folder\shell\cmdPrompt') _winreg.SetValue(subKey, 'command', _winreg.REG_SZ, 'C:\Windows\system32\cmd.exe cd' + ' "%1"') _winreg.CloseKey(key) _winreg.CloseKey(subKey)
def Run(self): try: new_config = config_lib.CONFIG.MakeNewConfig() new_config.SetWriteBack(config_lib.CONFIG["Config.writeback"]) for mapping in config_lib.CONFIG["Installer.old_key_map"]: try: src, parameter_name = mapping.split("->") src_components = re.split(r"[/\\]", src.strip()) parameter_name = parameter_name.strip() key_name = "\\".join(src_components[1:-1]) value_name = src_components[-1] key = _winreg.CreateKeyEx( getattr(_winreg, src_components[0]), key_name, 0, _winreg.KEY_ALL_ACCESS) value, _ = _winreg.QueryValueEx(key, value_name) new_config.SetRaw(parameter_name, utils.SmartStr(value)) _winreg.DeleteValue(key, value_name) logging.info("Migrated old parameter %s", src) except (OSError, AttributeError, IndexError, ValueError) as e: logging.debug("mapping %s ignored: %s", mapping, e) finally: new_config.Write()
def foCreateWinRegKey(oSelf, sKeyName, bForWriting=False, uRegistryBits=0): uAccessMask = _winreg.KEY_READ | (bForWriting and _winreg.KEY_SET_VALUE or 0) | { 32: _winreg.KEY_WOW64_32KEY, 64: _winreg.KEY_WOW64_64KEY }.get(uRegistryBits, 0) return _winreg.CreateKeyEx(oSelf.oHive, sKeyName, 0, uAccessMask)
def registerEaseOfAccess(installDir): with _winreg.CreateKeyEx( _winreg.HKEY_LOCAL_MACHINE, easeOfAccess.APP_KEY_PATH, 0, _winreg.KEY_ALL_ACCESS | _winreg.KEY_WOW64_64KEY) as appKey: _winreg.SetValueEx(appKey, "ApplicationName", None, _winreg.REG_SZ, versionInfo.name) _winreg.SetValueEx(appKey, "Description", None, _winreg.REG_SZ, versionInfo.longName) if easeOfAccess.canConfigTerminateOnDesktopSwitch: _winreg.SetValueEx( appKey, "Profile", None, _winreg.REG_SZ, '<HCIModel><Accommodation type="severe vision"/></HCIModel>') _winreg.SetValueEx(appKey, "SimpleProfile", None, _winreg.REG_SZ, "screenreader") _winreg.SetValueEx(appKey, "ATExe", None, _winreg.REG_SZ, "nvda.exe") _winreg.SetValueEx(appKey, "StartExe", None, _winreg.REG_SZ, os.path.join(installDir, u"nvda.exe")) _winreg.SetValueEx(appKey, "StartParams", None, _winreg.REG_SZ, "--ease-of-access") _winreg.SetValueEx(appKey, "TerminateOnDesktopSwitch", None, _winreg.REG_DWORD, 0) else: # We don't want NVDA to appear in EoA because # starting NVDA from there won't work in this case. # We can do this by not setting Profile and SimpleProfile. # NVDA can still change the EoA logon settings. _winreg.SetValueEx(appKey, "ATExe", None, _winreg.REG_SZ, "nvda_eoaProxy.exe") _winreg.SetValueEx(appKey, "StartExe", None, _winreg.REG_SZ, os.path.join(installDir, u"nvda_eoaProxy.exe"))
def add_registry_keys(): for key in get_local_machine_registry_subkeys(KHRONOS_REG_PATH): if key is not None: key = RegistryKey(key[0], key[2], key[1]) if key in KEYS_NEEDED: KEYS_NEEDED.remove(key) else: # print("?: "+str(key)) pass # print("No keys left\nKeys to add: "+str(KEYS_NEEDED)) for key_needed in KEYS_NEEDED: try: try: subkey = winreg.CreateKeyEx(REG_HIVE, KHRONOS_REG_PATH, 0, winreg.KEY_CREATE_SUB_KEY) except WindowsError as error: print("Couldn't create subkeys at: %s\tReason: %s" % (KHRONOS_REG_PATH, error)) exit(1) finally: subkey.Close() with winreg.OpenKey(REG_HIVE, KHRONOS_REG_PATH, 0, winreg.KEY_WRITE) as key: winreg.SetValueEx(key, key_needed.name, 0, key_needed.data_type, key_needed.value) # print("+"+str(key_needed)) except WindowsError as error: print("Couldn't create (%s)\tReason: %s" % (key_needed, error)) exit(1)
def _check_reg(self, sub_key): # see comments in check_httpd(), above, for why this routine exists and what it's doing. try: # Note that we HKCR is a union of HKLM and HKCR (with the latter # overriding the former), so reading from HKCR ensures that we get # the value if it is set in either place. See als comments below. hkey = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, sub_key) args = _winreg.QueryValue(hkey, '').split() _winreg.CloseKey(hkey) # In order to keep multiple checkouts from stepping on each other, we simply check that an # existing entry points to a valid path and has the right command line. if len(args) == 2 and self._filesystem.exists(args[0]) and args[0].endswith('perl.exe') and args[1] == '-wT': return True except WindowsError as error: # WindowsError is not defined on non-Windows platforms - pylint: disable=undefined-variable if error.errno != errno.ENOENT: raise # The key simply probably doesn't exist. # Note that we write to HKCU so that we don't need privileged access # to the registry, and that will get reflected in HKCR when it is read, above. cmdline = self._path_from_chromium_base( 'third_party', 'perl', 'perl', 'bin', 'perl.exe') + ' -wT' hkey = _winreg.CreateKeyEx(_winreg.HKEY_CURRENT_USER, 'Software\\Classes\\' + sub_key, 0, _winreg.KEY_WRITE) _winreg.SetValue(hkey, '', _winreg.REG_SZ, cmdline) _winreg.CloseKey(hkey) return True
def SetRetentionExperimentState(self, state): """Creates experiment state in the Retention key for |state|.""" medium = 'Medium' if self._system_level else '' path = r'%s\ClientState%s\%s\Retention' % ( ChromeState._GOOGLE_UPDATE_PATH, medium, self._config['guid']) if self._system_level: path += '\\' + GetUserSidString() # _winreg doesn't have support for REG_QWORD, so do it manually. qword_zero = struct.pack('<q', 0) with _winreg.CreateKeyEx( self._registry_root, path, 0, _winreg.KEY_WOW64_32KEY | _winreg.KEY_SET_VALUE) as key: _winreg.SetValueEx(key, 'State', 0, _winreg.REG_DWORD, state) _winreg.SetValueEx(key, 'Group', 0, _winreg.REG_DWORD, 0) _winreg.SetValueEx(key, 'ToastLocation', 0, _winreg.REG_DWORD, 0) _winreg.SetValueEx(key, 'InactiveDays', 0, _winreg.REG_DWORD, 0) _winreg.SetValueEx(key, 'ToastCount', 0, _winreg.REG_DWORD, 0) _winreg.SetValueEx(key, 'FirstDisplayTime', 0, ChromeState._REG_QWORD, qword_zero) _winreg.SetValueEx(key, 'LatestDisplayTime', 0, ChromeState._REG_QWORD, qword_zero) _winreg.SetValueEx(key, 'UserSessionUptime', 0, ChromeState._REG_QWORD, qword_zero) _winreg.SetValueEx(key, 'ActionDelay', 0, ChromeState._REG_QWORD, qword_zero)
def MakeChromeMulti(chrome_long_name, chrome_clients_key, chrome_client_state_key, binaries_clients_key): # Update the control panel's uninstall string. key = _winreg.OpenKey( _winreg.HKEY_CURRENT_USER, ('Software\\Microsoft\\Windows\\CurrentVersion\\' 'Uninstall\\%s' % chrome_long_name), 0, _winreg.KEY_QUERY_VALUE | _winreg.KEY_SET_VALUE | _winreg.KEY_WOW64_32KEY) string = _winreg.QueryValueEx(key, 'UninstallString')[0] string = string.replace('--uninstall', '--uninstall --multi-install --chrome') _winreg.SetValueEx(key, 'UninstallString', 0, _winreg.REG_SZ, string) # Read Chrome's version number. key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, chrome_clients_key, 0, _winreg.KEY_QUERY_VALUE | _winreg.KEY_WOW64_32KEY) pv = _winreg.QueryValueEx(key, 'pv')[0] _winreg.CloseKey(key) # Write that version for the binaries. key = _winreg.CreateKeyEx(_winreg.HKEY_CURRENT_USER, binaries_clients_key, 0, _winreg.KEY_SET_VALUE | _winreg.KEY_WOW64_32KEY) _winreg.SetValueEx(key, 'pv', 0, _winreg.REG_SZ, pv) _winreg.CloseKey(key) # Add "--multi-install --chrome" to Chrome's UninstallArguments. key = _winreg.OpenKey( _winreg.HKEY_CURRENT_USER, chrome_client_state_key, 0, _winreg.KEY_QUERY_VALUE | _winreg.KEY_SET_VALUE | _winreg.KEY_WOW64_32KEY) args = _winreg.QueryValueEx(key, 'UninstallArguments')[0] args += ' --multi-install --chrome' _winreg.SetValueEx(key, 'UninstallArguments', 0, _winreg.REG_SZ, args)
def set_key(hkey, path, key, value, vtype='REG_DWORD', reflection=True): ''' Set a registry key vtype: http://docs.python.org/2/library/_winreg.html#value-types CLI Example: .. code-block:: bash salt '*' reg.set_key HKEY_CURRENT_USER 'SOFTWARE\\Salt' 'version' '0.97' REG_DWORD ''' registry = Registry() hkey2 = getattr(registry, hkey) access_mask = registry.reflection_mask[reflection] try: _type = getattr(_winreg, vtype) except AttributeError: return False try: handle = _winreg.OpenKey(hkey2, path, 0, access_mask) _winreg.SetValueEx(handle, key, 0, _type, value) _winreg.CloseKey(handle) return True except Exception: handle = _winreg.CreateKeyEx(hkey2, path, 0, access_mask) _winreg.SetValueEx(handle, key, 0, _type, value) _winreg.CloseKey(handle) return True
def set_control_scheme(self, controls): control_string = self.control_string(controls) if control_string is None: return regkey = registry.CreateKeyEx(registry.HKEY_CURRENT_USER, "Software\epsxe\config", 0, registry.KEY_SET_VALUE) registry.SetValueEx(regkey, "Pad1", 0, registry.REG_SZ, control_string)
def set_device(self,device): regkey = registry.CreateKeyEx(registry.HKEY_CURRENT_USER,"Software\JaboSoft\Project64 DLL\DirectInput7 1.6",0,registry.KEY_SET_VALUE) # I decode the string here so that the user can enter in things like # \xDE to insert the binary 11011110. This is about the best I can do in # terms of letting a user input freeform binary... decoded = device.decode("string-escape") if decoded != "": registry.SetValueEx(regkey,"di.DeviceGUID(0)",0,registry.REG_BINARY,decoded)
def add_vc9_reg(vc_dir): key = _winreg.CreateKeyEx(HCU, r"Software\Microsoft\VisualStudio\9.0\Setup\VC") _winreg.SetValueEx(key, "ProductDir", None, _winreg.REG_SZ, vc_dir) bat_path = find_vcvarsall(9.0) if bat_path is not None and path.exists(bat_path): print "Succeeded" else: print "Failed"
def updatereg(): import _winreg with _winreg.CreateKeyEx( _winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat", 0, _winreg.KEY_WOW64_64KEY | _winreg.KEY_ALL_ACCESS) as key: _winreg.SetValueEx(key, "cadca5fe-87d3-4b96-b7fb-a231484277cc", 0, _winreg.REG_DWORD, 0) print "Successfully updated the Registry path!"
def SetLastRunTime(self, delta): """Sets Chrome's lastrun time for the current user.""" path = r'%s\ClientState\%s' % (ChromeState._GOOGLE_UPDATE_PATH, self._config['guid']) lastrun = InternalTimeFromPyTime(datetime.utcnow() - delta) with _winreg.CreateKeyEx( _winreg.HKEY_CURRENT_USER, path, 0, _winreg.KEY_WOW64_32KEY | _winreg.KEY_SET_VALUE) as key: _winreg.SetValueEx(key, 'lastrun', 0, _winreg.REG_SZ, str(lastrun))
def set_control_scheme(self,controls): # Open the keys in a way to set them self.set_device(controls["device"]) controls.pop("device",None) regkey = registry.CreateKeyEx(registry.HKEY_CURRENT_USER,"Software\JaboSoft\Project64 DLL\DirectInput7 1.6\Keys 0",0,registry.KEY_SET_VALUE) for control,value in controls.iteritems(): key_name = self.reg_key_for_control(control) if value != "": registry.SetValueEx(regkey,key_name,0,registry.REG_DWORD,int(value))
def _set_ie_mode(): """ By default hosted IE control emulates IE7 regardless which version of IE is installed. To fix this, a proper value must be set for the executable. See http://msdn.microsoft.com/en-us/library/ee330730%28v=vs.85%29.aspx#browser_emulation for details on this behaviour. """ try: import _winreg as winreg # Python 2 FileNotFoundError = WindowsError # FileNotFoundError is found in Python 3 except ImportError: import winreg # Python 3 def get_ie_mode(): """ Get the installed version of IE :return: """ ie_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'Software\Microsoft\Internet Explorer') try: version, type = winreg.QueryValueEx(ie_key, "svcVersion") except FileNotFoundError: version, type = winreg.QueryValueEx(ie_key, "Version") winreg.CloseKey(ie_key) if version.startswith("11"): value = 0x2AF9 elif version.startswith("10"): value = 0x2711 elif version.startswith("9"): value = 0x270F elif version.startswith("8"): value = 0x22B8 else: value = 0x2AF9 # Set IE11 as default return value try: browser_emulation = winreg.OpenKey( winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 0, winreg.KEY_ALL_ACCESS) except WindowsError: browser_emulation = winreg.CreateKeyEx( winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 0, winreg.KEY_ALL_ACCESS) mode = get_ie_mode() executable_name = sys.executable.split("\\")[-1] winreg.SetValueEx(browser_emulation, executable_name, 0, winreg.REG_DWORD, mode) winreg.CloseKey(browser_emulation)
def SetRebootPendingTime(reset=False): if reset: now = "None" else: now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") with _winreg.CreateKeyEx( _winreg.HKEY_LOCAL_MACHINE, R"SOFTWARE\Wpkg-GP-Client", 0, _winreg.KEY_ALL_ACCESS | _winreg.KEY_WOW64_64KEY) as key: _winreg.SetValueEx(key, "RebootPending", 0, _winreg.REG_EXPAND_SZ, now)
def writeConfig(data): try: key = wreg.OpenKey(baseKey, path, 0, wreg.KEY_ALL_ACCESS) # @UndefinedVariable except Exception: key = wreg.CreateKeyEx(baseKey, path, 0, wreg.KEY_ALL_ACCESS) # @UndefinedVariable fixRegistryPermissions(key.handle) wreg.SetValueEx(key, "", 0, wreg.REG_BINARY, encoder(cPickle.dumps(data))) # @UndefinedVariable wreg.CloseKey(key) # @UndefinedVariable
def set_value(hive, key, vname=None, vdata=None, vtype='REG_SZ', reflection=True): ''' Sets a registry value entry or the default value for a key. :param str hive: The name of the hive. Can be one of the following - HKEY_LOCAL_MACHINE or HKLM - HKEY_CURRENT_USER or HKCU - HKEY_USER or HKU :param str key: The key (looks like a path) to the value name. :param str vname: The value name. These are the individual name/data pairs under the key. If not passed, the key (Default) value will be set. :param str vdata: The value data to be set. :param str vtype: The value type. Can be one of the following: - REG_BINARY - REG_DWORD - REG_EXPAND_SZ - REG_MULTI_SZ - REG_SZ :param bool reflection: A boolean value indicating that the value should also be set in the Wow6432Node portion of the registry. Only applies to 64 bit Windows. This setting is ignored for 32 bit Windows. :return: Returns True if successful, False if not :rtype: bool CLI Example: .. code-block:: bash salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' ''' registry = Registry() hive = registry.hkeys[hive] vtype = registry.vtype[vtype] access_mask = registry.reflection_mask[reflection] try: handle = _winreg.CreateKeyEx(hive, key, 0, access_mask) _winreg.SetValueEx(handle, vname, 0, vtype, vdata) _winreg.CloseKey(handle) return True except (WindowsError, ValueError) as exc: # pylint: disable=E0602 log.error(exc) return False
def create(self): # TODO: document try: self._phkey = _winreg.CreateKeyEx(self.surkey.phkey, self.name, 0, self.sam) except WindowsError as e: raise WindowsError( e.winerror, "Could not create registry key <{0}> ({1})".format( self.fullname, e.strerror)) return self._phkey
def register_app_path(): try: if cons.OS_WIN and _winreg is not None: sub_key = os.path.join('Software', cons.APP_NAME) with _winreg.CreateKeyEx(_winreg.HKEY_CURRENT_USER, sub_key, 0, _winreg.KEY_WRITE) as key: _winreg.SetValueEx(key, 'path', 0, _winreg.REG_SZ, cons.APP_PATH) except Exception as err: logger.warning(err)
def recall(key): try: reg = winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, "SOFTWARE\\simscript", 0, winreg.KEY_READ) value, _ = winreg.QueryValueEx(reg, key) return value except: logging.getLogger(__name__).warn( "can't read %s from windows registry" % key) return None
def antiDebug(self, exe_name, start_address, end_address): teb = pykd.dbgCommand("r $teb").split("=")[1].strip("\n") # peb!isdebugged #TODO: Fix the below command #pykd.dbgCommand("eb "+ hex(int(teb,16)+int("1000",16)+2)[2:]+" 0") #PEB.ProcessHeap.Flags a = pykd.dbgCommand("dd " + hex(int(teb, 16) + int("1000", 16) + 24)[2:]).split("\n")[0].split(" ")[2] exe_entry_address = pykd.dbgCommand("r $exentry").split("=")[1].strip( "\n") self.breakpoints_info += exe_entry_address + " " + "exe_entry_address" + "\n" self.bp_init.append( pykd.setBp(int(exe_entry_address, 16), self.break_hit)) pykd.dbgCommand("ed " + hex(int(a, 16) + 64) + " 0") pykd.dbgCommand("ed " + hex(int(a, 16) + 68) + " 0") #peb!heapflags isdebugged = pykd.dbgCommand( "db " + hex(int(teb, 16) + int("1000", 16) + int("68", 16))[2:]) pykd.dbgCommand("eb " + hex(int(teb, 16) + int("1000", 16) + int("68", 16))[2:] + " 0") isdebugged = pykd.dbgCommand( "db " + hex(int(teb, 16) + int("1000", 16) + int("68", 16))[2:]) # Stack segment modification bypass a = pykd.dbgCommand("s " + start_address + " L" + hex(int(end_address, 16) - int(start_address, 16)) + " 66 9c 58") try: for i in a.split("\n"): print i.split(" ")[0] a = pykd.dbgCommand("!address " + i.split(" ")[0]) if "EXECUTE" in a and len(i.split(" ")[0]) > 6: b = pykd.dbgCommand("u " + i.split(" ")[0]) if "???" in b: pass else: # replaces 66 9c 58 # pushf pop eax to cc 33 c0 # int 3 xor eax,eax pykd.dbgCommand("bp " + i.split(" ")[0] + '"' + " eb @eip cc 33 c0;gc;" + '"') except: pass try: registry_key = _winreg.CreateKeyEx( _winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options" + "\\" + exe_name, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(registry_key, "GlobalFlags", 0, _winreg.REG_SZ, "") _winreg.CloseKey(registry_key) except Exception as e: print "exception in reg" + str(e)
def registerInstallation(installDir,startMenuFolder,shouldCreateDesktopShortcut,startOnLogonScreen,configInLocalAppData=False): import _winreg with _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\NVDA",0,_winreg.KEY_WRITE) as k: for name,value in uninstallerRegInfo.iteritems(): _winreg.SetValueEx(k,name,None,_winreg.REG_SZ,value.format(installDir=installDir)) with _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\nvda.exe",0,_winreg.KEY_WRITE) as k: _winreg.SetValueEx(k,"",None,_winreg.REG_SZ,os.path.join(installDir,"nvda.exe")) with _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE,config.NVDA_REGKEY,0,_winreg.KEY_WRITE) as k: _winreg.SetValueEx(k,"startMenuFolder",None,_winreg.REG_SZ,startMenuFolder) if configInLocalAppData: _winreg.SetValueEx(k,config.CONFIG_IN_LOCAL_APPDATA_SUBKEY,None,_winreg.REG_DWORD,int(configInLocalAppData)) if easeOfAccess.isSupported: registerEaseOfAccess(installDir) else: import nvda_service nvda_service.installService(installDir) nvda_service.startService() if startOnLogonScreen is not None: config._setStartOnLogonScreen(startOnLogonScreen) NVDAExe=os.path.join(installDir,u"nvda.exe") slaveExe=os.path.join(installDir,u"nvda_slave.exe") if shouldCreateDesktopShortcut: # Translators: The shortcut key used to start NVDA. # This should normally be left as is, but might be changed for some locales # if the default key causes problems for the normal locale keyboard layout. # The key must be formatted as described in this article: # http://msdn.microsoft.com/en-us/library/3zb1shc6%28v=vs.84%29.aspx createShortcut(u"NVDA.lnk",targetPath=slaveExe,arguments="launchNVDA -r",hotkey=_("CTRL+ALT+N"),workingDirectory=installDir,prependSpecialFolder="AllUsersDesktop") createShortcut(os.path.join(startMenuFolder,"NVDA.lnk"),targetPath=NVDAExe,workingDirectory=installDir,prependSpecialFolder="AllUsersPrograms") # Translators: A label for a shortcut in start menu and a menu entry in NVDA menu (to go to NVDA website). createShortcut(os.path.join(startMenuFolder,_("NVDA web site")+".lnk"),targetPath=versionInfo.url,prependSpecialFolder="AllUsersPrograms") # Translators: A label for a shortcut item in start menu to uninstall NVDA from the computer. createShortcut(os.path.join(startMenuFolder,_("Uninstall NVDA")+".lnk"),targetPath=os.path.join(installDir,"uninstall.exe"),workingDirectory=installDir,prependSpecialFolder="AllUsersPrograms") # Translators: A label for a shortcut item in start menu to open current user's NVDA configuration directory. createShortcut(os.path.join(startMenuFolder,_("Explore NVDA user configuration directory")+".lnk"),targetPath=slaveExe,arguments="explore_userConfigPath",workingDirectory=installDir,prependSpecialFolder="AllUsersPrograms") # Translators: The label of the NVDA Documentation menu in the Start Menu. docFolder=os.path.join(startMenuFolder,_("Documentation")) # Translators: The label of the Start Menu item to open the Commands Quick Reference document. createShortcut(os.path.join(docFolder,_("Commands Quick Reference")+".lnk"),targetPath=getDocFilePath("keyCommands.html",installDir),prependSpecialFolder="AllUsersPrograms") # Translators: A label for a shortcut in start menu to open NVDA user guide. createShortcut(os.path.join(docFolder,_("User Guide")+".lnk"),targetPath=getDocFilePath("userGuide.html",installDir),prependSpecialFolder="AllUsersPrograms") registerAddonFileAssociation(slaveExe)