Added a new rule
This commit is contained in:
Коммит
a9f08ca280
|
@ -0,0 +1,44 @@
|
|||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- '**.cs'
|
||||
- '**.csproj'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths:
|
||||
- '**.cs'
|
||||
- '**.csproj'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
|
||||
name: analyze
|
||||
runs-on: windows-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: ['csharp']
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32414.318
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpAssemblyExtractor", "CSharpAssemblyExtractor\CSharpAssemblyExtractor.csproj", "{A6445594-BFE8-4A89-9E17-15D0761F9100}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A6445594-BFE8-4A89-9E17-15D0761F9100}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A6445594-BFE8-4A89-9E17-15D0761F9100}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A6445594-BFE8-4A89-9E17-15D0761F9100}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A6445594-BFE8-4A89-9E17-15D0761F9100}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {82F07C1C-F0CC-4150-AF8A-102E3C3A20B2}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="C:\Users\pvillads\.nuget\packages\icsharpcode.decompiler\8.0.0.7007-preview1\contentFiles\any\netstandard2.0\Humanizer\LICENSE" />
|
||||
<Content Remove="C:\Users\pvillads\.nuget\packages\icsharpcode.decompiler\8.0.0.7007-preview1\contentFiles\any\netstandard2.0\Pattern Matching.html" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ICSharpCode.Decompiler" Version="8.0.0.7007-preview1" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,101 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CSharpAssemblyExtractor
|
||||
{
|
||||
using ICSharpCode.Decompiler;
|
||||
using ICSharpCode.Decompiler.CSharp;
|
||||
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
|
||||
using ICSharpCode.Decompiler.CSharp.Syntax;
|
||||
using ICSharpCode.Decompiler.DebugInfo;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using System.CommandLine;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
var assemblyFilenameOption = new Option<FileInfo>(
|
||||
new[] { "--assembly", "-a" },
|
||||
description: "The assembly to decompile into XML.");
|
||||
|
||||
var verboseOption = new Option<bool>(
|
||||
new[] { "--verbose", "-v" },
|
||||
description: "Provide output as code is running.");
|
||||
|
||||
var outputOption = new Option<DirectoryInfo>(
|
||||
new[] { "--output", "-o" },
|
||||
description: "The root directory where the XML files will be written. The directory must exist.");
|
||||
|
||||
var rootCommand = new RootCommand
|
||||
{
|
||||
assemblyFilenameOption,
|
||||
verboseOption,
|
||||
outputOption,
|
||||
};
|
||||
|
||||
rootCommand.Description = "Command to extract C# code into XML suitable for reasoning.";
|
||||
|
||||
rootCommand.SetHandler((FileInfo assemblyFile, bool verbose, DirectoryInfo outputDirectory) =>
|
||||
{
|
||||
if (assemblyFile == null)
|
||||
{
|
||||
Console.Error.WriteLine("No assembly provided to extract");
|
||||
return;
|
||||
}
|
||||
|
||||
if (outputDirectory == null)
|
||||
{
|
||||
Console.Error.WriteLine("No target directory provided");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up the preferences for the decompilation of the IL into source.
|
||||
var settings = new DecompilerSettings()
|
||||
{
|
||||
AlwaysUseBraces = true,
|
||||
ShowXmlDocumentation = true
|
||||
};
|
||||
settings.CSharpFormattingOptions.IndentationString = " ";
|
||||
|
||||
var decompiler = new CSharpDecompiler(assemblyFile.FullName, settings);
|
||||
|
||||
// Traverse all the types in the assembly
|
||||
foreach (var typeDefinition in decompiler.TypeSystem.MainModule.TopLevelTypeDefinitions)
|
||||
{
|
||||
if (typeDefinition.Name.StartsWith("<"))
|
||||
continue;
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Console.WriteLine($"Extracting {typeDefinition.FullName}.");
|
||||
}
|
||||
var syntaxTree = decompiler.DecompileType(typeDefinition.FullTypeName);
|
||||
|
||||
// This is needed to get the locations correctly set in the AST.
|
||||
StringWriter w = new StringWriter();
|
||||
|
||||
var q = new TextWriterTokenWriter(w);
|
||||
q.IndentationString = " ";
|
||||
|
||||
TokenWriter tokenWriter = q;
|
||||
|
||||
tokenWriter = TokenWriter.WrapInWriterThatSetsLocationsInAST(tokenWriter);
|
||||
syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions));
|
||||
var source = w.ToString();
|
||||
|
||||
var generator = new XmlGeneratorVisitor(assemblyFile.FullName, source);
|
||||
syntaxTree.AcceptVisitor(generator);
|
||||
|
||||
File.WriteAllText(Path.Combine(outputDirectory.FullName, typeDefinition.FullTypeName.Name) + ".xml", generator.Document.ToString());
|
||||
}
|
||||
},
|
||||
assemblyFilenameOption, verboseOption, outputOption);
|
||||
|
||||
return rootCommand.Invoke(args);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -9,9 +9,7 @@
|
|||
{
|
||||
for $c in /*
|
||||
for $m in $c//Method
|
||||
for $exprs in ($m//OrExpression/BooleanLiteralExpression
|
||||
, $m//AndExpression/BooleanLiteralExpression)
|
||||
where $exprs
|
||||
for $exprs in $m//(OrExpression | AndExpression)/BooleanLiteralExpression
|
||||
order by $m/Name ascending
|
||||
return <Res Artifact='{$c/@Artifact}' Method='{$m/@Name}'
|
||||
StartLine='{$exprs/@StartLine}' StartCol='{$exprs/@StartCol}'
|
||||
|
|
|
@ -222,7 +222,14 @@ namespace XppReasoningWpf
|
|||
var parts = name.Split(':');
|
||||
var kind = parts[0];
|
||||
|
||||
xquery = string.Format(@"for $c in //CompilationUnit for $cd in $c//{1}[@FullName='{0}']", name, kind) + " return <Source Language='{$c/@Language}'>{$c/@Source}</Source>";
|
||||
if (kind == "Type") // This comes from information extracted from assembly
|
||||
{
|
||||
xquery = string.Format(@"for $c in /Type[@Artifact='{0}']", name) + " return <Source Language='{$c/@Language}'>{$c/@Source}</Source>";
|
||||
}
|
||||
else
|
||||
{
|
||||
xquery = string.Format(@"for $c in //CompilationUnit for $cd in $c//{1}[@FullName='{0}']", name, kind) + " return <Source Language='{$c/@Language}'>{$c/@Source}</Source>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -258,7 +265,8 @@ namespace XppReasoningWpf
|
|||
|| string.Compare(name, "Query", StringComparison.OrdinalIgnoreCase) == 0
|
||||
|| string.Compare(name, "Map", StringComparison.OrdinalIgnoreCase) == 0
|
||||
|| string.Compare(name, "View", StringComparison.OrdinalIgnoreCase) == 0
|
||||
|| string.Compare(name, "Form", StringComparison.OrdinalIgnoreCase) == 0;
|
||||
|| string.Compare(name, "Form", StringComparison.OrdinalIgnoreCase) == 0
|
||||
|| string.Compare(name, "Type", StringComparison.OrdinalIgnoreCase) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -425,6 +433,10 @@ namespace XppReasoningWpf
|
|||
this.ShowSourceAt(artifact, "X++", sl, sc, el, ec);
|
||||
return;
|
||||
}
|
||||
else if (kind == "type")
|
||||
{
|
||||
this.ShowSourceAt(artifact, "C#", sl, sc, el, ec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче