Allow to make global variables unwritable
Is your feature request related to a problem? Please describe.
Some architectures have zero registers. They always hold the value zero and if they are written to don't change. The only way to represent this in our uplifted archs is by checking for them and generating different RzIL.
Like this:
RZ_IPI RzILOpEffect *set_g(const char *gname, RzILOpPure *gval) {
if (RZ_STR_EQ(gname, "g0")) {
rz_il_op_pure_free(gval);
return EMPTY();
}
return SETG(gname, gval);
}
#define SSETG(gname, gval) set_g(gname, gval)
// Use SSETG from here on.
~~These extra paths in an IL op take a lot of allocations and will be rarely used.~~
With the method above it doesn't take any allocations. But still would not prevent to write or ignore writes to the immutable register during runtime.
Describe the solution you'd like
Being able to define a callback in RzAnalysisILConfig to check for global variable names which are immutable would be nice. As long as the checks are constant time it shouldn't matter.
Describe alternatives you've considered
Adding extra checks in the uplifting, as described above.
Additional context
none
is this issue fixed or should i try to work on that?
Feel free to send a PR. You would need to check out RzAnalysisILConfig and rz_il_vm.h.
But contrary to the initial idea I think it is better to define not a callback, but simply an array of global variable names and let the VM check on a write.
Hi! @Rot127 I just wanted to confirm whether I am in the right direction.
I am thinking of the following approach (on the suggestion of array of global variables):
Adding a const char *immutable_regs[] in RzAnalaysisConfig struct and also in RzILVm struct and then setting them up in init function (in il_vm.c) and then adding a check in rz_il_vm_set_global_var .
So flow would be like this:
appropriate architecture plugin is loaded first -> analysis module requests IL config from arch plugin-> rz_il_vm_init() is called within the rz_il_vm_new() in analysis_il.c -> here, we can set immutable_regs -> once, vm is configured with immutable registers, then we can add a check in rz_il_vm_set_global_var
It is just a rough overview of what I am thinking.
What do you suggest ?
Yes, something like that. I removed the "good-first-issue" label for now, because I might have misjudged the required code knowledge for the tasks.
Okay, I'll raise a PR soon once I am comfortable with IL related code