rizin icon indicating copy to clipboard operation
rizin copied to clipboard

Allow to make global variables unwritable

Open Rot127 opened this issue 5 months ago • 5 comments

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

Rot127 avatar Jul 17 '25 12:07 Rot127

is this issue fixed or should i try to work on that?

revanthsaich avatar Jul 21 '25 15:07 revanthsaich

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.

Rot127 avatar Jul 21 '25 15:07 Rot127

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 ?

Sl4y3r-07 avatar Oct 30 '25 07:10 Sl4y3r-07

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.

Rot127 avatar Oct 31 '25 10:10 Rot127

Okay, I'll raise a PR soon once I am comfortable with IL related code

Sl4y3r-07 avatar Oct 31 '25 13:10 Sl4y3r-07