Skip to content

Commit 2e1407f

Browse files
authored
Merge pull request #38 from RevEngAI/dev_dzonerzy
Add new APIs endpoint
2 parents 64fa7b7 + 4d7164f commit 2e1407f

File tree

2 files changed

+126
-16
lines changed

2 files changed

+126
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "reait"
7-
version = "1.1.1"
7+
version = "1.2.0"
88
readme = "README.md"
99
classifiers=[
1010
"Programming Language :: Python :: 3",

src/reait/api.py

Lines changed: 125 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from datetime import datetime
1111
from hashlib import sha256
1212
from lief import parse, Binary, ELF, PE, MachO
13-
from numpy import array, vstack, dot, arccos, pi
13+
from numpy import array, vstack
1414
from pandas import DataFrame
1515
from requests import request, Response, HTTPError
1616
from sklearn.metrics.pairwise import cosine_similarity
1717

18-
__version__ = "1.1.1"
18+
__version__ = "1.2.0"
1919

2020
re_conf = {
2121
"apikey": environ.get("REAI_API_KEY", ""),
@@ -759,7 +759,9 @@ def RE_functions_list(
759759
params["max_v_address"] = max_v_address
760760

761761
res: Response = reveng_req(
762-
requests.get, f"v2/analyses/{analysis_id}/info/functions/list", params=params
762+
requests.get,
763+
f"v2/analyses/{analysis_id}/info/functions/list",
764+
params=params
763765
)
764766

765767
res.raise_for_status()
@@ -866,10 +868,12 @@ def _binary_format(binary: Binary) -> str:
866868
return "Mach-O"
867869

868870
logger.error(
869-
"Error, could not determine or unsupported" f" binary format: {binary.format}."
871+
"Error, could not determine or unsupported"
872+
f" binary format: {binary.format}."
870873
)
871874
raise RuntimeError(
872-
"Error, could not determine or " f"unsupported binary format: {binary.format}"
875+
"Error, could not determine or "
876+
f"unsupported binary format: {binary.format}"
873877
)
874878

875879

@@ -933,7 +937,42 @@ def RE_analysis_id(fpath: str, binary_id: int = 0) -> Response:
933937
return res
934938

935939

936-
def RE_generate_data_types(analysis_id: int, function_ids: list[int]) -> Response:
940+
def RE_functions_data_types(
941+
function_ids: list[int],
942+
) -> Response:
943+
"""
944+
Get data types for the functions
945+
:param functions_ids: List of function IDs
946+
:return: Response object
947+
"""
948+
endpoint = "/v2/functions/data_types"
949+
res: Response = reveng_req(
950+
requests.post, endpoint, json_data={"function_ids": function_ids}
951+
)
952+
res.raise_for_status()
953+
return res
954+
955+
956+
def RE_functions_data_types_poll(
957+
function_ids: list[int],
958+
) -> Response:
959+
"""
960+
Poll data types for the functions
961+
:param functions_ids: List of function IDs
962+
:return: Response object
963+
"""
964+
endpoint = "/v2/functions/data_types"
965+
res: Response = reveng_req(
966+
requests.get, endpoint, params={"function_ids": function_ids}
967+
)
968+
res.raise_for_status()
969+
return res
970+
971+
972+
def RE_generate_data_types(
973+
analysis_id: int,
974+
function_ids: list[int]
975+
) -> Response:
937976
"""
938977
Generate data types for the analysis
939978
:param aid: Analysis ID
@@ -947,6 +986,21 @@ def RE_generate_data_types(analysis_id: int, function_ids: list[int]) -> Respons
947986
return res
948987

949988

989+
def RE_poll_data_types(
990+
analysis_id: int,
991+
function_id: int,
992+
) -> Response:
993+
"""
994+
Poll data types for the analysis
995+
:param aid: Analysis ID
996+
"""
997+
end_point = f"/v2/analyses/{analysis_id}/functions/{function_id}/data_types"
998+
999+
res: Response = reveng_req(requests.get, end_point)
1000+
res.raise_for_status()
1001+
return res
1002+
1003+
9501004
def RE_list_data_types(analysis_id: int, function_ids: list[int]) -> Response:
9511005
"""
9521006
List data types for the analysis
@@ -978,16 +1032,25 @@ def RE_begin_ai_decompilation(function_id: int) -> Response:
9781032
return res
9791033

9801034

981-
def RE_poll_ai_decompilation(function_id: int) -> Response:
1035+
def RE_poll_ai_decompilation(
1036+
function_id: int,
1037+
summarise: bool = False
1038+
) -> Response:
9821039
"""
9831040
Poll AI decompilation for the function
9841041
:param function_id: Function ID
9851042
"""
9861043
end_point = f"/v2/functions/{function_id}/ai-decompilation"
9871044

1045+
params = {}
1046+
1047+
if summarise:
1048+
params["summarise"] = summarise
1049+
9881050
res: Response = reveng_req(
9891051
requests.get,
9901052
end_point,
1053+
params=params,
9911054
)
9921055
res.raise_for_status()
9931056
return res
@@ -1007,33 +1070,80 @@ def RE_analysis_lookup(binary_id: int) -> Response:
10071070
def RE_collections_search(
10081071
page: int = 1,
10091072
page_size: int = 10,
1010-
search: str = "",
1073+
query: dict = {},
10111074
) -> Response:
10121075
"""
1076+
Search for collections in the database
10131077
"""
10141078
end_point = "/v2/search/collections"
1015-
res: Response = reveng_req(requests.get, end_point, params={
1079+
params = {
10161080
"page": page,
10171081
"page_size": page_size,
1018-
"partial_collection_name": search,
1019-
})
1082+
}
1083+
1084+
# this api support:
1085+
# partial_collection_name
1086+
# partial_binary_name
1087+
# partial_binary_sha256
1088+
# model_name
1089+
# tags
1090+
1091+
def exist_and_populated(key: str) -> bool:
1092+
return key in query and query[key] is not None and len(query[key]) > 0
1093+
1094+
if exist_and_populated("collection_name"):
1095+
params["partial_collection_name"] = query["collection_name"]
1096+
elif exist_and_populated("binary_name"):
1097+
params["partial_binary_name"] = query["binary_name"]
1098+
elif exist_and_populated("sha_256_hash"):
1099+
params["partial_binary_sha256"] = query["sha_256_hash"]
1100+
elif exist_and_populated("tags"):
1101+
params["tags"] = query["tags"]
1102+
elif exist_and_populated("model_name"):
1103+
params["model_name"] = query["model_name"]
1104+
elif exist_and_populated("query"):
1105+
params["partial_collection_name"] = query["query"]
1106+
1107+
res: Response = reveng_req(requests.get, end_point, params=params)
10201108
res.raise_for_status()
10211109
return res
10221110

10231111

10241112
def RE_binaries_search(
10251113
page: int = 1,
10261114
page_size: int = 10,
1027-
search: str = "",
1115+
query: dict = {},
10281116
) -> Response:
10291117
"""
1118+
Search for binaries in the database
10301119
"""
10311120
end_point = "/v2/search/binaries"
1032-
res: Response = reveng_req(requests.get, end_point, params={
1121+
params = {
10331122
"page": page,
10341123
"page_size": page_size,
1035-
"partial_name": search,
1036-
})
1124+
}
1125+
1126+
# this api support:
1127+
# partial_name
1128+
# partial_sha256
1129+
# tags
1130+
# model_name
1131+
1132+
def exist_and_populated(key: str) -> bool:
1133+
return key in query and query[key] is not None and len(query[key]) > 0
1134+
1135+
if exist_and_populated("binary_name"):
1136+
params["partial_name"] = query["binary_name"]
1137+
elif exist_and_populated("sha_256_hash"):
1138+
params["partial_sha256"] = query["sha_256_hash"]
1139+
elif exist_and_populated("tags"):
1140+
params["tags"] = query["tags"]
1141+
elif exist_and_populated("model_name"):
1142+
params["model_name"] = query["model_name"]
1143+
elif exist_and_populated("query"):
1144+
params["partial_name"] = query["query"]
1145+
1146+
res: Response = reveng_req(requests.get, end_point, params=params)
10371147
res.raise_for_status()
10381148
return res
10391149

0 commit comments

Comments
 (0)