where
function was not taking a traversal. According to https://docs.joern.io/upgrade-guides this should work, and it was working in an earlier release (I tried with 1.1.33)
cpg.call.name("malloc").argument.isLiteral .l
and cpg.call.name("malloc").where{x=>x.argument.isLiteral}.l
is not the same.
Hi! Trying to plot the cpg as either AST or CPG gives me an error:
joern> cpg.method.name("iw_is_valid_density").plotDotCpg14
Executing image viewer failed. Is it installed?
java.io.IOException: Cannot run program "xdg-open": error=2, No such file or directory
I am currently running Joern v1.1.42 and JRE 12. I´m running it on a mac and suspect that's where the problem with Java xdg-open arises. I was wondering if someone has had the same issue?
@rasmusli_gitlab, you need to install xdg-utils
. xdg-open
is part of the xdg-utils
package and is for use with x11.
i had a similar issue on macOS and did the following. store the dot representation of the graph as a file and use the dot utilities from graphviz to display the graph
joern> cpg.method.name("main").dotCfg.head > "/tmp/cfg.dot"
then
dot -Tsvg /tmp/cfg.dot > /tmp/cfg.svg
joern > config.tools.imageViewer = "/path/to/a/different/viewer"
int i;
int buf[N];
for(i = 0; i <= N; i++){
buf[i] = 1;
}
buf[i]= 0;
joern> cpg.method.controlStructure.expressionDown.order(2).code.l
res45: List[String] = List("i <= N")
joern> val loopTo = cpg.method.controlStructure.expressionDown.order(2).isCallTo(Operators.lessEqualsThan).argument.order(2).code.l.head
loopTo: String = "N"
joern> cpg.method.local.typeFullNameExact(s"""int [ $loopTo ]""").code.l
res60: List[String] = List("buf")
cpg.method // query all methods
.controlStructure // filter for control structures
.parserTypeName("ForStatement") // only for statements
.expressionDown // "going one layer down"
.order(2) // choosing the second argument of the expression => for(i = 0; i <= N; i++){
.isCallTo(Operators.lessEqualsThan) // it has to be a call to "<="
.argument // going to the arguments of the call to "<="
.order(2) // second argument is the "N"
.code // get the code of the second argument
.l // as list (in this case it is only argument but could be more)
.head // get the first entry in the list
x42-c
for code at ./x42/c