本文整理匯總了C#中BigEndianBinaryReader.ReadByte方法的典型用法代碼示例。如果您正苦於以下問題:C# BigEndianBinaryReader.ReadByte方法的具體用法?C# BigEndianBinaryReader.ReadByte怎麽用?C# BigEndianBinaryReader.ReadByte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BigEndianBinaryReader
的用法示例。
在下文中一共展示了BigEndianBinaryReader.ReadByte方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: read
internal void read(BigEndianBinaryReader reader)
{
width = reader.ReadInt32();
height = reader.ReadInt32();
bitdepth = reader.ReadByte();
colortype = (ColorType)reader.ReadByte();
method = reader.ReadByte();
filter = reader.ReadByte();
interlace = reader.ReadByte();
}
示例2: 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);
}
}
示例3: ReadAnnotationElementValue
private static object ReadAnnotationElementValue(BigEndianBinaryReader rdr, ClassFile classFile, string[] utf8_cp)
{
try
{
byte tag = rdr.ReadByte();
switch (tag)
{
case (byte)'Z':
return classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()) != 0;
case (byte)'B':
return (byte)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16());
case (byte)'C':
return (char)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16());
case (byte)'S':
return (short)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16());
case (byte)'I':
return classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16());
case (byte)'F':
return classFile.GetConstantPoolConstantFloat(rdr.ReadUInt16());
case (byte)'J':
return classFile.GetConstantPoolConstantLong(rdr.ReadUInt16());
case (byte)'D':
return classFile.GetConstantPoolConstantDouble(rdr.ReadUInt16());
case (byte)'s':
return classFile.GetConstantPoolUtf8String(utf8_cp, rdr.ReadUInt16());
case (byte)'e':
{
ushort type_name_index = rdr.ReadUInt16();
ushort const_name_index = rdr.ReadUInt16();
return new object[] {
AnnotationDefaultAttribute.TAG_ENUM,
classFile.GetConstantPoolUtf8String(utf8_cp, type_name_index),
classFile.GetConstantPoolUtf8String(utf8_cp, const_name_index)
};
}
case (byte)'c':
return new object[] {
AnnotationDefaultAttribute.TAG_CLASS,
classFile.GetConstantPoolUtf8String(utf8_cp, rdr.ReadUInt16())
};
case (byte)'@':
return ReadAnnotation(rdr, classFile, utf8_cp);
case (byte)'[':
{
ushort num_values = rdr.ReadUInt16();
object[] array = new object[num_values + 1];
array[0] = AnnotationDefaultAttribute.TAG_ARRAY;
for (int i = 0; i < num_values; i++)
{
array[i + 1] = ReadAnnotationElementValue(rdr, classFile, utf8_cp);
}
return array;
}
default:
throw new ClassFormatError("Invalid tag {0} in annotation element_value", tag);
}
}
catch (NullReferenceException)
{
}
catch (InvalidCastException)
{
}
catch (IndexOutOfRangeException)
{
}
return new object[] { AnnotationDefaultAttribute.TAG_ERROR, "java.lang.IllegalArgumentException", "Wrong type at constant pool index" };
}
示例4: Read
internal void Read(ushort pc, BigEndianBinaryReader br, ClassFile classFile)
{
this.pc = pc;
ByteCode bc = (ByteCode)br.ReadByte();
switch(ByteCodeMetaData.GetMode(bc))
{
case ByteCodeMode.Simple:
break;
case ByteCodeMode.Constant_1:
arg1 = br.ReadByte();
classFile.MarkLinkRequiredConstantPoolItem(arg1);
break;
case ByteCodeMode.Local_1:
arg1 = br.ReadByte();
break;
case ByteCodeMode.Constant_2:
arg1 = br.ReadUInt16();
classFile.MarkLinkRequiredConstantPoolItem(arg1);
break;
case ByteCodeMode.Branch_2:
arg1 = br.ReadInt16();
break;
case ByteCodeMode.Branch_4:
arg1 = br.ReadInt32();
break;
case ByteCodeMode.Constant_2_1_1:
arg1 = br.ReadUInt16();
classFile.MarkLinkRequiredConstantPoolItem(arg1);
arg2 = br.ReadByte();
if(br.ReadByte() != 0)
{
throw new ClassFormatError("invokeinterface filler must be zero");
}
break;
case ByteCodeMode.Immediate_1:
arg1 = br.ReadSByte();
break;
case ByteCodeMode.Immediate_2:
arg1 = br.ReadInt16();
break;
case ByteCodeMode.Local_1_Immediate_1:
arg1 = br.ReadByte();
arg2 = br.ReadSByte();
break;
case ByteCodeMode.Constant_2_Immediate_1:
arg1 = br.ReadUInt16();
classFile.MarkLinkRequiredConstantPoolItem(arg1);
arg2 = br.ReadSByte();
break;
case ByteCodeMode.Tableswitch:
{
// skip the padding
uint p = pc + 1u;
uint align = ((p + 3) & 0x7ffffffc) - p;
br.Skip(align);
int default_offset = br.ReadInt32();
this.arg1 = default_offset;
int low = br.ReadInt32();
int high = br.ReadInt32();
if(low > high || high > 16384L + low)
{
throw new ClassFormatError("Incorrect tableswitch");
}
SwitchEntry[] entries = new SwitchEntry[high - low + 1];
for(int i = low; i < high; i++)
{
entries[i - low].value = i;
entries[i - low].target = br.ReadInt32();
}
// do the last entry outside the loop, to avoid overflowing "i", if high == int.MaxValue
entries[high - low].value = high;
entries[high - low].target = br.ReadInt32();
this.switch_entries = entries;
break;
}
case ByteCodeMode.Lookupswitch:
{
// skip the padding
uint p = pc + 1u;
uint align = ((p + 3) & 0x7ffffffc) - p;
br.Skip(align);
int default_offset = br.ReadInt32();
this.arg1 = default_offset;
int count = br.ReadInt32();
if(count < 0 || count > 16384)
{
throw new ClassFormatError("Incorrect lookupswitch");
}
SwitchEntry[] entries = new SwitchEntry[count];
for(int i = 0; i < count; i++)
{
entries[i].value = br.ReadInt32();
entries[i].target = br.ReadInt32();
}
this.switch_entries = entries;
break;
}
case ByteCodeMode.WidePrefix:
bc = (ByteCode)br.ReadByte();
// NOTE the PC of a wide instruction is actually the PC of the
//.........這裏部分代碼省略.........
示例5: ConstantPoolItemMethodHandle
internal ConstantPoolItemMethodHandle(BigEndianBinaryReader br)
{
ref_kind = br.ReadByte();
method_index = br.ReadUInt16();
}
示例6: ClassFile
internal ClassFile(byte[] buf, int offset, int length, string inputClassName, ClassFileParseOptions options)
{
try
{
BigEndianBinaryReader br = new BigEndianBinaryReader(buf, offset, length);
if(br.ReadUInt32() != 0xCAFEBABE)
{
throw new ClassFormatError("{0} (Bad magic number)", inputClassName);
}
ushort minorVersion = br.ReadUInt16();
ushort 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(inputClassName + " (" + majorVersion + "." + minorVersion + ")");
}
flags = majorVersion;
int constantpoolcount = br.ReadUInt16();
constantpool = new ConstantPoolItem[constantpoolcount];
string[] utf8_cp = new string[constantpoolcount];
for(int i = 1; i < constantpoolcount; i++)
{
Constant tag = (Constant)br.ReadByte();
switch(tag)
{
case Constant.Class:
constantpool[i] = new ConstantPoolItemClass(br);
break;
case Constant.Double:
constantpool[i] = new ConstantPoolItemDouble(br);
i++;
break;
case Constant.Fieldref:
constantpool[i] = new ConstantPoolItemFieldref(br);
break;
case Constant.Float:
constantpool[i] = new ConstantPoolItemFloat(br);
break;
case Constant.Integer:
constantpool[i] = new ConstantPoolItemInteger(br);
break;
case Constant.InterfaceMethodref:
constantpool[i] = new ConstantPoolItemInterfaceMethodref(br);
break;
case Constant.Long:
constantpool[i] = new ConstantPoolItemLong(br);
i++;
break;
case Constant.Methodref:
constantpool[i] = new ConstantPoolItemMethodref(br);
break;
case Constant.NameAndType:
constantpool[i] = new ConstantPoolItemNameAndType(br);
break;
case Constant.MethodHandle:
if (majorVersion < 51)
goto default;
constantpool[i] = new ConstantPoolItemMethodHandle(br);
break;
case Constant.MethodType:
if (majorVersion < 51)
goto default;
constantpool[i] = new ConstantPoolItemMethodType(br);
break;
case Constant.InvokeDynamic:
if (majorVersion < 51)
goto default;
constantpool[i] = new ConstantPoolItemInvokeDynamic(br);
break;
case Constant.String:
constantpool[i] = new ConstantPoolItemString(br);
break;
case Constant.Utf8:
utf8_cp[i] = br.ReadString(inputClassName);
break;
default:
throw new ClassFormatError("{0} (Illegal constant pool type 0x{1:X})", inputClassName, tag);
}
}
for(int i = 1; i < constantpoolcount; i++)
{
if(constantpool[i] != null)
{
try
{
constantpool[i].Resolve(this, utf8_cp, options);
}
catch(ClassFormatError x)
{
// HACK at this point we don't yet have the class name, so any exceptions throw
// are missing the class name
throw new ClassFormatError("{0} ({1})", inputClassName, x.Message);
}
catch(IndexOutOfRangeException)
{
throw new ClassFormatError("{0} (Invalid constant pool item #{1})", inputClassName, i);
}
//.........這裏部分代碼省略.........
示例7: DecodeMessage
/// <summary>
/// Decode messages from a payload and assign it a given kafka offset.
/// </summary>
/// <param name="offset">The offset represting the log entry from kafka of this message.</param>
/// <param name="payload">The byte[] encode as a message from kafka.</param>
/// <returns>Enumerable representing stream of messages decoded from byte[].</returns>
/// <remarks>The return type is an Enumerable as the message could be a compressed message set.</remarks>
public static IEnumerable<Message> DecodeMessage(long offset, byte[] payload)
{
var crc = payload.Take(4).ToArray();
using (var stream = new BigEndianBinaryReader(payload.Skip(4)))
{
if (crc.SequenceEqual(stream.CrcHash()) == false)
throw new FailCrcCheckException("Buffer did not match CRC validation.");
var message = new Message
{
Meta = new MessageMetadata { Offset = offset },
MagicNumber = stream.ReadByte(),
Attribute = stream.ReadByte(),
Key = stream.ReadIntPrefixedBytes()
};
var codec = (MessageCodec)(ProtocolConstants.AttributeCodeMask & message.Attribute);
switch (codec)
{
case MessageCodec.CodecNone:
message.Value = stream.ReadIntPrefixedBytes();
yield return message;
break;
case MessageCodec.CodecGzip:
var gZipData = stream.ReadIntPrefixedBytes();
foreach (var m in DecodeMessageSet(Compression.Unzip(gZipData)))
{
yield return m;
}
break;
default:
throw new NotSupportedException(string.Format("Codec type of {0} is not supported.", codec));
}
}
}
示例8: ClassFile
internal ClassFile(byte[] buf, int offset, int length, string inputClassName, bool allowJavaLangObject)
{
try
{
BigEndianBinaryReader br = new BigEndianBinaryReader(buf, offset, length);
if (br.ReadUInt32() != 0xCAFEBABE)
{
throw new ClassFormatError("{0} (Bad magic number)", inputClassName);
}
int minorVersion = br.ReadUInt16();
majorVersion = br.ReadUInt16();
if (majorVersion < SupportedVersions.Minimum || majorVersion > SupportedVersions.Maximum)
{
throw new UnsupportedClassVersionError(inputClassName + " (" + majorVersion + "." + minorVersion + ")");
}
int constantpoolcount = br.ReadUInt16();
constantpool = new ConstantPoolItem[constantpoolcount];
utf8_cp = new string[constantpoolcount];
for (int i = 1; i < constantpoolcount; i++)
{
Constant tag = (Constant) br.ReadByte();
switch (tag)
{
case Constant.Class:
constantpool[i] = new ConstantPoolItemClass(br);
break;
case Constant.Double:
constantpool[i] = new ConstantPoolItemDouble(br);
i++;
break;
case Constant.Fieldref:
constantpool[i] = new ConstantPoolItemFieldref(br);
break;
case Constant.Float:
constantpool[i] = new ConstantPoolItemFloat(br);
break;
case Constant.Integer:
constantpool[i] = new ConstantPoolItemInteger(br);
break;
case Constant.InterfaceMethodref:
constantpool[i] = new ConstantPoolItemInterfaceMethodref(br);
break;
case Constant.Long:
constantpool[i] = new ConstantPoolItemLong(br);
i++;
break;
case Constant.Methodref:
constantpool[i] = new ConstantPoolItemMethodref(br);
break;
case Constant.NameAndType:
constantpool[i] = new ConstantPoolItemNameAndType(br);
break;
case Constant.String:
constantpool[i] = new ConstantPoolItemString(br);
break;
case Constant.Utf8:
utf8_cp[i] = br.ReadString(inputClassName);
break;
default:
throw new ClassFormatError("{0} (Illegal constant pool type 0x{1:X})", inputClassName, tag);
}
}
for (int i = 1; i < constantpoolcount; i++)
{
if (constantpool[i] != null)
{
try
{
constantpool[i].Resolve(this);
}
catch (ClassFormatError x)
{
// HACK at this point we don't yet have the class name, so any exceptions throw
// are missing the class name
throw new ClassFormatError("{0} ({1})", inputClassName, x.Message);
}
catch (IndexOutOfRangeException)
{
throw new ClassFormatError("{0} (Invalid constant pool item #{1})", inputClassName, i);
}
catch (InvalidCastException)
{
throw new ClassFormatError("{0} (Invalid constant pool item #{1})", inputClassName, i);
}
}
}
access_flags = (__Modifiers) br.ReadUInt16();
// NOTE although the vmspec says (in 4.1) that interfaces must be marked abstract, earlier versions of
// javac (JDK 1.1) didn't do this, so the VM doesn't enforce this rule
// NOTE although the vmspec implies (in 4.1) that ACC_SUPER is illegal on interfaces, it doesn't enforce this
if ((IsInterface && IsFinal) || (IsAbstract && IsFinal))
{
throw new ClassFormatError("{0} (Illegal class modifiers 0x{1:X})", inputClassName, access_flags);
}
this_class = br.ReadUInt16();
ValidateConstantPoolItemClass(inputClassName, this_class);
super_class = br.ReadUInt16();
// NOTE for convenience we allow parsing java/lang/Object (which has no super class), so
// we check for super_class != 0
if (super_class != 0)
//.........這裏部分代碼省略.........
示例9: ReadConstantPool
ConstantPool[] ReadConstantPool(BigEndianBinaryReader reader)
{
ushort constantPoolCount = reader.ReadUInt16();
ConstantPool[] constantPool = new ConstantPool[constantPoolCount];
//Console.WriteLine("Reading {0} ConstantPool items", constantPoolCount);
// JVM Spec 4.1.
// The value of the constant_pool_count item is equal to the number
// of entries in the constant_pool table plus one. A constant_pool
// index is considered valid if it is greater than zero and less
// than constant_pool_count, with the exception for constants of
// type long and double noted in 4.4.5.
for (ushort i = 1; i < constantPoolCount; i++) {
ConstantType tag = (ConstantType) reader.ReadByte();
ConstantPool item = new ConstantPool();
constantPool[i] = item;
switch (tag) {
case ConstantType.Class:
/*
CONSTANT_Class_info {
u1 tag;
u2 name_index;
}
*/
item.ConstantType = ConstantType.Class;
item.NameIndex = reader.ReadUInt16();
break;
case ConstantType.Fieldref:
/*
CONSTANT_Fieldref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
*/
item.ConstantType = ConstantType.Fieldref;
item.ClassIndex = reader.ReadUInt16();
item.NameAndTypeIndex = reader.ReadUInt16();
break;
case ConstantType.Methodref:
/*
CONSTANT_Methodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
*/
item.ConstantType = ConstantType.Methodref;
item.ClassIndex = reader.ReadUInt16();
item.NameAndTypeIndex = reader.ReadUInt16();
break;
case ConstantType.InterfaceMethodref:
/*
CONSTANT_InterfaceMethodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
*/
item.ConstantType = ConstantType.InterfaceMethodref;
item.ClassIndex = reader.ReadUInt16();
item.NameAndTypeIndex = reader.ReadUInt16();
break;
case ConstantType.String:
/*
CONSTANT_String_info {
u1 tag;
u2 string_index;
}
*/
item.ConstantType = ConstantType.String;
item.StringIndex = reader.ReadUInt16();
break;
case ConstantType.Integer:
/*
CONSTANT_Integer_info {
u1 tag;
u4 bytes;
}
*/
item.ConstantType = ConstantType.Integer;
item.Integer = reader.ReadInt32();
break;
case ConstantType.Float:
/*
CONSTANT_Float_info {
u1 tag;
u4 bytes;
}
*/
item.ConstantType = ConstantType.Float;
item.Float = reader.ReadSingle();
break;
case ConstantType.Long:
/*
CONSTANT_Long_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}
*/
//.........這裏部分代碼省略.........
示例10: ReadAnnotationElementValue
private static object ReadAnnotationElementValue(BigEndianBinaryReader rdr, ClassFile classFile)
{
byte tag = rdr.ReadByte();
switch(tag)
{
case (byte)'Z':
return classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()) != 0;
case (byte)'B':
return (byte)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16());
case (byte)'C':
return (char)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16());
case (byte)'S':
return (short)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16());
case (byte)'I':
return classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16());
case (byte)'F':
return classFile.GetConstantPoolConstantFloat(rdr.ReadUInt16());
case (byte)'J':
return classFile.GetConstantPoolConstantLong(rdr.ReadUInt16());
case (byte)'D':
return classFile.GetConstantPoolConstantDouble(rdr.ReadUInt16());
case (byte)'s':
return classFile.GetConstantPoolUtf8String(rdr.ReadUInt16());
case (byte)'e':
{
ushort type_name_index = rdr.ReadUInt16();
ushort const_name_index = rdr.ReadUInt16();
return new object[] {
AnnotationDefaultAttribute.TAG_ENUM,
classFile.GetConstantPoolUtf8String(type_name_index),
classFile.GetConstantPoolUtf8String(const_name_index)
};
}
case (byte)'c':
return new object[] {
AnnotationDefaultAttribute.TAG_CLASS,
classFile.GetConstantPoolUtf8String(rdr.ReadUInt16())
};
case (byte)'@':
return ReadAnnotation(rdr, classFile);
case (byte)'[':
{
ushort num_values = rdr.ReadUInt16();
object[] array = new object[num_values + 1];
array[0] = AnnotationDefaultAttribute.TAG_ARRAY;
for(int i = 0; i < num_values; i++)
{
array[i + 1] = ReadAnnotationElementValue(rdr, classFile);
}
return array;
}
default:
throw new ClassFormatError("Invalid tag {0} in annotation element_value", tag);
}
}