Minor refactoring and cleanup.

This commit is contained in:
Achim D. Brucker 2017-08-28 19:20:50 +01:00
parent 5175d28edc
commit 030adb6adc
1 changed files with 2 additions and 12 deletions

View File

@ -39,7 +39,7 @@ class FileClassification(Enum):
LIKELY_LIBRARY = 2 LIKELY_LIBRARY = 2
APPLICATION = 3 APPLICATION = 3
def lib_identifiers(): def load_lib_identifiers():
"""Initialize identifiers for known libraries from JSON file.""" """Initialize identifiers for known libraries from JSON file."""
regex_file = os.path.join( regex_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)), '../resources/', os.path.dirname(os.path.realpath(__file__)), '../resources/',
@ -55,16 +55,6 @@ def unknown_filename_identifier():
r'(.+)[\-\_]([0-9]{1,2}[\.|\-|\_][0-9a-z]{1,2}[\.|\-|\_][0-9a-z\-\_]*)', r'(.+)[\-\_]([0-9]{1,2}[\.|\-|\_][0-9a-z]{1,2}[\.|\-|\_][0-9a-z\-\_]*)',
re.IGNORECASE) re.IGNORECASE)
def lib_isin_list(lib, ver, lib_list):
"""Check if a specific library/version has already been detected."""
for item in lib_list:
if (item['lib'].lower() == lib.lower() and
item['ver'].lower() == ver.lower()):
return True
return False
def unknown_lib_identifiers(): def unknown_lib_identifiers():
"""List of identifiers for generic library version headers.""" """List of identifiers for generic library version headers."""
return ([ return ([
@ -112,7 +102,7 @@ def init_jsinfo(zipfile, js_file):
def analyse_known_filename(zipfile, js_file): def analyse_known_filename(zipfile, js_file):
"""Check for known file name patterns.""" """Check for known file name patterns."""
libs = list() libs = list()
for lib, regex in lib_identifiers().items(): for lib, regex in load_lib_identifiers().items():
if 'filename' in regex: if 'filename' in regex:
filename_matched = re.search(regex['filename'], filename_matched = re.search(regex['filename'],
js_file.filename, re.IGNORECASE) js_file.filename, re.IGNORECASE)