- Home /
Limit namespace access on compiled scripts
Hello, I'll try and keep this as brief as possible:
I am building a sort of modding system for a certain aspect of my game.
It basically allows the common user to write some C# code which will be used to give access to certain elements of the game at certain times. Like giving the host of a multiplayer server the ability to decide what map to load with what parameters etc...
I already have the assembly loading working. It's quite neat and not very complicated XD
But now I've come to the point where it would be very nice if I could give the "user" some access to assemblies such as System
and UnityEngine
.
I could of course include the dll's in the ReferenceAssemblies
property of the CompilerParameters
, but that would give them access to possibly harmful functionality, such as reflection, Instantiation, Destroy as well as many others...
How would I limit the assembly references to only certain namespaces, such as System.IO
and System.Collections
, without giving access to System.Reflection
?
Now for the posting of some possibly relevant code:
//Excuse the UnityScript... I find it quicker to do things in
//Create compiler parameters
var params:CompilerParameters = new CompilerParameters();
params.GenerateExecutable = false;
params.GenerateInMemory = false;
//Add assembly reference
params.ReferencedAssemblies.Add("System.dll");
//I wish I could put System.IO in here instead of System.dll
//Create provider and load/compile assembly
var provider:CodeDomProvider = new CodeDomProvider.CreateProvider("CSharp");
var results:CompilerResults = provider.CompileAssemblyFromFile(params, path);
I hope this is even possible ;)
Thank you,
Benproductions1
EDIT:
I forgot to add: Is it possible to add: Is it possible to add the current Assmbly to that list? So I could inherit a class etc., or do I have to make my own assembly and include that in the project? (Not that it's hard, just a minor pain XD)
This sounds a bit like a question for StackOverflow to me... It's that kinda complicated.
It would probably be better if you wrote some kind of facade DLL to the bits you wanted from the system libraries and your own types and then add a reference to that (now I'm not convinced you wouldn't have to reference all of the others too though if you didn't repeat the structures).
@whydoidoit I was thinking of writing some sort of wrapper for all the necessary System
functions, but with the amount of stuff that would be useful and safe is enormous and I don't have that much time ;)
^- why I asked the question
$$anonymous$$aybe I should go ask this on Stack Overflow, thanks for the tip
Answer by HappyMoo · Jan 07, 2014 at 10:36 AM
Have you seen this?
MAF: http://stackoverflow.com/questions/1520113/restrict-plug-in-assembly-code-access
Thanks for the links! I'll check out $$anonymous$$AF, but it seems that $$anonymous$$ono doesn't support CAS...
There is no planned release date to support CAS in $$anonymous$$ono
Your answer
![](https://koobas.hobune.stream/wayback/20220613112815im_/https://answers.unity.com/themes/thub/images/avi.jpg)