Skip to content

Commit

Permalink
Add formatting and exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kam193 committed Nov 5, 2024
1 parent cef8f7b commit 2f3d91a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ASTGrep/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24
25
3 changes: 2 additions & 1 deletion ASTGrep/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ast-grep-cli >0.25.0, <0.26.0
pylspclient
cryptography
ast-grep-py
jinja2
jinja2
ruff
12 changes: 12 additions & 0 deletions ASTGrep/service/al_run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import json
import os
import subprocess
import tempfile
from collections import defaultdict
from copy import copy
Expand Down Expand Up @@ -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):
Expand All @@ -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(
Expand Down
13 changes: 6 additions & 7 deletions ASTGrep/service_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ stage: CORE
category: Static Analysis
uses_tags: false
file_required: true
timeout: 120
timeout: 150
is_external: false

config:
Expand All @@ -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
Expand Down

0 comments on commit 2f3d91a

Please sign in to comment.