reait 1.1.1__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reait
3
- Version: 1.1.1
3
+ Version: 1.2.0
4
4
  Summary: RevEng.AI Toolkit and Python API
5
5
  Home-page: https://github.com/RevEng-AI/reait
6
6
  Author: James Patrick-Evans
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "reait"
7
- version = "1.1.1"
7
+ version = "1.2.0"
8
8
  readme = "README.md"
9
9
  classifiers=[
10
10
  "Programming Language :: Python :: 3",
@@ -10,12 +10,12 @@ import tomli
10
10
  from datetime import datetime
11
11
  from hashlib import sha256
12
12
  from lief import parse, Binary, ELF, PE, MachO
13
- from numpy import array, vstack, dot, arccos, pi
13
+ from numpy import array, vstack
14
14
  from pandas import DataFrame
15
15
  from requests import request, Response, HTTPError
16
16
  from sklearn.metrics.pairwise import cosine_similarity
17
17
 
18
- __version__ = "1.1.1"
18
+ __version__ = "1.2.0"
19
19
 
20
20
  re_conf = {
21
21
  "apikey": environ.get("REAI_API_KEY", ""),
@@ -759,7 +759,9 @@ def RE_functions_list(
759
759
  params["max_v_address"] = max_v_address
760
760
 
761
761
  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
763
765
  )
764
766
 
765
767
  res.raise_for_status()
@@ -866,10 +868,12 @@ def _binary_format(binary: Binary) -> str:
866
868
  return "Mach-O"
867
869
 
868
870
  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}."
870
873
  )
871
874
  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}"
873
877
  )
874
878
 
875
879
 
@@ -933,7 +937,42 @@ def RE_analysis_id(fpath: str, binary_id: int = 0) -> Response:
933
937
  return res
934
938
 
935
939
 
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:
937
976
  """
938
977
  Generate data types for the analysis
939
978
  :param aid: Analysis ID
@@ -947,6 +986,21 @@ def RE_generate_data_types(analysis_id: int, function_ids: list[int]) -> Respons
947
986
  return res
948
987
 
949
988
 
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
+
950
1004
  def RE_list_data_types(analysis_id: int, function_ids: list[int]) -> Response:
951
1005
  """
952
1006
  List data types for the analysis
@@ -978,16 +1032,25 @@ def RE_begin_ai_decompilation(function_id: int) -> Response:
978
1032
  return res
979
1033
 
980
1034
 
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:
982
1039
  """
983
1040
  Poll AI decompilation for the function
984
1041
  :param function_id: Function ID
985
1042
  """
986
1043
  end_point = f"/v2/functions/{function_id}/ai-decompilation"
987
1044
 
1045
+ params = {}
1046
+
1047
+ if summarise:
1048
+ params["summarise"] = summarise
1049
+
988
1050
  res: Response = reveng_req(
989
1051
  requests.get,
990
1052
  end_point,
1053
+ params=params,
991
1054
  )
992
1055
  res.raise_for_status()
993
1056
  return res
@@ -1007,16 +1070,41 @@ def RE_analysis_lookup(binary_id: int) -> Response:
1007
1070
  def RE_collections_search(
1008
1071
  page: int = 1,
1009
1072
  page_size: int = 10,
1010
- search: str = "",
1073
+ query: dict = {},
1011
1074
  ) -> Response:
1012
1075
  """
1076
+ Search for collections in the database
1013
1077
  """
1014
1078
  end_point = "/v2/search/collections"
1015
- res: Response = reveng_req(requests.get, end_point, params={
1079
+ params = {
1016
1080
  "page": page,
1017
1081
  "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)
1020
1108
  res.raise_for_status()
1021
1109
  return res
1022
1110
 
@@ -1024,16 +1112,38 @@ def RE_collections_search(
1024
1112
  def RE_binaries_search(
1025
1113
  page: int = 1,
1026
1114
  page_size: int = 10,
1027
- search: str = "",
1115
+ query: dict = {},
1028
1116
  ) -> Response:
1029
1117
  """
1118
+ Search for binaries in the database
1030
1119
  """
1031
1120
  end_point = "/v2/search/binaries"
1032
- res: Response = reveng_req(requests.get, end_point, params={
1121
+ params = {
1033
1122
  "page": page,
1034
1123
  "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)
1037
1147
  res.raise_for_status()
1038
1148
  return res
1039
1149
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reait
3
- Version: 1.1.1
3
+ Version: 1.2.0
4
4
  Summary: RevEng.AI Toolkit and Python API
5
5
  Home-page: https://github.com/RevEng-AI/reait
6
6
  Author: James Patrick-Evans
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes