void RestoreBuffCtx(BufferContext value)
 {
     this.buffer = value.buffSv;
     this.code   = value.chrSv;
     this.cCol   = value.cColSv;
     this.lNum   = value.lNumSv;
 }
Ejemplo n.º 2
0
        private void TryInclude(string fName)
        {
            if (fName == null)
            {
                throw new ParserErrorException("{0} : Line: {1} : Row: {2} : Include error, /include, no filename", this.buffer.FileName, yyline, yycol);
            }

            try
            {
                /* Trim any leading and trailing whitespaces and " */
                fName = fName.Trim();
                char[] charsToTrim = { '\"', '\'' };
                fName = fName.Trim(charsToTrim);

                BufferContext savedCtx = MkBuffCtx();
                if (!Path.IsPathRooted(fName))
                {
                    /* Handle relative search path for the new file. */
                    fName = Path.Combine(Path.GetDirectoryName(this.buffer.FileName), fName);
                }
                var stream = new FileStream(fName, FileMode.Open);
                SetSource(stream);
                errorHandler.reportInformation(string.Format("{0} : Line: {1} : Row: {2} : Included file \"{3}\" opened", this.buffer.FileName, yyline, yycol, fName));
                buffStack.Push(savedCtx); // Don't push until file open succeeds!
                /* Push the new stream to a separate stack so it can be properly disposed. */
                streamStack.Push(stream);
            }
            catch
            {
                throw new ParserErrorException("{0} : Line: {1} : Row: {2} : Include error, /include, could not open file \"{3}\"", this.buffer.FileName, yyline, yycol, fName);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Returns a representation of the current buffer's members
        ///   and their locations. The caller may build a UI that lets
        ///   the user navigate to them quickly.
        /// </summary>
        public CurrentFileMembersAsTreeResponse GetCurrentFileMembersAsTree(CurrentFileMembersRequest request)
        {
            var context = new BufferContext(request, this._parser);

            var typesDefinedInThisFile = context.ParsedContent
                                         .UnresolvedFile.TopLevelTypeDefinitions;

            return(new CurrentFileMembersAsTreeResponse(typesDefinedInThisFile, context.Document));
        }
Ejemplo n.º 4
0
        public GetContextResponse GetContextResponse(TestCommandRequest request)
        {
            string methodName = null;

            var bufferContext = new BufferContext(request, _parser);
            var node          = bufferContext.NodeCurrentlyUnderCursor;

            TypeDeclaration      type = null;
            NamespaceDeclaration namespaceDeclaration = null;

            if (node != null)
            {
                var method = (MethodDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is MethodDeclaration);
                if (method != null)
                {
                    methodName = method.Name;
                }
                type = (TypeDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is TypeDeclaration);
                namespaceDeclaration = (NamespaceDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is NamespaceDeclaration);
            }

            if (type == null)
            {
                var tree = bufferContext.ParsedContent.SyntaxTree;
                type = (TypeDeclaration)tree.DescendantsAndSelf.FirstOrDefault(n => n is TypeDeclaration);
                namespaceDeclaration = (NamespaceDeclaration)tree.DescendantsAndSelf.FirstOrDefault(n => n is NamespaceDeclaration);
            }

            string typeName = type.Name;

            if (namespaceDeclaration != null)
            {
                typeName = namespaceDeclaration.FullName + "." + typeName;
            }

            var project   = _solution.ProjectContainingFile(request.FileName);
            var directory = new FileInfo(project.FileName).Directory.FullName;

            var assemblyName = "\"" +
                               Path.Combine(directory, "bin", "Debug", project.ProjectContent.FullAssemblyName + ".dll")
                               + "\"";

            return(new GetContextResponse
            {
                AssemblyName = assemblyName,
                TypeName = typeName,
                MethodName = methodName
            });
        }
Ejemplo n.º 5
0
        public static void ReadDocument(PwDatabase database, Stream stream, byte[] protectedStreamKey, byte[] expectedHashOfHeader)
        {
            var context = new BufferContext(database, new CryptoRandomStream(CrsAlgorithm.Salsa20, protectedStreamKey));

            // Deserialisation will occur into the database already in context.
            RuntimeTypeModel.Default.Deserialize(stream, null, typeof(PwDatabaseBuffer), new SerializationContext {
                Context = context
            });

            if (expectedHashOfHeader.Length > 0 &&
                !KeePassLib.Utility.MemUtil.ArraysEqual(context.HeaderHash, expectedHashOfHeader))
            {
                throw new IOException(KeePassLib.Resources.KLRes.FileCorrupted);
            }
        }
Ejemplo n.º 6
0
        public IEnumerable <QuickFix> GetCurrentFileMembersAsFlatWithoutAccessModifiers(CurrentFileMembersRequest request)
        {
            var context = new BufferContext(request, this._parser);

            var result = new List <QuickFix>();


            foreach (var item in context.ParsedContent.UnresolvedFile.TopLevelTypeDefinitions)
            {
                result.Add(new QuickFix()
                {
                    FileName    = item.Region.FileName
                    , Line      = item.Region.BeginLine
                    , Column    = item.Region.BeginColumn
                    , EndLine   = item.Region.EndLine
                    , EndColumn = item.Region.EndColumn
                    , Text      = item.Name
                });
            }

            var members = context.ParsedContent.UnresolvedFile.TopLevelTypeDefinitions
                          .SelectMany(x => x.Members);



            foreach (var item in members)
            {
                var ambience = new CSharpAmbience();
                ambience.ConversionFlags = ConversionFlags.ShowParameterList | ConversionFlags.ShowParameterNames;
                var memberTitle = ambience.ConvertSymbol(item.Resolve(context.ResolveContext));

                var qf = new QuickFix()
                {
                    FileName    = item.Region.FileName
                    , Line      = item.Region.BeginLine
                    , Column    = item.Region.BeginColumn
                    , EndLine   = item.Region.EndLine
                    , EndColumn = item.Region.EndColumn
                    , Text      = memberTitle
                };

                result.Add(qf);
            }

            return(result.OrderBy(x => x.Text));
        }
Ejemplo n.º 7
0
        GetFileRegions(Request request)
        {
            var context = new BufferContext(request, this._parser);

            var declarationCollector = new GetDirectivesAstVisitor();

            context.ParsedContent.SyntaxTree
            .AcceptVisitor(declarationCollector);

            var regions = declarationCollector.Directives
                          .Where(d => d.Type == PreProcessorDirectiveType.Region ||
                                 d.Type == PreProcessorDirectiveType.Endregion)
                          .Select(d => QuickFix.ForFirstLineInRegion
                                      (d.GetRegion(), context.Document));

            return(new QuickFixResponse(regions));
        }
Ejemplo n.º 8
0
		void RestoreBuffCtx(BufferContext value)
		{
			this.buffer = value.buffSv;
			this.code = value.chrSv;
			this.cCol = value.cColSv;
			this.lNum = value.lNumSv;
		}
Ejemplo n.º 9
0
 /// <summary>
 /// This method restores the buffer value and allied
 /// scanner state from the given context record value.
 /// </summary>
 void RestoreBuffCtx(BufferContext value)
 {
     this.buffer = value.buffSv;
     this.chr = value.chrSv;
     this.cNum = value.cNumSv;
     this.lNum = value.lNumSv;
     this.lineStartNum = value.startSv;
 } 
Ejemplo n.º 10
0
 public NamedProtectedBinaryListBuffer(IEnumerable <KeyValuePair <String, ProtectedBinary> > binaries, int binariesCount, BufferContext context)
 {
     mNamedBinaries = new List <NamedProtectedBinaryBuffer>(binariesCount);
     foreach (var kvp in binaries)
     {
         NamedProtectedBinaryBuffer namedProtectedBinaryBuffer;
         if (!context.BinaryPool.TryGetValue(kvp.Value, out namedProtectedBinaryBuffer))
         {
             // Hasn't been put in the pool yet, so create it
             namedProtectedBinaryBuffer = new NamedProtectedBinaryBuffer(kvp);
             context.BinaryPool.Add(kvp.Value, namedProtectedBinaryBuffer);
         }
         mNamedBinaries.Add(namedProtectedBinaryBuffer);
     }
 }
Ejemplo n.º 11
0
            public ProtectedStandardFieldDictionaryBuffer(IEnumerable <KeyValuePair <String, ProtectedString> > entryStrings, int entryStringCount, BufferContext context,
                                                          out List <KeyValuePair <String, ProtectedString> > customFields) // Perf optimisation - return the custom fields so we don't have to determine them again
                : base(entryStringCount)
            {
                customFields = new List <KeyValuePair <string, ProtectedString> >(entryStringCount);

                var database = context.Database;

                foreach (var kvp in entryStrings)
                {
                    var field = GetField(kvp.Key);

                    if (field.HasValue)
                    {
                        // Logic from KdbxFile.Write

                        bool?overrideProtect = null;
                        // Adjust memory protection setting (which might be different
                        // from the database default, e.g. due to an import which
                        // didn't specify the correct setting)
                        switch (field.Value)
                        {
                        case StandardField.Title:
                            overrideProtect = database.MemoryProtection.ProtectTitle;
                            break;

                        case StandardField.UserName:
                            overrideProtect = database.MemoryProtection.ProtectUserName;
                            break;

                        case StandardField.Password:
                            overrideProtect = database.MemoryProtection.ProtectPassword;
                            break;

                        case StandardField.Url:
                            overrideProtect = database.MemoryProtection.ProtectUrl;
                            break;

                        case StandardField.Notes:
                            overrideProtect = database.MemoryProtection.ProtectNotes;
                            break;
                        }

                        AddStringField(field.Value, kvp.Value, overrideProtect);
                    }
                    else
                    {
                        customFields.Add(kvp);
                    }
                }
            }