コード例 #1
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public CEXTDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            int startIndex = context.ExternalNames.Count;

            while (!reader.IsEOF)
            {
                UInt16 nameIndex = reader.ReadIndex();
                if (nameIndex == 0 || nameIndex > context.Names.Count)
                {
                    throw new InvalidDataException("LogicalNameIndex is out of range.");
                }
                UInt16 typeIndex = reader.ReadIndex();

                ExternalNameDefinition def = new ExternalNameDefinition();

                def.Name      = context.Names[nameIndex - 1];
                def.TypeIndex = typeIndex;
                def.DefinedBy = reader.RecordNumber;
                context.ExternalNames.Add(def);
            }
            int endIndex = context.ExternalNames.Count;

            this.Definitions = context.ExternalNames.Slice(
                startIndex, endIndex - startIndex);
        }
コード例 #2
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public GRPDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            this.Definition = new GroupDefinition();

            UInt16 groupNameIndex = reader.ReadIndex();

            if (groupNameIndex == 0 || groupNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("GroupNameIndex is out of range.");
            }
            this.Definition.Name = context.Names[groupNameIndex - 1];

            while (!reader.IsEOF)
            {
                reader.ReadByte(); // 'type' ignored
                UInt16 segmentIndex = reader.ReadIndex();
                if (segmentIndex == 0 || segmentIndex > context.Segments.Count)
                {
                    throw new InvalidDataException("SegmentIndex is out of range.");
                }
                this.Definition.Segments.Add(context.Segments[segmentIndex - 1]);
            }

            context.Groups.Add(Definition);
        }
コード例 #3
0
ファイル: Comments.cs プロジェクト: meloscheng/dos-debugger
        internal WKEXTComment(RecordReader reader)
        {
            var defs = new List <WeakExternalDefinition>();

            while (!reader.IsEOF)
            {
                var def = new WeakExternalDefinition();
                def.WeakExternalIndex      = reader.ReadIndex();
                def.DefaultResolutionIndex = reader.ReadIndex();
                defs.Add(def);
            }
            this.Definitions = defs.ToArray();
            // TODO: add this information into the Context
        }
コード例 #4
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public PUBDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            int baseGroupIndex = reader.ReadIndex();

            if (baseGroupIndex > context.Groups.Count)
            {
                throw new InvalidDataException("GroupIndex is out of range.");
            }
            if (baseGroupIndex > 0)
            {
                this.BaseGroup = context.Groups[baseGroupIndex - 1];
            }

            int baseSegmentIndex = reader.ReadIndex();

            if (baseSegmentIndex > context.Segments.Count)
            {
                throw new InvalidDataException("SegmentIndex is out of range.");
            }
            if (baseSegmentIndex == 0)
            {
                this.BaseFrame = reader.ReadUInt16();
            }
            else
            {
                this.BaseSegment = context.Segments[baseSegmentIndex - 1];
            }

            int startIndex = context.PublicNames.Count;

            while (!reader.IsEOF)
            {
                PublicNameDefinition def = new PublicNameDefinition();
                def.DefinedBy   = reader.RecordNumber;
                def.BaseGroup   = BaseGroup;
                def.BaseSegment = BaseSegment;
                def.BaseFrame   = BaseFrame;
                def.Name        = reader.ReadPrefixedString();
                def.Offset      = (int)reader.ReadUInt16Or32();
                def.TypeIndex   = reader.ReadIndex();
                context.PublicNames.Add(def);
            }
            int endIndex = context.PublicNames.Count;

            this.Definitions = context.PublicNames.Slice(
                startIndex, endIndex - startIndex);
        }
コード例 #5
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public COMDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            int startIndex = context.ExternalNames.Count;

            while (!reader.IsEOF)
            {
                CommunalNameDefinition def = new CommunalNameDefinition();
                def.DefinedBy    = reader.RecordNumber;
                def.Name         = reader.ReadPrefixedString();
                def.TypeIndex    = reader.ReadIndex();
                def.DataType     = reader.ReadByte();
                def.ElementCount = ReadEncodedInteger(reader);
                if (def.DataType == 0x61) // FAR data: count, elemsize
                {
                    def.ElementSize = ReadEncodedInteger(reader);
                }
                else
                {
                    def.ElementSize = 1;
                }
                context.ExternalNames.Add(def);
            }
            int endIndex = context.ExternalNames.Count;

            this.Definitions = context.ExternalNames.Slice(
                startIndex, endIndex - startIndex);
        }
