示例#1
0
 public override void Write(EndianWriter writer)
 {
     writer.Write(Unknown1);
     writer.Write(Unknown2);
     writer.Write(Unknown3);
     writer.Write(Unknown4);
 }
示例#2
0
 /// <summary>
 /// Writes the field in a decompiled state to the stream specified.
 /// </summary>
 /// <param name="bw">Stream to write the field to.</param>
 public override void Write(EndianWriter bw)
 {
     bw.Write(X);
     bw.Write(Y);
     bw.Write(W);
     bw.Write(H);
 }
示例#3
0
 public void Write(EndianWriter writer)
 {
     writer.Write(Size);
     writer.Write(Offset);
     writer.Write(CacheIndex);
     writer.Write(MapId);
 }
示例#4
0
 public override void Write(EndianWriter bw)
 {
     bw.Write(A);
     bw.Write(R);
     bw.Write(G);
     bw.Write(B);
 }
示例#5
0
        public void ExpandingWrite()
        {
            var original = new byte[byte.MaxValue];

            for (byte i = 0; i < original.Length; i++)
            {
                original[i] = i;
            }

            var ms   = new MemoryStream(original);
            var tran = new TransactionStream(ms);

            var reader = new EndianReader(tran);
            var writer = new EndianWriter(tran);

            //start within the source stream, then write past the end of it
            tran.Position = 240;
            writer.Write(Enumerable.Repeat((byte)99, 30).ToArray());
            Assert.AreEqual(270L, tran.Position);
            Assert.AreEqual(270L, tran.Length);

            //seek past the end of the source stream, then start writing
            tran.Position = 300;
            writer.Write(Enumerable.Repeat((byte)77, 30).ToArray());
            Assert.AreEqual(330L, tran.Position);
            Assert.AreEqual(330L, tran.Length);

            //read beyond the source stream but between patches
            tran.Position = 270;
            var data = reader.ReadBytes(30);

            Assert.AreEqual(300L, tran.Position);

            for (int i = 0; i < 30; i++)
            {
                Assert.AreEqual(byte.MinValue, data[i]);
            }

            //read beyond the source stream including patches
            tran.Position = 0;
            data          = reader.ReadBytes(330);
            Assert.AreEqual(330L, tran.Position);

            for (byte i = 0; i < 240; i++)
            {
                Assert.AreEqual(i, data[i]);
            }
            for (int i = 240; i < 270; i++)
            {
                Assert.AreEqual((byte)99, data[i]);
            }
            for (int i = 270; i < 300; i++)
            {
                Assert.AreEqual(byte.MinValue, data[i]);
            }
            for (int i = 300; i < 330; i++)
            {
                Assert.AreEqual((byte)77, data[i]);
            }
        }
        public void DataLength01(ByteOrder order, bool dynamicRead)
        {
            var rng = new Random();

            using (var stream = new MemoryStream(new byte[500]))
                using (var reader = new EndianReader(stream, order))
                    using (var writer = new EndianWriter(stream, order))
                    {
                        reader.DynamicReadEnabled = dynamicRead;

                        writer.Write(5);
                        writer.Write(100);

                        stream.Position = 0;
                        var obj = reader.ReadObject <DataClass14>();

                        Assert.AreEqual(5, obj.Property1);
                        Assert.AreEqual(100, obj.Property2);
                        Assert.AreEqual(100, stream.Position);

                        stream.Position = 0;
                        writer.Write(7);
                        writer.Write(45);

                        stream.Position = 0;
                        obj             = reader.ReadObject <DataClass14>();

                        Assert.AreEqual(7, obj.Property1);
                        Assert.AreEqual(45, obj.Property2);
                        Assert.AreEqual(45, stream.Position);
                    }
        }
        public void Int16Mixed(ByteOrder readOrder, ByteOrder writeOrder)
        {
            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, readOrder))
                    using (var writer = new EndianWriter(stream, writeOrder))
                    {
                        var rand = new Random().Next(short.MinValue, short.MaxValue);

                        var bytes = BitConverter.GetBytes((short)rand);
                        Array.Reverse(bytes);

                        writer.Write(unchecked ((short)0x0100));
                        writer.Write(unchecked ((short)0xFFFF));
                        writer.Write(unchecked ((short)0xFF00));
                        writer.Write((short)rand);

                        Assert.AreEqual(stream.Length, 8);

                        stream.Position = 0;
                        Assert.AreEqual(unchecked ((short)0x0001), reader.PeekInt16());
                        Assert.AreEqual(0, stream.Position);

                        Assert.AreEqual(unchecked ((short)0x0001), reader.ReadInt16());
                        Assert.AreEqual(unchecked ((short)0xFFFF), reader.ReadInt16());
                        Assert.AreEqual(unchecked ((short)0x00FF), reader.ReadInt16());
                        Assert.AreEqual(BitConverter.ToInt16(bytes, 0), reader.ReadInt16());

                        Assert.AreEqual(reader.BaseStream.Position, stream.Length);
                    }
        }
        public void Int16Same(ByteOrder order)
        {
            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, order))
                    using (var writer = new EndianWriter(stream, order))
                    {
                        var rand = new Random().Next(short.MinValue, short.MaxValue);

                        writer.Write(unchecked ((short)0x0100));
                        writer.Write(unchecked ((short)0x7F7F));
                        writer.Write(unchecked ((short)0xFFFF));
                        writer.Write((short)rand);

                        Assert.AreEqual(stream.Length, 8);

                        stream.Position = 0;
                        Assert.AreEqual(unchecked ((short)0x0100), reader.PeekInt16());
                        Assert.AreEqual(0, stream.Position);

                        Assert.AreEqual(unchecked ((short)0x0100), reader.ReadInt16());
                        Assert.AreEqual(unchecked ((short)0x7F7F), reader.ReadInt16());
                        Assert.AreEqual(unchecked ((short)0xFFFF), reader.ReadInt16());
                        Assert.AreEqual(rand, reader.ReadInt16());

                        Assert.AreEqual(reader.BaseStream.Position, stream.Length);
                    }
        }
