From 2f3d91afcb995a5abc817d6249be45808b83fd02 Mon Sep 17 00:00:00 2001 From: "Kamil Mankowski (kam193)" Date: Tue, 5 Nov 2024 19:52:40 +0100 Subject: [PATCH] Add formatting and exceptions --- ASTGrep/VERSION | 2 +- ASTGrep/requirements.txt | 3 ++- ASTGrep/service/al_run.py | 12 ++++++++++++ ASTGrep/service_manifest.yml | 13 ++++++------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ASTGrep/VERSION b/ASTGrep/VERSION index a45fd52..7273c0f 100644 --- a/ASTGrep/VERSION +++ b/ASTGrep/VERSION @@ -1 +1 @@ -24 +25 diff --git a/ASTGrep/requirements.txt b/ASTGrep/requirements.txt index 7e50403..4a909e1 100644 --- a/ASTGrep/requirements.txt +++ b/ASTGrep/requirements.txt @@ -3,4 +3,5 @@ ast-grep-cli >0.25.0, <0.26.0 pylspclient cryptography ast-grep-py -jinja2 \ No newline at end of file +jinja2 +ruff diff --git a/ASTGrep/service/al_run.py b/ASTGrep/service/al_run.py index b0cecc4..1133893 100644 --- a/ASTGrep/service/al_run.py +++ b/ASTGrep/service/al_run.py @@ -1,6 +1,7 @@ import hashlib import json import os +import subprocess import tempfile from collections import defaultdict from copy import copy @@ -205,6 +206,7 @@ def _process_file(self, request: ServiceRequest, file_path, file_type): request.add_supplementary(f.name, "astgrep_raw_results.json", "AST-Grep Results") if self._should_deobfuscate: + reformat_code = request.get_param("reformat_deobfuscated_code") extracted_layers = [] result_no = 1 for deobf_result, layer in self._deobfuscator.deobfuscate_file(file_path, file_type): @@ -220,10 +222,20 @@ def _process_file(self, request: ServiceRequest, file_path, file_type): ) ) else: + if reformat_code: + try: + subprocess.run( + ["ruff", "format", "--no-cache", "--isolated", path], + timeout=5, + check=False, + ) + except Exception: + self.log.warning("Error reformatting deobfuscated code", exc_info=True) request.add_extracted( path, f"_deobfuscated_code_FINAL{LANGUAGE_TO_EXT[file_type]}", "Final deobfuscation layer", + safelist_interface=self.api_interface, ) result_no += 1 deobf_section = ResultTextSection( diff --git a/ASTGrep/service_manifest.yml b/ASTGrep/service_manifest.yml index 4e562f9..8c6bbfe 100644 --- a/ASTGrep/service_manifest.yml +++ b/ASTGrep/service_manifest.yml @@ -11,7 +11,7 @@ stage: CORE category: Static Analysis uses_tags: false file_required: true -timeout: 120 +timeout: 150 is_external: false config: @@ -22,12 +22,11 @@ config: EXTRACT_INTERMEDIATE_LAYERS: false TRY_LANGUAGE_FROM_EXTENSION: true -# submission_params: -# - default: "auto" -# name: platform -# type: list -# value: "auto" -# list: ["auto", "linux"] +submission_params: + - default: true + name: reformat_deobfuscated_code + type: bool + value: true heuristics: - description: Suspicious code pattern