本文整理汇总了C#中IKVM.Reflection.Reader.ByteReader.ReadCompressedInt方法的典型用法代码示例。如果您正苦于以下问题:C# ByteReader.ReadCompressedInt方法的具体用法?C# ByteReader.ReadCompressedInt怎么用?C# ByteReader.ReadCompressedInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Reader.ByteReader
的用法示例。
在下文中一共展示了ByteReader.ReadCompressedInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromBlob
internal static ByteReader FromBlob(byte[] blobHeap, int blob)
{
ByteReader br = new ByteReader(blobHeap, blob, 4);
int length = br.ReadCompressedInt();
br.end = br.pos + length;
return br;
}
示例2: DecodeDeclSecurity
bool DecodeDeclSecurity(StringBuilder sb, IList<CustomAttributeData> list, int level)
{
try
{
sb.Append(" = {");
bool first = true;
foreach (var sec in list)
{
if (!first)
{
sb.Append(',');
sb.AppendLine();
sb.Append(' ', level + 14);
}
first = false;
string typeName = sec.Constructor.DeclaringType.AssemblyQualifiedName;
if (typeName.EndsWith(", mscorlib", StringComparison.Ordinal))
{
typeName = typeName.Substring(0, typeName.Length - 10);
}
AppendTypeName(sb, sec.Constructor.DeclaringType, typeName, compat != CompatLevel.None);
sb.Append(" = {");
byte[] blob = sec.__GetBlob();
// LAMESPEC the count of named arguments is a compressed integer (instead of UInt16 as NumNamed in custom attributes)
var br = new ByteReader(blob, 0, blob.Length);
int count = br.ReadCompressedInt();
ReadNamedArguments(sb, br, count, 0, compat != CompatLevel.None && count > 1);
sb.Append('}');
}
sb.Append('}');
return true;
}
catch (IKVM.Reflection.BadImageFormatException)
{
return false;
}
}
示例3: ReadGenericInst
private static Type ReadGenericInst(ModuleReader module, ByteReader br, IGenericContext context)
{
switch (br.ReadByte())
{
case ELEMENT_TYPE_CLASS:
case ELEMENT_TYPE_VALUETYPE:
break;
default:
throw new BadImageFormatException();
}
Type type = ReadTypeDefOrRefEncoded(module, br, context);
if (!type.__IsMissing && !type.IsGenericTypeDefinition)
{
throw new BadImageFormatException();
}
int genArgCount = br.ReadCompressedInt();
Type[] args = new Type[genArgCount];
Type[][] reqmod = null;
Type[][] optmod = null;
for (int i = 0; i < genArgCount; i++)
{
// LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for genericinst, but C++ uses it, the verifier allows it and ildasm also supports it
CustomModifiers mods = ReadCustomModifiers(module, br, context);
if (mods.required != null || mods.optional != null)
{
if (reqmod == null)
{
reqmod = new Type[genArgCount][];
optmod = new Type[genArgCount][];
}
reqmod[i] = mods.required;
optmod[i] = mods.optional;
}
args[i] = ReadType(module, br, context);
}
return GenericTypeInstance.Make(type, args, reqmod, optmod);
}
示例4: ReadOptionalParameterTypes
// this reads just the optional parameter types, from a MethodRefSig
internal static Type[] ReadOptionalParameterTypes(ModuleReader module, ByteReader br)
{
br.ReadByte();
int paramCount = br.ReadCompressedInt();
SkipCustomModifiers(br);
ReadRetType(module, br, null);
for (int i = 0; i < paramCount; i++)
{
if (br.PeekByte() == SENTINEL)
{
br.ReadByte();
Type[] types = new Type[paramCount - i];
for (int j = 0; j < types.Length; j++)
{
SkipCustomModifiers(br);
types[j] = ReadType(module, br, null);
}
return types;
}
SkipCustomModifiers(br);
ReadType(module, br, null);
}
return Type.EmptyTypes;
}
示例5: ReadTypeDefOrRefEncoded
private static Type ReadTypeDefOrRefEncoded(ModuleReader module, ByteReader br, IGenericContext context)
{
int encoded = br.ReadCompressedInt();
switch (encoded & 3)
{
case 0:
return module.ResolveType((TypeDefTable.Index << 24) + (encoded >> 2), null, null);
case 1:
return module.ResolveType((TypeRefTable.Index << 24) + (encoded >> 2), null, null);
case 2:
return module.ResolveType((TypeSpecTable.Index << 24) + (encoded >> 2), context);
default:
throw new BadImageFormatException();
}
}
示例6: SkipCustomModifiers
protected static void SkipCustomModifiers(ByteReader br)
{
byte b = br.PeekByte();
while (IsCustomModifier(b))
{
br.ReadByte();
br.ReadCompressedInt();
b = br.PeekByte();
}
}
示例7: ReadLocalVarSig
internal static void ReadLocalVarSig(ModuleReader module, ByteReader br, IGenericContext context, List<LocalVariableInfo> list)
{
if (br.Length < 2 || br.ReadByte() != LOCAL_SIG)
{
throw new BadImageFormatException("Invalid local variable signature");
}
int count = br.ReadCompressedInt();
for (int i = 0; i < count; i++)
{
if (br.PeekByte() == ELEMENT_TYPE_TYPEDBYREF)
{
br.ReadByte();
list.Add(new LocalVariableInfo(i, module.universe.System_TypedReference, false));
}
else
{
SkipCustomModifiers(br);
bool pinned = false;
if (br.PeekByte() == ELEMENT_TYPE_PINNED)
{
br.ReadByte();
pinned = true;
}
SkipCustomModifiers(br);
Type type = ReadTypeOrByRef(module, br, context);
list.Add(new LocalVariableInfo(i, type, pinned));
}
}
}
示例8: ReadStandAloneMethodSig
internal static __StandAloneMethodSig ReadStandAloneMethodSig(ModuleReader module, ByteReader br, IGenericContext context)
{
CallingConventions callingConvention = 0;
System.Runtime.InteropServices.CallingConvention unmanagedCallingConvention = 0;
bool unmanaged;
byte flags = br.ReadByte();
switch (flags & 7)
{
case DEFAULT:
callingConvention = CallingConventions.Standard;
unmanaged = false;
break;
case 0x01: // C
unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl;
unmanaged = true;
break;
case 0x02: // STDCALL
unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall;
unmanaged = true;
break;
case 0x03: // THISCALL
unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.ThisCall;
unmanaged = true;
break;
case 0x04: // FASTCALL
unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.FastCall;
unmanaged = true;
break;
case VARARG:
callingConvention = CallingConventions.VarArgs;
unmanaged = false;
break;
default:
throw new BadImageFormatException();
}
if ((flags & HASTHIS) != 0)
{
callingConvention |= CallingConventions.HasThis;
}
if ((flags & EXPLICITTHIS) != 0)
{
callingConvention |= CallingConventions.ExplicitThis;
}
if ((flags & GENERIC) != 0)
{
throw new BadImageFormatException();
}
int paramCount = br.ReadCompressedInt();
SkipCustomModifiers(br);
Type returnType = ReadRetType(module, br, context);
List<Type> parameterTypes = new List<Type>();
List<Type> optionalParameterTypes = new List<Type>();
List<Type> curr = parameterTypes;
for (int i = 0; i < paramCount; i++)
{
if (br.PeekByte() == SENTINEL)
{
br.ReadByte();
curr = optionalParameterTypes;
}
SkipCustomModifiers(br);
curr.Add(ReadParam(module, br, context));
}
return new __StandAloneMethodSig(unmanaged, unmanagedCallingConvention, callingConvention, returnType, parameterTypes.ToArray(), optionalParameterTypes.ToArray());
}
示例9: ReadMethodSpec
internal static Type[] ReadMethodSpec(ModuleReader module, ByteReader br, IGenericContext context)
{
if (br.ReadByte() != GENERICINST)
{
throw new BadImageFormatException();
}
Type[] args = new Type[br.ReadCompressedInt()];
for (int i = 0; i < args.Length; i++)
{
args[i] = ReadType(module, br, context);
}
return args;
}
示例10: ReadDeclarativeSecurity
internal static void ReadDeclarativeSecurity(Assembly asm, List<CustomAttributeData> list, int action, ByteReader br)
{
Universe u = asm.universe;
if (br.PeekByte() == '.')
{
br.ReadByte();
int count = br.ReadCompressedInt();
for (int j = 0; j < count; j++)
{
Type type = ReadType(asm, br);
ConstructorInfo constructor;
if (type == u.System_Security_Permissions_HostProtectionAttribute && action == (int)System.Security.Permissions.SecurityAction.LinkDemand)
{
constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
}
else
{
constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { u.System_Security_Permissions_SecurityAction }, null);
}
// LAMESPEC there is an additional length here (probably of the named argument list)
ByteReader slice = br.Slice(br.ReadCompressedInt());
// LAMESPEC the count of named arguments is a compressed integer (instead of UInt16 as NumNamed in custom attributes)
list.Add(new CustomAttributeData(constructor, action, ReadNamedArguments(asm, slice, slice.ReadCompressedInt(), type)));
}
}
else
{
// .NET 1.x format (xml)
char[] buf = new char[br.Length / 2];
for (int i = 0; i < buf.Length; i++)
{
buf[i] = br.ReadChar();
}
string xml = new String(buf);
ConstructorInfo constructor = u.System_Security_Permissions_PermissionSetAttribute.GetConstructor(new Type[] { u.System_Security_Permissions_SecurityAction });
List<CustomAttributeNamedArgument> args = new List<CustomAttributeNamedArgument>();
args.Add(new CustomAttributeNamedArgument(u.System_Security_Permissions_PermissionSetAttribute.GetProperty("XML"),
new CustomAttributeTypedArgument(u.System_String, xml)));
list.Add(new CustomAttributeData(constructor, action, args));
}
}
示例11: ReadString
private static string ReadString(ByteReader br)
{
return Encoding.UTF8.GetString(br.ReadBytes(br.ReadCompressedInt()));
}
示例12: ReadSig
internal static PropertySignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
{
byte flags = br.ReadByte();
if ((flags & PROPERTY) == 0)
{
throw new BadImageFormatException();
}
CallingConventions callingConvention = CallingConventions.Standard;
if ((flags & HASTHIS) != 0)
{
callingConvention |= CallingConventions.HasThis;
}
if ((flags & EXPLICITTHIS) != 0)
{
callingConvention |= CallingConventions.ExplicitThis;
}
Type returnType;
Type[] parameterTypes;
int paramCount = br.ReadCompressedInt();
CustomModifiers[] mods = null;
PackedCustomModifiers.Pack(ref mods, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
returnType = ReadRetType(module, br, context);
parameterTypes = new Type[paramCount];
for (int i = 0; i < parameterTypes.Length; i++)
{
PackedCustomModifiers.Pack(ref mods, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
parameterTypes[i] = ReadParam(module, br, context);
}
return new PropertySignature(callingConvention, returnType, parameterTypes, PackedCustomModifiers.Wrap(mods));
}
示例13: ReadSig
internal static PropertySignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
{
byte flags = br.ReadByte();
if ((flags & PROPERTY) == 0)
{
throw new BadImageFormatException();
}
CallingConventions callingConvention = CallingConventions.Standard;
if ((flags & HASTHIS) != 0)
{
callingConvention |= CallingConventions.HasThis;
}
if ((flags & EXPLICITTHIS) != 0)
{
callingConvention |= CallingConventions.ExplicitThis;
}
Type returnType;
Type[] returnTypeRequiredCustomModifiers;
Type[] returnTypeOptionalCustomModifiers;
Type[] parameterTypes;
Type[][] parameterRequiredCustomModifiers;
Type[][] parameterOptionalCustomModifiers;
int paramCount = br.ReadCompressedInt();
ReadCustomModifiers(module, br, context, out returnTypeRequiredCustomModifiers, out returnTypeOptionalCustomModifiers);
returnType = ReadRetType(module, br, context);
parameterTypes = new Type[paramCount];
parameterRequiredCustomModifiers = null;
parameterOptionalCustomModifiers = null;
for (int i = 0; i < parameterTypes.Length; i++)
{
if (IsCustomModifier(br.PeekByte()))
{
if (parameterOptionalCustomModifiers == null)
{
parameterOptionalCustomModifiers = new Type[parameterTypes.Length][];
parameterRequiredCustomModifiers = new Type[parameterTypes.Length][];
}
ReadCustomModifiers(module, br, context, out parameterRequiredCustomModifiers[i], out parameterOptionalCustomModifiers[i]);
}
parameterTypes[i] = ReadParam(module, br, context);
}
return new PropertySignature(callingConvention, returnType, returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
parameterTypes, parameterOptionalCustomModifiers, parameterRequiredCustomModifiers);
}
示例14: ReadGenericInst
private static Type ReadGenericInst(ModuleReader module, ByteReader br, IGenericContext context)
{
Type type;
switch (br.ReadByte())
{
case ELEMENT_TYPE_CLASS:
type = ReadTypeDefOrRefEncoded(module, br, context).MarkNotValueType();
break;
case ELEMENT_TYPE_VALUETYPE:
type = ReadTypeDefOrRefEncoded(module, br, context).MarkValueType();
break;
default:
throw new BadImageFormatException();
}
if (!type.__IsMissing && !type.IsGenericTypeDefinition)
{
throw new BadImageFormatException();
}
int genArgCount = br.ReadCompressedInt();
Type[] args = new Type[genArgCount];
CustomModifiers[] mods = null;
for (int i = 0; i < genArgCount; i++)
{
// LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for genericinst, but C++ uses it, the verifier allows it and ildasm also supports it
CustomModifiers cm = CustomModifiers.Read(module, br, context);
if (!cm.IsEmpty)
{
if (mods == null)
{
mods = new CustomModifiers[genArgCount];
}
mods[i] = cm;
}
args[i] = ReadType(module, br, context);
}
return GenericTypeInstance.Make(type, args, mods);
}
示例15: ReadOptionalParameterTypes
// this reads just the optional parameter types, from a MethodRefSig
internal static Type[] ReadOptionalParameterTypes(ModuleReader module, ByteReader br, IGenericContext context, out CustomModifiers[] customModifiers)
{
br.ReadByte();
int paramCount = br.ReadCompressedInt();
CustomModifiers.Skip(br);
ReadRetType(module, br, context);
for (int i = 0; i < paramCount; i++)
{
if (br.PeekByte() == SENTINEL)
{
br.ReadByte();
Type[] types = new Type[paramCount - i];
customModifiers = new CustomModifiers[types.Length];
for (int j = 0; j < types.Length; j++)
{
customModifiers[j] = CustomModifiers.Read(module, br, context);
types[j] = ReadType(module, br, context);
}
return types;
}
CustomModifiers.Skip(br);
ReadType(module, br, context);
}
customModifiers = Empty<CustomModifiers>.Array;
return Type.EmptyTypes;
}