示例#9
0
        public override void Serialize(EndianWriter writer)
        {
            var protectedPayloadWriter = new EndianWriter();

            SerializeProtectedPayload(protectedPayloadWriter);

            // length is before padding
            Header.ProtectedPayloadLength = (ushort)protectedPayloadWriter.Length;

            // padding is before encryption
            byte[] padding = Padding.CreatePaddingData(
                PaddingType.PKCS7,
                protectedPayloadWriter.Length,
                alignment: payloadSizeAlignment
                );

            protectedPayloadWriter.Write(padding);

            // encrypt without adding padding to the encrypted value
            var encryptedPayload = Crypto.EncryptWithoutPadding(protectedPayloadWriter.ToBytes(), InitVector);

            base.Serialize(writer);
            writer.Write(encryptedPayload);

            var signature = Crypto.CalculateMessageSignature(writer.ToBytes());

            writer.Write(signature);
        }
        private void WriteVariableHeader(EndianWriter writer, VariableHeader header)
        {
            //name offset
            writer.Write(header.NameOffset);
            //startOffset
            writer.Write(header.StartOffset);
            //Size
            writer.Write(header.Variable.Length);
            //flags
            writer.Write((uint)ShaderVariableFlags.Used);             //Unity only packs used variables as far as I can tell

            uint typeOffset = m_typeLookup[header.Variable.ShaderType];

            //type offset
            writer.Write(typeOffset);
            //default value offset
            writer.Write((uint)0);             //Not used
            if (majorVersion >= 5)
            {
                //StartTexture
                writer.Write((uint)0);
                //TextureSize
                writer.Write((uint)0);
                //StartSampler
                writer.Write((uint)0);
                //SamplerSize
                writer.Write((uint)0);
            }
        }
        internal void Write(EndianWriter writer)
        {
            foreach (VariableHeader header in m_variableHeaders)
            {
                WriteVariableHeader(writer, header);
            }
            foreach (Variable variable in m_variables)
            {
                writer.WriteStringZeroTerm(variable.Name);
                WriteShaderType(writer, variable.ShaderType);

                foreach (ShaderTypeMember member in variable.ShaderType.Members)
                {
                    uint nameOffset = m_variableNameLookup[member.Name];
                    writer.Write(nameOffset);
                    uint memberOffset = m_typeLookup[member.ShaderType];
                    writer.Write(memberOffset);
                    writer.Write(member.Index);
                }
                foreach (ShaderTypeMember member in variable.ShaderType.Members)
                {
                    writer.WriteStringZeroTerm(member.Name);
                    WriteShaderType(writer, member.ShaderType);
                }
            }
        }
示例#12
0
        public void StoreType01(ByteOrder order, bool dynamicRead)
        {
            var rng = new Random();

            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, order))
                    using (var writer = new EndianWriter(stream, order))
                    {
                        reader.DynamicReadEnabled = dynamicRead;
                        var rand = new object[3];

                        rand[0] = (short)rng.Next(short.MinValue, short.MaxValue);
                        writer.Write((short)rand[0]);

                        rand[1] = (byte)rng.Next(byte.MinValue, byte.MaxValue);
                        writer.Write((byte)rand[1]);

                        rand[2] = (float)rng.NextDouble();
                        writer.Write((float)rand[2]);

                        stream.Position = 0;
                        var obj = (DataClass11)reader.ReadObject(typeof(DataClass11));

                        Assert.AreEqual(rand[0], (short)obj.Property1);
                        Assert.AreEqual(rand[1], (byte)obj.Property2);
                        Assert.AreEqual(rand[2], (float)obj.Property3);
                    }
        }
