예제 #1
0
 /// <summary>
 /// Process the reference data to a stream
 /// </summary>
 /// <param name="s">Stream</param>
 public override void WriteHeader(IO.EndianWriter s)
 {
     s.Write(elements.Count);
     headerOffset = s.PositionUnsigned;             // we'll come back here and write the element's offset
     s.Write(-1);
     s.Write(0);
 }
예제 #2
0
 /// <summary>
 /// Stream the field to a buffer
 /// </summary>
 /// <param name="output"></param>
 public override void Write(IO.EndianWriter output)
 {
     if (StringType == StringType.Normal)
     {
         output.Write(Value, false);
     }
     else if (StringType == StringType.Unicode)
     {
         output.WriteUnicodeString(Value, Length);
     }
     else if (StringType == StringType.Ascii)
     {
         output.Write(Value, Length);
     }
     else if (StringType == StringType.Halo1Profile)
     {
         output.WriteUnicodeString(Value, 12);
     }
     else if (StringType == StringType.Halo2Profile)
     {
         output.WriteUnicodeString(Value, 16);
     }
     else if (StringType == StringType.CString)
     {
         output.Write(Value, true);
     }
 }
예제 #3
0
            public override void Write(IO.EndianWriter stream)
            {
                Compiler comp = stream.Owner as Compiler;

                uint elementsAddress = 0;
                int  flags           = (
                    (tagRef.IsNonResolving ? 1 << 1 : 0)
                    );

                if (tagRef.Elements.Count > 1)
                {
                    elementsAddress = stream.PositionUnsigned;
                    foreach (string i in tagRef.Elements)
                    {
                        stream.WriteTag(i);
                    }

                    comp.MarkLocationFixup(tagRef.Name, stream, true);
                    stream.Write(flags);
                    stream.Write((int)-1);
                    stream.WritePointer(elementsAddress);
                }
                else
                {
                    comp.MarkLocationFixup(tagRef.Name, stream, true);
                    stream.Write(flags);
                    stream.WriteTag(tagRef.Elements[0]);
                    stream.Write((int)0);
                }
            }
예제 #4
0
 void WriteHeader(IO.EndianWriter s, IO.ITagStream ts)
 {
     headerGroupTag.Write(s);
     s.Write((int)state.Attribute.Version - 1);
     s.Write(expectedCount);
     s.Write(state.RuntimeSizes.SizeOf);                 // sizeof a single block would go here but its not actually required
 }
예제 #5
0
        public void Write(IO.EndianWriter s)
        {
            //Flags = EnumFlags.Remove(Flags, FileFlags.EncryptHeader | FileFlags.EncryptContent);

            s.Write(Flags, FileFlagsStreamer.Instance);
            s.Write((ushort)kVersion);

            Write(s, EnumFlags.Test(Flags, FileFlags.EncryptHeader), Header, MediaHeader.kSizeOf);
            GenerateHash();

            if (EnumFlags.Test(Flags, FileFlags.CompressContent))
            {
                using (var cs = new CompressedStream(true))
                    using (var ms = new System.IO.MemoryStream(kMaxContentSize))
                        using (var sout = new IO.EndianWriter(ms, Shell.EndianFormat.Big))
                        {
                            sout.Write(Content);
                            sout.Seek(0);

                            cs.InitializeFromStream(ms);
                            cs.Compress();

                            Write(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs,
                                  userKey: Header.DataCryptKey, writeLeftovers: WriteLeftovers);
                        }
            }
            else
            {
                s.Write(Content);
            }
        }
예제 #6
0
            public void Write(IO.EndianWriter s)
            {
                var xmbContext = s.UserData as XmbFileContext;

                s.Write(RootElementIndex);
                XmbVariantSerialization.Write(s, NameVariant);
                XmbVariantSerialization.Write(s, InnerTextVariant);
                if (xmbContext.PointerSize == Shell.ProcessorSize.x64)
                {
                    s.Pad32();
                }

                #region Attributes header
                s.Write(Attributes.Count);
                if (xmbContext.PointerSize == Shell.ProcessorSize.x64)
                {
                    s.Pad32();
                }
                mAttributesOffsetPos = s.PositionPtr;
                s.WriteVirtualAddress(Values.PtrHandle.InvalidHandle32);
                #endregion

                #region Children header
                s.Write(ChildrenIndices.Count);
                if (xmbContext.PointerSize == Shell.ProcessorSize.x64)
                {
                    s.Pad32();
                }
                mChildrenOffsetPos = s.PositionPtr;
                s.WriteVirtualAddress(Values.PtrHandle.InvalidHandle32);
                #endregion
            }
