From 5c42f47d9f8ab253f75229c1c0fd8293c763fe6c Mon Sep 17 00:00:00 2001 From: dzonerzy Date: Thu, 10 Apr 2025 11:57:42 +0200 Subject: [PATCH 1/6] update RE_collections_search and RE_binaries_search --- src/reait/api.py | 74 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/reait/api.py b/src/reait/api.py index 9f3cf34..b6bbcf5 100755 --- a/src/reait/api.py +++ b/src/reait/api.py @@ -972,16 +972,25 @@ def RE_begin_ai_decompilation(function_id: int) -> Response: return res -def RE_poll_ai_decompilation(function_id: int) -> Response: +def RE_poll_ai_decompilation( + function_id: int, + summarise: bool = False +) -> Response: """ Poll AI decompilation for the function :param function_id: Function ID """ end_point = f"/v2/functions/{function_id}/ai-decompilation" + params = {} + + if summarise: + params["summarise"] = summarise + res: Response = reveng_req( requests.get, end_point, + params=params, ) res.raise_for_status() return res @@ -1001,16 +1010,41 @@ def RE_analysis_lookup(binary_id: int) -> Response: def RE_collections_search( page: int = 1, page_size: int = 10, - search: str = "", + query: dict = {}, ) -> Response: """ + Search for collections in the database """ end_point = "/v2/search/collections" - res: Response = reveng_req(requests.get, end_point, params={ + params = { "page": page, "page_size": page_size, - "partial_collection_name": search, - }) + } + + # this api support: + # partial_collection_name + # partial_binary_name + # partial_binary_sha256 + # model_name + # tags + + def exist_and_populated(key: str) -> bool: + return key in query and query[key] is not None and len(query[key]) > 0 + + if exist_and_populated("collection_name"): + params["partial_collection_name"] = query["collection_name"] + elif exist_and_populated("binary_name"): + params["partial_binary_name"] = query["binary_name"] + elif exist_and_populated("sha_256_hash"): + params["partial_binary_sha256"] = query["sha_256_hash"] + elif exist_and_populated("tags"): + params["tags"] = query["tags"] + elif exist_and_populated("model_name"): + params["model_name"] = query["model_name"] + elif exist_and_populated("query"): + params["partial_collection_name"] = query["query"] + + res: Response = reveng_req(requests.get, end_point, params=params) res.raise_for_status() return res @@ -1018,16 +1052,38 @@ def RE_collections_search( def RE_binaries_search( page: int = 1, page_size: int = 10, - search: str = "", + query: dict = {}, ) -> Response: """ + Search for binaries in the database """ end_point = "/v2/search/binaries" - res: Response = reveng_req(requests.get, end_point, params={ + params = { "page": page, "page_size": page_size, - "partial_name": search, - }) + } + + # this api support: + # partial_name + # partial_sha256 + # tags + # model_name + + def exist_and_populated(key: str) -> bool: + return key in query and query[key] is not None and len(query[key]) > 0 + + if exist_and_populated("binary_name"): + params["partial_name"] = query["binary_name"] + elif exist_and_populated("sha_256_hash"): + params["partial_sha256"] = query["sha_256_hash"] + elif exist_and_populated("tags"): + params["tags"] = query["tags"] + elif exist_and_populated("model_name"): + params["model_name"] = query["model_name"] + elif exist_and_populated("query"): + params["partial_name"] = query["query"] + + res: Response = reveng_req(requests.get, end_point, params=params) res.raise_for_status() return res From cf9b647133fab65354e1481d6b8df718371551b0 Mon Sep 17 00:00:00 2001 From: dzonerzy Date: Thu, 10 Apr 2025 17:02:14 +0200 Subject: [PATCH 2/6] added endpoint for data types polling --- src/reait/api.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/reait/api.py b/src/reait/api.py index c2c10ad..5be422d 100755 --- a/src/reait/api.py +++ b/src/reait/api.py @@ -933,7 +933,10 @@ def RE_analysis_id(fpath: str, binary_id: int = 0) -> Response: return res -def RE_generate_data_types(analysis_id: int, function_ids: list[int]) -> Response: +def RE_generate_data_types( + analysis_id: int, + function_ids: list[int] +) -> Response: """ Generate data types for the analysis :param aid: Analysis ID @@ -947,6 +950,21 @@ def RE_generate_data_types(analysis_id: int, function_ids: list[int]) -> Respons return res +def RE_poll_data_types( + analysis_id: int, + function_id: int, +) -> Response: + """ + Poll data types for the analysis + :param aid: Analysis ID + """ + end_point = f"/v2/analyses/{analysis_id}/functions/{function_id}/data_types" + + res: Response = reveng_req(requests.get, end_point) + res.raise_for_status() + return res + + def RE_list_data_types(analysis_id: int, function_ids: list[int]) -> Response: """ List data types for the analysis From 48ce13010c76aa3380939f0025ce88c29ca0bc69 Mon Sep 17 00:00:00 2001 From: dzonerzy Date: Mon, 14 Apr 2025 16:07:21 +0200 Subject: [PATCH 3/6] fix linter --- src/reait/api.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/reait/api.py b/src/reait/api.py index 5be422d..02652bf 100755 --- a/src/reait/api.py +++ b/src/reait/api.py @@ -759,7 +759,9 @@ def RE_functions_list( params["max_v_address"] = max_v_address res: Response = reveng_req( - requests.get, f"v2/analyses/{analysis_id}/info/functions/list", params=params + requests.get, + f"v2/analyses/{analysis_id}/info/functions/list", + params=params ) res.raise_for_status() @@ -866,10 +868,12 @@ def _binary_format(binary: Binary) -> str: return "Mach-O" logger.error( - "Error, could not determine or unsupported" f" binary format: {binary.format}." + "Error, could not determine or unsupported" + f" binary format: {binary.format}." ) raise RuntimeError( - "Error, could not determine or " f"unsupported binary format: {binary.format}" + "Error, could not determine or " + f"unsupported binary format: {binary.format}" ) From d4ad8414237f345a4700dba011e5c1796fa6f98c Mon Sep 17 00:00:00 2001 From: dzonerzy Date: Fri, 18 Apr 2025 11:00:24 +0200 Subject: [PATCH 4/6] RE_functions_data_types --- src/reait/api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/reait/api.py b/src/reait/api.py index 02652bf..e8c03de 100755 --- a/src/reait/api.py +++ b/src/reait/api.py @@ -937,6 +937,22 @@ def RE_analysis_id(fpath: str, binary_id: int = 0) -> Response: return res +def RE_functions_data_types( + function_ids: list[int], +) -> Response: + """ + Get data types for the functions + :param functions_ids: List of function IDs + :return: Response object + """ + endpoint = "/v2/functions/data_types" + res: Response = reveng_req( + requests.post, endpoint, json_data={"function_ids": function_ids} + ) + res.raise_for_status() + return res + + def RE_generate_data_types( analysis_id: int, function_ids: list[int] From 3b22694d7b701f0180299080a187dd1698c96876 Mon Sep 17 00:00:00 2001 From: dzonerzy Date: Fri, 18 Apr 2025 17:09:13 +0200 Subject: [PATCH 5/6] RE_functions_data_types_poll --- src/reait/api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/reait/api.py b/src/reait/api.py index e8c03de..95b5482 100755 --- a/src/reait/api.py +++ b/src/reait/api.py @@ -953,6 +953,22 @@ def RE_functions_data_types( return res +def RE_functions_data_types_poll( + function_ids: list[int], +) -> Response: + """ + Poll data types for the functions + :param functions_ids: List of function IDs + :return: Response object + """ + endpoint = "/v2/functions/data_types" + res: Response = reveng_req( + requests.get, endpoint, params={"function_ids": function_ids} + ) + res.raise_for_status() + return res + + def RE_generate_data_types( analysis_id: int, function_ids: list[int] From 4d7164f1b9dcd7c77b97e85274dda82b732da70b Mon Sep 17 00:00:00 2001 From: dzonerzy Date: Sat, 19 Apr 2025 11:56:48 +0200 Subject: [PATCH 6/6] prepare for 1.2.0 release --- pyproject.toml | 2 +- src/reait/api.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 39e5b95..81e3641 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "reait" -version = "1.1.1" +version = "1.2.0" readme = "README.md" classifiers=[ "Programming Language :: Python :: 3", diff --git a/src/reait/api.py b/src/reait/api.py index 95b5482..29f17f5 100755 --- a/src/reait/api.py +++ b/src/reait/api.py @@ -10,12 +10,12 @@ from datetime import datetime from hashlib import sha256 from lief import parse, Binary, ELF, PE, MachO -from numpy import array, vstack, dot, arccos, pi +from numpy import array, vstack from pandas import DataFrame from requests import request, Response, HTTPError from sklearn.metrics.pairwise import cosine_similarity -__version__ = "1.1.1" +__version__ = "1.2.0" re_conf = { "apikey": environ.get("REAI_API_KEY", ""),