Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another attempt to do EsilHooks ##esil #21939

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libr/esil/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pre: libr_esil.$(EXT_SO) libr_esil.$(EXT_AR)

include $(STATIC_ESIL_PLUGINS)
STATIC_OBJS=$(subst ..,p/..,$(subst esil_,p/esil_,$(STATIC_OBJ)))
OBJS=esil.o esil_plugin.o esil_handler.o esil_stats.o esil_trace.o
OBJS=esil.o esil_plugin.o esil_handler.o esil_hooks.o esil_stats.o esil_trace.o
OBJS+=${STATIC_OBJS}

include ../rules.mk
15 changes: 14 additions & 1 deletion libr/esil/esil.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ R_API REsil *r_esil_new(int stacksize, int iotrap, unsigned int addrsize) {
r_esil_plugins_init (esil);
esil->addrmask = genmask (addrsize - 1);
esil->trace = r_esil_trace_new (esil);
esil->hooks = r_esil_hooks_new ();
esil->stats_mr_handle = UT32_MAX;
esil->stats_mw_handle = UT32_MAX;
esil->stats_rr_handle = UT32_MAX;
esil->stats_rw_handle = UT32_MAX;
return esil;
}

Expand Down Expand Up @@ -208,6 +213,7 @@ R_API void r_esil_free(REsil *esil) {
esil->anal->arch->esil = NULL;
}

r_esil_hooks_free (esil->hooks);
r_esil_plugins_fini (esil);
r_esil_handlers_fini (esil);
ht_pp_free (esil->ops);
Expand Down Expand Up @@ -885,7 +891,7 @@ static bool esil_eq(REsil *esil) {
}
free (newreg);
free (src2);
} else if (src && dst && r_esil_reg_read_nocallback (esil, dst, &num, NULL)) {
} else if (src && dst && r_esil_reg_read1 (esil, dst, &num, NULL)) {
if (r_esil_get_parm (esil, src, &num2)) {
ret = r_esil_reg_write (esil, dst, num2);
esil->cur = num2;
Expand Down Expand Up @@ -4003,6 +4009,7 @@ R_API bool r_esil_setup(REsil *esil, RAnal *anal, int romem, int stats, int nonu
esil->trap_code = 0;
//esil->user = NULL;
esil->cb.reg_read = internal_esil_reg_read;
r_esil_set_reg_read_imp (esil, (REsilImpHookRegReadCB)internal_esil_reg_read, esil);
if (nonull) {
// this is very questionable, most platforms allow accessing NULL
// never writes zero to PC, BP, SP, why? because writing
Expand All @@ -4011,10 +4018,16 @@ R_API bool r_esil_setup(REsil *esil, RAnal *anal, int romem, int stats, int nonu
esil->cb.reg_write = internal_esil_reg_write_no_null;
esil->cb.mem_read = internal_esil_mem_read_no_null;
esil->cb.mem_write = internal_esil_mem_write_no_null;
r_esil_set_reg_write_imp (esil, (REsilImpHookRegWriteCB)internal_esil_reg_write_no_null, esil);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally the cast shuoldnt be needed, otherwise we can pass functions with different signature and get runtime crashes hard to debug

r_esil_set_mem_read_imp (esil, (REsilImpHookMemReadCB)internal_esil_mem_read_no_null, esil);
r_esil_set_mem_write_imp (esil, (REsilImpHookMemWriteCB)internal_esil_mem_write_no_null, esil);
} else {
esil->cb.reg_write = internal_esil_reg_write;
esil->cb.mem_read = internal_esil_mem_read;
esil->cb.mem_write = internal_esil_mem_write;
r_esil_set_reg_write_imp (esil, (REsilImpHookRegWriteCB)internal_esil_reg_write, esil);
r_esil_set_mem_read_imp (esil, (REsilImpHookMemReadCB)internal_esil_mem_read, esil);
r_esil_set_mem_write_imp (esil, (REsilImpHookMemWriteCB)internal_esil_mem_write, esil);
}
r_esil_mem_ro (esil, romem);
r_esil_stats (esil, stats);
Expand Down
Loading