Hi
I was having some trouble reading the SecurityAttributes from my
assembly.
When I declare multiple security attributes in my AssemblyInfo.cs file
on the assembly to reflect...
...
[assembly: AspNetHostingPermission(SecurityAction.RequestMinimum)]
[assembly: UIPermission(SecurityAction.RequestMinimum,
Unrestricted=true)]
[assembly: FileIOPermission(SecurityAction.RequestMinimum, Read = "c:\
\temp.txt")]
[assembly: SiteIdentityPermission(SecurityAction.RequestMinimum)]
[assembly: SharePointPermission(SecurityAction.RequestMinimum,
ObjectModel= true)]
[assembly: EnvironmentPermission(SecurityAction.RequestMinimum,
Unrestricted = true)]
Only one IPermission "EnvironmentPermission" in the PermissionSet is
returned from the assembly.SecurityDeclarations. It should have been
five IPermission in the PermissionSet and not only one.
I have looked though the Cecil code and it seems that there is a bug
in the SecurityDeclarationReader.cs file reading the declarations.
When adding this line "start = (int)br.BaseStream.Position;" to the
bottom of the last method, it all worked perfectly. I have not
included the whole file here but it should be clear enough.
Note that only one line have been added to the method
CreateSecurityAttribute(), see the bottom line.
Otherwise thanks for a great project, its really useful.
Thank you
Carsten Keutmann
...
private SSP.SecurityAttribute CreateSecurityAttribute (SecurityAction
action, BinaryReader br, byte [] permset, int pos, out int start, bool
resolve)
{
string cname = SignatureReader.ReadUTF8String (permset, pos, out
start);
Type secattr = null;
// note: the SecurityAction parameter isn't important to generate the
XML
SSP.SecurityAttribute sa = null;
try {
secattr = Type.GetType (cname, false);
if (secattr == null)
return null;
sa = Activator.CreateInstance (secattr, new object []
{(SSP.SecurityAction) action}) as SSP.SecurityAttribute;
} catch {}
if (sa == null)
return null;
// encoded length of all parameters (we don't need the value - except
the updated pos)
Utilities.ReadCompressedInteger (permset, start, out pos);
int numparams = Utilities.ReadCompressedInteger (permset, pos, out
start);
if (numparams == 0)
return sa;
br.BaseStream.Position = start;
for (int j = 0; j < numparams; j++) {
bool read = true;
CustomAttrib.NamedArg na = sr.ReadNamedArg (permset, br, ref
read,
resolve);
if (!read)
return null;
if (na.Field) {
FieldInfo fi = secattr.GetField (na.FieldOrPropName);
fi.SetValue (sa, na.FixedArg.Elems[0].Value);
} else if (na.Property) {
PropertyInfo pi = secattr.GetProperty
(na.FieldOrPropName);
pi.SetValue (sa, na.FixedArg.Elems[0].Value, null);
}
}
// CK. Set 'start' to br.BaseStream.Position otherwise the start
position will get out of sync with the stream.
start = (int)br.BaseStream.Position;
return sa;
}
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---