示例#13
0
 public void Write(EndianWriter writer)
 {
     writer.Format = EndianFormat.BigEndian;
     writer.Write(Channels);
     writer.Write(Reserved);
     writer.Write((short)ChannelMask);
 }
示例#14
0
        private void con_redeem(ref TmpEntry entry, EndianIO readerIO, EndianIO writerIO, EndianWriter structIO)
        {
            // Grabbing the token from the request.
            string recCpuKey  = Misc.BytesToHexString(readerIO.Reader.ReadBytes(0x10)); // Cross check the CPUKey here with the one in the DB.
            string recSession = Misc.BytesToHexString(readerIO.Reader.ReadBytes(0x10)); // Receiving their sent session to cross check.

            entry.inToken = Misc.BytesToHexString(readerIO.Reader.ReadBytes(0x19));     // We'll need to change the length later.
            if (ConsoleMySQL.getConsole(ref entry))
            {
                if (entry.ClientEnabled)
                {
                    if (ConsoleMySQL.getToken(ref entry))
                    {
                        entry.daysLeft = !entry.TokenUsed ? entry.daysLeft + entry.TokenDays : entry.daysLeft;
                        string retMsgSuccess = String.Format("Token has been successfully redeemed!\nCPUKey: {0}\nRedeemed {1} Days\n{2}\0", entry.CPUKey, entry.TokenDays, (entry.daysLeft >= 500 ? "You still have lifetime." : "You have " + entry.daysLeft + " days on reserve.")),
                               retMsgUsed    = String.Format("Token seems to already be used.\n\nIf you feel this is a mistake, please message staff ASAP!\n\nYour CPUKey: {0}\0", entry.CPUKey);
                        uint   size          = (sizeof(uint) * 4) + Convert.ToUInt32((!entry.TokenUsed ? retMsgSuccess.Length : retMsgUsed.Length) + 2);
                        byte[] tmpBuff       = new byte[size];
                        mainBuff = new byte[size];
                        Buffer.BlockCopy(Encoding.ASCII.GetBytes(retMsgSuccess), 0, tmpBuff, 0, (!entry.TokenUsed ? retMsgSuccess.Length : retMsgUsed.Length) + 2);
                        structIO.Write(Globals.XSTL_STATUS_SUCCESS);
                        structIO.Write(!entry.TokenUsed ? retMsgSuccess : retMsgUsed);
                        writerIO.Writer.Write(mainBuff);
                        Globals.write("Client [{0}] CPUKey: {1}\n{2} Token: {3}", IPAddr, entry.CPUKey, (!entry.TokenUsed ? "Redeemed" : "Tried Redeeming"), entry.outToken);
                        if (!entry.TokenUsed)
                        {
                            ConsoleMySQL.saveToken(ref entry); ConsoleMySQL.saveConsole(ref entry);
                        }
                        return;
                    }
                    structIO.Write(Globals.XSTL_STATUS_ERROR);
                }
            }
        }
示例#15
0
        public override void Write(EndianWriter bw)
        {
            // Add
            if (Tag != "Null Reference")
            {
                try { Index = ((Dictionary <string, int>)EngineManager.Engines[Global.Application.Instance.Project.Engine]["TagIds"])[Tag]; }
                catch
                {
                    Index = ((Dictionary <string, int>)EngineManager.Engines[Global.Application.Instance.Project.Engine]["TagIds"]).Count;
                    ((Dictionary <string, int>)EngineManager.Engines[Global.Application.Instance.Project.Engine]["TagIds"]).Add(Tag, Index);
                }

                // Get class
                groupTag = EngineManager.Engines[Global.Application.Instance.Project.Engine]["Class", Tag.Substring(Tag.LastIndexOf(".") + 1)];
            }
            else
            {
                Index = -1;
            }

            if (groupTag.Length != 4)
            {
                throw new Exception("this is bad");
            }

            bw.Write(Microsoft.VisualBasic.Strings.StrReverse(groupTag).ToCharArray());
            if (Engine != EngineManager.HaloEngine.Halo2)
            {
                bw.Write((long)0);
            }
            bw.Write(Index);
        }
示例#16
0
        public void ReadStrings02(ByteOrder order, bool dynamicRead)
        {
            var value1 = "Length_Prefixed_String_#01!";
            var value2 = "Length_Prefixed_String_#02!";
            var value3 = "Length_Prefixed_String_#03!";

            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, order))
                    using (var writer = new EndianWriter(stream, order))
                    {
                        reader.DynamicReadEnabled = dynamicRead;
                        writer.Write(value1, ByteOrder.BigEndian);

                        stream.Position = 0x20;
                        writer.Write(value2, ByteOrder.LittleEndian);

                        stream.Position = 0x40;
                        writer.Write(value3, ByteOrder.BigEndian);

                        stream.Position = 0;
                        var obj = reader.ReadObject <DataClass06>();

                        Assert.AreEqual(value1, obj.Property1);
                        Assert.AreEqual(value2, obj.Property2);
                        Assert.AreEqual(value3, obj.Property3);
                    }
        }
