Example #1
0
 public Psf Load(Stream Stream)
 {
     EntryDictionary = new Dictionary<string, object>();
     Header = Stream.ReadStruct<HeaderStruct>();
     Entries = Stream.ReadStructVector<EntryStruct>(Header.NumberOfPairs);
     KeysStream = Stream.SliceWithLength(Header.KeyTable);
     ValuesStream = Stream.SliceWithLength(Header.ValueTable);
     foreach (var Entry in Entries)
     {
         var Key = KeysStream.ReadStringzAt(Entry.KeyOffset);
         var ValueStream = ValuesStream.SliceWithLength(Entry.ValueOffset, Entry.ValueSize);;
         switch (Entry.DataType)
         {
             case DataType.Binary: EntryDictionary[Key] = ValueStream.ReadAll(); break;
             case DataType.Int: EntryDictionary[Key] = ValueStream.ReadStruct<int>(); break;
             case DataType.Text: EntryDictionary[Key] = ValueStream.ReadStringz(-1, Encoding.UTF8); break;
             default: throw(new NotImplementedException());
         }
     }
     return this;
 }
Example #2
0
        public PGF Load(Stream FileStream)
        {
            this.Header = FileStream.ReadStruct<HeaderStruct>();

            if (this.Header.Revision >= 3)
            {
                this.HeaderExtraRevision3 = FileStream.ReadStruct<HeaderRevision3Struct>();
            }

            FileStream.ReadStructVector(ref DimensionTable, Header.TableDimLength);
            FileStream.ReadStructVector(ref XAdjustTable, Header.TableXAdjustLength);
            FileStream.ReadStructVector(ref YAdjustTable, Header.TableYAdjustLength);
            FileStream.ReadStructVector(ref AdvanceTable, Header.TableAdvanceLength);

            PackedShadowCharMap = FileStream.ReadBytes(BitsToBytesHighAligned(Header.TableShadowMapLength * Header.TableShadowMapBpe));

            if (Header.Revision == 3)
            {
                FileStream.ReadStructVector(ref CharmapCompressionTable1, HeaderExtraRevision3.TableCompCharMapLength1);
                FileStream.ReadStructVector(ref CharmapCompressionTable2, HeaderExtraRevision3.TableCompCharMapLength2);
            }

            PackedCharMap = FileStream.ReadBytes(BitsToBytesHighAligned(Header.TableCharMapLength * Header.TableCharMapBpe));
            PackedCharPointerTable = FileStream.ReadBytes(BitsToBytesHighAligned(Header.TableCharPointerLength * Header.TableCharPointerBpe));

            /*
            int BytesLeft = (int)(FileStream.Length - FileStream.Position);
            charData = new byte[BytesLeft];
            FileStream.Read(charData, 0, BytesLeft);
            */

            CharData = FileStream.ReadBytes((int)(FileStream.Length - FileStream.Position));

            var NumberOfCharacters = Header.TableCharPointerLength;

            CharMap = new int[Header.FirstGlyph + Header.LastGlyph + 1];
            CharPointer = new int[NumberOfCharacters];
            Glyphs = new Glyph[NumberOfCharacters];
            ReverseCharMap = new Dictionary<int, int>();
            ShadowCharMap = new Dictionary<int, int>();
            ReverseShadowCharMap = new Dictionary<int, int>();

            foreach (var Pair in BitReader.FixedBitReader(PackedShadowCharMap, Header.TableShadowMapBpe))
            {
                var UnicodeIndex = (int)Pair.Key + Header.FirstGlyph;
                var GlyphIndex = (int)Pair.Value;
                ShadowCharMap[UnicodeIndex] = GlyphIndex;
                ReverseShadowCharMap[GlyphIndex] = UnicodeIndex;
            }

            foreach (var Pair in BitReader.FixedBitReader(PackedCharMap, Header.TableCharMapBpe))
            {
                var UnicodeIndex = (int)Pair.Key + Header.FirstGlyph;
                var GlyphIndex = (int)Pair.Value;
                CharMap[UnicodeIndex] = GlyphIndex;
                ReverseCharMap[GlyphIndex] = UnicodeIndex;
            }

            foreach (var Pair in BitReader.FixedBitReader(PackedCharPointerTable, Header.TableCharPointerBpe))
            {
                CharPointer[Pair.Key] = (int)Pair.Value;
            }

            /*
            for (int n = 0; n < NumberOfCharacters; n++)
            {
                Glyphs[n] = new Glyph().Read(this, n);
            }
            */

            Console.WriteLine(this.Header.FontName);

            /*
            Console.WriteLine(this.header.fontName);
            for (int n = 0; n < 300; n++)
            {
                Console.WriteLine(GetGlyphId((char)n));
            }
            */

            return this;
        }
