本文整理汇总了C#中IKVM.Reflection.Reader.ByteReader类的典型用法代码示例。如果您正苦于以下问题:C# ByteReader类的具体用法?C# ByteReader怎么用?C# ByteReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteReader类属于IKVM.Reflection.Reader命名空间,在下文中一共展示了ByteReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromBlob
internal static ByteReader FromBlob(byte[] blobHeap, int blob)
{
ByteReader br = new ByteReader(blobHeap, blob, 4);
int length = br.ReadCompressedUInt();
br.end = br.pos + length;
return br;
}
示例2: ReadSig
internal static FieldSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
{
if (br.ReadByte() != FIELD)
{
throw new BadImageFormatException();
}
CustomModifiers mods = CustomModifiers.Read(module, br, context);
Type fieldType = ReadType(module, br, context);
return new FieldSignature(fieldType, mods);
}
示例3: ExtractResources
private static void ExtractResources(ResourceDirectoryEntry root, byte[] buf)
{
ByteReader br = new ByteReader(buf, 0, buf.Length);
while (br.Length >= 32)
{
br.Align(4);
RESOURCEHEADER hdr = new RESOURCEHEADER(br);
if (hdr.DataSize != 0)
{
root[hdr.TYPE][hdr.NAME][new OrdinalOrName(hdr.LanguageId)].Data = ByteBuffer.Wrap(br.ReadBytes(hdr.DataSize));
}
}
}
示例4: CustomAttributeData
internal CustomAttributeData(Assembly asm, ConstructorInfo constructor, ByteReader br)
{
this.lazyConstructor = constructor;
if (br.Length == 0)
{
// it's legal to have an empty blob
lazyConstructorArguments = Empty<CustomAttributeTypedArgument>.Array;
lazyNamedArguments = Empty<CustomAttributeNamedArgument>.Array;
}
else
{
if (br.ReadUInt16() != 1)
{
throw new BadImageFormatException();
}
lazyConstructorArguments = ReadConstructorArguments(asm, br, constructor);
lazyNamedArguments = ReadNamedArguments(asm, br, br.ReadUInt16(), constructor.DeclaringType);
}
}
示例5: 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];
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);
}
示例6: 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;
}
}
示例7: ReadSig
internal static MethodSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
{
CallingConventions callingConvention;
int genericParamCount;
Type returnType;
Type[] parameterTypes;
byte flags = br.ReadByte();
switch (flags & 7)
{
case DEFAULT:
callingConvention = CallingConventions.Standard;
break;
case VARARG:
callingConvention = CallingConventions.VarArgs;
break;
default:
throw new BadImageFormatException();
}
if ((flags & HASTHIS) != 0)
{
callingConvention |= CallingConventions.HasThis;
}
if ((flags & EXPLICITTHIS) != 0)
{
callingConvention |= CallingConventions.ExplicitThis;
}
genericParamCount = 0;
if ((flags & GENERIC) != 0)
{
genericParamCount = br.ReadCompressedInt();
context = new UnboundGenericMethodContext(context);
}
int paramCount = br.ReadCompressedInt();
Type[][][] modifiers = null;
Type[] optionalCustomModifiers;
Type[] requiredCustomModifiers;
ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
returnType = ReadRetType(module, br, context);
parameterTypes = new Type[paramCount];
PackedCustomModifiers.SetModifiers(ref modifiers, 0, 0, optionalCustomModifiers, paramCount + 1);
PackedCustomModifiers.SetModifiers(ref modifiers, 0, 1, requiredCustomModifiers, paramCount + 1);
for (int i = 0; i < parameterTypes.Length; i++)
{
if ((callingConvention & CallingConventions.VarArgs) != 0 && br.PeekByte() == SENTINEL)
{
Array.Resize(ref parameterTypes, i);
if (modifiers != null)
{
Array.Resize(ref modifiers, i + 1);
}
break;
}
ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
PackedCustomModifiers.SetModifiers(ref modifiers, i + 1, 0, optionalCustomModifiers, paramCount + 1);
PackedCustomModifiers.SetModifiers(ref modifiers, i + 1, 1, requiredCustomModifiers, paramCount + 1);
parameterTypes[i] = ReadParam(module, br, context);
}
return new MethodSignature(returnType, parameterTypes, modifiers, callingConvention, genericParamCount);
}
示例8: ReadString
private static string ReadString(ByteReader br)
{
return Encoding.UTF8.GetString(br.ReadBytes(br.ReadCompressedUInt()));
}
示例9: ReadType
Type ReadType(ByteReader br, out string typeName)
{
typeName = br.ReadString();
if (typeName == null)
{
return null;
}
if (typeName.Length > 0 && typeName[typeName.Length - 1] == 0)
{
// there are broken compilers that emit an extra NUL character after the type name
typeName = typeName.Substring(0, typeName.Length - 1);
}
var type = universe.ResolveType(assembly, typeName);
if (type != null && type.Assembly == mscorlib)
{
// we don't want that!
type = universe.ResolveType(assembly, type.FullName + ", mscorlib, Version=0.0.0.0");
}
return type;
}
示例10: ReadNamedArguments
void ReadNamedArguments(StringBuilder sb, ByteReader br, int named, int level, bool securityCompatHack)
{
for (int i = 0; i < named; i++)
{
if (i != 0)
{
AppendNewLine(sb, level);
}
byte fieldOrProperty = br.ReadByte();
switch (fieldOrProperty)
{
case 0x53:
sb.Append("field ");
break;
case 0x54:
sb.Append("property ");
break;
default:
throw new IKVM.Reflection.BadImageFormatException();
}
string typeName;
Type fieldOrPropertyType = ReadFieldOrPropType(sb, br, out typeName);
AppendCATypeName(sb, fieldOrPropertyType, typeName, securityCompatHack);
sb.Append(' ').Append(QuoteIdentifier(br.ReadString(), true)).Append(" = ");
ReadFixedArg(sb, br, fieldOrPropertyType);
}
}
示例11: DecodeCABlob
bool DecodeCABlob(StringBuilder sb, ConstructorInfo constructor, byte[] blob, int level)
{
try
{
// CustomAttribute
var br = new ByteReader(blob, 2, blob.Length - 4);
ReadConstructorArguments(sb, br, constructor, level);
br = new ByteReader(blob, blob.Length - (br.Length + 2), br.Length + 2);
int named = br.ReadUInt16();
if (constructor.GetParameters().Length != 0 && named != 0)
{
AppendNewLine(sb, level);
}
ReadNamedArguments(sb, br, named, level, false);
return true;
}
catch (IKVM.Reflection.BadImageFormatException) { }
catch (ArgumentOutOfRangeException) { }
return false;
}
示例12: ReadArrayBounds
private static int[] ReadArrayBounds(ByteReader br)
{
int num = br.ReadCompressedUInt();
if (num == 0)
{
return null;
}
int[] arr = new int[num];
for (int i = 0; i < num; i++)
{
arr[i] = br.ReadCompressedInt();
}
return arr;
}
示例13: ReadMethodSpec
internal static Type[] ReadMethodSpec(ModuleReader module, ByteReader br, IGenericContext context)
{
if (br.ReadByte() != GENERICINST)
{
throw new BadImageFormatException();
}
Type[] args = new Type[br.ReadCompressedUInt()];
for (int i = 0; i < args.Length; i++)
{
CustomModifiers.Skip(br);
args[i] = ReadType(module, br, context);
}
return args;
}
示例14: ReadFunctionPointer
private static Type ReadFunctionPointer(ModuleReader module, ByteReader br, IGenericContext context)
{
__StandAloneMethodSig sig = MethodSignature.ReadStandAloneMethodSig(module, br, context);
if (module.universe.EnableFunctionPointers)
{
return FunctionPointerType.Make(module.universe, sig);
}
else
{
// by default, like .NET we return System.IntPtr here
return module.universe.System_IntPtr;
}
}
示例15: ReadTypeSpec
internal static Type ReadTypeSpec(ModuleReader module, ByteReader br, IGenericContext context)
{
// LAMESPEC a TypeSpec can contain custom modifiers (C++/CLI generates "newarr (TypeSpec with custom modifiers)")
CustomModifiers.Skip(br);
// LAMESPEC anything can be adorned by (useless) custom modifiers
// also, VAR and MVAR are also used in TypeSpec (contrary to what the spec says)
return ReadType(module, br, context);
}