Spaces:
Sleeping
Sleeping
change yara to async
Browse files
app.py
CHANGED
|
@@ -376,7 +376,7 @@ async def analyse_bin(file_name: str):
|
|
| 376 |
os.remove(temp_image)
|
| 377 |
|
| 378 |
@app.get("/analyse/yara/{file_name}")
|
| 379 |
-
def analyse_yara(file_name: str):
|
| 380 |
"""Analyze file using YARA rules from the GitHub repository"""
|
| 381 |
sanitized_name = Path(file_name).name
|
| 382 |
file_path = os.path.join(UPLOAD_DIR, sanitized_name)
|
|
@@ -394,21 +394,22 @@ def analyse_yara(file_name: str):
|
|
| 394 |
)
|
| 395 |
|
| 396 |
try:
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
matches = app.state.yara_rules.match(file_path)
|
| 402 |
if matches:
|
| 403 |
-
|
| 404 |
"matches": [{
|
| 405 |
"rule": match.rule,
|
| 406 |
"namespace": match.namespace,
|
| 407 |
"tags": match.tags,
|
| 408 |
"meta": match.meta,
|
| 409 |
-
"strings": [s for s in match.strings]
|
| 410 |
} for match in matches]
|
| 411 |
}
|
|
|
|
| 412 |
else:
|
| 413 |
return {"result": "Does not match"}
|
| 414 |
except Exception as e:
|
|
|
|
| 376 |
os.remove(temp_image)
|
| 377 |
|
| 378 |
@app.get("/analyse/yara/{file_name}")
|
| 379 |
+
async def analyse_yara(file_name: str):
|
| 380 |
"""Analyze file using YARA rules from the GitHub repository"""
|
| 381 |
sanitized_name = Path(file_name).name
|
| 382 |
file_path = os.path.join(UPLOAD_DIR, sanitized_name)
|
|
|
|
| 394 |
)
|
| 395 |
|
| 396 |
try:
|
| 397 |
+
matches = await run_in_threadpool(
|
| 398 |
+
app.state.yara_rules.match,
|
| 399 |
+
file_path
|
| 400 |
+
)
|
| 401 |
+
# matches = app.state.yara_rules.match(file_path)
|
| 402 |
if matches:
|
| 403 |
+
result = {"result": "Found",
|
| 404 |
"matches": [{
|
| 405 |
"rule": match.rule,
|
| 406 |
"namespace": match.namespace,
|
| 407 |
"tags": match.tags,
|
| 408 |
"meta": match.meta,
|
| 409 |
+
# "strings": [s for s in match.strings]
|
| 410 |
} for match in matches]
|
| 411 |
}
|
| 412 |
+
return result
|
| 413 |
else:
|
| 414 |
return {"result": "Does not match"}
|
| 415 |
except Exception as e:
|