Example #3
0
        public Xex LoadHeader(Stream XexStream)
        {
            Header = XexStream.ReadStruct<HeaderStruct>();
            var OptionalHeaders = XexStream.ReadStructVector<OptionalHeader>(Header.OptionalHeaderCount);
            Console.WriteLine("{0:X}", XexStream.Position);
            InfoList = new Dictionary<OptionalHeader.Ids, ulong>();
            foreach (var OptionalHeader in OptionalHeaders)
            {
                //Console.WriteLine("{0}: 0x{1:X}", OptionalHeader.Id, (uint)OptionalHeader.Data);
                //InfoList[OptionalHeader.Id] = OptionalHeader.Data;
                InfoList.Add(OptionalHeader.Id, OptionalHeader.Data);

                switch (OptionalHeader.Id)
                {
                    case Xex.OptionalHeader.Ids.OriginalPEName:
                        this.OriginalPeName = LoadChunk(XexStream, OptionalHeader.Data).ReadStringz(Encoding: Encoding.UTF8);
                        break;
                    case Xex.OptionalHeader.Ids.LANKey:
                        this.LanKey = XexStream.SliceWithLength(OptionalHeader.Data, 0x10).ReadAll();
                        break;
                    case Xex.OptionalHeader.Ids.DefaultStackSize:
                        this.DefaultStackSize = OptionalHeader.Data;
                        break;
                    case Xex.OptionalHeader.Ids.ChecksumTimestamp:
                        this.ChecksumTimestamp = XexStream.SliceWithLength(OptionalHeader.Data).ReadStruct<ChecksumTimestampStruct>();
                        break;
                    case Xex.OptionalHeader.Ids.ImageBaseAddress:
                        this.ImageBaseAddress = OptionalHeader.Data;
                        break;
                    case Xex.OptionalHeader.Ids.EntryPoint:
                        this.EntryPoint = OptionalHeader.Data;
                        break;
                    case Xex.OptionalHeader.Ids.StaticLibraries:
                        this.StaticLibs = LoadChunk(XexStream, OptionalHeader.Data).ReadStructVectorUntilTheEndOfStream<StaticLib>();
                        foreach (var StaticLib in StaticLibs)
                        {
                            Console.WriteLine("StaticLib: {0}", StaticLib.ToStringDefault());
                        }
                        break;
                    case Xex.OptionalHeader.Ids.ImportLibraries:
                        {
                            var ImportLibrariesStream = LoadChunk(XexStream, OptionalHeader.Data);
                            var TextLength = (uint)ImportLibrariesStream.ReadStruct<uint_be>();
                            var LibraryCount = (uint)ImportLibrariesStream.ReadStruct<uint_be>();
                            var TextStream = ImportLibrariesStream.ReadStream(TextLength);

                            var LibraryNames = new String[LibraryCount];
                            for (int n = 0; n < LibraryCount; n++)
                            {
                                LibraryNames[n] = TextStream.ReadStringz(AllowEndOfStream: false);
                                Console.WriteLine("ImportLib: {0}", LibraryNames[n]);
                            }

                            var ChunkUnk1 = ReadChunkIncludingTheSize(ImportLibrariesStream);
                            var ImportAddressList = ReadChunkIncludingTheSize(ImportLibrariesStream);
                            Console.Error.WriteLine("@TODO: Xex.OptionalHeader.Ids.ImportLibraries");
                        }
                        break;
                    case Xex.OptionalHeader.Ids.TLSInfo:
                        {
                            this.TLSInfo = XexStream.SliceWithLength(OptionalHeader.Data).ReadStruct<TLSInfoStruct>();
                        }
                        break;
                    default:
                        Console.WriteLine("{0}: 0x{1:X}", OptionalHeader.Id, (uint)OptionalHeader.Data);
                        break;
                }
            }
            PeStream = XexStream.SliceWithLength(Header.PeDataOffset);
            Pe = new Pe().LoadHeader(PeStream);

            Console.WriteLine("SecurityInfoOffset: {0:X}", (uint)Header.SecurityInfoOffset);
            var SecurityStream = LoadChunk(XexStream, Header.SecurityInfoOffset);
            var NumberOfSections = (ushort)SecurityStream.ReadStruct<ushort_be>();
            Console.WriteLine("NumberOfSections: {0:X}", NumberOfSections);

            return this;
        }