示例#17
0
        public static byte[] GenerateIndexBuffer(IExportContainer container, ref LOD origin)
        {
            int indexCount = origin.MeshData.Sum(t => t.Faces.Length) * 3;
            int dataSize   = indexCount * sizeof(ushort);

            byte[] buffer = new byte[dataSize];
            using (MemoryStream stream = new MemoryStream(buffer))
            {
                EndianType endian = container.ExportPlatform == Platform.XBox360 ? EndianType.BigEndian : EndianType.LittleEndian;
                using (EndianWriter writer = new EndianWriter(stream, endian))
                {
                    for (int i = 0; i < origin.MeshData.Length; i++)
                    {
                        MeshData meshData = origin.MeshData[i];
                        for (int j = 0; j < meshData.Faces.Length; j++)
                        {
                            Face face = meshData.Faces[j];
                            writer.Write(face.V1);
                            writer.Write(face.V2);
                            writer.Write(face.V3);
                        }
                    }
                }
            }
            return(buffer);
        }
示例#18
0
        public void Int64Same(ByteOrder order)
        {
            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, order))
                    using (var writer = new EndianWriter(stream, order))
                    {
                        var rand = unchecked ((long)(ulong)(new Random().NextDouble() * ulong.MaxValue));

                        writer.Write(unchecked ((long)0x0100000000000000));
                        writer.Write(unchecked ((long)0x7F7F7F7F7F7F7F7F));
                        writer.Write(unchecked ((long)0xFFFFFFFFFFFFFFFF));
                        writer.Write((long)rand);

                        Assert.AreEqual(stream.Length, 32);

                        stream.Position = 0;
                        Assert.AreEqual(unchecked ((long)0x0100000000000000), reader.PeekInt64());
                        Assert.AreEqual(0, stream.Position);

                        Assert.AreEqual(unchecked ((long)0x0100000000000000), reader.ReadInt64());
                        Assert.AreEqual(unchecked ((long)0x7F7F7F7F7F7F7F7F), reader.ReadInt64());
                        Assert.AreEqual(unchecked ((long)0xFFFFFFFFFFFFFFFF), reader.ReadInt64());
                        Assert.AreEqual(rand, reader.ReadInt64());

                        Assert.AreEqual(reader.BaseStream.Position, stream.Length);
                    }
        }
示例#19
0
        public void DecimalSame(ByteOrder order)
        {
            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, order))
                    using (var writer = new EndianWriter(stream, order))
                    {
                        var rng   = new Random();
                        var rands = new decimal[4];

                        for (int i = 0; i < 4; i++)
                        {
                            rands[i] = (decimal)(ulong.MaxValue * Math.Pow(rng.NextDouble(), 3));
                        }

                        writer.Write(rands[0]);
                        writer.Write(rands[1]);
                        writer.Write(rands[2]);
                        writer.Write(rands[3]);

                        Assert.AreEqual(stream.Length, 64);

                        stream.Position = 0;
                        Assert.AreEqual(rands[0], reader.PeekDecimal());
                        Assert.AreEqual(0, stream.Position);

                        Assert.AreEqual(rands[0], reader.ReadDecimal());
                        Assert.AreEqual(rands[1], reader.ReadDecimal());
                        Assert.AreEqual(rands[2], reader.ReadDecimal());
                        Assert.AreEqual(rands[3], reader.ReadDecimal());

                        Assert.AreEqual(reader.BaseStream.Position, stream.Length);
                    }
        }
示例#20
0
        public void UInt32Same(ByteOrder order)
        {
            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, order))
                    using (var writer = new EndianWriter(stream, order))
                    {
                        var rand = (uint)(new Random().NextDouble() * uint.MaxValue);

                        writer.Write(unchecked ((uint)0x01000000));
                        writer.Write(unchecked ((uint)0x7F7F7F7F));
                        writer.Write(unchecked ((uint)0xFFFFFFFF));
                        writer.Write((uint)rand);

                        Assert.AreEqual(stream.Length, 16);

                        stream.Position = 0;
                        Assert.AreEqual(unchecked ((uint)0x01000000), reader.PeekUInt32());
                        Assert.AreEqual(0, stream.Position);

                        Assert.AreEqual(unchecked ((uint)0x01000000), reader.ReadUInt32());
                        Assert.AreEqual(unchecked ((uint)0x7F7F7F7F), reader.ReadUInt32());
                        Assert.AreEqual(unchecked ((uint)0xFFFFFFFF), reader.ReadUInt32());
                        Assert.AreEqual(rand, reader.ReadUInt32());

                        Assert.AreEqual(reader.BaseStream.Position, stream.Length);
                    }
        }