コード例 #6
0
        public SEGDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            SegmentDefinition def = new SegmentDefinition();

            // Read the record.
            byte acbp = reader.ReadByte();
            def.Alignment = GetAlignment(acbp);
            def.Combination = GetCombination(acbp);
            def.IsUse32 = GetUse32(acbp);

            if (def.Alignment == SegmentAlignment.Absolute)
            {
                def.Frame = reader.ReadUInt16();
                def.Offset = reader.ReadByte();
            }

            UInt32 storedLength=reader.ReadUInt16Or32();
            def.Length = GetLength(acbp, storedLength, reader.RecordNumber);

            UInt16 segmentNameIndex = reader.ReadIndex();
            if (segmentNameIndex > context.Names.Count)
                throw new InvalidDataException("SegmentNameIndex is out of range.");
            if (segmentNameIndex > 0)
                def.SegmentName = context.Names[segmentNameIndex - 1];

            UInt16 classNameIndex = reader.ReadIndex();
            if (classNameIndex > context.Names.Count)
                throw new InvalidDataException("ClassNameIndex is out of range.");
            if (classNameIndex > 0)
                def.ClassName = context.Names[classNameIndex - 1];

            UInt16 overlayNameIndex = reader.ReadIndex();
            if (overlayNameIndex > context.Names.Count)
                throw new InvalidDataException("OverlayNameIndex is out of range.");
            if (overlayNameIndex > 0)
                def.OverlayName = context.Names[overlayNameIndex - 1];

            def.Data = new byte[def.Length];
            //def.Fixups = new List<FixupDefinition>();

            this.Definition = def;
            context.Segments.Add(def);
        }
コード例 #7
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public LIDATARecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            this.SegmentIndex = reader.ReadIndex();
            if (SegmentIndex == 0 || SegmentIndex > context.Segments.Count)
            {
                throw new InvalidDataException("SegmentIndex is out of range.");
            }

            this.DataOffset = reader.ReadUInt16Or32();
            this.Data       = reader.ReadToEnd();

            // TODO: parse LIDATA (recursive; a bit messy)
        }
コード例 #8
0
        private FixupThreadDefinition ParseThreadSubrecord(RecordReader reader)
        {
            FixupThreadDefinition thread = new FixupThreadDefinition();

            byte b = reader.ReadByte();

            thread.Kind         = ((b & 0x40) == 0) ? FixupThreadKind.Target : FixupThreadKind.Frame;
            thread.Method       = (byte)((b >> 2) & 3);
            thread.ThreadNumber = (byte)(b & 3);

            if (thread.Method <= 2) // TBD: should be 3 for intel
            {
                thread.IndexOrFrame = reader.ReadIndex();
            }

            thread.IsDefined = true;
            return(thread);
        }
コード例 #9
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public EXTDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            int startIndex = context.ExternalNames.Count;

            while (!reader.IsEOF)
            {
                ExternalNameDefinition def = new ExternalNameDefinition();
                def.Name      = reader.ReadPrefixedString();
                def.TypeIndex = reader.ReadIndex();
                def.DefinedBy = reader.RecordNumber;
                context.ExternalNames.Add(def);
            }
            int endIndex = context.ExternalNames.Count;

            this.Definitions = context.ExternalNames.Slice(
                startIndex, endIndex - startIndex);
        }
コード例 #10
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public LEDATARecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            UInt16 segmentIndex = reader.ReadIndex();

            if (segmentIndex == 0 || segmentIndex > context.Segments.Count)
            {
                throw new InvalidDataException("SegmentIndex is out of range.");
            }
            this.Segment = context.Segments[segmentIndex - 1];

            this.DataOffset = reader.ReadUInt16Or32();
            this.Data       = reader.ReadToEnd(); // TBD: this can be optimized to
                                                  // reduce extra data copy

            // Fill the segment's data.
            if (Data.Length + DataOffset > Segment.Length)
            {
                throw new InvalidDataException("The LEDATA overflows the segment.");
            }

            Array.Copy(Data, 0, Segment.Data, DataOffset, Data.Length);
        }
コード例 #11
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public CEXTDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            int startIndex = context.ExternalNames.Count;
            while (!reader.IsEOF)
            {
                UInt16 nameIndex = reader.ReadIndex();
                if (nameIndex == 0 || nameIndex > context.Names.Count)
                {
                    throw new InvalidDataException("LogicalNameIndex is out of range.");
                }
                UInt16 typeIndex = reader.ReadIndex();

                ExternalNameDefinition def = new ExternalNameDefinition();

                def.Name = context.Names[nameIndex - 1];
                def.TypeIndex = typeIndex;
                def.DefinedBy = reader.RecordNumber;
                context.ExternalNames.Add(def);
            }
            int endIndex = context.ExternalNames.Count;
            this.Definitions = context.ExternalNames.Slice(
                startIndex, endIndex - startIndex);
        }
