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
1.97k stars 267 forks source link

[Bug] Can't run script in Interactive Shell #4805

Open hac425xxx opened 1 month ago

hac425xxx commented 1 month ago

I want to execute script in interrept, but failed.

┌──(kali㉿kali)-[~/joern-cli]
└─$ ./joern

     ██╗ ██████╗ ███████╗██████╗ ███╗   ██╗
     ██║██╔═══██╗██╔════╝██╔══██╗████╗  ██║
     ██║██║   ██║█████╗  ██████╔╝██╔██╗ ██║
██   ██║██║   ██║██╔══╝  ██╔══██╗██║╚██╗██║
╚█████╔╝╚██████╔╝███████╗██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚══════╝╚═╝  ╚═╝╚═╝  ╚═══╝
Version: 4.0.6
Type `help` to begin

joern> importCode(inputPath="/home/example", projectName="example")

joern> cpg.runScript
-- [E008] Not Found Error: -----------------------------------------------------
1 |cpg.runScript
  |^^^^^^^^^^^^^
  |value runScript is not a member of io.shiftleft.codepropertygraph.generated.Cpg
1 error found

importing command alos error.


joern> importing 
-- [E006] Not Found Error: -----------------------------------------------------
1 |importing 
  |^^^^^^^^^
  |Not found: importing - did you mean importCpg?
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Each identifier in Scala needs a matching declaration. There are two kinds of
  | identifiers: type identifiers and value identifiers. Value identifiers are introduced
  | by `val`, `def`, or `object` declarations. Type identifiers are introduced by `type`,
  | `class`, `enum`, or `trait` declarations.
  |
  | Identifiers refer to matching declarations in their environment, or they can be
  | imported from elsewhere.
  |
  | Possible reasons why no matching declaration was found:
  |  - The declaration or the use is mis-spelt.
  |  - An import is missing.
   -----------------------------------------------------------------------------
1 error found
max-leuthaeuser commented 1 month ago

We have the --script argument for joern. See e.g., https://github.com/joernio/joern/blob/1379bb9744b923241d9b61189eae2a2d9c029264/tests/frontends-tests.sh#L11

You could also simply paste the content of your script directly into the repl and run it there.

hac425xxx commented 1 month ago

paste the content of script is too much trouble when I need to test script.

start joern with --script will waste time, because joern takes a long time to start, while script will run fast.