You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to open source and I am trying to create a analyzer for detecting the parameter values used in crypto Algorithm invocations. And I dont know if the current built-in roslyn flowAnalyzers like dataFlow/ValueContentAnalysis are sufficient enough to do so.
Just a wild example of what I am trying to achieve:
// For this Example i want my analyzer to show that the Node of Type ArgumentSyntax has a possible value of 32.
How do I achieve this? I tried the ValueContentAnalysis but was'nt able to get the values. Maybe I did something wrong can you help?
//Code I have written so far.
usingSystem.Collections.Immutable;usingAnalyzer.Utilities;usingMicrosoft.CodeAnalysis;usingMicrosoft.CodeAnalysis.CSharp;usingMicrosoft.CodeAnalysis.CSharp.Syntax;usingMicrosoft.CodeAnalysis.Diagnostics;usingMicrosoft.CodeAnalysis.FlowAnalysis;usingMicrosoft.CodeAnalysis.FlowAnalysis.DataFlow;usingMicrosoft.CodeAnalysis.FlowAnalysis.DataFlow.PointsToAnalysis;usingMicrosoft.CodeAnalysis.FlowAnalysis.DataFlow.ValueContentAnalysis;usingMicrosoft.CodeAnalysis.Operations;[DiagnosticAnalyzer(LanguageNames.CSharp)]publicclassMyCustomAnalyzer:DiagnosticAnalyzer{publicconststringDiagnosticId="MyCustomAnalyzer";privatestaticreadonlyLocalizableStringTitle="Title of the analyzer";privatestaticreadonlyLocalizableStringMessageFormat="Message format of the analyzer";privatestaticreadonlyLocalizableStringDescription="Description of the analyzer";privateconststringCategory="Naming";privatestaticreadonlyDiagnosticDescriptorRule=newDiagnosticDescriptor(DiagnosticId,Title,MessageFormat,Category,DiagnosticSeverity.Warning,isEnabledByDefault:true,description:Description);publicoverrideImmutableArray<DiagnosticDescriptor>SupportedDiagnostics=>ImmutableArray.Create(Rule);publicDiagnosticDescriptorAlwaysTrueFalseOrNullRule{get;privateset;}publicoverridevoidInitialize(AnalysisContextcontext){context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze|GeneratedCodeAnalysisFlags.ReportDiagnostics);context.EnableConcurrentExecution();context.RegisterSyntaxNodeAction(AnalyzeInvocations,SyntaxKind.InvocationExpression);}publicstaticvoidAnalyzeInvocations(SyntaxNodeAnalysisContextcontext){varcontainingSymbol=context.ContainingSymbol;varcompilation=context.Compilation;varsemanticModel=context.SemanticModel;varwellKnownTypeProvider=WellKnownTypeProvider.GetOrCreate(compilation);varmethodNode=context.Node.Ancestors().OfType<MethodDeclarationSyntax>().First();varcfg=ControlFlowGraph.Create(methodNode,semanticModel);varvalueContent=ValueContentAnalysis.TryGetOrComputeResult(cfg,containingSymbol,wellKnownTypeProvider,newAnalyzerOptions(new()),Rule,PointsToAnalysisKind.Complete,InterproceduralAnalysisKind.ContextSensitive,default);foreach(varchildincontext.Node.DescendantNodes().OfType<ArgumentSyntax>()){vardata=valueContent[OperationKind.Invocation,child];// breakpoint to see output}}}
Any slight help or suggestion is highly appreciated. Thanks.
The text was updated successfully, but these errors were encountered:
Hello everyone . Need Help!!
I am new to open source and I am trying to create a analyzer for detecting the parameter values used in crypto Algorithm invocations. And I dont know if the current built-in roslyn flowAnalyzers like dataFlow/ValueContentAnalysis are sufficient enough to do so.
Just a wild example of what I am trying to achieve:
// For this Example i want my analyzer to show that the Node of Type ArgumentSyntax has a possible value of 32.
How do I achieve this? I tried the ValueContentAnalysis but was'nt able to get the values. Maybe I did something wrong can you help?
//Code I have written so far.
Any slight help or suggestion is highly appreciated. Thanks.
The text was updated successfully, but these errors were encountered: