Skip to content

Commit

Permalink
purl as a name tag
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
  • Loading branch information
prabhu committed Oct 11, 2023
1 parent e38c52a commit d281cbf
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "chen"
ThisBuild / organization := "io.appthreat"
ThisBuild / version := "0.0.12"
ThisBuild / version := "0.0.13"
ThisBuild / scalaVersion := "3.3.1"

val cpgVersion = "1.4.22"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Path {
lazy val maxTrackedWidth = sys.env.get("CHEN_DATAFLOW_TRACKED_WIDTH").map(_.toInt).getOrElse(DefaultMaxTrackedWidth)

private def tagAsString(tag: Iterator[Tag]) =
if (tag.nonEmpty) tag.filterNot(_.name == "purl").name.mkString(", ") else ""
if (tag.nonEmpty) tag.name.mkString(", ") else ""

implicit val show: Show[Path] = { path =>
var caption = ""
Expand Down Expand Up @@ -65,6 +65,7 @@ object Path {
var tags: String = tagAsString(astNode.tag)
if (fileLocation == "#") fileLocation = "N/A"
astNode match {
case _: MethodReturn =>
case methodParameterIn: MethodParameterIn =>
val methodName = methodParameterIn.method.name
if (tags.isEmpty && methodParameterIn.method.tag.nonEmpty) {
Expand Down Expand Up @@ -172,7 +173,7 @@ object Path {
{
val end_section = row.head == "call"
val trow: Array[String] = row.tail
if (trow(3) != "RET" && !trow(4).startsWith("<operator>.fieldAccess")) {
if (!trow(4).startsWith("<operator>.fieldAccess")) {
val tagsStr: String = if (trow(4).nonEmpty) s"Tags: ${trow(4)}" else ""
val methodStr = s"${trow(1)}\n${tagsStr}"
table.add_row(trow(0), methodStr.stripMargin, trow(2), trow(3), end_section = end_section)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class CdxPass(cpg: Cpg) extends CpgPass(cpg) {
val nsstr = ns.hcursor.downField("value").as[String].getOrElse("")
nsstr.split("\n").filterNot(_.contains("test")).filterNot(_.contains("mock")).foreach { (pkg: String) =>
val bpkg = pkg.takeWhile(_ != '$')
cpg.call.typeFullNameExact(bpkg).newTagNodePair(PURL_TYPE, compPurl).store()(dstGraph)
cpg.method.parameter.typeFullNameExact(bpkg).newTagNodePair(PURL_TYPE, compPurl).store()(dstGraph)
cpg.call.typeFullNameExact(bpkg).newTagNode(compPurl).store()(dstGraph)
cpg.method.parameter.typeFullNameExact(bpkg).newTagNode(compPurl).store()(dstGraph)
if (!containsRegex(bpkg))
cpg.method.fullName(s"${Pattern.quote(bpkg)}.*").newTagNodePair(PURL_TYPE, compPurl).store()(dstGraph)
cpg.method.fullName(s"${Pattern.quote(bpkg)}.*").newTagNode(compPurl).store()(dstGraph)
if (compType != "library") {
cpg.call.typeFullNameExact(bpkg).newTagNode(compType).store()(dstGraph)
cpg.call.typeFullNameExact(bpkg).receiver.newTagNode(s"$compType-value").store()(dstGraph)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object ChenExport {
}

private def parseConfig(args: Array[String]): Option[Config] = {
new scopt.OptionParser[Config]("joern-export") {
new scopt.OptionParser[Config]("chen-export") {
head("Dump intermediate graph representations (or entire graph) of code in a given export format")
help("help")
arg[String]("cpg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object ChenFlow {
}

private def parseConfig(args: Array[String]): Option[FlowConfig] = {
new scopt.OptionParser[FlowConfig]("joern-flow") {
new scopt.OptionParser[FlowConfig]("chen-flow") {
head("Find flows")
help("help")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object ChenParse {
}
}

val optionParser = new scopt.OptionParser[ParserConfig]("joern-parse") {
val optionParser = new scopt.OptionParser[ParserConfig]("chen-parse") {
arg[String]("input")
.optional()
.text("source file or directory containing source files")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "appthreat-chen"
version = "0.0.12"
version = "0.0.13"
description = "Code Hierarchy Exploration Net (chen)"
authors = ["Team AppThreat <cloud@appthreat.com>"]
license = "Apache-2.0"
Expand Down

0 comments on commit d281cbf

Please sign in to comment.