Example #1
0
        private void Read(EndianAwareBinaryReader reader, bool keepImageOpen)
        {
            this.reader = reader;
            this.dosHeader.Read(reader);
            if ((dosHeader.PEHeaderPointer - reader.BaseStream.Position) < 0)
            {
                throw new BadImageFormatException();
            }
            byte[] dosStub = new byte[msDosStubProgram.Length];
            reader.Read(dosStub, 0, dosStub.Length);

            /* *
             * ToDo: Handle alternate stub programs that are valid.
             * */
            if (!msDosStubProgram.SequenceEqual(dosStub))
            {
                throw new BadImageFormatException();
            }

            reader.BaseStream.Seek(dosHeader.PEHeaderPointer, SeekOrigin.Begin);
            coffHeader.Read(reader);
            extendedHeader.Read(reader);
            CoffSection[] sections = new CoffSection[this.coffHeader.SectionCount];
            for (int i = 0; i < sections.Length; i++)
            {
                sections[i] = CoffSection.Read(reader, keepImageOpen);
            }
            this.sections      = new ControlledCollection <CoffSection>(sections);
            this.keepImageOpen = keepImageOpen;
        }
Example #2
0
 internal void Initialize(IControlledCollection <TMetadata> collection)
 {
     if (collection == null) /* If we get 'nothing' from the metadata */
     {
         collection = new ControlledCollection <TMetadata>(new TMetadata[0]);
     }
     this.metadataCollection = collection;
     this.state           = METADATA_SOURCE_COLLECTION;
     this.declarationData = new TDeclaration[collection.Count];
 }
        public GrammarBreakdown(IGrammarSymbol[] symbols)
        {
            /* *
             * Obtain a sequence of the elements which are constant items within a series of other constants (i.e.: enum field members.)
             * */
            var symbolSets = (from symbol in symbols
                              let itemSymbol = symbol as IGrammarConstantItemSymbol
                                               where itemSymbol != null
                                               select itemSymbol).ToArray();
            //Obtain the distinct container tokens.
            var tokenSets = (from symbol in symbolSets
                             select symbol.Source).Distinct().ToArray();

            /* *
             * Obtain the container tokens along with the individual elements within them relative to the symbols provided.
             * */
            var tokenSymbolSets = from entry in tokenSets
                                  join itemSymbol in symbolSets on entry equals itemSymbol.Source into entrySymbols
                                  select new { Entry = entry, Items = entrySymbols.ToArray() };
            //Obtain the tokens which are just a constant by themselves.
            var constantEntries = (from symbol in symbols
                                   let constantEntry = symbol as IGrammarConstantEntrySymbol
                                                       where constantEntry != null
                                                       select constantEntry).ToArray();
            //Obtain the rules within the symbols.
            var ruleEntries = (from symbol in symbols
                               let ruleEntry = symbol as IGrammarRuleSymbol
                                               where ruleEntry != null
                                               select ruleEntry).ToArray();
            //Obtain the capture-style token symbols.
            var tokenEntries = (from symbol in symbols
                                let tokenEntry = symbol as IGrammarTokenSymbol
                                                 where tokenEntry != null &&
                                                 (!(tokenEntry is IGrammarConstantEntrySymbol)) &&
                                                 (!(tokenEntry is IGrammarConstantItemSymbol))
                                                 select tokenEntry).ToArray();
            var literalSeriesTokens = new Dictionary <IOilexerGrammarTokenEntry, TokenElements>();

            foreach (var tokenSymbolSet in tokenSymbolSets)
            {
                literalSeriesTokens.Add(tokenSymbolSet.Entry, new TokenElements(tokenSymbolSet.Items));
            }
            this.LiteralSeriesTokens = new ControlledDictionary <IOilexerGrammarTokenEntry, TokenElements>(literalSeriesTokens);
            ConstantTokens           = new ControlledCollection <IGrammarConstantEntrySymbol>(constantEntries);
            CaptureTokens            = new ControlledCollection <IGrammarTokenSymbol>(tokenEntries);
            Rules  = new ControlledCollection <IGrammarRuleSymbol>(ruleEntries);
            Tokens = new ControlledCollection <IOilexerGrammarTokenEntry>((
                                                                              from constant in ConstantTokens
                                                                              select constant.Source).Concat(
                                                                              from captureToken in CaptureTokens
                                                                              select captureToken.Source).Concat(
                                                                              from literalToken in LiteralSeriesTokens.Keys
                                                                              select literalToken).Distinct().ToArray());
        }
Example #4
0
 public void Dispose()
 {
     DisposeReader();
     if (this.sections != null)
     {
         foreach (var section in this.sections)
         {
             section.Dispose();
         }
         this.sections = null;
     }
 }
 public CaptureTokenLiteralStructuralItem(ILiteralTokenItem source)
 {
     this.sources = new ControlledCollection <ILiteralTokenItem>();
     this.Add(source);
     if (source.IsFlag.HasValue && source.IsFlag.Value)
     {
         this.ResultType = ResultedDataType.FlagEnumerationItem;
     }
     else
     {
         this.ResultType = ResultedDataType.EnumerationItem;
     }
 }
Example #6
0
 protected override sealed IControlledCollection <IProductionRuleSource> OnGetSources()
 {
     return(sources ?? (this.sources = new ControlledCollection <IProductionRuleSource>(this.references.Cast <IProductionRuleSource>().ToArray())));
 }
 public CaptureTokenGeneralStructuralItem(IEnumerable <ITokenSource> items)
 {
     this.sources = new ControlledCollection <ITokenSource>(items.ToArray());
 }
 public CaptureTokenCharRangeStructuralItem(IEnumerable <ICharRangeTokenItem> sources)
 {
     this.sources    = new ControlledCollection <ICharRangeTokenItem>(sources.ToArray());
     this.ResultType = ResultedDataType.Character;
 }
 public CaptureTokenCharRangeStructuralItem(ICharRangeTokenItem source)
 {
     this.sources = new ControlledCollection <ICharRangeTokenItem>();
     this.sources.baseList.Add(source);
     this.ResultType = ResultedDataType.Character;
 }