From 8f318ccd6471ae113be226493f6aba46f50a22d0 Mon Sep 17 00:00:00 2001 From: LoRexxar Date: Tue, 22 Jun 2021 17:10:24 +0800 Subject: [PATCH] fix bug & add favicon --- core/pretreatment.py | 46 +------------------ static/favicon.ico | Bin 0 -> 3705 bytes templates/dashboard/base.html | 1 + templates/index.html | 2 +- templates/login.html | 2 +- templates/register.html | 2 +- utils/file.py | 83 ++++++++++++++++++++++++++++++++-- 7 files changed, 83 insertions(+), 53 deletions(-) create mode 100644 static/favicon.ico diff --git a/core/pretreatment.py b/core/pretreatment.py index b25d69d8..0cc56e78 100644 --- a/core/pretreatment.py +++ b/core/pretreatment.py @@ -17,6 +17,7 @@ from utils.log import logger from Kunlun_M.const import ext_dict +from utils.file import un_zip import gc import os @@ -31,51 +32,6 @@ could_ast_pase_lans = ["php", "chromeext", "javascript", "html"] -def un_zip(target_path): - """ - 解压缩目标压缩包 - 实现新需求,解压缩后相应的js文件做代码格式化 - :return: - """ - - logger.info("[Pre][Unzip] Upzip file {}...".format(target_path)) - - if not os.path.isfile(target_path): - logger.warn("[Pre][Unzip] Target file {} is't exist...pass".format(target_path)) - return False - - zip_file = zipfile.ZipFile(target_path) - target_file_path = target_path + "_files/" - - if os.path.isdir(target_file_path): - logger.debug("[Pre][Unzip] Target files {} is exist...continue".format(target_file_path)) - return target_file_path - else: - os.mkdir(target_file_path) - - for names in zip_file.namelist(): - zip_file.extract(names, target_file_path) - - # 对其中部分文件中为js的时候,将js代码格式化便于阅读 - if names.endswith(".js"): - file_path = os.path.join(target_file_path, names) - file = codecs.open(file_path, 'r+', encoding='utf-8', errors='ignore') - file_content = file.read() - file.close() - - new_file = codecs.open(file_path, 'w+', encoding='utf-8', errors='ignore') - - opts = jsbeautifier.default_options() - opts.indent_size = 2 - - new_file.write(jsbeautifier.beautify(file_content, opts)) - new_file.close() - - zip_file.close() - - return target_file_path - - class Pretreatment: def __init__(self): diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000000000000000000000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TXzQ&4aweHdp4(I+&fMY+ma8^^VKzkb5Pp3NfuhTO?~9*u79^^(e@e|x7t;FOIyhE z<9!{U=*gE;qSc^sKB7_#c}&{KQp8r!@`BZ4Jt5B>hTXOzsNlfMjpQ$WEO*7oiTRZW z-d2l*RY~4KN818k&d^q^E8e<~;th7Wd*;O46keS+iw^b2Tb*}@GZ5I6Il?<>BDeMq zf_rYRX7N71Ur4sOl%}*kKf{f)zQgrvivD!ZH+e@S{OD{o!TV{1%5MI*?oQ4_WT%qf zHlL-yck6J%8JUCYuH)Y$=ERUTG+xDcZ3(8Mh{cRRevOfq@|_56muUL8fhBo0Yg+bP zOH;sU|D6EyhT|;h1H(#m`yby&h(81TyC=G8r@+2iSrkTGr+4l<_Hqu_KF9Y)t4fk_ zr1vJIx^&}cRKe4~_SL^Y6$%7WyFQv@Ar@bLG+doDh%&8A-ye_=bvA?)HKkreN48#FwMCKunLun-MA | {% block title %}index{% endblock %} {% load static %} + diff --git a/templates/index.html b/templates/index.html index 58b015c5..22aaaef6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@ {% load static %} - + diff --git a/templates/login.html b/templates/login.html index 26ce123a..41d4ff58 100644 --- a/templates/login.html +++ b/templates/login.html @@ -5,7 +5,7 @@ {% load static %} - + diff --git a/templates/register.html b/templates/register.html index db085de5..a54c34cb 100644 --- a/templates/register.html +++ b/templates/register.html @@ -5,7 +5,7 @@ {% load static %} - + diff --git a/utils/file.py b/utils/file.py index 28f214c1..4648dbe9 100644 --- a/utils/file.py +++ b/utils/file.py @@ -15,10 +15,12 @@ import re import os import time +import json import codecs +import zipfile import traceback +import jsbeautifier from utils.log import logger -from core.pretreatment import ast_object from Kunlun_M.const import ext_dict, default_black_list, IGNORE_LIST from Kunlun_M.settings import IGNORE_PATH @@ -54,6 +56,79 @@ def file_list_parse(filelist, language=None): return result +def un_zip(target_path): + """ + 解压缩目标压缩包 + 实现新需求,解压缩后相应的js文件做代码格式化 + :return: + """ + + logger.info("[Pre][Unzip] Upzip file {}...".format(target_path)) + + if not os.path.isfile(target_path): + logger.warn("[Pre][Unzip] Target file {} is't exist...pass".format(target_path)) + return False + + zip_file = zipfile.ZipFile(target_path) + target_file_path = target_path + "_files/" + + if os.path.isdir(target_file_path): + logger.debug("[Pre][Unzip] Target files {} is exist...continue".format(target_file_path)) + return target_file_path + else: + os.mkdir(target_file_path) + + for names in zip_file.namelist(): + zip_file.extract(names, target_file_path) + + # 对其中部分文件中为js的时候,将js代码格式化便于阅读 + if names.endswith(".js"): + file_path = os.path.join(target_file_path, names) + file = codecs.open(file_path, 'r+', encoding='utf-8', errors='ignore') + file_content = file.read() + file.close() + + new_file = codecs.open(file_path, 'w+', encoding='utf-8', errors='ignore') + + opts = jsbeautifier.default_options() + opts.indent_size = 2 + + new_file.write(jsbeautifier.beautify(file_content, opts)) + new_file.close() + + zip_file.close() + + return target_file_path + + +def get_manifest_from_crt(file_path): + """ + 从chrome插件种获取manifest.json 文件内容 + :param file_path: + :return: + """ + target_files_path = un_zip(file_path) + + # 分析manifest.json + manifest_path = os.path.join(target_files_path, "manifest.json") + manifest = "" + + if os.path.isfile(manifest_path): + fi = codecs.open(manifest_path, "r", encoding='utf-8', errors='ignore') + manifest_content = fi.read() + fi.close() + + try: + manifest = json.loads(manifest_content, encoding='utf-8') + + except json.decoder.JSONDecodeError: + logger.warning( + "[Pretreatment][Chrome Ext] File {} parse error...".format(target_files_path)) + return "" + + return manifest + + def get_line(file_path, line_rule): """ 搜索指定文件的指定行到指定行的内容 @@ -454,13 +529,11 @@ def special_crx_keyword_match(self, keyword, match, unmatch): if not ffile_path: continue - ffile_object = ast_object.get_object(ffile_path) + manifest = get_manifest_from_crt(ffile_path) - if not ffile_object or 'manifest' not in ffile_object: + if not manifest: continue - manifest = ffile_object['manifest'] - target_files_path = ffile_object['target_files_path'] keywords = keyword.split('.') value_list = self.keyword_object_parse(keywords, manifest)