コード例 #12
0
ファイル: Comments.cs プロジェクト: meloscheng/dos-debugger
 internal WKEXTComment(RecordReader reader)
 {
     var defs = new List<WeakExternalDefinition>();
     while (!reader.IsEOF)
     {
         var def = new WeakExternalDefinition();
         def.WeakExternalIndex = reader.ReadIndex();
         def.DefaultResolutionIndex = reader.ReadIndex();
         defs.Add(def);
     }
     this.Definitions = defs.ToArray();
     // TODO: add this information into the Context
 }
コード例 #13
0
        public SEGDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            SegmentDefinition def = new SegmentDefinition();

            // Read the record.
            byte acbp = reader.ReadByte();

            def.Alignment   = GetAlignment(acbp);
            def.Combination = GetCombination(acbp);
            def.IsUse32     = GetUse32(acbp);

            if (def.Alignment == SegmentAlignment.Absolute)
            {
                def.Frame  = reader.ReadUInt16();
                def.Offset = reader.ReadByte();
            }

            UInt32 storedLength = reader.ReadUInt16Or32();

            def.Length = GetLength(acbp, storedLength, reader.RecordNumber);

            UInt16 segmentNameIndex = reader.ReadIndex();

            if (segmentNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("SegmentNameIndex is out of range.");
            }
            if (segmentNameIndex > 0)
            {
                def.SegmentName = context.Names[segmentNameIndex - 1];
            }

            UInt16 classNameIndex = reader.ReadIndex();

            if (classNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("ClassNameIndex is out of range.");
            }
            if (classNameIndex > 0)
            {
                def.ClassName = context.Names[classNameIndex - 1];
            }

            UInt16 overlayNameIndex = reader.ReadIndex();

            if (overlayNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("OverlayNameIndex is out of range.");
            }
            if (overlayNameIndex > 0)
            {
                def.OverlayName = context.Names[overlayNameIndex - 1];
            }

            def.Data = new byte[def.Length];
            //def.Fixups = new List<FixupDefinition>();

            this.Definition = def;
            context.Segments.Add(def);
        }
コード例 #14
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public PUBDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            int baseGroupIndex = reader.ReadIndex();
            if (baseGroupIndex > context.Groups.Count)
                throw new InvalidDataException("GroupIndex is out of range.");
            if (baseGroupIndex > 0)
                this.BaseGroup = context.Groups[baseGroupIndex - 1];

            int baseSegmentIndex = reader.ReadIndex();
            if (baseSegmentIndex > context.Segments.Count)
                throw new InvalidDataException("SegmentIndex is out of range.");
            if (baseSegmentIndex == 0)
                this.BaseFrame = reader.ReadUInt16();
            else
                this.BaseSegment = context.Segments[baseSegmentIndex - 1];

            int startIndex = context.PublicNames.Count;
            while (!reader.IsEOF)
            {
                PublicNameDefinition def = new PublicNameDefinition();
                def.DefinedBy = reader.RecordNumber;
                def.BaseGroup = BaseGroup;
                def.BaseSegment = BaseSegment;
                def.BaseFrame = BaseFrame;
                def.Name = reader.ReadPrefixedString();
                def.Offset = (int)reader.ReadUInt16Or32();
                def.TypeIndex = reader.ReadIndex();
                context.PublicNames.Add(def);
            }
            int endIndex = context.PublicNames.Count;
            this.Definitions = context.PublicNames.Slice(
                startIndex, endIndex - startIndex);
        }
コード例 #15
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public LIDATARecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            this.SegmentIndex = reader.ReadIndex();
            if (SegmentIndex == 0 || SegmentIndex > context.Segments.Count)
                throw new InvalidDataException("SegmentIndex is out of range.");

            this.DataOffset = reader.ReadUInt16Or32();
            this.Data = reader.ReadToEnd();

            // TODO: parse LIDATA (recursive; a bit messy)
        }
コード例 #16
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public LEDATARecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            UInt16 segmentIndex = reader.ReadIndex();
            if (segmentIndex == 0 || segmentIndex > context.Segments.Count)
            {
                throw new InvalidDataException("SegmentIndex is out of range.");
            }
            this.Segment = context.Segments[segmentIndex - 1];

            this.DataOffset = reader.ReadUInt16Or32();
            this.Data = reader.ReadToEnd(); // TBD: this can be optimized to
                                            // reduce extra data copy

            // Fill the segment's data.
            if (Data.Length + DataOffset > Segment.Length)
                throw new InvalidDataException("The LEDATA overflows the segment.");

            Array.Copy(Data, 0, Segment.Data, DataOffset, Data.Length);
        }
