예제 #1
0
        internal static Record ReadRecord(
            BinaryReader binaryReader,
            RecordContext context,
            RecordNumber expectedRecord)
        {
            RecordReader reader = new RecordReader(binaryReader);
            if (expectedRecord != RecordNumber.None &&
                reader.RecordNumber != expectedRecord)
            {
                throw new InvalidDataException(string.Format(
                    "Expecting record {0}, but got record {1}.",
                    expectedRecord, reader.RecordNumber));
            }

            Record r;
            switch (reader.RecordNumber)
            {
                case RecordNumber.LibraryHeader:
                    r = new LibraryHeaderRecord(reader, context);
                    break;
                case RecordNumber.LibraryEnd:
                    r = new LibraryEndRecord(reader, context);
                    break;
                case RecordNumber.ALIAS:
                    r = new ALIASRecord(reader, context);
                    break;
                case RecordNumber.CEXTDEF:
                    r = new CEXTDEFRecord(reader, context);
                    break;
                case RecordNumber.COMDAT:
                case RecordNumber.COMDAT32:
                    r = new COMDATRecord(reader, context);
                    break;
                case RecordNumber.COMDEF:
                    r = new COMDEFRecord(reader, context);
                    break;
                case RecordNumber.COMENT:
                    r = new CommentRecord(reader, context);
                    break;
                case RecordNumber.EXTDEF:
                    r = new EXTDEFRecord(reader, context);
                    break;
                case RecordNumber.FIXUPP:
                case RecordNumber.FIXUPP32:
                    r = new FixupRecord(reader, context);
                    break;
                case RecordNumber.GRPDEF:
                    r = new GRPDEFRecord(reader, context);
                    break;
                case RecordNumber.LCOMDEF:
                    r = new LCOMDEFRecord(reader, context);
                    break;
                case RecordNumber.LEDATA:
                case RecordNumber.LEDATA32:
                    r = new LEDATARecord(reader, context);
                    break;
                case RecordNumber.LEXTDEF:
                case RecordNumber.LEXTDEF32:
                    r = new LEXTDEFRecord(reader, context);
                    break;
                case RecordNumber.LHEADR:
                    r = new LHEADRRecord(reader, context);
                    break;
                case RecordNumber.LIDATA:
                case RecordNumber.LIDATA32:
                    r = new LIDATARecord(reader, context);
                    break;
                case RecordNumber.LNAMES:
                    r = new ListOfNamesRecord(reader, context);
                    break;
                case RecordNumber.LPUBDEF:
                case RecordNumber.LPUBDEF32:
                    r = new LPUBDEFRecord(reader, context);
                    break;
                case RecordNumber.MODEND:
                    r = new MODENDRecord(reader, context);
                    break;
                case RecordNumber.PUBDEF:
                case RecordNumber.PUBDEF32:
                    r = new PUBDEFRecord(reader, context);
                    break;
                case RecordNumber.SEGDEF:
                case RecordNumber.SEGDEF32:
                    r = new SEGDEFRecord(reader, context);
                    break;
                case RecordNumber.THEADR:
                    r = new THEADRRecord(reader, context);
                    break;
                default:
                    r = new UnknownRecord(reader, context);
                    break;
            }

            // TODO: check all bytes are consumed.
            // ...

            // Update RecordContext.LastRecord. This is necessary so that
            // a FIXUPP record knows which record to fix up.
            if (context != null)
            {
                context.LastRecord = r;
            }

            return r;
        }
예제 #2
0
        internal static Record ReadRecord(
            BinaryReader binaryReader,
            RecordContext context,
            RecordNumber expectedRecord)
        {
            RecordReader reader = new RecordReader(binaryReader);

            if (expectedRecord != RecordNumber.None &&
                reader.RecordNumber != expectedRecord)
            {
                throw new InvalidDataException(string.Format(
                                                   "Expecting record {0}, but got record {1}.",
                                                   expectedRecord, reader.RecordNumber));
            }

            Record r;

            switch (reader.RecordNumber)
            {
            case RecordNumber.LibraryHeader:
                r = new LibraryHeaderRecord(reader, context);
                break;

            case RecordNumber.LibraryEnd:
                r = new LibraryEndRecord(reader, context);
                break;

            case RecordNumber.ALIAS:
                r = new ALIASRecord(reader, context);
                break;

            case RecordNumber.CEXTDEF:
                r = new CEXTDEFRecord(reader, context);
                break;

            case RecordNumber.COMDAT:
            case RecordNumber.COMDAT32:
                r = new COMDATRecord(reader, context);
                break;

            case RecordNumber.COMDEF:
                r = new COMDEFRecord(reader, context);
                break;

            case RecordNumber.COMENT:
                r = new CommentRecord(reader, context);
                break;

            case RecordNumber.EXTDEF:
                r = new EXTDEFRecord(reader, context);
                break;

            case RecordNumber.FIXUPP:
            case RecordNumber.FIXUPP32:
                r = new FixupRecord(reader, context);
                break;

            case RecordNumber.GRPDEF:
                r = new GRPDEFRecord(reader, context);
                break;

            case RecordNumber.LCOMDEF:
                r = new LCOMDEFRecord(reader, context);
                break;

            case RecordNumber.LEDATA:
            case RecordNumber.LEDATA32:
                r = new LEDATARecord(reader, context);
                break;

            case RecordNumber.LEXTDEF:
            case RecordNumber.LEXTDEF32:
                r = new LEXTDEFRecord(reader, context);
                break;

            case RecordNumber.LHEADR:
                r = new LHEADRRecord(reader, context);
                break;

            case RecordNumber.LIDATA:
            case RecordNumber.LIDATA32:
                r = new LIDATARecord(reader, context);
                break;

            case RecordNumber.LNAMES:
                r = new ListOfNamesRecord(reader, context);
                break;

            case RecordNumber.LPUBDEF:
            case RecordNumber.LPUBDEF32:
                r = new LPUBDEFRecord(reader, context);
                break;

            case RecordNumber.MODEND:
                r = new MODENDRecord(reader, context);
                break;

            case RecordNumber.PUBDEF:
            case RecordNumber.PUBDEF32:
                r = new PUBDEFRecord(reader, context);
                break;

            case RecordNumber.SEGDEF:
            case RecordNumber.SEGDEF32:
                r = new SEGDEFRecord(reader, context);
                break;

            case RecordNumber.THEADR:
                r = new THEADRRecord(reader, context);
                break;

            default:
                r = new UnknownRecord(reader, context);
                break;
            }

            // TODO: check all bytes are consumed.
            // ...

            // Update RecordContext.LastRecord. This is necessary so that
            // a FIXUPP record knows which record to fix up.
            if (context != null)
            {
                context.LastRecord = r;
            }

            return(r);
        }