本文整理汇总了C#中BigEndianBinaryReader.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# BigEndianBinaryReader.Skip方法的具体用法?C# BigEndianBinaryReader.Skip怎么用?C# BigEndianBinaryReader.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigEndianBinaryReader
的用法示例。
在下文中一共展示了BigEndianBinaryReader.Skip方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetClassName
// This method parses just enough of the class file to obtain its name, it doesn't
// validate the class file structure, but it may throw a ClassFormatError if it
// encounters bogus data
internal static string GetClassName(byte[] buf, int offset, int length)
{
BigEndianBinaryReader br = new BigEndianBinaryReader(buf, offset, length);
if(br.ReadUInt32() != 0xCAFEBABE)
{
throw new ClassFormatError("Bad magic number");
}
int minorVersion = br.ReadUInt16();
int majorVersion = br.ReadUInt16();
if((majorVersion & FLAG_MASK_MAJORVERSION) != majorVersion
|| majorVersion < SupportedVersions.Minimum
|| majorVersion > SupportedVersions.Maximum
|| (majorVersion == SupportedVersions.Minimum && minorVersion < 3)
|| (majorVersion == SupportedVersions.Maximum && minorVersion != 0))
{
throw new UnsupportedClassVersionError(majorVersion + "." + minorVersion);
}
int constantpoolcount = br.ReadUInt16();
int[] cpclass = new int[constantpoolcount];
string[] utf8_cp = new string[constantpoolcount];
for(int i = 1; i < constantpoolcount; i++)
{
Constant tag = (Constant)br.ReadByte();
switch(tag)
{
case Constant.Class:
cpclass[i] = br.ReadUInt16();
break;
case Constant.Double:
case Constant.Long:
br.Skip(8);
i++;
break;
case Constant.Fieldref:
case Constant.InterfaceMethodref:
case Constant.Methodref:
case Constant.InvokeDynamic:
case Constant.NameAndType:
case Constant.Float:
case Constant.Integer:
br.Skip(4);
break;
case Constant.MethodHandle:
br.Skip(3);
break;
case Constant.String:
case Constant.MethodType:
br.Skip(2);
break;
case Constant.Utf8:
utf8_cp[i] = br.ReadString("<unknown>");
break;
default:
throw new ClassFormatError("Illegal constant pool type 0x{0:X}", tag);
}
}
br.ReadUInt16(); // access_flags
try
{
return String.Intern(utf8_cp[cpclass[br.ReadUInt16()]].Replace('/', '.'));
}
catch(Exception x)
{
throw new ClassFormatError("{0}: {1}", x.GetType().Name, x.Message);
}
}
示例2: Read
//.........这里部分代码省略.........
{
endIndex = pcIndexMap[end_pc];
}
int handlerIndex = pcIndexMap[handler_pc];
exception_table[i] = new ExceptionTableEntry(startIndex, endIndex, handlerIndex, catch_type, i);
}
ushort attributes_count = br.ReadUInt16();
for(int i = 0; i < attributes_count; i++)
{
switch(classFile.GetConstantPoolUtf8String(utf8_cp, br.ReadUInt16()))
{
case "LineNumberTable":
if((options & ClassFileParseOptions.LineNumberTable) != 0)
{
BigEndianBinaryReader rdr = br.Section(br.ReadUInt32());
int count = rdr.ReadUInt16();
lineNumberTable = new LineNumberTableEntry[count];
for(int j = 0; j < count; j++)
{
lineNumberTable[j].start_pc = rdr.ReadUInt16();
lineNumberTable[j].line_number = rdr.ReadUInt16();
if(lineNumberTable[j].start_pc >= code_length)
{
throw new ClassFormatError("{0} (LineNumberTable has invalid pc)", classFile.Name);
}
}
if(!rdr.IsAtEnd)
{
throw new ClassFormatError("{0} (LineNumberTable attribute has wrong length)", classFile.Name);
}
}
else
{
br.Skip(br.ReadUInt32());
}
break;
case "LocalVariableTable":
if((options & ClassFileParseOptions.LocalVariableTable) != 0)
{
BigEndianBinaryReader rdr = br.Section(br.ReadUInt32());
int count = rdr.ReadUInt16();
localVariableTable = new LocalVariableTableEntry[count];
for(int j = 0; j < count; j++)
{
localVariableTable[j].start_pc = rdr.ReadUInt16();
localVariableTable[j].length = rdr.ReadUInt16();
localVariableTable[j].name = classFile.GetConstantPoolUtf8String(utf8_cp, rdr.ReadUInt16());
localVariableTable[j].descriptor = classFile.GetConstantPoolUtf8String(utf8_cp, rdr.ReadUInt16()).Replace('/', '.');
localVariableTable[j].index = rdr.ReadUInt16();
}
// NOTE we're intentionally not checking that we're at the end of the section
// (optional attributes shouldn't cause ClassFormatError)
}
else
{
br.Skip(br.ReadUInt32());
}
break;
default:
br.Skip(br.ReadUInt32());
break;
}
}
// build the argmap
string sig = method.Signature;
List<int> args = new List<int>();
示例3: Field
//.........这里部分代码省略.........
throw new ClassFormatError("Invalid ConstantValue attribute length");
}
ushort index = br.ReadUInt16();
try
{
switch(Signature)
{
case "I":
constantValue = classFile.GetConstantPoolConstantInteger(index);
break;
case "S":
constantValue = (short)classFile.GetConstantPoolConstantInteger(index);
break;
case "B":
constantValue = (byte)classFile.GetConstantPoolConstantInteger(index);
break;
case "C":
constantValue = (char)classFile.GetConstantPoolConstantInteger(index);
break;
case "Z":
constantValue = classFile.GetConstantPoolConstantInteger(index) != 0;
break;
case "J":
constantValue = classFile.GetConstantPoolConstantLong(index);
break;
case "F":
constantValue = classFile.GetConstantPoolConstantFloat(index);
break;
case "D":
constantValue = classFile.GetConstantPoolConstantDouble(index);
break;
case "Ljava.lang.String;":
constantValue = classFile.GetConstantPoolConstantString(index);
break;
default:
throw new ClassFormatError("{0} (Invalid signature for constant)", classFile.Name);
}
}
catch(InvalidCastException)
{
throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name);
}
catch(IndexOutOfRangeException)
{
throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name);
}
catch(InvalidOperationException)
{
throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name);
}
catch(NullReferenceException)
{
throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name);
}
break;
}
case "Signature":
if(classFile.MajorVersion < 49)
{
goto default;
}
if(br.ReadUInt32() != 2)
{
throw new ClassFormatError("Signature attribute has incorrect length");
}
signature = classFile.GetConstantPoolUtf8String(utf8_cp, br.ReadUInt16());
break;
case "RuntimeVisibleAnnotations":
if(classFile.MajorVersion < 49)
{
goto default;
}
annotations = ReadAnnotations(br, classFile, utf8_cp);
break;
case "RuntimeInvisibleAnnotations":
if(classFile.MajorVersion < 49)
{
goto default;
}
foreach(object[] annot in ReadAnnotations(br, classFile, utf8_cp))
{
if(annot[1].Equals("Likvm/lang/Property;"))
{
DecodePropertyAnnotation(classFile, annot);
}
#if STATIC_COMPILER
else if(annot[1].Equals("Likvm/lang/Internal;"))
{
this.access_flags &= ~Modifiers.AccessMask;
flags |= FLAG_MASK_INTERNAL;
}
#endif
}
break;
default:
br.Skip(br.ReadUInt32());
break;
}
}
}
示例4: Method
//.........这里部分代码省略.........
if(classFile.MajorVersion < 49)
{
goto default;
}
if(low == null)
{
low = new LowFreqData();
}
BigEndianBinaryReader rdr = br.Section(br.ReadUInt32());
low.annotationDefault = ReadAnnotationElementValue(rdr, classFile, utf8_cp);
if(!rdr.IsAtEnd)
{
throw new ClassFormatError("{0} (AnnotationDefault attribute has wrong length)", classFile.Name);
}
break;
}
#if STATIC_COMPILER
case "RuntimeInvisibleAnnotations":
if(classFile.MajorVersion < 49)
{
goto default;
}
foreach(object[] annot in ReadAnnotations(br, classFile, utf8_cp))
{
if(annot[1].Equals("Likvm/lang/Internal;"))
{
if (classFile.IsInterface)
{
StaticCompiler.IssueMessage(Message.InterfaceMethodCantBeInternal, classFile.Name, this.Name, this.Signature);
}
else
{
this.access_flags &= ~Modifiers.AccessMask;
flags |= FLAG_MASK_INTERNAL;
}
}
if(annot[1].Equals("Likvm/internal/HasCallerID;"))
{
flags |= FLAG_HAS_CALLERID;
}
if(annot[1].Equals("Likvm/lang/DllExport;"))
{
string name = null;
int? ordinal = null;
for (int j = 2; j < annot.Length; j += 2)
{
if (annot[j].Equals("name") && annot[j + 1] is string)
{
name = (string)annot[j + 1];
}
else if (annot[j].Equals("ordinal") && annot[j + 1] is int)
{
ordinal = (int)annot[j + 1];
}
}
if (name != null && ordinal != null)
{
if (!IsStatic)
{
StaticCompiler.IssueMessage(Message.DllExportMustBeStaticMethod, classFile.Name, this.Name, this.Signature);
}
else
{
if (low == null)
{
low = new LowFreqData();
}
low.DllExportName = name;
low.DllExportOrdinal = ordinal.Value;
}
}
}
}
break;
#endif
default:
br.Skip(br.ReadUInt32());
break;
}
}
if(IsAbstract || IsNative)
{
if(!code.IsEmpty)
{
throw new ClassFormatError("Abstract or native method cannot have a Code attribute");
}
}
else
{
if(code.IsEmpty)
{
if(ReferenceEquals(this.Name, StringConstants.CLINIT))
{
code.verifyError = string.Format("Class {0}, method {1} signature {2}: No Code attribute", classFile.Name, this.Name, this.Signature);
return;
}
throw new ClassFormatError("Method has no Code attribute");
}
}
}
示例5: ClassFile
//.........这里部分代码省略.........
{
int class_index = br.ReadUInt16();
int method_index = br.ReadUInt16();
if(method_index == 0)
{
enclosingMethod = new string[] {
GetConstantPoolClass(class_index),
null,
null
};
}
else
{
ConstantPoolItemNameAndType m = (ConstantPoolItemNameAndType)GetConstantPoolItem(method_index);
enclosingMethod = new string[] {
GetConstantPoolClass(class_index),
GetConstantPoolUtf8String(utf8_cp, m.name_index),
GetConstantPoolUtf8String(utf8_cp, m.descriptor_index).Replace('/', '.')
};
}
}
break;
case "RuntimeVisibleAnnotations":
if(majorVersion < 49)
{
goto default;
}
annotations = ReadAnnotations(br, this, utf8_cp);
break;
#if STATIC_COMPILER
case "RuntimeInvisibleAnnotations":
if(majorVersion < 49)
{
goto default;
}
foreach(object[] annot in ReadAnnotations(br, this, utf8_cp))
{
if(annot[1].Equals("Likvm/lang/Internal;"))
{
this.access_flags &= ~Modifiers.AccessMask;
flags |= FLAG_MASK_INTERNAL;
}
}
break;
#endif
case "BootstrapMethods":
if(majorVersion < 51)
{
goto default;
}
bootstrapMethods = ReadBootstrapMethods(br, this);
break;
case "IKVM.NET.Assembly":
if(br.ReadUInt32() != 2)
{
throw new ClassFormatError("IKVM.NET.Assembly attribute has incorrect length");
}
ikvmAssembly = GetConstantPoolUtf8String(utf8_cp, br.ReadUInt16());
break;
default:
br.Skip(br.ReadUInt32());
break;
}
}
// validate the invokedynamic entries to point into the bootstrapMethods array
for(int i = 1; i < constantpoolcount; i++)
{
ConstantPoolItemInvokeDynamic cpi;
if(constantpool[i] != null
&& (cpi = constantpool[i] as ConstantPoolItemInvokeDynamic) != null)
{
if(bootstrapMethods == null || cpi.BootstrapMethod >= bootstrapMethods.Length)
{
throw new ClassFormatError("Short length on BootstrapMethods in class file");
}
}
}
if(br.Position != offset + length)
{
throw new ClassFormatError("Extra bytes at the end of the class file");
}
}
catch(OverflowException)
{
throw new ClassFormatError("Truncated class file (or section)");
}
catch(IndexOutOfRangeException)
{
// TODO we should throw more specific errors
throw new ClassFormatError("Unspecified class file format error");
}
// catch(Exception x)
// {
// Console.WriteLine(x);
// FileStream fs = File.Create(inputClassName + ".broken");
// fs.Write(buf, offset, length);
// fs.Close();
// throw;
// }
}
示例6: ClassFile
//.........这里部分代码省略.........
int methods_count = br.ReadUInt16();
methods = new Method[methods_count];
Hashtable methodNameSigs = new Hashtable();
for (int i = 0; i < methods_count; i++)
{
methods[i] = new Method(this, br);
string name = methods[i].Name;
string sig = methods[i].Signature;
if (!IsValidIdentifier(name) && name != "<init>" && name != "<clinit>")
{
throw new ClassFormatError("{0} (Illegal method name \"{1}\")", Name, name);
}
if ((name == "<init>" || name == "<clinit>") && !sig.EndsWith("V"))
{
throw new ClassFormatError("{0} (Method \"{1}\" has illegal signature \"{2}\")", Name, name, sig);
}
try
{
methodNameSigs.Add(name + sig, null);
}
catch (ArgumentException)
{
throw new ClassFormatError("{0} (Repetitive method name/signature)", Name);
}
}
int attributes_count = br.ReadUInt16();
for (int i = 0; i < attributes_count; i++)
{
switch (GetConstantPoolUtf8String(br.ReadUInt16()))
{
case "Deprecated":
deprecated = true;
#if FUZZ_HACK
br.Skip(br.ReadUInt32());
#else
if(br.ReadUInt32() != 0)
{
throw new ClassFormatError("Deprecated attribute has non-zero length");
}
#endif
break;
case "SourceFile":
if (br.ReadUInt32() != 2)
{
throw new ClassFormatError("SourceFile attribute has incorrect length");
}
sourceFile = GetConstantPoolUtf8String(br.ReadUInt16());
break;
case "InnerClasses":
#if FUZZ_HACK
// Sun totally ignores the length of InnerClasses attribute,
// so when we're running Fuzz this shows up as lots of differences.
// To get rid off these differences define the FUZZ_HACK symbol.
BigEndianBinaryReader rdr = br;
br.ReadUInt32();
#else
BigEndianBinaryReader rdr = br.Section(br.ReadUInt32());
#endif
ushort count = rdr.ReadUInt16();
innerClasses = new InnerClass[count];
for (int j = 0; j < innerClasses.Length; j++)
{
innerClasses[j].innerClass = rdr.ReadUInt16();
innerClasses[j].outerClass = rdr.ReadUInt16();
innerClasses[j].name = rdr.ReadUInt16();
innerClasses[j].accessFlags = (__Modifiers) rdr.ReadUInt16();
示例7: Read
internal void Read(ClassFile classFile, Method method, BigEndianBinaryReader br)
{
max_stack = br.ReadUInt16();
max_locals = br.ReadUInt16();
uint code_length = br.ReadUInt32();
if (code_length > 65536)
{
throw new ClassFormatError("{0} (Invalid Code length {1})", classFile.Name, code_length);
}
Instruction[] instructions = new Instruction[code_length + 1];
int basePosition = br.Position;
int instructionIndex = 0;
try
{
BigEndianBinaryReader rdr = br.Section(code_length);
while (!rdr.IsAtEnd)
{
instructions[instructionIndex++].Read((ushort) (rdr.Position - basePosition), rdr);
}
// we add an additional nop instruction to make it easier for consumers of the code array
instructions[instructionIndex++].SetTermNop((ushort) (rdr.Position - basePosition));
}
catch (ClassFormatError x)
{
// any class format errors in the code block are actually verify errors
verifyError = x.Message;
}
this.instructions = new Instruction[instructionIndex];
Array.Copy(instructions, 0, this.instructions, 0, instructionIndex);
ushort exception_table_length = br.ReadUInt16();
exception_table = new ExceptionTableEntry[exception_table_length];
for (int i = 0; i < exception_table_length; i++)
{
exception_table[i] = new ExceptionTableEntry();
exception_table[i].start_pc = br.ReadUInt16();
exception_table[i].end_pc = br.ReadUInt16();
exception_table[i].handler_pc = br.ReadUInt16();
exception_table[i].catch_type = br.ReadUInt16();
exception_table[i].ordinal = i;
}
ushort attributes_count = br.ReadUInt16();
for (int i = 0; i < attributes_count; i++)
{
switch (classFile.GetConstantPoolUtf8String(br.ReadUInt16()))
{
case "LineNumberTable":
br.Skip(br.ReadUInt32());
break;
case "LocalVariableTable":
br.Skip(br.ReadUInt32());
break;
default:
br.Skip(br.ReadUInt32());
break;
}
}
// build the pcIndexMap
pcIndexMap = new int[this.instructions[instructionIndex - 1].PC + 1];
for (int i = 0; i < pcIndexMap.Length; i++)
{
pcIndexMap[i] = -1;
}
for (int i = 0; i < instructionIndex - 1; i++)
{
pcIndexMap[this.instructions[i].PC] = i;
}
// build the argmap
string sig = method.Signature;
ArrayList args = new ArrayList();
int pos = 0;
if (!method.IsStatic)
{
args.Add(pos++);
}
for (int i = 1; sig[i] != ')'; i++)
{
args.Add(pos++);
switch (sig[i])
{
case 'L':
i = sig.IndexOf(';', i);
break;
case 'D':
case 'J':
args.Add(-1);
break;
case '[':
{
while (sig[i] == '[')
{
i++;
}
if (sig[i] == 'L')
{
i = sig.IndexOf(';', i);
}
break;
}
}
}
//.........这里部分代码省略.........
示例8: Method
internal Method(ClassFile classFile, BigEndianBinaryReader br) : base(classFile, br)
{
// vmspec 4.6 says that all flags, except ACC_STRICT are ignored on <clinit>
if (Name == "<clinit>" && Signature == "()V")
{
access_flags &= __Modifiers.Strictfp;
access_flags |= (__Modifiers.Static | __Modifiers.Private);
}
else
{
// LAMESPEC: vmspec 4.6 says that abstract methods can not be strictfp (and this makes sense), but
// javac (pre 1.5) is broken and marks abstract methods as strictfp (if you put the strictfp on the class)
if ((Name == "<init>" && (IsStatic || IsSynchronized || IsFinal || IsAbstract || IsNative))
|| (IsPrivate && IsPublic) || (IsPrivate && IsProtected) || (IsPublic && IsProtected)
|| (IsAbstract && (IsFinal || IsNative || IsPrivate || IsStatic || IsSynchronized))
|| (classFile.IsInterface && (!IsPublic || !IsAbstract)))
{
throw new ClassFormatError("{0} (Illegal method modifiers: 0x{1:X})", classFile.Name, access_flags);
}
}
int attributes_count = br.ReadUInt16();
for (int i = 0; i < attributes_count; i++)
{
switch (classFile.GetConstantPoolUtf8String(br.ReadUInt16()))
{
case "Deprecated":
deprecated = true;
#if FUZZ_HACK
br.Skip(br.ReadUInt32());
#else
if(br.ReadUInt32() != 0)
{
throw new ClassFormatError("{0} (Deprecated attribute has non-zero length)", classFile.Name);
}
#endif
break;
case "Code":
{
if (!code.IsEmpty)
{
throw new ClassFormatError("{0} (Duplicate Code attribute)", classFile.Name);
}
BigEndianBinaryReader rdr = br.Section(br.ReadUInt32());
code.Read(classFile, this, rdr);
if (!rdr.IsAtEnd)
{
throw new ClassFormatError("{0} (Code attribute has wrong length)", classFile.Name);
}
break;
}
case "Exceptions":
{
if (exceptions != null)
{
throw new ClassFormatError("{0} (Duplicate Exceptions attribute)", classFile.Name);
}
BigEndianBinaryReader rdr = br.Section(br.ReadUInt32());
ushort count = rdr.ReadUInt16();
exceptions = new string[count];
for (int j = 0; j < count; j++)
{
exceptions[j] = classFile.GetConstantPoolClass(rdr.ReadUInt16());
}
if (!rdr.IsAtEnd)
{
throw new ClassFormatError("{0} (Exceptions attribute has wrong length)", classFile.Name);
}
break;
}
default:
br.Skip(br.ReadUInt32());
break;
}
}
if (IsAbstract || IsNative)
{
if (!code.IsEmpty)
{
throw new ClassFormatError("Abstract or native method cannot have a Code attribute");
}
}
else
{
if (code.IsEmpty)
{
#if FUZZ_HACK
if (this.Name == "<clinit>")
{
code.verifyError = string.Format("Class {0}, method {1} signature {2}: No Code attribute", classFile.Name, this.Name, this.Signature);
return;
}
#endif
throw new ClassFormatError("Method has no Code attribute");
}
}
}
示例9: Field
internal Field(ClassFile classFile, BigEndianBinaryReader br) : base(classFile, br)
{
if ((IsPrivate && IsPublic) || (IsPrivate && IsProtected) || (IsPublic && IsProtected)
|| (IsFinal && IsVolatile)
|| (classFile.IsInterface && (!IsPublic || !IsStatic || !IsFinal || IsTransient)))
{
throw new ClassFormatError("{0} (Illegal field modifiers: 0x{1:X})", classFile.Name, access_flags);
}
int attributes_count = br.ReadUInt16();
for (int i = 0; i < attributes_count; i++)
{
switch (classFile.GetConstantPoolUtf8String(br.ReadUInt16()))
{
case "Deprecated":
deprecated = true;
#if FUZZ_HACK
br.Skip(br.ReadUInt32());
#else
if(br.ReadUInt32() != 0)
{
throw new ClassFormatError("Deprecated attribute has non-zero length");
}
#endif
break;
case "ConstantValue":
{
if (br.ReadUInt32() != 2)
{
throw new ClassFormatError("Invalid ConstantValue attribute length");
}
ushort index = br.ReadUInt16();
try
{
switch (Signature)
{
case "I":
constantValue = classFile.GetConstantPoolConstantInteger(index);
break;
case "S":
constantValue = (short) classFile.GetConstantPoolConstantInteger(index);
break;
case "B":
constantValue = (byte) classFile.GetConstantPoolConstantInteger(index);
break;
case "C":
constantValue = (char) classFile.GetConstantPoolConstantInteger(index);
break;
case "Z":
constantValue = classFile.GetConstantPoolConstantInteger(index) != 0;
break;
case "J":
constantValue = classFile.GetConstantPoolConstantLong(index);
break;
case "F":
constantValue = classFile.GetConstantPoolConstantFloat(index);
break;
case "D":
constantValue = classFile.GetConstantPoolConstantDouble(index);
break;
case "Ljava.lang.String;":
constantValue = classFile.GetConstantPoolConstantString(index);
break;
default:
throw new ClassFormatError("{0} (Invalid signature for constant)", classFile.Name);
}
}
catch (InvalidCastException)
{
throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name);
}
catch (IndexOutOfRangeException)
{
throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name);
}
catch (InvalidOperationException)
{
throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name);
}
catch (NullReferenceException)
{
throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name);
}
break;
}
default:
br.Skip(br.ReadUInt32());
break;
}
}
}