示例#21
0
        public override void Serialize(EndianWriter writer)
        {
            var messageWriter = new EndianWriter();

            base.Serialize(messageWriter);

            var message = messageWriter.ToBytes();

            var initVectorSource = message.Take(16).ToArray();
            var initVector       = Crypto.CreateDerivedInitVector(initVectorSource);

            var fragmentWriter = new EndianWriter();

            byte[] padding = Padding.CreatePaddingData(
                PaddingType.PKCS7,
                Fragment,
                alignment: payloadSizeAlignment
                );

            fragmentWriter.Write(Fragment);
            fragmentWriter.Write(padding);

            var encryptedFragment = Crypto.EncryptWithoutPadding(fragmentWriter.ToBytes(), initVector);

            Header.Serialize(writer);
            writer.Write(encryptedFragment);

            var signature = Crypto.CalculateMessageSignature(writer.ToBytes());

            writer.Write(signature);
        }
示例#22
0
        public void UInt32Mixed(ByteOrder readOrder, ByteOrder writeOrder)
        {
            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, readOrder))
                    using (var writer = new EndianWriter(stream, writeOrder))
                    {
                        var rand = (uint)(new Random().NextDouble() * uint.MaxValue);

                        var bytes = BitConverter.GetBytes((uint)rand);
                        Array.Reverse(bytes);

                        writer.Write(unchecked ((uint)0x01000000));
                        writer.Write(unchecked ((uint)0xFFFFFFFF));
                        writer.Write(unchecked ((uint)0xFF00FF00));
                        writer.Write((uint)rand);

                        Assert.AreEqual(stream.Length, 16);

                        stream.Position = 0;
                        Assert.AreEqual(unchecked ((uint)0x00000001), reader.PeekUInt32());
                        Assert.AreEqual(0, stream.Position);

                        Assert.AreEqual(unchecked ((uint)0x00000001), reader.ReadUInt32());
                        Assert.AreEqual(unchecked ((uint)0xFFFFFFFF), reader.ReadUInt32());
                        Assert.AreEqual(unchecked ((uint)0x00FF00FF), reader.ReadUInt32());
                        Assert.AreEqual(BitConverter.ToUInt32(bytes, 0), reader.ReadUInt32());

                        Assert.AreEqual(reader.BaseStream.Position, stream.Length);
                    }
        }
示例#23
0
        public void Enums01(ByteOrder order, bool dynamicRead)
        {
            var rng = new Random();

            using (var stream = new MemoryStream())
                using (var reader = new EndianReader(stream, order))
                    using (var writer = new EndianWriter(stream, order))
                    {
                        reader.DynamicReadEnabled = dynamicRead;
                        var rand = new object[4];

                        rand[0] = (Enum01)rng.Next(1, 4);
                        writer.Write((byte)(Enum01)rand[0]);

                        rand[1] = (Enum02)rng.Next(4, 7);
                        writer.Write((short)(Enum02)rand[1]);

                        rand[2] = (Enum03)rng.Next(7, 10);
                        writer.Write((int)(Enum03)rand[2]);

                        rand[3] = (Enum04)rng.Next(10, 13);
                        writer.Write((long)(Enum04)rand[3]);

                        stream.Position = 0;
                        var obj = reader.ReadObject <DataClass12>();

                        Assert.AreEqual((Enum01)rand[0], obj.Property1);
                        Assert.AreEqual((Enum02)rand[1], obj.Property2);
                        Assert.AreEqual((Enum03)rand[2], obj.Property3);
                        Assert.AreEqual((Enum04)rand[3], obj.Property4);
                    }
        }
示例#24
0
        internal void Write(EndianWriter writer)
        {
            foreach (var header in variableHeaders)
            {
                WriteVariableHeader(writer, header);
            }
            foreach (var variable in variables)
            {
                writer.WriteStringZeroTerm(variable.Name);
                WriteShaderType(writer, variable.ShaderType);

                foreach (var member in variable.ShaderType.members)
                {
                    var nameOffset = variableNameLookup[member.Name];
                    writer.Write(nameOffset);
                    var memberOffset = typeLookup[member.ShaderType];
                    writer.Write(memberOffset);
                    writer.Write(member.Index);
                }
                foreach (var member in variable.ShaderType.members)
                {
                    writer.WriteStringZeroTerm(member.Name);
                    WriteShaderType(writer, member.ShaderType);
                }
            }
        }
示例#25
0
 public void Write(EndianWriter writer)
 {
     writer.Write(Data0);
     writer.Write(Data1);
     writer.Write(Data2);
     writer.Write(Data3);
 }