コード例 #17
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
        public GRPDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            this.Definition = new GroupDefinition();

            UInt16 groupNameIndex = reader.ReadIndex();
            if (groupNameIndex == 0 || groupNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("GroupNameIndex is out of range.");
            }
            this.Definition.Name = context.Names[groupNameIndex - 1];

            while (!reader.IsEOF)
            {
                reader.ReadByte(); // 'type' ignored
                UInt16 segmentIndex = reader.ReadIndex();
                if (segmentIndex == 0 || segmentIndex > context.Segments.Count)
                {
                    throw new InvalidDataException("SegmentIndex is out of range.");
                }
                this.Definition.Segments.Add(context.Segments[segmentIndex - 1]);
            }

            context.Groups.Add(Definition);
        }
コード例 #18
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
 public EXTDEFRecord(RecordReader reader, RecordContext context)
     : base(reader, context)
 {
     int startIndex = context.ExternalNames.Count;
     while (!reader.IsEOF)
     {
         ExternalNameDefinition def = new ExternalNameDefinition();
         def.Name = reader.ReadPrefixedString();
         def.TypeIndex = reader.ReadIndex();
         def.DefinedBy = reader.RecordNumber;
         context.ExternalNames.Add(def);
     }
     int endIndex = context.ExternalNames.Count;
     this.Definitions = context.ExternalNames.Slice(
         startIndex, endIndex - startIndex);
 }
コード例 #19
0
        private FixupDefinition ParseFixupSubrecord(RecordReader reader, RecordContext context)
        {
            FixupDefinition fixup = new FixupDefinition();

            byte b1 = reader.ReadByte();
            byte b2 = reader.ReadByte();
            UInt16 w = (UInt16)((b1 << 8) | b2); // big endian

            fixup.Mode = (w & 0x4000) != 0 ? FixupMode.SegmentRelative : FixupMode.SelfRelative;
            fixup.Location = (FixupLocation)((w >> 10) & 0x0F);
            fixup.DataOffset = (UInt16)(w & 0x03FF);

            byte b = reader.ReadByte();
            bool useFrameThread = (b & 0x80) != 0;
            if (useFrameThread)
            {
                int frameNumber = (b >> 4) & 0x3;
                FixupThreadDefinition thread = context.FrameThreads[frameNumber];
                if (!thread.IsDefined)
                    throw new InvalidDataException("Frame thread " + frameNumber + " is not defined.");

                FixupFrame spec = new FixupFrame();
                spec.Method = (FixupFrameMethod)thread.Method;
                spec.IndexOrFrame = thread.IndexOrFrame;
                fixup.Frame = spec;
            }
            else
            {
                FixupFrame spec = new FixupFrame();
                spec.Method = (FixupFrameMethod)((b >> 4) & 7);
                if ((int)spec.Method <= 3)
                {
                    spec.IndexOrFrame = reader.ReadIndex();
                }
                fixup.Frame = spec;
            }

            bool useTargetThread = (b & 0x08) != 0;
            if (useTargetThread)
            {
                bool hasTargetDisplacement = (b & 0x04) != 0;
                int targetNumber = b & 3;
                FixupThreadDefinition thread = context.TargetThreads[targetNumber];
                if (!thread.IsDefined)
                    throw new InvalidDataException("Target thread " + targetNumber + " is not defined.");

                FixupTargetMethod method = (FixupTargetMethod)((int)thread.Method & 3);
                if (hasTargetDisplacement)
                    method |= (FixupTargetMethod)4;

                FixupTarget spec = new FixupTarget();
                spec.Referent = ResolveFixupReferent(context, method, thread.IndexOrFrame);
                if ((int)method <= 3)
                {
                    spec.Displacement = reader.ReadUInt16Or32();
                }
                fixup.Target = spec;
            }
            else
            {
                FixupTargetMethod method = (FixupTargetMethod)(b & 7);
                UInt16 indexOrFrame = reader.ReadIndex();

                FixupTarget spec = new FixupTarget();
                spec.Referent = ResolveFixupReferent(context, method, indexOrFrame);
                if ((int)method <= 3)
                {
                    spec.Displacement = reader.ReadUInt16Or32();
                }
                fixup.Target = spec;
            }
            return fixup;
        }
