views:

35

answers:

2

I want to remove the security permissions from a class I don't have access to the source for. Is it possible to, via reflection, remove or modify the attribute?

[...PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust"), PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]


after some consideration, it's occurred to me that maybe this approach to the problem is wrong. Is there a way to run a windows service in full trust so that its permissions would satisfy the above demands?

+1  A: 

Nope - .NET reflection is read-only. If you want to edit an existing assembly, look at Mono Cecil, although removing an attribute & replacing the assembly would remove any strong name signing on it

thecoop
Although if you're going to use Cecil, you may as well disassemble using ildasm, remove the attributes by hand, and reassemble using ilasm. Or even use Reflector to reverse engineer to C# source.
Tim Robinson
That's the road I started going down. I just wanted to see if there were any other options I wasn't aware of.
Joshua Evensen
@Joshua FWIW doing that will most likely be unlawful or at the very least in breach of contract of the software.
Chris Marisic
Yeah, i'm thinking an alternate approach is in order. See above.
Joshua Evensen
A: 

You can always create a wrapper class and give the wrapper class more restricted permissions.

Mike
I want to give it less restricted permissions.
Joshua Evensen