/// <summary> /// Search for default.xex /// </summary> /// <returns>true if found; false if not found</returns> private bool SearchForDefaultXeX() { try { this.iso.Reader.BaseStream.Seek((long)(((long)this.iso.IsoInfo.RootDirSector * (long)this.iso.IsoInfo.SectorSize) + (long)this.iso.IsoInfo.RootOffset), System.IO.SeekOrigin.Begin); byte[] rootDirBuffer = this.iso.Reader.ReadBytes((int)this.iso.IsoInfo.RootDirSize); MemoryStream ms = new MemoryStream(rootDirBuffer); MyBinaryReader reader = new MyBinaryReader(ms); while (reader.BaseStream.Position < this.iso.IsoInfo.RootDirSize) { ushort offsetLeftSubTreeTmp = reader.ReadUInt16(); ushort offsetRightSubTreeTmp = reader.ReadUInt16(); if (offsetLeftSubTreeTmp != 0xffff && offsetRightSubTreeTmp != 0xffff) { uint startingSectorOfFileTmp = reader.ReadUInt32(); uint fileSizeTmp = reader.ReadUInt32(); uint fileAttribute = (uint)reader.ReadByte(); byte fileNameLengthTmp = reader.ReadByte(); string fileNameTmp = Encoding.ASCII.GetString(rootDirBuffer, (int)reader.BaseStream.Position, fileNameLengthTmp); reader.BaseStream.Seek((long)fileNameLengthTmp, SeekOrigin.Current); long num1 = reader.BaseStream.Position % 4L; if ((reader.BaseStream.Position % 4L) != 0L) { reader.BaseStream.Seek(4L - (reader.BaseStream.Position % 4L), SeekOrigin.Current); } if (fileNameTmp.ToLower() == this.fileName.ToLower()) { this.offsetLeftSubTree = offsetLeftSubTreeTmp; this.offsetRightSubTree = offsetRightSubTreeTmp; this.startingSectorOfFile = startingSectorOfFileTmp; this.fileSize = fileSizeTmp; this.fileNameLength = fileNameLengthTmp; //this.iso.Reader.Read(this.file, (int)(this.iso.IsoInfo.RootOffset + (this.startingSectorOfFile * this.iso.IsoInfo.SectorSize)), (int)this.fileSize); this.iso.Reader.BaseStream.Seek((long)((long)this.iso.IsoInfo.RootOffset + ((long)this.startingSectorOfFile * (long)this.iso.IsoInfo.SectorSize)), SeekOrigin.Begin); this.file = this.iso.Reader.ReadBytes((int)this.fileSize); return(true); } } } } catch (Exception ex) { throw new Exception("Error browsing ISO for default.xex", ex); } return(false); }
private long SearchForDefaultXeX() { try { this.iso.Reader.BaseStream.Seek((long)((long)((long)this.iso.IsoInfo.RootDirSector * (long)this.iso.IsoInfo.SectorSize) + (long)this.iso.IsoInfo.RootOffset), SeekOrigin.Begin); byte[] buffer = this.iso.Reader.ReadBytes((int)this.iso.IsoInfo.RootDirSize); MemoryStream s = new MemoryStream(buffer); MyBinaryReader reader = new MyBinaryReader(s); while (reader.BaseStream.Position < this.iso.IsoInfo.RootDirSize) { ushort num = reader.ReadUInt16(); ushort num2 = reader.ReadUInt16(); if ((num != 0xffff) && (num2 != 0xffff)) { uint num3 = reader.ReadUInt32(); uint num4 = reader.ReadUInt32(); uint num5 = reader.ReadByte(); byte count = reader.ReadByte(); string str = Encoding.ASCII.GetString(buffer, (int)reader.BaseStream.Position, count); reader.BaseStream.Seek((long)count, SeekOrigin.Current); long num7 = reader.BaseStream.Position % 4L; if ((reader.BaseStream.Position % 4L) != 0L) { reader.BaseStream.Seek(4L - (reader.BaseStream.Position % 4L), SeekOrigin.Current); } if ((str.ToLower() == this.fileName.ToLower()) || (str.ToLower() == this.fileName2.ToLower())) { this.offsetLeftSubTree = num; this.offsetRightSubTree = num2; this.startingSectorOfFile = num3; this.fileSize = num4; this.fileNameLength = count; this.iso.Reader.BaseStream.Seek(((long)this.iso.IsoInfo.RootOffset + (long)((long)this.startingSectorOfFile * (long)this.iso.IsoInfo.SectorSize)), SeekOrigin.Begin); return(iso.Reader.BaseStream.Position); } } } } catch (Exception exception) { throw new Exception("Error browsing ISO for default.xex/xeb", exception); } return(-1); }
public List <ushort> Parse(MyBinaryReader reader) { var pool = new List <ushort>(interfacesCount); // int index; // for (index = 0; index < fragment.Length - 1; index += 2) // Pool.Add((ushort) (fragment[index] << 8 + fragment[index + 1])); // // if (index != fragment.Length / 2) throw new Exception("Ошибка с интерфейсами"); // return index; for (var _ = 0; _ < interfacesCount; _++) { pool.Add(reader.ReadUInt16()); } return(pool); }
public ParsedClassFile Parse() { if (_bReader.ReadUInt32() != Magic) { throw new Exception("MagicException"); // Ошибочку нужно создать } var minorVersion = _bReader.ReadUInt16(); var majorVersion = _bReader.ReadUInt16(); var constantPoolCount = _bReader.ReadUInt16(); var constantPool = GetConstantPool(constantPoolCount); var acessFlags = _bReader.ReadUInt16(); var thisClass = _bReader.ReadUInt16(); var superClass = _bReader.ReadUInt16(); var interfacesCount = _bReader.ReadUInt16(); var interfaces = GetInterfaces(_interfacesCount); return(new ParsedClassFile(minorVersion, majorVersion, constantPoolCount, constantPool)); }
private object?LoadObjectV1(int dataOffset) { Debug.Assert(System.Threading.Monitor.IsEntered(reader)); reader.Seek(dataSectionPosition + dataOffset, SeekOrigin.Begin); int typeIndex = reader.Read7BitEncodedInt(); if (typeIndex == -1) { return(null); } string typeName = FindType(typeIndex); int comma = typeName.IndexOf(','); if (comma > 0) { // strip assembly name typeName = typeName.Substring(0, comma); } switch (typeName) { case "System.String": return(reader.ReadString()); case "System.Byte": return(reader.ReadByte()); case "System.SByte": return(reader.ReadSByte()); case "System.Int16": return(reader.ReadInt16()); case "System.UInt16": return(reader.ReadUInt16()); case "System.Int32": return(reader.ReadInt32()); case "System.UInt32": return(reader.ReadUInt32()); case "System.Int64": return(reader.ReadInt64()); case "System.UInt64": return(reader.ReadUInt64()); case "System.Single": return(reader.ReadSingle()); case "System.Double": return(reader.ReadDouble()); case "System.DateTime": // Ideally we should use DateTime's ToBinary & FromBinary, // but we can't for compatibility reasons. return(new DateTime(reader.ReadInt64())); case "System.TimeSpan": return(new TimeSpan(reader.ReadInt64())); case "System.Decimal": int[] bits = new int[4]; for (int i = 0; i < bits.Length; i++) { bits[i] = reader.ReadInt32(); } return(new decimal(bits)); default: return(new ResourceSerializedObject(FindType(typeIndex), this, reader.BaseStream.Position)); } }
public List <IConstant> Parse(MyBinaryReader reader) { // заполняем первый индекс заглушкой, т.к. здесь нумерация с единицы var pool = new List <IConstant>(_poolCount) { null }; while (_poolCount - pool.Count > 0) { switch ((Tags)reader.ReadByte()) { // Здесь всем методам будем передавать index + 1 case Tags.CONSTANT_Class: // parse 2byte name_index pool.Add(new ClassInfo(reader.ReadUInt16())); break; case Tags.CONSTANT_Fieldref: case Tags.CONSTANT_Methodref: case Tags.CONSTANT_InterfaceMethodref: // u2 class_index // u2 name_and_type_index pool.Add(new FiMeInRef(reader.ReadUInt16(), reader.ReadUInt16())); break; case Tags.CONSTANT_String: // u2 string_index pool.Add(new StringRef(reader.ReadUInt16())); break; case Tags.CONSTANT_Integer: // u4 bytes pool.Add(ParseIntegerConstant(reader)); //index += 4; break; case Tags.CONSTANT_Float: // Не знаю, что будет с float, попробую не пользоваться формулой s * m * 2**(e-150) // u4 bytes pool.Add(ParseFloatConstant(reader)); //index += 4; break; case Tags.CONSTANT_Long: case Tags.CONSTANT_Double: var pair = ParseLongOrDoubleConstant(reader); pool.Add(pair.Item1); pool.Add(pair.Item2); //index += 8; break; case Tags.CONSTANT_NameAndType: // u2 name_index // u2 descriptor_index pool.Add(new NameAndTypeInfo(reader.ReadUInt16(), reader.ReadUInt16())); break; case Tags.CONSTANT_Utf8: var length = reader.ReadUInt16(); var fragment = reader.ReadBytes(length); pool.Add(ParseUtfStrings(fragment, length)); break; case Tags.CONSTANT_MethodHandle: // u1 reference_kind in range(1 to 9) // u2 reference_index pool.Add(new MethodHandle(reader.ReadByte(), reader.ReadUInt16())); // Надо бы валидацию break; case Tags.CONSTANT_MethodType: // u2 descriptor_index pool.Add(new MethodType(reader.ReadUInt16())); break; case Tags.CONSTANT_InvokeDynamic: // u2 bootstrap_method_attr_index // u2 name_and_type_index pool.Add(new InvokeDynamic(reader.ReadUInt16(), reader.ReadUInt16())); break; } } return(pool); }