- Home /
Obfuscating variable names c#
As an example I would like to turn "int x" into "int y" in the build automatically. I couldn't find much info on how to do this, I couldn't find a free obfuscator that does this either though I would rather do it myself. I am not doing this against piracy and I know people will still figure out what the variable does but I simply don't want them to know what I named them. I am hoping there is a relatively straightforward way I missed, if anyone could point me to the right direction it would be great. Thanks.
Answer by ElementalVenom · Oct 13, 2018 at 03:40 PM
The way ive always done this(and afaik this is the only way to do it unless you use a custom compiler) is to write a program using the "Mono.Cecil" dll's to load your compiled assembly(named Assembly-CSharp.dll) and then go through each variable of the assembly using a for loop and change the variables name. Then save the assembly as a new assembly and use that new assembly as your games main assembly(as in replace the original Assembly-CSharp.dll with the new one you made with your program) and then youre done!
=========================
This will take a lot of reading to figure out though so its not straightforward by any means. But just google "Mono.Cecil" and read through the programming docs and maybe even look at some tutorials.
Yes obfuscating is usually done on the compiled assembly since any "names" are just metadata tokens in the file. However you will run into issues when you have serialized data in Unity which is based on a type from that assembly.
$$anonymous$$ono.Cecil is what I was looking for, not sure how I didn't find it. Also couldn't find much documentation but once I figured it out it is quite easy to change things. Thanks.
Your answer
Follow this Question
Related Questions
Practical Obfuscation Experience 3 Answers
proguard obfuscation 0 Answers
Using Dotfuscator in Unity's build pipeline 0 Answers
Keeping my files safe to a download? (obfuscation) 2 Answers
Android obfuscator 1 Answer