void WriteDirectoryRecord(Byte[] buffer, Int32 offset, DirectoryRecord record) { Assert.IsNotNull(buffer, nameof(buffer)); Assert.IsNotNull(record, nameof(record)); buffer[offset + 0] = record.GetSize(); buffer[offset + 1] = record.ExtendedAttributeRecordLength; BinaryIO.WriteIntoBuffer(buffer, offset + 2, record.SectorNumber, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, offset + 6, record.SectorNumber, Endian.BigEndian); BinaryIO.WriteIntoBuffer(buffer, offset + 10, record.DataLength, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, offset + 14, record.DataLength, Endian.BigEndian); WriteDirectoryRecordDateTime(buffer, offset + 18, record.RecordingDateAndTime); buffer[offset + 25] = (Byte)record.Flags; buffer[offset + 26] = record.FileUnitSize; buffer[offset + 27] = record.InterleaveGapSize; BinaryIO.WriteIntoBuffer(buffer, offset + 28, record.VolumeSequenceNumber, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, offset + 30, record.VolumeSequenceNumber, Endian.BigEndian); buffer[offset + 32] = (Byte)record.FileIdentifier.Length; BinaryIO.WriteIntoBuffer(buffer, offset + 33, Encodings.ASCII, record.FileIdentifier, record.FileIdentifier.Length, ' '); var padding = record.FileIdentifier.Length % 2 == 0; if (record.SystemUseData != null) { Array.Copy(record.SystemUseData, 0, buffer, offset + 33 + record.FileIdentifier.Length + (padding ? 1 : 0), record.SystemUseData.Length); } }
void WriteBasicVolumeDescriptor(BinaryWriter writer, BasicVolumeDescriptor descriptor) { Assert.IsNotNull(writer, nameof(writer)); Assert.IsNotNull(descriptor, nameof(descriptor)); var buffer = new Byte[DefaultSectorSize]; buffer[0] = (Byte)descriptor.VolumeDescriptorType; BinaryIO.WriteIntoBuffer(buffer, 1, Encodings.ASCII, descriptor.StandardIdentifier, 5, ' '); buffer[6] = descriptor.VolumeDescriptorVersion; BinaryIO.WriteIntoBuffer(buffer, 8, Encodings.ASCII, descriptor.SystemIdentifier, 32, ' '); BinaryIO.WriteIntoBuffer(buffer, 40, Encodings.ASCII, descriptor.VolumeIdentifier, 32, ' '); BinaryIO.WriteIntoBuffer(buffer, 80, descriptor.VolumeSpaceSize, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, 84, descriptor.VolumeSpaceSize, Endian.BigEndian); BinaryIO.WriteIntoBuffer(buffer, 120, descriptor.VolumeSetSize, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, 122, descriptor.VolumeSetSize, Endian.BigEndian); BinaryIO.WriteIntoBuffer(buffer, 124, descriptor.VolumeSequenceNumber, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, 126, descriptor.VolumeSequenceNumber, Endian.BigEndian); BinaryIO.WriteIntoBuffer(buffer, 128, descriptor.LogicalBlockSize, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, 130, descriptor.LogicalBlockSize, Endian.BigEndian); BinaryIO.WriteIntoBuffer(buffer, 132, descriptor.PathTableSize, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, 136, descriptor.PathTableSize, Endian.BigEndian); BinaryIO.WriteIntoBuffer(buffer, 140, descriptor.TypeLPathTableLocation, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, 144, descriptor.OptionalTypeLPathTableLocation, Endian.LittleEndian); BinaryIO.WriteIntoBuffer(buffer, 148, descriptor.TypeMPathTableLocation, Endian.BigEndian); BinaryIO.WriteIntoBuffer(buffer, 152, descriptor.OptionalTypeMPathTableLocation, Endian.BigEndian); WriteDirectoryRecord(buffer, 156, descriptor.RootDirectory); BinaryIO.WriteIntoBuffer(buffer, 190, Encodings.ASCII, descriptor.VolumeSetIdentifier, 128, ' '); BinaryIO.WriteIntoBuffer(buffer, 318, Encodings.ASCII, descriptor.PublisherIdentifier, 128, ' '); BinaryIO.WriteIntoBuffer(buffer, 446, Encodings.ASCII, descriptor.DataPreparerIdentifier, 128, ' '); BinaryIO.WriteIntoBuffer(buffer, 574, Encodings.ASCII, descriptor.ApplicationIdentifier, 128, ' '); BinaryIO.WriteIntoBuffer(buffer, 702, Encodings.ASCII, descriptor.CopyrightFileIdentifier, 37, ' '); BinaryIO.WriteIntoBuffer(buffer, 739, Encodings.ASCII, descriptor.AbstractFileIdentifier, 37, ' '); BinaryIO.WriteIntoBuffer(buffer, 776, Encodings.ASCII, descriptor.BibliographicFileIdentifier, 37, ' '); WriteVolumeDescriptorDateTime(buffer, 813, descriptor.CreationDateAndTime); WriteVolumeDescriptorDateTime(buffer, 830, descriptor.ModificationDateAndTime); WriteVolumeDescriptorDateTime(buffer, 847, descriptor.ExpirationDateAndTime); WriteVolumeDescriptorDateTime(buffer, 864, descriptor.EffectiveDateAndTime); buffer[881] = descriptor.FileStructureVersion; writer.Write(buffer); }
public Int32 Write(Encoding encoding, Byte[] buffer, Int32 offset) { Assert.IsNotNull(encoding, nameof(encoding)); Assert.IsNotNull(buffer, nameof(buffer)); switch (Type) { case OperandType.Byte: BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Byte>()); return(1); case OperandType.SByte: BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <SByte>()); return(1); case OperandType.UInt16: BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <UInt16>()); return(2); case OperandType.Int16: BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Int16>()); return(2); case OperandType.UInt32: case OperandType.InstructionOffset: case OperandType.BattleOffset: BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <UInt32>()); return(4); case OperandType.Int32: BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Int32>()); return(4); case OperandType.Instruction: return(GetValue <Instruction>().Write(encoding, buffer, offset)); case OperandType.Expression: return(GetValue <Expression>().Write(encoding, buffer, offset)); case OperandType.Operation: return(GetValue <Operation>().Write(encoding, buffer, offset)); case OperandType.String: var bytes = EncodedStringUtil.GetBytes(GetValue <String>(), encoding); Array.Copy(bytes, 0, buffer, offset, bytes.Length); return(bytes.Length); case OperandType.None: default: throw new Exception(); } }
void WriteSetTerminatorVolumeDescriptor(BinaryWriter writer, SetTerminatorVolumeDescriptor descriptor) { Assert.IsNotNull(writer, nameof(writer)); Assert.IsNotNull(descriptor, nameof(descriptor)); var buffer = new Byte[DefaultSectorSize]; buffer[0] = (Byte)descriptor.VolumeDescriptorType; BinaryIO.WriteIntoBuffer(buffer, 1, Encodings.ASCII, descriptor.StandardIdentifier, 5, ' '); buffer[6] = descriptor.VolumeDescriptorVersion; writer.Write(buffer); }
public static Byte[] Write(SCENARIO_CHIPFRAMEINFO input) { var buffer = new Byte[4 + MathUtil.RoundUp(input.SubChipCount, 8)]; BinaryIO.WriteIntoBuffer(buffer, 0, input.Speed, Endian.LittleEndian); buffer[2] = input.Reserve; buffer[3] = input.SubChipCount; for (var i = 0; i != input.SubChipCount; ++i) { buffer[4 + i] = input.SubChipIndex[i]; } return(buffer); }
static void UpdateMonsterNote(IO.IFileSystem filesystem, Encoding encoding) { Assert.IsNotNull(filesystem, nameof(filesystem)); Assert.IsNotNull(encoding, nameof(encoding)); Console.WriteLine("monsnote.dt2"); var filelist = GetMonsterNoteFileList(); var allbuffers = new List <Byte[]>(); foreach (var monsterfilenumber in filelist) { var monsterfilepath = Path.Combine(@"data\battle\dat", "ms" + monsterfilenumber + ".dat"); using (var monsterreader = filesystem.OpenFile(monsterfilepath, encoding)) { var monsterfiledata = monsterreader.ReadBytes((Int32)monsterreader.Length); var buffer = new Byte[8 + monsterreader.Length]; var foo = "300" + monsterfilenumber; var foobytes = Enumerable.Range(0, 4).Select(i => foo.Substring(i * 2, 2)).Select(str => (Byte)Int32.Parse(str, System.Globalization.NumberStyles.HexNumber)).Reverse().ToArray(); Array.Copy(foobytes, 0, buffer, 0, 4); BinaryIO.WriteIntoBuffer(buffer, 4, (UInt32)monsterreader.Length); Array.Copy(monsterfiledata, 0, buffer, 8, monsterfiledata.Length); allbuffers.Add(buffer); } } allbuffers.Add(new Byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); var totalsize = allbuffers.Sum(x => x.Length); var filebuffer = new Byte[totalsize]; var memorystream = new MemoryStream(filebuffer); foreach (var item in allbuffers) { memorystream.Write(item, 0, item.Length); } filesystem.SaveFile(@"data\monsnote\monsnote.dt2", filebuffer); }
static void Update_datalst(Iso9660.IsoImage iso, String filepath) { Assert.IsNotNull(iso, nameof(iso)); Assert.IsValidString(filepath, nameof(filepath)); var datalist = iso.GetFile(IsoFilePaths.FilePath_datalst); var datalistbuffer = datalist.GetData(); var extensionslist = ReadDataLstExtensions(new FileReader(datalistbuffer, Encodings.ASCII)); var filerecord = iso.GetFile(filepath); var index = FindDataLstIndex(filepath, datalistbuffer, extensionslist); BinaryIO.WriteIntoBuffer(datalistbuffer, index + 8, filerecord.Record.DataLength, Endian.LittleEndian); var sectorbytes = new Byte[4]; BinaryIO.WriteIntoBuffer(sectorbytes, 0, filerecord.Record.SectorNumber, Endian.LittleEndian); for (var i = 0; i != 3; ++i) { datalistbuffer[index + 12 + i] = sectorbytes[i]; } }