Example #1
0
        public override void Write(Stream output, IDirectory inputDirectory)
        {
            BinaryWriter writer = new BinaryWriter(output, Encoding.ASCII, true);

            const int sbpHeaderSize = 8;
            int entityHeaderSize = Entries.Count * SbpEntry.HeaderSize;
            int headerSize = sbpHeaderSize + entityHeaderSize;

            long headerPosition = output.Position;
            output.Position += headerSize;
            output.AlignWrite(16, 0x00);

            foreach (var entry in Entries)
            {
                entry.WriteData(output, inputDirectory);
                output.AlignWrite(16, 0x00);
            }

            long endPosition = output.Position;

            output.Position = headerPosition;
            writer.Write(0x4C504253); // SBPL
            writer.Write(Convert.ToByte(Entries.Count));
            writer.Write(Convert.ToUInt16(headerSize));
            writer.Write((byte)0x00);

            foreach (var entry in Entries)
            {
                entry.Write(output);
            }

            output.Position = endPosition;
        }
Example #2
0
        public override void Write(Stream output, IDirectory inputDirectory)
        {
            const uint xorMask1 = 0x41441043;
            const uint xorMask2 = 0x11C22050;
            const uint xorMask3 = 0xD05608C3;
            const uint xorMask4 = 0x532C7319;
            const int headerSize = 32;
            int shift = (Flags & 0x800) > 0 ? 12 : 10;
            int alignment = 1 << shift;

            BinaryWriter writer = new BinaryWriter(output, Encoding.Default, true);
            long headerPosition = output.Position;
            output.Skip(headerSize);
            long tableOffset = output.Position;
            output.Skip(8 * Entries.Count);
            //long unknownTableOffset = output.Position;
            //output.Skip(16 * UnknownEntries.Count);

            output.AlignWrite(alignment, 0x00);
            long dataOffset = output.Position;
            ulong[] sections = new ulong[Entries.Count];
            for (int i = 0; i < Entries.Count; i++)
            {
                QarEntry entry = Entries[i];
                entry.CalculateHash();
                ulong section = (ulong) (output.Position >> shift) << 40
                                | (entry.Hash & 0xFF) << 32
                                | entry.Hash >> 32 & 0xFFFFFFFFFF;
                sections[i] = section;
                entry.Write(output, inputDirectory);
                output.AlignWrite(alignment, 0x00);
            }
            long endPosition = output.Position;
            uint endPositionHead = (uint) (endPosition >> shift);

            output.Position = headerPosition;
            writer.Write(QarMagicNumber); // SQAR
            writer.Write(Flags ^ xorMask1);
            writer.Write((uint)Entries.Count ^ xorMask2);
            writer.Write(xorMask3); // unknown count (not saved in the xml and output directory)
            writer.Write(endPositionHead ^ xorMask4);
            writer.Write((uint)dataOffset ^ xorMask1);
            writer.Write(1 ^ xorMask1);
            writer.Write(0 ^ xorMask2);

            output.Position = tableOffset;
            byte[] encryptedSectionsData = EncryptSections(sections);
            writer.Write(encryptedSectionsData);

            output.Position = endPosition;
        }
 public void Write(Stream output)
 {
     BinaryWriter writer = new BinaryWriter(output, Encoding.Default, true);
     long headerPosition = output.Position;
     output.Position += HeaderSize;
     foreach (var staticProperty in StaticProperties)
     {
         staticProperty.Write(output);
     }
     uint staticDataSize = (uint) (output.Position - headerPosition);
     foreach (var dynamicProperty in DynamicProperties)
     {
         dynamicProperty.Write(output);
     }
     long endPosition = output.Position;
     uint dataSize = (uint) (endPosition - headerPosition);
     output.Position = headerPosition;
     writer.Write(HeaderSize);
     writer.Write(Unknown1);
     writer.WriteZeros(2); // padding1
     writer.Write(MagicNumber);
     writer.Write(Address);
     writer.WriteZeros(4); // padding2
     writer.Write(Unknown2);
     writer.WriteZeros(4);
     writer.Write(Version);
     writer.Write(ClassNameHash);
     writer.Write(Convert.ToUInt16(StaticProperties.Count()));
     writer.Write(Convert.ToUInt16(DynamicProperties.Count()));
     writer.Write((int) HeaderSize);
     writer.Write(staticDataSize);
     writer.Write(dataSize);
     output.AlignWrite(16, 0x00);
     //writer.WriteZeros(12);
     output.Position = endPosition;
 }
Example #4
0
        public void Write(Stream output)
        {
            BinaryWriter writer = new BinaryWriter(output, Encoding.Default, true);
            long headerPosition = output.Position;
            output.Position += HeaderSize;
            foreach (var foxEntity in Entities)
            {
                foxEntity.Write(output);
            }
            int offsetHashMap = (int) output.Position;
            foreach (var foxStringLookupLiteral in StringLookupLiterals)
            {
                // TODO: Write the encrypted file name.
                if (string.IsNullOrEmpty(foxStringLookupLiteral.Literal) == false)
                    foxStringLookupLiteral.Write(output);
            }

            output.AlignWrite(16, 0x00);
            writer.Write(new byte[] {0x00, 0x00, 0x65, 0x6E, 0x64});
            output.AlignWrite(16, 0x00);

            long endPosition = output.Position;
            output.Position = headerPosition;
            int entityCount = Entities.Count();
            writer.Write(MagicNumber1);
            writer.Write(MagicNumber2);
            writer.Write(entityCount);
            writer.Write(offsetHashMap);
            writer.Write(HeaderSize);
            writer.WriteZeros(12);
            output.Position = endPosition;
        }