reait 1.2.1__tar.gz → 1.2.3__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.2.1
3
+ Version: 1.2.3
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.2.1"
7
+ version = "1.2.3"
8
8
  readme = "README.md"
9
9
  classifiers=[
10
10
  "Programming Language :: Python :: 3",
@@ -15,11 +15,12 @@ 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.2.1"
18
+ __version__ = "1.2.3"
19
19
 
20
20
  re_conf = {
21
21
  "apikey": environ.get("REAI_API_KEY", ""),
22
22
  "host": environ.get("REAI_API_HOST", "https://api.reveng.ai"),
23
+ "user_agent": environ.get("REAI_USER_AGENT", "RevEng.AI Toolkit"),
23
24
  }
24
25
 
25
26
 
@@ -65,7 +66,8 @@ def reveng_req(
65
66
  :param files: Dictionary of files to send to the specified URL
66
67
  """
67
68
  url = f"{re_conf['host']}/{end_point if end_point[0] != '/' else end_point[1:]}"
68
- headers = {"Authorization": re_conf["apikey"]}
69
+ headers = {"Authorization": re_conf["apikey"],
70
+ "User-Agent": re_conf["user_agent"]}
69
71
 
70
72
  if ex_headers:
71
73
  headers.update(ex_headers)
@@ -246,7 +248,7 @@ def RE_analyse(
246
248
  skip_scraping: bool = False,
247
249
  skip_capabilities: bool = False,
248
250
  skip_sbom: bool = False,
249
- advanced_analysis: bool = False
251
+ advanced_analysis: bool = False,
250
252
  ) -> Response:
251
253
  """
252
254
  Start analysis job for binary file
@@ -308,7 +310,8 @@ def RE_analyse(
308
310
  "skip_scraping",
309
311
  "skip_capabilities",
310
312
  "skip_sbom",
311
- "advanced_analysis"
313
+ "advanced_analysis",
314
+ "skip_cves",
312
315
  ):
313
316
  p_value = locals()[p_name]
314
317
 
@@ -335,43 +338,25 @@ def RE_upload(fpath: str) -> Response:
335
338
  :param fpath: File path for binary to analyse
336
339
  """
337
340
  bin_id = re_binary_id(fpath)
338
- result = re_hash_check(bin_id)
339
341
 
340
- if result:
342
+ with open(fpath, "rb") as fd:
343
+ res: Response = reveng_req(
344
+ requests.post, "v1/upload", files={"file": fd})
345
+
346
+ if res.ok:
341
347
  logger.info(
342
- "File %s - %s already uploaded. Skipping upload...", fpath, bin_id)
343
-
344
- res = Response()
345
- res.status_code = 200
346
- res.url = f"{re_conf['host']}/v1/upload"
347
- res._content = (
348
- (
349
- '{0}"success": true,'
350
- '"message": "File already uploaded!",'
351
- '"sha_256_hash": "{1}"{2}'
352
- )
353
- .format("{", bin_id, "}")
354
- .encode()
348
+ "Successfully uploaded binary to your account. %s - %s", fpath, bin_id
349
+ )
350
+ elif res.status_code == 400:
351
+ if "error" in res.json().keys():
352
+ logger.warning("Error uploading %s - %s",
353
+ fpath, res.json()["error"])
354
+ elif res.status_code == 413:
355
+ logger.warning("File too large. Please upload files under 10MB.")
356
+ elif res.status_code == 500:
357
+ logger.error(
358
+ "Internal Server Error. Please contact support. Skipping upload..."
355
359
  )
356
- else:
357
- with open(fpath, "rb") as fd:
358
- res: Response = reveng_req(
359
- requests.post, "v1/upload", files={"file": fd})
360
-
361
- if res.ok:
362
- logger.info(
363
- "Successfully uploaded binary to your account. %s - %s", fpath, bin_id
364
- )
365
- elif res.status_code == 400:
366
- if "error" in res.json().keys():
367
- logger.warning("Error uploading %s - %s",
368
- fpath, res.json()["error"])
369
- elif res.status_code == 413:
370
- logger.warning("File too large. Please upload files under 10MB.")
371
- elif res.status_code == 500:
372
- logger.error(
373
- "Internal Server Error. Please contact support. Skipping upload..."
374
- )
375
360
 
376
361
  res.raise_for_status()
377
362
  return res
@@ -759,9 +744,7 @@ def RE_functions_list(
759
744
  params["max_v_address"] = max_v_address
760
745
 
761
746
  res: Response = reveng_req(
762
- requests.get,
763
- f"/v2/analyses/{analysis_id}/functions/list",
764
- params=params
747
+ requests.get, f"/v2/analyses/{analysis_id}/functions/list", params=params
765
748
  )
766
749
 
767
750
  res.raise_for_status()
@@ -868,12 +851,10 @@ def _binary_format(binary: Binary) -> str:
868
851
  return "Mach-O"
869
852
 
870
853
  logger.error(
871
- "Error, could not determine or unsupported"
872
- f" binary format: {binary.format}."
854
+ "Error, could not determine or unsupported" f" binary format: {binary.format}."
873
855
  )
874
856
  raise RuntimeError(
875
- "Error, could not determine or "
876
- f"unsupported binary format: {binary.format}"
857
+ "Error, could not determine or " f"unsupported binary format: {binary.format}"
877
858
  )
878
859
 
879
860
 
@@ -969,10 +950,7 @@ def RE_functions_data_types_poll(
969
950
  return res
970
951
 
971
952
 
972
- def RE_generate_data_types(
973
- analysis_id: int,
974
- function_ids: list[int]
975
- ) -> Response:
953
+ def RE_generate_data_types(analysis_id: int, function_ids: list[int]) -> Response:
976
954
  """
977
955
  Generate data types for the analysis
978
956
  :param aid: Analysis ID
@@ -1032,10 +1010,7 @@ def RE_begin_ai_decompilation(function_id: int) -> Response:
1032
1010
  return res
1033
1011
 
1034
1012
 
1035
- def RE_poll_ai_decompilation(
1036
- function_id: int,
1037
- summarise: bool = False
1038
- ) -> Response:
1013
+ def RE_poll_ai_decompilation(function_id: int, summarise: bool = False) -> Response:
1039
1014
  """
1040
1015
  Poll AI decompilation for the function
1041
1016
  :param function_id: Function ID
@@ -1068,9 +1043,9 @@ def RE_analysis_lookup(binary_id: int) -> Response:
1068
1043
 
1069
1044
 
1070
1045
  def RE_collections_search(
1071
- page: int = 1,
1072
- page_size: int = 10,
1073
- query: dict = {},
1046
+ page: int = 1,
1047
+ page_size: int = 10,
1048
+ query: dict = {},
1074
1049
  ) -> Response:
1075
1050
  """
1076
1051
  Search for collections in the database
@@ -1110,9 +1085,9 @@ def RE_collections_search(
1110
1085
 
1111
1086
 
1112
1087
  def RE_binaries_search(
1113
- page: int = 1,
1114
- page_size: int = 10,
1115
- query: dict = {},
1088
+ page: int = 1,
1089
+ page_size: int = 10,
1090
+ query: dict = {},
1116
1091
  ) -> Response:
1117
1092
  """
1118
1093
  Search for binaries in the database
@@ -1271,6 +1246,40 @@ def RE_recent_analysis(
1271
1246
  return res
1272
1247
 
1273
1248
 
1249
+ def RE_recent_analysis_v2(
1250
+ search: str = "",
1251
+ workspace: str = "personal",
1252
+ status: str = "All",
1253
+ users: list[str] = [],
1254
+ limit: int = 50
1255
+ ) -> Response:
1256
+ """
1257
+ Get recent analysis using the v2 API
1258
+ :param status: Status of the analysis (default: "All")
1259
+ :param scope: Scope of the analysis (default: "ALL")
1260
+ :param nb_analysis: Number of analysis to retrieve (default: 50)
1261
+ """
1262
+ res: Response = reveng_req(
1263
+ requests.get,
1264
+ "/v2/analyses/list",
1265
+ params={
1266
+ "search_term": search, "status": status, "workspace": workspace,
1267
+ "limit": limit, "usernames": users},
1268
+ )
1269
+
1270
+ res.raise_for_status()
1271
+ return res
1272
+
1273
+
1274
+ def RE_users_me() -> Response:
1275
+ """
1276
+ Get the current user's information
1277
+ """
1278
+ res: Response = reveng_req(requests.get, "/v2/users/me")
1279
+ res.raise_for_status()
1280
+ return res
1281
+
1282
+
1274
1283
  def RE_search(fpath: str) -> Response:
1275
1284
  bin_id = re_binary_id(fpath)
1276
1285
 
@@ -1301,3 +1310,76 @@ def RE_similar_functions(
1301
1310
 
1302
1311
  res.raise_for_status()
1303
1312
  return res
1313
+
1314
+
1315
+ def RE_binary_ann(
1316
+ analysis_id: int,
1317
+ confidence: float = 0.0,
1318
+ nns: int = 1,
1319
+ collection_ids: list[int] = None,
1320
+ binary_ids: list[int] = None,
1321
+ ) -> Response:
1322
+ """
1323
+ Perform binary ANN (Approximate Nearest Neighbor) search.
1324
+ :param analysis_id: Analysis ID
1325
+ :param confidence: Confidence threshold for the search
1326
+ :param nns: Number of nearest neighbors to retrieve
1327
+ :param collection_ids: List of collection IDs to search within
1328
+ :param binary_ids: List of binary IDs to search within
1329
+ """
1330
+ end_point = f"v2/binary_ann/{analysis_id}"
1331
+ json_data = {
1332
+ "confidence": confidence,
1333
+ "nns": nns,
1334
+ "collection_ids": collection_ids or [],
1335
+ "binary_ids": binary_ids or [],
1336
+ }
1337
+
1338
+ res: Response = reveng_req(requests.post, end_point, json_data=json_data)
1339
+ res.raise_for_status()
1340
+ return res
1341
+
1342
+
1343
+ def RE_name_score(functions: list, is_debug: bool = False) -> Response:
1344
+
1345
+ body = {"functions": functions, "is_debug": is_debug}
1346
+ res: Response = reveng_req(
1347
+ requests.post, "v2/confidence/functions/name_score", json_data=body
1348
+ )
1349
+
1350
+ res.raise_for_status()
1351
+ return res
1352
+
1353
+
1354
+ def RE_get_analysis_id_from_binary_id(binary_id: int) -> Response:
1355
+
1356
+ res: Response = reveng_req(requests.get, f"v2/analyses/lookup/{binary_id}")
1357
+
1358
+ res.raise_for_status()
1359
+ return res
1360
+
1361
+
1362
+ def RE_get_functions_from_analysis(analysis_id: int) -> Response:
1363
+
1364
+ res: Response = reveng_req(
1365
+ requests.get, f"v2/analyses/{analysis_id}/functions/list"
1366
+ )
1367
+
1368
+ res.raise_for_status()
1369
+ return res
1370
+
1371
+
1372
+ def RE_update_collection_description(
1373
+ collection_id: int,
1374
+ description: str = "",
1375
+ ):
1376
+ params = {
1377
+ "description": description,
1378
+ }
1379
+
1380
+ res: Response = reveng_req(
1381
+ requests.patch, f"v2/collections/{collection_id}", json_data=params
1382
+ )
1383
+
1384
+ res.raise_for_status()
1385
+ return res
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reait
3
- Version: 1.2.1
3
+ Version: 1.2.3
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