From cacdf1f72756c15f6fe048b21348a20075ab31f2 Mon Sep 17 00:00:00 2001 From: "Achim D. Brucker" Date: Wed, 30 Aug 2017 08:28:39 +0100 Subject: [PATCH] Refactoring. --- ExtensionCrawler/js_decomposer.py | 32 +++++++++++++++---------------- ExtensionCrawler/sqlite.py | 5 +++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ExtensionCrawler/js_decomposer.py b/ExtensionCrawler/js_decomposer.py index 4ec6c94..ace9952 100755 --- a/ExtensionCrawler/js_decomposer.py +++ b/ExtensionCrawler/js_decomposer.py @@ -92,8 +92,8 @@ def init_jsinfo(zipfile, js_file): data = js_file_obj.read() js_info = { 'lib': None, - 'ver': None, - 'detectMethod': None, + 'version': None, + 'detectionMethod': None, 'type': None, 'evidenceStartPos': None, 'evidenceEndPos': None, @@ -120,17 +120,17 @@ def analyse_checksum(zipfile, js_file, js_info): for file in json_data[lib]['sha1']: if file['sha1'] == js_info['sha1']: js_info['lib'] = lib - js_info['ver'] = file['version'] + js_info['version'] = file['version'] js_info['type'] = FileClassification.LIBRARY - js_info['detectMethod'] = DetectionType.SHA1 + js_info['detectionMethod'] = DetectionType.SHA1 return [js_info] if info == 'md5': for file in json_data[lib]['md5']: if file['md5'] == js_info['md5']: js_info['lib'] = lib - js_info['ver'] = file['version'] + js_info['version'] = file['version'] js_info['type'] = FileClassification.LIBRARY - js_info['detectMethod'] = DetectionType.MD5 + js_info['detectionMethod'] = DetectionType.MD5 return [js_info] return None @@ -145,9 +145,9 @@ def analyse_known_filename(zipfile, js_file, js_info): js_file.filename, re.IGNORECASE) if filename_matched: js_info['lib'] = lib - js_info['ver'] = filename_matched.group(2) + js_info['version'] = filename_matched.group(2) js_info['type'] = FileClassification.LIBRARY - js_info['detectMethod'] = DetectionType.FILENAME + js_info['detectionMethod'] = DetectionType.FILENAME libs.append(js_info) return libs @@ -158,9 +158,9 @@ def analyse_generic_filename(zipfile, js_file, js_info): js_file.filename) if unknown_filename_match: js_info['lib'] = unknown_filename_match.group(1) - js_info['ver'] = unknown_filename_match.group(2) + js_info['version'] = unknown_filename_match.group(2) js_info['type'] = FileClassification.LIKELY_LIBRARY - js_info['detectMethod'] = DetectionType.FILENAME + js_info['detectionMethod'] = DetectionType.FILENAME libs.append(js_info) return libs @@ -180,8 +180,8 @@ def analyse_comment_known_libs(zipfile, js_file, js_info, comment): for match in unkown_lib_matched: js_info['lib'] = ((js_file.filename).replace( '.js', '')).replace('.min', '') - js_info['ver'] = match.group(2) - js_info['detectMethod'] = DetectionType.COMMENTBLOCK + js_info['version'] = match.group(2) + js_info['detectionMethod'] = DetectionType.COMMENTBLOCK js_info['type'] = FileClassification.LIKELY_LIBRARY libs.append(js_info) return libs @@ -194,8 +194,8 @@ def analyse_comment_generic_libs(zipfile, js_file, js_info, comment): for match in unkown_lib_matched: js_info['lib'] = ((js_file.filename).replace( '.js', '')).replace('.min', '') - js_info['ver'] = match.group(2) - js_info['detectMethod'] = DetectionType.COMMENTBLOCK + js_info['version'] = match.group(2) + js_info['detectionMethod'] = DetectionType.COMMENTBLOCK js_info['type'] = FileClassification.LIKELY_LIBRARY libs.append(js_info) return libs @@ -242,8 +242,8 @@ def decompose_js(zipfile): if not js_info_file: # if no library could be detected, we report the JavaScript file as 'application'. js_info['lib'] = None - js_info['ver'] = None - js_info['detectMethod'] = DetectionType.DEFAULT + js_info['version'] = None + js_info['detectionMethod'] = DetectionType.DEFAULT js_info['type'] = FileClassification.APPLICATION js_inventory.append(js_info) else: diff --git a/ExtensionCrawler/sqlite.py b/ExtensionCrawler/sqlite.py index 80f30c5..fc5b129 100644 --- a/ExtensionCrawler/sqlite.py +++ b/ExtensionCrawler/sqlite.py @@ -248,17 +248,18 @@ def parse_and_insert_crx(ext_id, date, datepath, con): js_files = decompose_js(f) for js_file_info in js_files: # TODO: Add: evidenceStartPos, evidenceEndPos, and EvidenceText, sha1 + # TODO: md5, sha1, size, path, type, detect_method, crx_etag, filename should be non-null con.insert( "jsfile", crx_etag=etag, - detect_method=(js_file_info['detectMethod']).value, + detect_method=(js_file_info['detectionMethod']).value, filename=js_file_info['jsFilename'], type=(js_file_info['type']).value, lib=js_file_info['lib'], path=js_file_info['path'], md5=js_file_info['md5'], size=js_file_info['size'], - version=js_file_info['ver']) + version=js_file_info['version']) def get(d, k):