This is a MSHookFunction shim, which supports writing to RX memory on all modern jailbreaks.
Requires linking against CydiaSubstrate for MSFindSymbol, but dlsym should work fine, to remove this dependency.
On unc0ver and checkra1n, write_memory directly uses MSHookMemory, the functionality provided by substrate to write to RX memory.
On Electra and Chimera, it changes virtual memory permissions to allow writing, then vm_write's your data over the address, finally setting the permissions back to RX.
The fallback method used on Electra and Chimera should work on all jailbreaks, providing CS_DEBUGGED is set.