joernio / joern

Open-source code analysis platform for C/C++/Java/Binary/Javascript/Python/Kotlin based on code property graphs. Discord https://discord.gg/vv4MH284Hc
https://joern.io/
Apache License 2.0
2.03k stars 272 forks source link

[Bug][csharpsrc2cpg]Unable to create cpg for c# code #4850

Open wooyune1 opened 1 month ago

wooyune1 commented 1 month ago

Describe the bug Unable to create cpg for c# code.The following error occurs:

[main] INFO io.joern.csharpsrc2cpg.utils.DotNetAstGenRunner - Running dotnetastgen on 'D:\Workspace\Java\CsharpAnalysis\src\main\resources'
[main] ERROR io.joern.csharpsrc2cpg.utils.DotNetAstGenRunner -  - running dotnetastgen failed!
java.lang.RuntimeException: 
    at io.joern.x2cpg.utils.ExternalCommand.handleRunResult(ExternalCommand.scala:22)
    at io.joern.x2cpg.utils.ExternalCommand.handleRunResult$(ExternalCommand.scala:8)
    at io.joern.x2cpg.utils.ExternalCommand$.handleRunResult(ExternalCommand.scala:39)
    at io.joern.x2cpg.utils.ExternalCommand.run(ExternalCommand.scala:34)
    at io.joern.x2cpg.utils.ExternalCommand.run$(ExternalCommand.scala:8)
    at io.joern.x2cpg.utils.ExternalCommand$.run(ExternalCommand.scala:39)
    at io.joern.csharpsrc2cpg.utils.DotNetAstGenRunner.runAstGenNative(DotNetAstGenRunner.scala:67)
    at io.joern.x2cpg.astgen.AstGenRunnerBase.execute(AstGenRunner.scala:181)
    at io.joern.x2cpg.astgen.AstGenRunnerBase.execute$(AstGenRunner.scala:83)
    at io.joern.csharpsrc2cpg.utils.DotNetAstGenRunner.execute(DotNetAstGenRunner.scala:14)
    at io.joern.csharpsrc2cpg.CSharpSrc2Cpg.createCpg$$anonfun$1$$anonfun$1(CSharpSrc2Cpg.scala:36)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at better.files.Dispose.apply(Dispose.scala:75)
    at better.files.Dispose.foreach(Dispose.scala:91)
    at better.files.File$.usingTemporaryDirectory(File.scala:1320)
    at io.joern.csharpsrc2cpg.CSharpSrc2Cpg.createCpg$$anonfun$1(CSharpSrc2Cpg.scala:68)
    at scala.runtime.function.JProcedure2.apply(JProcedure2.java:15)
    at scala.runtime.function.JProcedure2.apply(JProcedure2.java:10)
    at io.joern.x2cpg.X2Cpg$.withNewEmptyCpg$$anonfun$1$$anonfun$1(X2Cpg.scala:322)
    at io.joern.x2cpg.X2Cpg$.$anonfun$adapted$1(X2Cpg.scala:323)
    at scala.util.Try$.apply(Try.scala:210)
    at io.joern.x2cpg.X2Cpg$.withNewEmptyCpg$$anonfun$1(X2Cpg.scala:323)
    at scala.util.Try$.apply(Try.scala:210)
    at io.joern.x2cpg.X2Cpg$.withNewEmptyCpg(X2Cpg.scala:329)
    at io.joern.csharpsrc2cpg.CSharpSrc2Cpg.createCpg(CSharpSrc2Cpg.scala:69)
    at TaintAnalysis$.run(TaintAnalysis.scala:39)
    at Main$.main(Main.scala:3)
    at Main.main(Main.scala)

To Reproduce my code

  def run(): Unit = {
    val config = Config()
      .withInputPath("src\\main\\resources")

    implicit val cpg: Cpg = new CSharpSrc2Cpg().createCpg(config).get
  }

c# code to parse

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            int a = i + 1;
            Console.WriteLine(a);
        }
    }
}

Desktop (please complete the following information):

wozhendeshuai commented 1 week ago

same question