예제 #7
0
        /// <summary>
        /// Write the header for this pool to a stream for future re-initializing
        /// and usage, storing things such as the configuration, count, etc
        /// </summary>
        /// <param name="s"></param>
        public void WriteHeader(IO.EndianWriter s)
        {
            Contract.Requires(s != null);

//			Configuration.Write(s);
            s.Write(Count);
            s.Write(Size);
        }
            public uint WriteFields(IO.EndianWriter stream, Compiler comp)
            {
                uint fieldsAddress = stream.PositionUnsigned;

                WriteFieldsRecursive(stream, comp, mFields);

                stream.Write(comp.TypeIndexTerminator); stream.Write((int)0); stream.Write((int)0);
                return(fieldsAddress);
            }
예제 #9
0
        protected void AlignMemoryStream(int k_alignment)
        {
            int align = k_alignment - (MemoryStream.Length % k_alignment);

            if (align != k_alignment)
            {
                MemoryStream.Write(new byte[align]);
            }
        }
        void Write(IO.EndianWriter s, float value)
        {
            bool not_zero = value != 0f;

            s.Write(not_zero);

            if (not_zero)
            {
                s.Write(value);
            }
        }
예제 #11
0
        private void TransformGfxToSwfFileInternal(byte[] eraFileEntryBuffer, string fullPath, uint bufferSignature)
        {
            uint swf_signature = ResourceUtils.GfxHeaderToSwf(bufferSignature);

            using (var fs = System.IO.File.Create(fullPath + ".swf"))
                using (var out_s = new IO.EndianWriter(fs, Shell.EndianFormat.Little))
                {
                    out_s.Write(swf_signature);
                    out_s.Write(eraFileEntryBuffer, sizeof(uint), eraFileEntryBuffer.Length - sizeof(uint));
                }
        }
예제 #12
0
 /// <summary>Stream the pointer data to a buffer</summary>
 /// <param name="s"></param>
 /// <remarks>Number of bytes written depends on <see cref="Is64bit"/></remarks>
 public void Write(IO.EndianWriter s)
 {
     if (!Is64bit)
     {
         s.Write(this.u32);
     }
     else
     {
         s.Write(this.u64);
     }
 }
            public override void Write(IO.EndianWriter stream)
            {
                Compiler comp = stream.Owner as Compiler;

                comp.MarkLocationFixup(glob.Name, stream, false);
                stream.Write(glob.Name);
                stream.Write(glob.type.Opcode);
                stream.Write((short)(glob.IsInternal ? 1 : 0));                //stream.Write(ushort.MinValue);
                stream.Write(uint.MaxValue);
                stream.Write(uint.MinValue);
            }
예제 #14
0
파일: test.cs 프로젝트: mloc/scc
 public override void Write(IO.EndianWriter s)
 {
     s.Write((ushort)engine);
     s.Write(ushort.MinValue);
     #region FileNames
     s.Write(files.Count);
     foreach (string str in files)
     {
         s.Write(str, true);
     }
     #endregion
 }
예제 #15
0
        public void Write(IO.EndianWriter s)
        {
            var context = s.UserData as XmbFileContext;

            s.Write(kSignature);
            if (context.PointerSize == Shell.ProcessorSize.x64)
            {
                s.Pad32();
            }

            #region Elements header
            s.Write(mElements.Count);
            if (context.PointerSize == Shell.ProcessorSize.x64)
            {
                s.Pad32();
            }
            var elements_offset_pos = s.MarkVirtualAddress(context.PointerSize);
            #endregion

            #region Pool header
            s.Write(mPool.Size);
            if (context.PointerSize == Shell.ProcessorSize.x64)
            {
                s.Pad32();
            }
            var pool_offset_pos = s.MarkVirtualAddress(context.PointerSize);
            #endregion

            if (context.PointerSize == Shell.ProcessorSize.x64)
            {
                s.Pad64();
            }

            var elements_offset = s.PositionPtr;
            foreach (var e in mElements)
            {
                e.Write(s);
            }
            foreach (var e in mElements)
            {
                e.WriteAttributes(s);
                e.WriteChildren(s);
            }

            var pool_offset = s.PositionPtr;
            mPool.Write(s);

            s.Seek((long)elements_offset_pos);
            s.WriteVirtualAddress(elements_offset);
            s.Seek((long)pool_offset_pos);
            s.WriteVirtualAddress(pool_offset);
        }
