Skip to content

Commit

Permalink
AI Decompilation Support
Browse files Browse the repository at this point in the history
- Added endpoint for AI decompilation
- Some memory bug fixes
  • Loading branch information
brightprogrammer committed Jan 30, 2025
1 parent 3412096 commit 30074eb
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 119 deletions.
5 changes: 5 additions & 0 deletions Include/Reai/Api/Reai.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Reai/AnalysisInfo.h>
#include <Reai/AnnFnMatch.h>
#include <Reai/Api/Request.h>
#include <Reai/Api/Response.h>
#include <Reai/Common.h>
#include <Reai/Types.h>
#include <Reai/Util/CStrVec.h>
Expand Down Expand Up @@ -100,6 +101,10 @@ extern "C" {

CStrVec* reai_get_available_models (Reai* reai, ReaiResponse* response);

Reai* reai_begin_ai_decompilation (Reai* reai, ReaiResponse* response, ReaiFunctionId fn_id);
ReaiAiDecompilationStatus
reai_poll_ai_decompilation (Reai* reai, ReaiResponse* response, ReaiFunctionId fn_id);

#ifdef __cplusplus
}
#endif
Expand Down
38 changes: 36 additions & 2 deletions Include/Reai/Api/Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,40 @@ extern "C" {
REAI_RESPONSE_TYPE_MAX, /* enum value less than this is valid */
} ReaiResponseType;

typedef enum ReaiAiDecompilationStatus {
REAI_AI_DECOMPILATION_STATUS_ERROR,
REAI_AI_DECOMPILATION_STATUS_UNINITIALIZED,
REAI_AI_DECOMPILATION_STATUS_PENDING,
REAI_AI_DECOMPILATION_STATUS_SUCCESS,
} ReaiAiDecompilationStatus;

static inline ReaiAiDecompilationStatus reai_ai_decompilation_status_from_cstr (CString status
) {
if (!status) {
return REAI_AI_DECOMPILATION_STATUS_ERROR;
} else if (!strcmp (status, "uninitialized")) {
return REAI_AI_DECOMPILATION_STATUS_UNINITIALIZED;
} else if (!strcmp (status, "pending")) {
return REAI_AI_DECOMPILATION_STATUS_PENDING;
} else if (!strcmp (status, "success")) {
return REAI_AI_DECOMPILATION_STATUS_SUCCESS;
} else {
return REAI_AI_DECOMPILATION_STATUS_ERROR;
}
}

static inline CString reai_ai_decompilation_status_to_cstr (ReaiAiDecompilationStatus status) {
switch (status) {
case REAI_AI_DECOMPILATION_STATUS_UNINITIALIZED :
return "uninitialized";
case REAI_AI_DECOMPILATION_STATUS_PENDING :
return "pending";
case REAI_AI_DECOMPILATION_STATUS_SUCCESS :
return "success";
default :
return "error";
}
}

/**
* @b Structure returned and taken by reai_request calls that get
Expand Down Expand Up @@ -181,8 +215,8 @@ extern "C" {
struct {
Bool status;
struct {
CString status;
CString decompilation;
ReaiAiDecompilationStatus status;
CString decompilation;
// TODO: function mapping?
} data;
CString message;
Expand Down
8 changes: 6 additions & 2 deletions Include/Reai/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
# define ALLOCATE(type, n) (type *)calloc (n, sizeof (type))
# define REALLOCATE(ptr, type, n) (type *)realloc (ptr, n * sizeof (type));
# define FREE(x) \
free ((void *)(x)); \
x = NULL
do { \
if (x) { \
free ((void *)(x)); \
x = NULL; \
} \
} while (0)
#endif
#define PACKED __attribute__ ((packed))

Expand Down
6 changes: 4 additions & 2 deletions Include/Reai/Util/CStrVec.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ extern "C" {
* @return @c NULL otherwise.
* */
PRIVATE CString *cstr_clone_deinit (CString *clone) {
RETURN_VALUE_IF (!clone || !*clone, (CString *)NULL, ERR_INVALID_ARGUMENTS);
RETURN_VALUE_IF (!clone, (CString *)NULL, ERR_INVALID_ARGUMENTS);

FREE (*clone);
if (*clone) {
FREE (*clone);
}

return clone;
}
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ There are three main objects you need to interact with.
### Configurations

To connect with RevEng.AI servers, you first need to load a config file. The config file must
usually be present in your home directory and must have name `~/.reai-rz.toml`. When using a
usually be present in your home directory and must have name `~/.creait.toml`. When using a
plugin, this file can be auto-generated using one of the commands. A very basic config is

```toml
apikey = "libr3" # Replace this with your own API key
host = "https://api.reveng.ai/v1" # API version and base endpoint
model = "binnet-0.3-x86" # Set the latest AI model here.
db_dir_path = "/home/<user>/.reai" # This path may change depending on your OS
log_dir_path = "/tmp" # This path may change depending on your OS
```

To load the config, you must create a `ReaiConfig` object that parses this toml file and stores
Expand Down
Loading

0 comments on commit 30074eb

Please sign in to comment.