Author: jbevain
Date: 2007-09-28 05:28:35 -0400 (Fri, 28 Sep 2007)
New Revision: 86559
Modified:
trunk/mcs/class/Mono.Cecil/ChangeLog
trunk/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionReader.cs
Log:
2007-09-28 Jb Evain <[EMAIL PROTECTED]>
* Mono.Cecil/SecurityDeclarationReader.cs:
Adapt patch from Carlo Kok <[EMAIL PROTECTED]>.
Properly read unicode string constants.
Modified: trunk/mcs/class/Mono.Cecil/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Cecil/ChangeLog 2007-09-28 09:14:40 UTC (rev
86558)
+++ trunk/mcs/class/Mono.Cecil/ChangeLog 2007-09-28 09:28:35 UTC (rev
86559)
@@ -2,6 +2,10 @@
* Mono.Cecil/SecurityDeclarationReader.cs:
Adapt patch from Carlo Kok <[EMAIL PROTECTED]>.
+ Properly read unicode string constants.
+
+ * Mono.Cecil/SecurityDeclarationReader.cs:
+ Adapt patch from Carlo Kok <[EMAIL PROTECTED]>.
For some MS assemblies, the security declaration contains
one zero byte.
Modified: trunk/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionReader.cs
===================================================================
--- trunk/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionReader.cs 2007-09-28
09:14:40 UTC (rev 86558)
+++ trunk/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionReader.cs 2007-09-28
09:28:35 UTC (rev 86559)
@@ -1084,9 +1084,26 @@
return type;
}
+ static bool IsOdd (int i)
+ {
+ return (i & 1) == 1;
+ }
+
protected object GetConstant (uint pos, ElementType elemType)
{
+ if (elemType == ElementType.Class)
+ return null;
+
byte [] constant = m_root.Streams.BlobHeap.Read (pos);
+
+ if (elemType == ElementType.String) {
+ int length = constant.Length;
+ if (IsOdd (length))
+ length--;
+
+ return Encoding.Unicode.GetString (constant, 0,
length);
+ }
+
BinaryReader br = new BinaryReader (new MemoryStream
(constant));
switch (elemType) {
@@ -1114,10 +1131,6 @@
return br.ReadSingle ();
case ElementType.R8 :
return br.ReadDouble ();
- case ElementType.String :
- byte [] bytes = br.ReadBytes (constant.Length);
- string str = Encoding.Unicode.GetString (bytes,
0, bytes.Length);
- return str;
case ElementType.Class :
return null;
default :
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches