Skip to main content

protect

Attribute Macro protect 

Source
#[protect]
Expand description

Declares how ruwrite is allowed to treat the function or static it is placed on.

ⓘ
#[protect(immutable)]
fn check_license() -> bool { true }

#[protect(protected)]
static SECRET_KEY: u32 = 0xDEAD_BEEF;

Modes, from least to most restrictive:

ModeMeaning
editableexplicitly not protected; the same as writing nothing, spelled out
immutableruwrite refuses every edit that touches it
protectedimmutable, and also included when the program later checks its own integrity (see Executable::integrity_snapshot)
hideimmutable, and its name is not stored as readable text in the binary and is left out of Executable::functions() / variables(); see the limitations below

ruwrite reads this declaration back from the compiled executable, so every edit through it is checked, however it is made: by name, by address, by raw bytes, or by content ([Executable::find_value]). It is the program declaring the rule, not ruwrite guessing at one — there is deliberately no option to bypass it.

What hide does and does not do. It keeps the plain name out of the .ruwprot record (a hash is stored instead, so ruwrite can still match the right item without ever holding its readable name) and filters it out of ruwrite’s own listings. It does not rename the function’s debug or symbol-table entry, strip its machine code, or defend against disassembly: a determined reader with objdump still sees it. Build without debug info and strip symbols for that.

Mark a protected function #[inline(never)] so the compiler keeps one identifiable copy of it instead of folding it into every caller.