joern icon indicating copy to clipboard operation
joern copied to clipboard

[Bug] Can't run script in Interactive Shell

Open hac425xxx opened this issue 1 year ago • 2 comments

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
                     

hac425xxx avatar Jul 27 '24 08:07 hac425xxx

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.

max-leuthaeuser avatar Jul 28 '24 07:07 max-leuthaeuser

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.

hac425xxx avatar Jul 29 '24 05:07 hac425xxx

use :load :load myfile.sc Strange it's not documented

skirge avatar Sep 15 '24 20:09 skirge