示例#26
0
 override public void WriteChunk(EndianWriter writer)
 {
     writer.Format = EndianFormat.BigEndian;
     writer.Write(Name);
     writer.Format = EndianFormat.LittleEndian;
     writer.Write(DataLength);
     writer.Write(Data);
 }
示例#27
0
        public void WriteTo([NotNull] Stream stream)
        {
            if (stream == null) throw new ArgumentNullException(nameof(stream));

            var writer = new EndianWriter(stream, Endianness.BigEndian);
            writer.Write(ChannelIdentifier);
            writer.Write(PaketSequence);
            stream.Write(Data.Array, Data.Offset, Data.Count);
        }
示例#28
0
 override public void WriteChunk(EndianWriter writer)
 {
     writer.Format = EndianFormat.BigEndian;
     writer.Write(Name);
     writer.Format = EndianFormat.LittleEndian;
     writer.Write(Size);
     writer.Format = EndianFormat.BigEndian;
     writer.Write(WAVE);
 }
        protected override void SerializePayload(EndianWriter writer)
        {
            writer.Write(DeviceId.ToByteArray());

            writer.WriteBE((ushort)PublicKeyType);
            writer.Write(PublicKey);

            writer.Write(InitVector);
        }
示例#30
0
 public void Write(EndianWriter ew, uint magic)
 {
     ew.WriteFourCC(type);
     ew.WriteFourCC(parent);
     ew.WriteFourCC(grandparent);
     ew.Write(identifier);
     ew.Write((uint)(stringOffset + magic));
     ew.Write((uint)(metaOffset + magic));
     ew.Write(flags);
     ew.Write(reserved);
 }
示例#31
0
文件: ChunkAttach.cs 项目: X-Hax/SA3D
        public override uint Write(EndianWriter writer, uint imageBase, bool DX, Dictionary <string, uint> labels)
        {
            // writing vertices
            uint vertexAddress = 0;

            if (VertexChunks != null && VertexChunks.Length > 0)
            {
                if (labels.ContainsKey(VertexName))
                {
                    vertexAddress = labels[VertexName];
                }
                else
                {
                    vertexAddress = writer.Position + imageBase;
                    foreach (VertexChunk cnk in VertexChunks)
                    {
                        cnk.Write(writer);
                    }
                    // end chunk
                    byte[] bytes = new byte[8];
                    bytes[0] = 255;
                    writer.Write(bytes);
                }
            }
            uint polyAddress = 0;

            if (PolyChunks != null && PolyChunks.Length > 0)
            {
                if (labels.ContainsKey(PolyName))
                {
                    polyAddress = labels[PolyName];
                }
                else
                {
                    polyAddress = writer.Position + imageBase;
                    foreach (PolyChunk cnk in PolyChunks)
                    {
                        cnk.Write(writer);
                    }
                    // end chunk
                    byte[] bytes = new byte[2];
                    bytes[0] = 255;
                    writer.Write(bytes);
                }
            }

            uint address = writer.Position + imageBase;

            labels.AddLabel(Name, address);
            writer.WriteUInt32(vertexAddress);
            writer.WriteUInt32(polyAddress);
            MeshBounds.Write(writer);
            return(address);
        }
        public void WriteTo([NotNull] Stream stream)
        {
            if (stream == null) throw new ArgumentNullException(nameof(stream));

            var writer = new EndianWriter(stream, Endianness.BigEndian);
            writer.Write(ChannelIdentifier);
            writer.Write(CommandIdentifier);
            writer.Write((byte)((PayloadLength >> 8) & 0xFF));
            writer.Write((byte)((PayloadLength >> 0) & 0xFF));
            stream.Write(Data.Array, Data.Offset, Data.Count);
        }
示例#33
0
 /// <exception cref="U2FException"/>
 /// <exception cref="System.IO.IOException"/>
 static void SendResponse(Stream outputStream, byte[] encodedBytes)
 {
     if (encodedBytes.Length > 65535)
     {
         throw new U2FException("Message is too long to be transmitted over this protocol");
     }
     using (var dataOutputStream = new EndianWriter(outputStream, Endianness.BigEndian))
     {
         dataOutputStream.Write((short)encodedBytes.Length);
         dataOutputStream.Write(encodedBytes);
     }
 }
示例#34
0
        public static ArraySegment<byte> EncodeResponse(ApduResponse response)
        {
            var buffer = new byte[response.ResponseData.Count + 2];

            using (var stream = new EndianWriter(new MemoryStream(buffer), Endianness.BigEndian))
            {
                stream.Write(response.ResponseData.Array, response.ResponseData.Offset, response.ResponseData.Count);
                var status = (short)response.Status;
                stream.Write(status);
            }

            return buffer.Segment();
        }
示例#35
0
        public static byte[] BuildBinary(Endianness endianess, params object[] args)
        {
            using (var stream = new MemoryStream(64))
            {
                var writer = new EndianWriter(stream, endianess);

                foreach (var arg in args)
                {
                    var type = arg.GetType();
                    if (type == typeof(uint))
                    {
                        writer.Write((uint)arg);
                    }
                    else if (type == typeof(ushort))
                    {
                        writer.Write((ushort)arg);
                    }
                    else if (type == typeof(byte))
                    {
                        writer.Write((byte)arg);
                    }
                    else if (type == typeof(BytesHolder))
                    {
                        var holder = ((BytesHolder)arg);
                        writer.Write(holder.Bytes);
                    }
                    else if (type == typeof(ArraySegment<byte>))
                    {
                        var segment = (ArraySegment<byte>)arg;
                        writer.Write(segment.Array, segment.Offset, segment.Count);
                    }
                    else if (type == typeof(byte[]))
                    {
                        var array = (byte[])arg;
                        writer.Write(array);
                    }
                }

                return stream.GetBuffer();
            }
        }
示例#36
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                FileStream stream = new FileStream(ofd.FileName, FileMode.Open);
                EndianReader reader = new EndianReader(stream, EndianType.BigEndian);
                EndianWriter writer = new EndianWriter(stream, EndianType.BigEndian);

                int CSum = 0;
                reader.BaseStream.Position = 0xD000;
                for (int i = 0; i < 0x768; i += 4)
                    CSum += reader.ReadInt32();

                writer.Write(CSum);
                writer.Flush();
                writer.Close();
                reader.Close();
                MessageBox.Show("New Checksum: " + CSum.ToString("X2"), "Done!");
            }
        }
示例#37
0
 public static void DeleteBytes(string filePath, int startOffset, int size)
 {
     var input = new FileStream(filePath, FileMode.Open);
     var er = new EndianReader(input);
     var buffer = er.ReadBytes(startOffset);
     var baseStream = er.BaseStream;
     baseStream.Position += size;
     var buffer2 = er.ReadBytes(((int)er.BaseStream.Length) - ((int)er.BaseStream.Position));
     er.Close();
     input.Close();
     input = new FileStream(filePath, FileMode.Create);
     var ew = new EndianWriter(input);
     ew.Write(buffer);
     ew.Write(buffer2);
     input.Close();
     ew.Close();
 }
