def detect(self, section): """Check whether to show the section The logic: If the DetectOS does not match, the section is inactive. If any Detect or DetectFile matches, the section is active. If neither Detect or DetectFile was given, the section is active. Otherwise, the section is inactive. """ if self.parser.has_option(section, 'detectos'): required_ver = self.parser.get(section, 'detectos') if not detectos(required_ver): return False any_detect_option = False if self.parser.has_option(section, 'specialdetect'): any_detect_option = True sd_code = self.parser.get(section, 'specialdetect') if special_detect(sd_code): return True for option in self.parser.options(section): if re.match(self.re_detect, option): # Detect= checks for a registry key any_detect_option = True key = self.parser.get(section, option) if Windows.detect_registry_key(key): return True elif re.match(self.re_detectfile, option): # DetectFile= checks for a file any_detect_option = True key = self.parser.get(section, option) if detect_file(key): return True return not any_detect_option
def detect(self, section): """Check whether to show the section The logic: If the DetectOS does not match, the section is inactive. If any Detect or DetectFile matches, the section is active. If neither Detect or DetectFile was given, the section is active. Otherwise, the section is inactive. """ if self.parser.has_option(section, 'detectos'): required_ver = self.parser.get(section, 'detectos').decode(FSE) if not detectos(required_ver): return False any_detect_option = False if self.parser.has_option(section, 'specialdetect'): any_detect_option = True sd_code = self.parser.get(section, 'specialdetect') if special_detect(sd_code): return True for option in self.parser.options(section): if re.match(self.re_detect, option): # Detect= checks for a registry key any_detect_option = True key = self.parser.get(section, option).decode(FSE) if Windows.detect_registry_key(key): return True elif re.match(self.re_detectfile, option): # DetectFile= checks for a file any_detect_option = True key = self.parser.get(section, option).decode(FSE) if detect_file(key): return True return not any_detect_option
def special_detect(code): """Check whether the SpecialDetect== software exists""" # The last two are used only for testing sd_keys = {'DET_CHROME': r'HKCU\Software\Google\Chrome', 'DET_MOZILLA': r'HKCU\Software\Mozilla\Firefox', 'DET_OPERA': r'HKCU\Software\Opera Software', 'DET_THUNDERBIRD': r'HKLM\SOFTWARE\Clients\Mail\Mozilla Thunderbird', 'DET_WINDOWS': r'HKCU\Software\Microsoft', 'DET_SPACE_QUEST': r'HKCU\Software\Sierra Games\Space Quest'} if code in sd_keys: return Windows.detect_registry_key(sd_keys[code]) else: logger.error('Unknown SpecialDetect=%s', code) return False
def special_detect(code): """Check whether the SpecialDetect== software exists""" # The last two are used only for testing sd_keys = {'DET_CHROME': r'HKCU\Software\Google\Chrome', 'DET_MOZILLA': r'HKCU\Software\Mozilla\Firefox', 'DET_OPERA': r'HKCU\Software\Opera Software', 'DET_THUNDERBIRD': r'HKLM\SOFTWARE\Clients\Mail\Mozilla Thunderbird', 'DET_WINDOWS': r'HKCU\Software\Microsoft', 'DET_SPACE_QUEST': r'HKCU\Software\Sierra Games\Space Quest'} if sd_keys.has_key(code): return Windows.detect_registry_key(sd_keys[code]) else: logger.error('Unknown SpecialDetect=%s', code) return False
def handle_section(self, section): """Parse a section""" # if simple detection fails then discard the section if self.parser.has_option(section, 'detect'): key = self.parser.get(section, 'detect').decode(FSE) if not Windows.detect_registry_key(key): return if self.parser.has_option(section, 'detectfile'): if not detect_file( self.parser.get(section, 'detectfile').decode(FSE)): return if self.parser.has_option(section, 'detectos'): required_ver = self.parser.get(section, 'detectos').decode(FSE) if not detectos(required_ver): return # in case of multiple detection, discard if none match if self.parser.has_option(section, 'detectfile1'): matches = 0 for n in range(1, MAX_DETECT): option_id = 'detectfile%d' % n if self.parser.has_option(section, option_id): if detect_file( self.parser.get(section, option_id).decode(FSE)): matches += 1 if 0 == matches: return if self.parser.has_option(section, 'detect1'): matches = 0 for n in range(1, MAX_DETECT): option_id = 'detect%d' % n if self.parser.has_option(section, option_id): if Windows.detect_registry_key( self.parser.get(section, option_id).decode(FSE)): matches += 1 if 0 == matches: return # excludekeys ignores a file, path, or registry key excludekeys = [] if self.parser.has_option(section, 'excludekey1'): for n in range(1, MAX_DETECT): option_id = 'excludekey%d' % n if self.parser.has_option(section, option_id): excludekeys.append( self.excludekey_to_nwholeregex( self.parser.get(section, option_id).decode(FSE))) # there are two ways to specify sections: langsecref= and section= if self.parser.has_option(section, 'langsecref'): # verify the langsecref number is known # langsecref_num is 3021, games, etc. langsecref_num = self.parser.get(section, 'langsecref').decode(FSE) elif self.parser.has_option(section, 'section'): langsecref_num = self.parser.get(section, 'section').decode(FSE) else: logger.error( 'neither option LangSecRef nor Section found in section %s', section) return # find the BleachBit internal cleaner ID lid = self.section_to_cleanerid(langsecref_num) self.cleaners[lid].add_option(section2option(section), section.replace('*', ''), '') for option in self.parser.options(section): if option.startswith('filekey'): self.handle_filekey(lid, section, option, excludekeys) elif option.startswith('regkey'): self.handle_regkey(lid, section, option) elif option == 'warning': self.cleaners[lid].set_warning( section2option(section), self.parser.get(section, 'warning').decode(FSE)) elif option in ('default', 'detectfile', 'detect', 'langsecref', 'section') \ or ['detect%d' % x for x in range(1, MAX_DETECT)] \ or ['detectfile%d' % x for x in range(1, MAX_DETECT)]: pass else: logger.warning('unknown option %s in section %s', option, section) return
def handle_section(self, section): """Parse a section""" # if simple detection fails then discard the section if self.parser.has_option(section, 'detect'): key = self.parser.get(section, 'detect').decode(FSE) if not Windows.detect_registry_key(key): return if self.parser.has_option(section, 'detectfile'): if not detect_file(self.parser.get(section, 'detectfile').decode(FSE)): return if self.parser.has_option(section, 'detectos'): required_ver = self.parser.get(section, 'detectos').decode(FSE) if not detectos(required_ver): return # in case of multiple detection, discard if none match if self.parser.has_option(section, 'detectfile1'): matches = 0 for n in range(1, MAX_DETECT): option_id = 'detectfile%d' % n if self.parser.has_option(section, option_id): if detect_file(self.parser.get(section, option_id).decode(FSE)): matches += 1 if 0 == matches: return if self.parser.has_option(section, 'detect1'): matches = 0 for n in range(1, MAX_DETECT): option_id = 'detect%d' % n if self.parser.has_option(section, option_id): if Windows.detect_registry_key(self.parser.get(section, option_id).decode(FSE)): matches += 1 if 0 == matches: return # excludekeys ignores a file, path, or registry key excludekeys = [] if self.parser.has_option(section, 'excludekey1'): for n in range(1, MAX_DETECT): option_id = 'excludekey%d' % n if self.parser.has_option(section, option_id): excludekeys.append( self.excludekey_to_nwholeregex(self.parser.get(section, option_id).decode(FSE))) # there are two ways to specify sections: langsecref= and section= if self.parser.has_option(section, 'langsecref'): # verify the langsecref number is known # langsecref_num is 3021, games, etc. langsecref_num = self.parser.get(section, 'langsecref').decode(FSE) elif self.parser.has_option(section, 'section'): langsecref_num = self.parser.get(section, 'section').decode(FSE) else: logger.error('neither option LangSecRef nor Section found in section %s', section) return # find the BleachBit internal cleaner ID lid = self.section_to_cleanerid(langsecref_num) self.cleaners[lid].add_option( section2option(section), section.replace('*', ''), '') for option in self.parser.options(section): if option.startswith('filekey'): self.handle_filekey(lid, section, option, excludekeys) elif option.startswith('regkey'): self.handle_regkey(lid, section, option) elif option == 'warning': self.cleaners[lid].set_warning( section2option(section), self.parser.get(section, 'warning').decode(FSE)) elif option in ('default', 'detectfile', 'detect', 'langsecref', 'section') \ or ['detect%d' % x for x in range(1, MAX_DETECT)] \ or ['detectfile%d' % x for x in range(1, MAX_DETECT)]: pass else: logger.warning('unknown option %s in section %s', option, section) return