Skip to content

Commit

Permalink
Ropchain constraint syntax parser (#4552)
Browse files Browse the repository at this point in the history
Co-authored-by: Giridhar Prasath R <[email protected]>
  • Loading branch information
giridharprasath and giridharprasath committed Jul 10, 2024
1 parent e3d27c9 commit c8d0505
Show file tree
Hide file tree
Showing 23 changed files with 2,472 additions and 1,511 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ peda-session-*
/.vs
.cache/
test/.tmp/*
test/.sync_disk_db
subprojects/capstone-*/
subprojects/pcre2*/
subprojects/libzip-*/
Expand Down
28 changes: 28 additions & 0 deletions librz/arch/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <rz_util/rz_path.h>
#include <rz_arch.h>
#include <rz_lib.h>
#include <rz_rop.h>

/**
* \brief Returns the default size byte width of memory access operations.
Expand Down Expand Up @@ -129,6 +130,7 @@ RZ_API RzAnalysis *rz_analysis_new(void) {
}
}
analysis->ht_global_var = ht_sp_new(HT_STR_DUP, NULL, (HtSPFreeValue)rz_analysis_var_global_free);
analysis->ht_rop = NULL;
analysis->global_var_tree = NULL;
analysis->il_vm = NULL;
analysis->hash = rz_hash_new();
Expand Down Expand Up @@ -185,6 +187,7 @@ RZ_API RzAnalysis *rz_analysis_free(RzAnalysis *a) {
rz_list_free(a->imports);
rz_str_constpool_fini(&a->constpool);
ht_sp_free(a->ht_global_var);
ht_up_free(a->ht_rop);
rz_list_free(a->plugins);
rz_analysis_debug_info_free(a->debug_info);
free(a);
Expand Down Expand Up @@ -240,6 +243,31 @@ RZ_API char *rz_analysis_get_reg_profile(RzAnalysis *analysis) {
: NULL;
}

/**
* \brief Check if a register is in the analysis profile.
* \param analysis Pointer to the RzAnalysis object.
* \param name The register name to check.
* \return true if the register name is found, false otherwise.
*
* This function checks if the given register name is present
* in the register profile of the given RzAnalysis.
*/
RZ_API bool rz_analysis_is_reg_in_profile(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL const char *name) {
rz_return_val_if_fail(analysis && name, false);

char *reg_prof = rz_analysis_get_reg_profile(analysis);
if (!reg_prof) {
return false;
}

if (strstr(reg_prof, name)) {
free(reg_prof);
return true;
}
free(reg_prof);
return false;
}

RZ_API bool rz_analysis_set_reg_profile(RzAnalysis *analysis) {
bool ret = false;
char *p = rz_analysis_get_reg_profile(analysis);
Expand Down
3 changes: 1 addition & 2 deletions librz/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3735,8 +3735,7 @@ RZ_API int rz_core_config_init(RzCore *core) {

/* rop */
SETI("rop.len", 5, "Maximum ROP gadget length");
SETBPREF("rop.sdb", "false", "Cache results in sdb (experimental)");
SETBPREF("rop.db", "true", "Categorize rop gadgets in sdb");
SETBPREF("rop.cache", "false", "Cache rop gadget results(experimental)");
SETBPREF("rop.subchains", "false", "Display every length gadget from rop.len=X to 2 in /Rl");
SETBPREF("rop.conditional", "false", "Include conditional jump, calls and returns in ropsearch");
SETBPREF("rop.comments", "false", "Display comments in rop search output");
Expand Down
Loading

0 comments on commit c8d0505

Please sign in to comment.