Add one more RReg wrapper in RAnal for bindings (#18946)

This commit is contained in:
pancake 2021-07-28 12:09:23 +02:00 committed by GitHub
parent 6f10062f0c
commit a242ecf943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 7 deletions

View File

@ -229,7 +229,7 @@ R_API bool r_anal_use(RAnal *anal, const char *name) {
} }
#endif #endif
anal->cur = h; anal->cur = h;
r_anal_set_reg_profile (anal); r_anal_set_reg_profile (anal, NULL);
return true; return true;
} }
} }
@ -242,7 +242,10 @@ R_API char *r_anal_get_reg_profile(RAnal *anal) {
} }
// deprecate.. or at least reuse get_reg_profile... // deprecate.. or at least reuse get_reg_profile...
R_API bool r_anal_set_reg_profile(RAnal *anal) { R_API bool r_anal_set_reg_profile(RAnal *anal, const char *p) {
if (p) {
return r_reg_set_profile_string (anal->reg, p);
}
bool ret = false; bool ret = false;
if (anal && anal->cur && anal->cur->set_reg_profile) { if (anal && anal->cur && anal->cur->set_reg_profile) {
ret = anal->cur->set_reg_profile (anal); ret = anal->cur->set_reg_profile (anal);
@ -315,7 +318,7 @@ R_API bool r_anal_set_bits(RAnal *anal, int bits) {
case 64: case 64:
if (anal->bits != bits) { if (anal->bits != bits) {
anal->bits = bits; anal->bits = bits;
r_anal_set_reg_profile (anal); r_anal_set_reg_profile (anal, NULL);
} }
return true; return true;
} }

View File

@ -797,7 +797,7 @@ static bool cb_asmbits(void *user, void *data) {
free (rp); free (rp);
} }
} else { } else {
(void)r_anal_set_reg_profile (core->anal); (void)r_anal_set_reg_profile (core->anal, NULL);
} }
} }
r_core_anal_cc_init (core); r_core_anal_cc_init (core);

View File

@ -1536,7 +1536,7 @@ R_API int r_anal_add(RAnal *anal, RAnalPlugin *foo);
R_API int r_anal_archinfo(RAnal *anal, int query); R_API int r_anal_archinfo(RAnal *anal, int query);
R_API bool r_anal_use(RAnal *anal, const char *name); R_API bool r_anal_use(RAnal *anal, const char *name);
R_API bool r_anal_esil_use(RAnal *anal, const char *name); R_API bool r_anal_esil_use(RAnal *anal, const char *name);
R_API bool r_anal_set_reg_profile(RAnal *anal); R_API bool r_anal_set_reg_profile(RAnal *anal, const char *rp);
R_API char *r_anal_get_reg_profile(RAnal *anal); R_API char *r_anal_get_reg_profile(RAnal *anal);
R_API ut64 r_anal_get_bbaddr(RAnal *anal, ut64 addr); R_API ut64 r_anal_get_bbaddr(RAnal *anal, ut64 addr);
R_API bool r_anal_set_bits(RAnal *anal, int bits); R_API bool r_anal_set_bits(RAnal *anal, int bits);

View File

@ -133,6 +133,9 @@ R_API bool r_reg_set_profile_string(RReg *reg, const char *str) {
const char *p = str; const char *p = str;
r_return_val_if_fail (reg && str, false); r_return_val_if_fail (reg && str, false);
if (R_STR_ISEMPTY (str)) {
return true;
}
// Same profile, no need to change // Same profile, no need to change
if (reg->reg_profile_str && !strcmp (reg->reg_profile_str, str)) { if (reg->reg_profile_str && !strcmp (reg->reg_profile_str, str)) {
@ -262,6 +265,7 @@ R_API bool r_reg_set_profile_string(RReg *reg, const char *str) {
return true; return true;
} }
// read profile from file
R_API bool r_reg_set_profile(RReg *reg, const char *profile) { R_API bool r_reg_set_profile(RReg *reg, const char *profile) {
r_return_val_if_fail (reg && profile, NULL); r_return_val_if_fail (reg && profile, NULL);
char *str = r_file_slurp (profile, NULL); char *str = r_file_slurp (profile, NULL);

View File

@ -7,7 +7,7 @@ bool test_filter_regs(void) {
RAnal *anal = r_anal_new (); RAnal *anal = r_anal_new ();
r_anal_use (anal, "x86"); r_anal_use (anal, "x86");
r_anal_set_bits (anal, 32); r_anal_set_bits (anal, 32);
r_anal_set_reg_profile (anal); r_anal_set_reg_profile (anal, NULL);
RAnalEsil *esil = r_anal_esil_new (4096, 0, 1); RAnalEsil *esil = r_anal_esil_new (4096, 0, 1);
esil->anal = anal; esil->anal = anal;
@ -54,7 +54,7 @@ bool test_lemon_const_folder(void) {
RAnal *anal = r_anal_new (); RAnal *anal = r_anal_new ();
r_anal_use (anal, "x86"); r_anal_use (anal, "x86");
r_anal_set_bits (anal, 32); r_anal_set_bits (anal, 32);
r_anal_set_reg_profile (anal); r_anal_set_reg_profile (anal, NULL);
RAnalEsilDFG *dfg = r_anal_esil_dfg_expr (anal, NULL, "4,!,3,ebx,:=,!,1,+,eax,:="); RAnalEsilDFG *dfg = r_anal_esil_dfg_expr (anal, NULL, "4,!,3,ebx,:=,!,1,+,eax,:=");
r_anal_esil_dfg_fold_const (anal, dfg); r_anal_esil_dfg_fold_const (anal, dfg);