コード例 #20
0
        private FixupDefinition ParseFixupSubrecord(RecordReader reader, RecordContext context)
        {
            FixupDefinition fixup = new FixupDefinition();

            byte   b1 = reader.ReadByte();
            byte   b2 = reader.ReadByte();
            UInt16 w  = (UInt16)((b1 << 8) | b2); // big endian

            fixup.Mode       = (w & 0x4000) != 0 ? FixupMode.SegmentRelative : FixupMode.SelfRelative;
            fixup.Location   = (FixupLocation)((w >> 10) & 0x0F);
            fixup.DataOffset = (UInt16)(w & 0x03FF);

            byte b = reader.ReadByte();
            bool useFrameThread = (b & 0x80) != 0;

            if (useFrameThread)
            {
                int frameNumber = (b >> 4) & 0x3;
                FixupThreadDefinition thread = context.FrameThreads[frameNumber];
                if (!thread.IsDefined)
                {
                    throw new InvalidDataException("Frame thread " + frameNumber + " is not defined.");
                }

                FixupFrame spec = new FixupFrame();
                spec.Method       = (FixupFrameMethod)thread.Method;
                spec.IndexOrFrame = thread.IndexOrFrame;
                fixup.Frame       = spec;
            }
            else
            {
                FixupFrame spec = new FixupFrame();
                spec.Method = (FixupFrameMethod)((b >> 4) & 7);
                if ((int)spec.Method <= 3)
                {
                    spec.IndexOrFrame = reader.ReadIndex();
                }
                fixup.Frame = spec;
            }

            bool useTargetThread = (b & 0x08) != 0;

            if (useTargetThread)
            {
                bool hasTargetDisplacement   = (b & 0x04) != 0;
                int  targetNumber            = b & 3;
                FixupThreadDefinition thread = context.TargetThreads[targetNumber];
                if (!thread.IsDefined)
                {
                    throw new InvalidDataException("Target thread " + targetNumber + " is not defined.");
                }

                FixupTargetMethod method = (FixupTargetMethod)((int)thread.Method & 3);
                if (hasTargetDisplacement)
                {
                    method |= (FixupTargetMethod)4;
                }

                FixupTarget spec = new FixupTarget();
                spec.Referent = ResolveFixupReferent(context, method, thread.IndexOrFrame);
                if ((int)method <= 3)
                {
                    spec.Displacement = reader.ReadUInt16Or32();
                }
                fixup.Target = spec;
            }
            else
            {
                FixupTargetMethod method       = (FixupTargetMethod)(b & 7);
                UInt16            indexOrFrame = reader.ReadIndex();

                FixupTarget spec = new FixupTarget();
                spec.Referent = ResolveFixupReferent(context, method, indexOrFrame);
                if ((int)method <= 3)
                {
                    spec.Displacement = reader.ReadUInt16Or32();
                }
                fixup.Target = spec;
            }
            return(fixup);
        }
コード例 #21
0
        private FixupThreadDefinition ParseThreadSubrecord(RecordReader reader)
        {
            FixupThreadDefinition thread = new FixupThreadDefinition();

            byte b = reader.ReadByte();
            thread.Kind = ((b & 0x40) == 0) ? FixupThreadKind.Target : FixupThreadKind.Frame;
            thread.Method = (byte)((b >> 2) & 3);
            thread.ThreadNumber = (byte)(b & 3);

            if (thread.Method <= 2) // TBD: should be 3 for intel
                thread.IndexOrFrame = reader.ReadIndex();

            thread.IsDefined = true;
            return thread;
        }
コード例 #22
0
ファイル: Records.cs プロジェクト: meloscheng/dos-debugger
 public COMDEFRecord(RecordReader reader, RecordContext context)
     : base(reader, context)
 {
     int startIndex = context.ExternalNames.Count;
     while (!reader.IsEOF)
     {
         CommunalNameDefinition def = new CommunalNameDefinition();
         def.DefinedBy = reader.RecordNumber;
         def.Name = reader.ReadPrefixedString();
         def.TypeIndex = reader.ReadIndex();
         def.DataType = reader.ReadByte();
         def.ElementCount = ReadEncodedInteger(reader);
         if (def.DataType == 0x61) // FAR data: count, elemsize
             def.ElementSize = ReadEncodedInteger(reader);
         else
             def.ElementSize = 1;
         context.ExternalNames.Add(def);
     }
     int endIndex = context.ExternalNames.Count;
     this.Definitions = context.ExternalNames.Slice(
         startIndex, endIndex - startIndex);
 }