示例#38
0
 public static void InsertBytes(string filePath, int startOffset, int size)
 {
     var input = new FileStream(filePath, FileMode.Open);
     var er = new EndianReader(input)
     {
         BaseStream = { Position = startOffset }
     };
     var buffer = er.ReadBytes(((int)er.BaseStream.Length) - ((int)er.BaseStream.Position));
     er.Close();
     input.Close();
     input = new FileStream(filePath, FileMode.Open);
     var ew = new EndianWriter(input)
     {
         BaseStream = { Position = startOffset }
     };
     ew.Write(new byte[size]);
     ew.Write(buffer);
     input.Close();
     ew.Close();
 }
        /// <summary>
        /// Extracts an xWMA sound and converts it to WAV.
        /// </summary>
        /// <param name="reader">The stream to read from.</param>
        /// <param name="offset">The offset of the data to extract.</param>
        /// <param name="rifx">The RIFX data for the sound.</param>
        /// <param name="outPath">The path of the file to save to.</param>
        public static void ExtractXWMAToWAV(EndianReader reader, int offset, RIFX rifx, string outPath)
        {
            // Create a temporary file to write an XWMA to
            string tempFile = Path.GetTempFileName();

            try
            {
                using (EndianWriter output = new EndianWriter(File.OpenWrite(tempFile), EndianFormat.BigEndian))
                {
                    // Generate a little-endian XWMA header
                    // TODO: move this into a class?
                    output.Write(0x52494646); // 'RIFF'

                    // Recompute the file size because the one Wwise gives us is trash
                    // fileSize = header size (always 0x2C) + dpds data size + data header size (always 0x8) + data size
                    int fileSize = 0x2C + rifx.SeekOffsets.Length * 0x4 + 0x8 + rifx.DataSize;
                    output.EndianType = EndianFormat.LittleEndian;
                    output.Write(fileSize);

                    output.EndianType = EndianFormat.BigEndian;
                    output.Write(RIFFFormat.XWMA);

                    // Generate the 'fmt ' chunk
                    output.Write(0x666D7420); // 'fmt '
                    output.EndianType = EndianFormat.LittleEndian;
                    output.Write(0x18); // Chunk size
                    output.Write(rifx.Codec);
                    output.Write(rifx.ChannelCount);
                    output.Write(rifx.SampleRate);
                    output.Write(rifx.BytesPerSecond);
                    output.Write(rifx.BlockAlign);
                    output.Write(rifx.BitsPerSample);

                    // Write the extradata
                    // Bytes 4 and 5 have to be flipped because they make up an int16
                    // TODO: add error checking to make sure the extradata is the correct size (0x6)
                    output.Write((short)0x6);
                    output.WriteBlock(rifx.ExtraData, 0, 4);
                    output.Write(rifx.ExtraData[5]);
                    output.Write(rifx.ExtraData[4]);

                    // Generate the 'dpds' chunk
                    // It's really just the 'seek' chunk from the original data but renamed
                    output.EndianType = EndianFormat.BigEndian;
                    output.Write(0x64706473); // 'dpds'

                    output.EndianType = EndianFormat.LittleEndian;
                    output.Write(rifx.SeekOffsets.Length * 4); // One uint32 per offset
                    foreach (int seek in rifx.SeekOffsets)
                        output.Write(seek);

                    // 'data' chunk
                    output.EndianType = EndianFormat.BigEndian;
                    output.Write(0x64617461); // 'data'
                    output.EndianType = EndianFormat.LittleEndian;
                    output.Write(rifx.DataSize);

                    // Copy the data chunk contents from the original RIFX
                    reader.SeekTo(offset + rifx.DataOffset);
                    StreamUtil.Copy(reader, output, rifx.DataSize);
                }

                // Convert it with xWMAEncode
                RunProgramSilently("Helpers/xWMAEncode.exe", "\"" + tempFile + "\" \"" + outPath + "\"", Directory.GetCurrentDirectory());
            }
            finally
            {
                // Delete the temporary XWMA file
                if (File.Exists(tempFile))
                    File.Delete(tempFile);
            }
        }
        /// <summary>
        /// Extracts an XMA sound and converts it to a WAV.
        /// </summary>
        /// <param name="reader">The stream to read from.</param>
        /// <param name="offset">The offset of the data to extract.</param>
        /// <param name="rifx">The RIFX data for the sound.</param>
        /// <param name="outPath">The path of the file to save to.</param>
        public static void ExtractXMAToWAV(EndianReader reader, int offset, RIFX rifx, string outPath)
        {
            // Create a temporary file to write an XMA to
            string tempFile = Path.GetTempFileName();

            try
            {
                using (EndianWriter output = new EndianWriter(File.OpenWrite(tempFile), EndianFormat.BigEndian))
                {
                    // Generate an XMA header
                    // ADAPTED FROM wwisexmabank - I DO NOT TAKE ANY CREDIT WHATSOEVER FOR THE FOLLOWING CODE.
                    // See http://hcs64.com/vgm_ripping.html for more information
                    output.Write(0x52494646); // 'RIFF'
                    output.EndianType = EndianFormat.LittleEndian;
                    output.Write(rifx.DataSize + 0x34);
                    output.EndianType = EndianFormat.BigEndian;
                    output.Write(RIFFFormat.WAVE);

                    // Generate the 'fmt ' chunk
                    output.Write(0x666D7420); // 'fmt '
                    output.EndianType = EndianFormat.LittleEndian;
                    output.Write(0x20);
                    output.Write((short)0x165); // WAVE_FORMAT_XMA
                    output.Write((short)16);    // 16 bits per sample
                    output.Write((short)0);     // encode options **
                    output.Write((short)0);     // largest skip
                    output.Write((short)1);     // # streams
                    output.Write((byte)0);      // loops
                    output.Write((byte)3);      // encoder version
                    output.Write(0);            // bytes per second **
                    output.Write(rifx.SampleRate); // sample rate
                    output.Write(0);            // loop start
                    output.Write(0);            // loop end
                    output.Write((byte)0);      // subframe loop data
                    output.Write((byte)rifx.ChannelCount); // channels
                    output.Write((short)0x0002);// channel mask

                    // 'data' chunk
                    output.EndianType = EndianFormat.BigEndian;
                    output.Write(0x64617461); // 'data'
                    output.EndianType = EndianFormat.LittleEndian;
                    output.Write(rifx.DataSize);

                    // Copy the data chunk contents from the original RIFX
                    reader.SeekTo(offset + rifx.DataOffset);
                    StreamUtil.Copy(reader, output, rifx.DataSize);

                    // END ADAPTED CODE
                }

                // Convert it with towav
                RunProgramSilently("Helpers/towav.exe", "\"" + Path.GetFileName(tempFile) + "\"", Path.GetDirectoryName(tempFile));

                // Move the WAV to the destination path
                if (File.Exists(outPath))
                    File.Delete(outPath);
                File.Move(Path.ChangeExtension(tempFile, "wav"), outPath);
            }
            finally
            {
                // Delete the temporary XMA file
                if (File.Exists(tempFile))
                    File.Delete(tempFile);
            }
        }
示例#41
0
		public override void Write(EndianWriter s)
		{
			s.Write(Directory);
			s.Write(Files.Count);
			foreach (string str in Files.Keys)
			{
				List<string> files = Files[str];
				s.Write(str);
				s.Write(files.Count);
				foreach (string file in files)
					s.Write(file);
			}
		}