#I want to write a macro which can encrypt a function in compilation and decrypt it during runtime, h

3 messages · Page 1 of 1 (latest)

ruby dagger
#

hi, so it's likely you'll want a procedural macro to do this, as i doubt a declarative macro will have the capabilities to do this. since you don't want to add things and would like to instead replace the content entirely, you don't want to write a function or derive proc macro, but likely an attribute proc macro. this is a good site that has info on these, i highly recommend reading it: https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros

an attribute proc macro can read the entirety of the entered code, parse it, and modify it in anyway and it returns new code that the compiler will see and process.

an important question i have is what sort of encryption do you want to use. do you want it to be unclear what the code does to the person running the source code or someone decompiling the binary?

hasty rivet
#

I think this is mostly beyond the capabilities of simple macros. I think answering this requires more details. Why are you trying to do this? What goal are you trying to achieve? Should functions called by the function also be encrypted recursively?

azure stream
#

This doesn’t sound possible to me, at least as a rust macro, under current tools. It would require the ability to evaluate arbitrary rust code at runtime, which just isn’t a thing since currently all rust code needs to be compiled before run. This would be theoretically possible if you ran the code inside an interpreter like python, but as far as I know no one has made that yet since you could just use python instead.