예제 #16
0
        public void Create()
        {
            Debug.Assert.If(OutputStream != null,
                            "Can't create a definition file when we're not initialized for that mode");

            OutputStream.WriteTag(Ext);
            groupTag.Write(OutputStream);
            OutputStream.Write((uint)engine);
            OutputStream.Write(version);
            OutputStream.Write(header);

            Create(def);
        }
예제 #17
0
        internal uint RamAddMemory(string data, out int length)
        {
            uint offset = RamMemory.PositionUnsigned;

            byte[] bytes = Util.ByteStringToArray(data);
            RamMemory.Write(bytes);
            length = bytes.Length;

            //int align = 4 - (RamMemory.Length % 4);
            //if (align != 4) RamMemory.Write(new byte[align]);

            return(offset);
        }
        static byte[] GenerateSoundFile(byte[] buffer, byte[] footer)
        {
            byte[] sound_file;

            using (MemoryStream ms = new MemoryStream())
                using (IO.EndianWriter write = new IO.EndianWriter(ms))
                {
                    write.Write("RIFF", "RIFF".Length);
                    write.Write(uint.MinValue);
                    write.Write("WAVEdata", "WAVEdata".Length);
                    write.Write(uint.MinValue);

                    write.Write(buffer);

                    if (footer != null)
                    {
                        write.Write(footer);
                    }

                    int size = (int)ms.Length;

                    // Write file size to RIFF header
                    write.Seek(4);
                    write.Write(size - 8);

                    // Write data size to WAVE header
                    write.Seek(16);
                    write.Write(buffer.Length);

                    sound_file = ms.ToArray();
                }

            return(sound_file);
        }
예제 #19
0
 /// <summary>
 /// Stream the field to a buffer
 /// </summary>
 /// <param name="output"></param>
 public override void Write(IO.EndianWriter output)
 {
     if (Internal != null)
     {
         output.Write(Internal);
     }
     else
     {
         byte[] temp = new byte[Value];
         temp.Initialize();
         output.Write(temp);
         temp = null;
     }
 }
 /// <summary>Build debug streams which foreign native code can easily interop with</summary>
 /// <param name="offsets">Buffer containing the offsets of the string values in <paramref name="buffer"/></param>
 /// <param name="buffer">Buffer containing the string values</param>
 /// <param name="pack">If true, the strings are stored as null terminated strings, else in 128 character strings</param>
 public void ToDebugStream(IO.EndianWriter offsets, IO.EndianWriter buffer, bool pack)
 {
     foreach (var kv in m_set.Set)
     {
         offsets.Write(buffer.Position);
         if (pack)
         {
             buffer.Write(kv.Value, true);
         }
         else
         {
             buffer.Write(kv.Value, mOwner.Definition.Description.ValueBufferSize);
         }
     }
 }
예제 #21
0
            public override void Write(IO.EndianWriter stream)
            {
                Compiler comp = stream.Owner as Compiler;

                TagBlock tb = new TagBlock((Import.TagBlock)tagStruct.Block);

                tb.Write(stream);

                comp.MarkLocationFixup(tagStruct.Name, stream, false);

                stream.Write(tagStruct.Name);
                stream.WriteTag(tagStruct.GroupTag);
                stream.Write(tagStruct.Block.DisplayName);
                stream.WritePointer(tb.RuntimeAddress);
            }
예제 #22
0
        void StreamCompressedContent(IO.EndianStream s)
        {
            if (s.IsReading)
            {
                using (var cs = new CompressedStream(true))
                {
                    Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs,
                           userKey: Header.DataCryptKey, streamLeftovers: StreamLeftovers);

                    cs.Decompress();
                    Content = cs.UncompressedData;
                }
            }
            else if (s.IsWriting)
            {
                using (var cs = new CompressedStream(true))
                    using (var ms = new System.IO.MemoryStream(kMaxContentSize))
                        using (var sout = new IO.EndianWriter(ms, s.ByteOrder))
                        {
                            sout.Write(Content);
                            sout.Seek(0);

                            cs.InitializeFromStream(ms);
                            cs.Compress();

                            Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs,
                                   userKey: Header.DataCryptKey, streamLeftovers: StreamLeftovers);
                        }
            }
        }
예제 #23
0
 /// <summary>
 /// Stream the field to a buffer
 /// </summary>
 /// <param name="output"></param>
 public override void Write(IO.EndianWriter output)
 {
     byte[] temp = new byte[Value];
     temp.Initialize();
     output.Write(temp);
     temp = null;
 }
예제 #24
0
        void WriteLeftovers(IO.EndianWriter ew)
        {
//			WriteRandomBlocks(ew);

            if (ew.BaseStream.Length < kMaxContentSize)
            {
                int padding_bytes_count = System.Math.Min(PaddingBytes.Length, kMaxContentSize - (int)(ew.BaseStream.Length));
                ew.Write(PaddingBytes, 0, padding_bytes_count);
            }

            if (ew.BaseStream.Length < kMaxContentSize)
            {
                byte[] zero = new byte[kMaxContentSize - (int)(ew.BaseStream.Length)];
                Array.Clear(zero, 0, zero.Length);
                ew.Write(zero, 0, zero.Length);
            }
        }
예제 #25
0
        internal void RamToStream(IO.EndianWriter stream, uint reference, int length)
        {
            var ms = RamMemory.BaseStream as System.IO.MemoryStream;

            byte[] buffer = new byte[length];
            ms.Seek(reference, System.IO.SeekOrigin.Begin);
            ms.Read(buffer, 0, length);

            stream.Write(buffer);

            int align = 4 - (stream.Length % 4);

            if (align != 4)
            {
                stream.Write(new byte[align]);
            }
        }
예제 #26
0
            public override void Write(IO.EndianWriter stream)
            {
                Compiler comp = stream.Owner as Compiler;

                comp.MarkLocationFixup(tagData.Name, stream, false);

                int flags = (
                    (tagData.IsNeverStreamed ? 1 << 0 : 0) |
                    (tagData.IsTextData ? 1 << 1 : 0) |
                    (tagData.IsDebugData ? 1 << 2 : 0)
                    );

                stream.Write(tagData.Name);
                stream.Write(flags);
                stream.Write(tagData.MaxSize);
                stream.Write((int)0);                 // should come back later and write the address of the proc via a lookup table from a xml or text file
            }
예제 #27
0
            public override void Write(IO.EndianWriter stream)
            {
                Compiler comp = stream.Owner as Compiler;

                uint elementsAddress = stream.PositionUnsigned;

                // write string list's element's addresses
                foreach (uint i in stringList.Elements)
                {
                    stream.Write(i);
                }

                comp.MarkLocationFixup(stringList.Name, stream, true);

                stream.Write(stringList.Elements.Count);
                stream.WritePointer(elementsAddress);
            }
예제 #28
0
        /// <summary>Only used for Interop situations where explicit lengths are needed for cases (like enumeration) in unmanaged code</summary>
        /// <param name="s"></param>
        public void WriteStringByteLengths(IO.EndianWriter s)
        {
            Contract.Requires(s != null);

            foreach (string str in mPool)
            {
                s.Write(CalculateStringByteLength(str));
            }
        }
예제 #29
0
        /// <summary>Write the string values to a stream</summary>
        /// <param name="s"></param>
        public void WriteStrings(IO.EndianWriter s)
        {
            Contract.Requires(s != null);

            foreach (string str in mPool)
            {
                s.Write(str, mEncoding);
            }
        }
 /// <summary>Build debug streams which foreign native code can easily interop with</summary>
 /// <param name="offsets">Buffer containing the offsets of the string values in <paramref name="buffer"/></param>
 /// <param name="buffer">Buffer containing the string values</param>
 /// <param name="pack">If true, the strings are stored as null terminated strings, else in 128 character strings</param>
 public void ToDebugStream(IO.EndianWriter offsets, IO.EndianWriter buffer, bool pack)
 {
     foreach (var set in m_sets)
     {
         foreach (var kv in set.Set)
         {
             offsets.Write(buffer.Position);
             if (pack)
             {
                 buffer.Write(kv.Value, true);
             }
             else
             {
                 buffer.Write(kv.Value, 128);
             }
         }
     }
 }