Skip to content

Commit

Permalink
Update scalafmt-core to 3.4.3 (joernio#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
scala-steward authored Feb 13, 2022
1 parent 9b8d225 commit 93157c8
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.4.2
version = 3.4.3
runner.dialect = scala213
preset = IntelliJ
maxColumn = 120
Expand Down
5 changes: 2 additions & 3 deletions joern-cli/src/main/resources/scripts/binary/gadgets.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

def instrBefore(x : CfgNode, n: Int) =
x.cfgPrev(n).l.reverse.map(y => y.address.get + ": " + y.code)
def instrBefore(x: CfgNode, n: Int) =
x.cfgPrev(n).l.reverse.map(y => y.address.get + ": " + y.code)

cpg.ret.map(x => instrBefore(x, 5).mkString("|\t") + "\n").l |> "/tmp/gadgets.txt"
13 changes: 4 additions & 9 deletions joern-cli/src/main/resources/scripts/c/const-ish.sc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import io.shiftleft.semanticcpg.language._
import overflowdb.traversal._

@main def main() = {
cpg.method
.internal
.filter { method =>
method
.start
.assignment
.target
.reachableBy(method.parameter.filter(_.code.contains("const")))
.nonEmpty
cpg.method.internal.filter { method =>
method.start.assignment.target
.reachableBy(method.parameter.filter(_.code.contains("const")))
.nonEmpty
}.toSetImmutable
}
4 changes: 2 additions & 2 deletions joern-cli/src/main/resources/scripts/c/malloc-leak.sc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import io.shiftleft.semanticcpg.language.operatorextension.OpNodes.Assignment
import overflowdb.traversal._

@main def main() = {
def allocated = cpg.call("malloc").inAssignment.target.dedup
def freed = cpg.call("free").argument(1)
def allocated = cpg.call("malloc").inAssignment.target.dedup
def freed = cpg.call("free").argument(1)
def flowsFromAllocToFree = freed.reachableBy(allocated).toSetImmutable
allocated.map(_.code).toSetImmutable.diff(flowsFromAllocToFree.map(_.code))
}
10 changes: 5 additions & 5 deletions joern-cli/src/main/resources/scripts/c/pointer-to-int.sc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ private def expressionIsPointer(argument: Expression, isSubExpression: Boolean =
argument match {
case identifier: Identifier =>
identifier.typeFullName.endsWith("*") ||
identifier.typeFullName.endsWith("]") ||
cpg.local(identifier.name).l.headOption.exists(_.code.contains("*"))
identifier.typeFullName.endsWith("]") ||
cpg.local(identifier.name).l.headOption.exists(_.code.contains("*"))
case call: Call if call.name == Operators.indirectFieldAccess => // On '->', only check the selected field.
expressionIsPointer(call.start.argument.l.last, isSubExpression = true)
case call: Call => // On normal nested call, check all arguments are also pointers.
call.name == Operators.addressOf ||
call.start.argument.l.exists(expressionIsPointer(_, isSubExpression = true))
call.start.argument.l.exists(expressionIsPointer(_, isSubExpression = true))
case _ => false
}
}
Expand All @@ -29,7 +29,7 @@ private def expressionIsPointer(argument: Expression, isSubExpression: Boolean =

source.name.contains(Operators.subtraction) &&
target.typeFullName == "int" &&
expressionIsPointer(source)
expressionIsPointer(source)
}
.l
}
}
1 change: 0 additions & 1 deletion joern-cli/src/main/resources/scripts/c/syscalls.sc
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,3 @@ private val linuxSyscalls: Set[String] = Set(
@main def main(): List[Call] = {
cpg.call.filter(c => linuxSyscalls.contains(c.name)).l
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ private val calls: Set[String] = Set(

@main def main(): List[Call] = {
cpg.call.filter(call => calls.contains(call.name)).l
}
}
34 changes: 18 additions & 16 deletions joern-cli/src/universal/schema-extender/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,41 @@ val cpgVersion = IO.read(file("cpg-version"))

val generateDomainClasses = taskKey[Seq[File]]("generate overflowdb domain classes for our schema")

val joernInstallPath = settingKey[String]("path to joern installation, e.g. `/home/username/bin/joern/joern-cli` or `../../joern/joern-cli`")
val joernInstallPath =
settingKey[String]("path to joern installation, e.g. `/home/username/bin/joern/joern-cli` or `../../joern/joern-cli`")
joernInstallPath := "../"

val replaceDomainClassesInJoern = taskKey[Unit]("generates new domain classes based on the given schema, and installs them in the joern distribution")
val replaceDomainClassesInJoern =
taskKey[Unit]("generates new domain classes based on the given schema, and installs them in the joern distribution")

replaceDomainClassesInJoern := {
import java.nio.file._
val newDomainClassesJar = (domainClasses/Compile/packageBin).value
val newDomainClassesJar = (domainClasses / Compile / packageBin).value

val targetFile = file(joernInstallPath.value) / "lib" / s"io.shiftleft.codepropertygraph-domain-classes_2.13-${cpgVersion}.jar"
val targetFile =
file(joernInstallPath.value) / "lib" / s"io.shiftleft.codepropertygraph-domain-classes_2.13-${cpgVersion}.jar"
assert(targetFile.exists, s"target jar assumed to be $targetFile, but that file doesn't exist...")

println(s"copying $newDomainClassesJar to $targetFile")
Files.copy(newDomainClassesJar.toPath, targetFile.toPath, StandardCopyOption.REPLACE_EXISTING)
}

ThisBuild/libraryDependencies ++= Seq(
"io.shiftleft" %% "codepropertygraph-schema" % cpgVersion,
"io.shiftleft" %% "codepropertygraph-domain-classes" % cpgVersion,
ThisBuild / libraryDependencies ++= Seq(
"io.shiftleft" %% "codepropertygraph-schema" % cpgVersion,
"io.shiftleft" %% "codepropertygraph-domain-classes" % cpgVersion
)
ThisBuild/scalaVersion := "2.13.5"
ThisBuild / scalaVersion := "2.13.5"

lazy val schema = project.in(file("schema")).settings(
generateDomainClasses := {
lazy val schema = project
.in(file("schema"))
.settings(generateDomainClasses := {
val outputRoot = target.value / "odb-codegen"
FileUtils.deleteRecursively(outputRoot)
val invoked = (Compile/runMain).toTask(s" CpgExtCodegen schema/target/odb-codegen").value
val invoked = (Compile / runMain).toTask(s" CpgExtCodegen schema/target/odb-codegen").value
FileUtils.listFilesRecursively(outputRoot)
}
)
})

lazy val domainClasses = project.in(file("domain-classes")).settings(
Compile / sourceGenerators += schema / generateDomainClasses
)
lazy val domainClasses =
project.in(file("domain-classes")).settings(Compile / sourceGenerators += schema / generateDomainClasses)

Global / onChangedBuildSource := ReloadOnSourceChanges
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object FileUtils {
if (root.exists) {
Files.walk(root.toPath).iterator.asScala.map(_.toFile).collect {
case file if (file.isDirectory) => deleteRecursively(file)
case file => file.delete()
case file => file.delete()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@ object CpgExtCodegen extends App {
.map(new File(_))
.getOrElse(throw new AssertionError("please pass outputDir as first parameter"))

val builder = new SchemaBuilder(
domainShortName = "Cpg",
basePackage = "io.shiftleft.codepropertygraph.generated")
val builder = new SchemaBuilder(domainShortName = "Cpg", basePackage = "io.shiftleft.codepropertygraph.generated")
val cpgSchema = new CpgSchema(builder)

// START extensions for this build - add your's here and remove the example properties
val exampleProperty = builder.addProperty(
name = "EXAMPLE_PROPERTY",
valueType = ValueType.String,
comment = "an example property")
val exampleProperty =
builder.addProperty(name = "EXAMPLE_PROPERTY", valueType = ValueType.String, comment = "an example property")

val exampleNode = builder.addNodeType(
name = "EXAMPLE_NODE",
comment = "an example node"
).addProperties(exampleProperty)
val exampleNode =
builder.addNodeType(name = "EXAMPLE_NODE", comment = "an example node").addProperties(exampleProperty)

cpgSchema.fs.file.addProperties(exampleProperty)
// END extensions for this build
Expand Down
14 changes: 6 additions & 8 deletions tests/frontends-testscript.sc
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
@main def main(inputPath: String,
minMethodCount: Int,
expectedMethod: String,
frontend: String) = {
@main def main(inputPath: String, minMethodCount: Int, expectedMethod: String, frontend: String) = {
importCode(inputPath, language = frontend.toUpperCase)
val methodCount = cpg.method.size
assert(methodCount >= minMethodCount,
s"expected at least $minMethodCount methods, but only found $methodCount")
assert(methodCount >= minMethodCount, s"expected at least $minMethodCount methods, but only found $methodCount")

val methodNames = cpg.method.name.toSet
assert(methodNames.contains(expectedMethod), s"expected method `$expectedMethod` not found... available methods: $methodNames")
assert(
methodNames.contains(expectedMethod),
s"expected method `$expectedMethod` not found... available methods: $methodNames"
)
}

0 comments on commit 93157c8

Please sign in to comment.