예제 #1
0
        static private System.Collections.Generic.SortedList <System.UInt64, System.IntPtr> ReadFile(System.IO.BinaryReader binaryReader, AddressLibrary.Header header)
        {
            var offsets = new System.Collections.Generic.SortedList <System.UInt64, System.IntPtr>(header.AddressCount);

            System.UInt64 identifier;
            System.UInt64 offset;

            System.UInt64 previousIdentifier = 0;
            System.UInt64 previousOffset     = 0;

            for (var index = 0; index < header.AddressCount; index++)
            {
                var type           = binaryReader.ReadByte();
                var identifierType = type & 0xF;
                var offsetType     = type >> 4;

                switch ((AddressLibrary.ReadTypes)identifierType)
                {
                case AddressLibrary.ReadTypes.ReadUInt64:
                {
                    identifier = binaryReader.ReadUInt64();

                    break;
                }

                case AddressLibrary.ReadTypes.Add1:
                {
                    identifier = previousIdentifier + 1;

                    break;
                }

                case AddressLibrary.ReadTypes.AddReadByte:
                {
                    identifier = previousIdentifier + binaryReader.ReadByte();

                    break;
                }

                case AddressLibrary.ReadTypes.SubtractReadByte:
                {
                    identifier = previousIdentifier - binaryReader.ReadByte();

                    break;
                }

                case AddressLibrary.ReadTypes.AddReadUInt16:
                {
                    identifier = previousIdentifier + binaryReader.ReadUInt16();

                    break;
                }

                case AddressLibrary.ReadTypes.SubtractReadUInt16:
                {
                    identifier = previousIdentifier - binaryReader.ReadUInt16();

                    break;
                }

                case AddressLibrary.ReadTypes.ReadUInt16:
                {
                    identifier = binaryReader.ReadUInt16();

                    break;
                }

                case AddressLibrary.ReadTypes.ReadUInt32:
                {
                    identifier = binaryReader.ReadUInt32();

                    break;
                }

                default:
                {
                    try
                    {
                        throw new System.InvalidOperationException($"{nameof(AddressLibrary)}: Unexpected {nameof(identifierType)} encountered, {identifierType}.");
                    }
                    catch (System.InvalidOperationException invalidOperationException)
                    {
                        Log.Information($"{invalidOperationException}");

                        throw;
                    }
                }
                }

                var temporaryOffset = (offsetType & 8) != 0 ? previousOffset / (System.UInt64)header.PointerSize : previousOffset;

                switch ((AddressLibrary.ReadTypes)(offsetType & 7))
                {
                case AddressLibrary.ReadTypes.ReadUInt64:
                {
                    offset = binaryReader.ReadUInt64();

                    break;
                }

                case AddressLibrary.ReadTypes.Add1:
                {
                    offset = temporaryOffset + 1;

                    break;
                }

                case AddressLibrary.ReadTypes.AddReadByte:
                {
                    offset = temporaryOffset + binaryReader.ReadByte();

                    break;
                }

                case AddressLibrary.ReadTypes.SubtractReadByte:
                {
                    offset = temporaryOffset - binaryReader.ReadByte();

                    break;
                }

                case AddressLibrary.ReadTypes.AddReadUInt16:
                {
                    offset = temporaryOffset + binaryReader.ReadUInt16();

                    break;
                }

                case AddressLibrary.ReadTypes.SubtractReadUInt16:
                {
                    offset = temporaryOffset - binaryReader.ReadUInt16();

                    break;
                }

                case AddressLibrary.ReadTypes.ReadUInt16:
                {
                    offset = binaryReader.ReadUInt16();

                    break;
                }

                case AddressLibrary.ReadTypes.ReadUInt32:
                {
                    offset = binaryReader.ReadUInt32();

                    break;
                }

                default:
                {
                    try
                    {
                        throw new System.InvalidOperationException($"{nameof(AddressLibrary)}: Unexpected {nameof(offsetType)} encountered, {offsetType}.");
                    }
                    catch (System.InvalidOperationException invalidOperationException)
                    {
                        Log.Information($"{invalidOperationException}");

                        throw;
                    }
                }
                }

                if ((offsetType & 8) != 0)
                {
                    offset *= (System.UInt64)header.PointerSize;
                }

                offsets.Add(identifier, new System.IntPtr((System.Int64)offset));

                previousIdentifier = identifier;
                previousOffset     = offset;
            }

            return(offsets);
        }
예제 #2
0
        static private AddressLibrary.Header ReadHeader(System.IO.BinaryReader binaryReader, System.Int32 versionMajor, System.Int32 versionMinor, System.Int32 versionBuild, System.Int32 versionPrivate)
        {
            var header = new AddressLibrary.Header();

            header.Format = binaryReader.ReadInt32();

            if (header.Format != 1)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.Format)} encountered, {header.Format}. Expected 1");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.VersionMajor = binaryReader.ReadInt32();

            if (header.VersionMajor != versionMajor)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.VersionMajor)} encountered, {header.VersionMajor}. Expected {versionMajor}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.VersionMinor = binaryReader.ReadInt32();

            if (header.VersionMinor != versionMinor)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.VersionMinor)} encountered, {header.VersionMinor}. Expected {versionMinor}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.VersionBuild = binaryReader.ReadInt32();

            if (header.VersionBuild != versionBuild)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.VersionBuild)} encountered, {header.VersionBuild}. Expected {versionBuild}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.VersionPrivate = binaryReader.ReadInt32();

            if (header.VersionPrivate != versionPrivate)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.VersionPrivate)} encountered, {header.VersionPrivate}. Expected {versionPrivate}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.NameLength = binaryReader.ReadInt32();
            header.Name       = new System.String(binaryReader.ReadChars(header.NameLength));

            if (header.Name != Main.MainModuleName)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.Name)} encountered, {header.Name}. Expected {Main.MainModuleName}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.PointerSize  = binaryReader.ReadInt32();
            header.AddressCount = binaryReader.ReadInt32();

            return(header);
        }