Skip to content

Commit

Permalink
Added tags for windows drivers
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu committed Nov 30, 2023
1 parent 372526c commit 88bbf81
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 8 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 := "1.0.4"
ThisBuild / version := "1.0.5"
ThisBuild / scalaVersion := "3.3.1"

val cpgVersion = "1.4.22"
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"downloadUrl": "https://github.com/AppThreat/chen",
"issueTracker": "https://github.com/AppThreat/chen/issues",
"name": "chen",
"version": "1.0.4",
"version": "1.0.5",
"description": "Code Hierarchy Exploration Net (chen) is an advanced exploration toolkit for your application source code and its dependency hierarchy.",
"applicationCategory": "code-analysis",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions console/src/main/scala/io/appthreat/console/Console.scala
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class Console[T <: Project](
): String =
if tree then
val rootTree = richTreeLib.Tree(title, highlight = true)
atom.file.whereNot(_.name("<unknown>")).foreach { f =>
atom.file.whereNot(_.name("<(unknown|includes)>")).foreach { f =>
val childTree = richTreeLib.Tree(f.name, highlight = true)
f.method.foreach(m =>
val addedMethods = mutable.Map.empty[String, Boolean]
Expand Down Expand Up @@ -528,7 +528,7 @@ class Console[T <: Project](
val table = richTableLib.Table(title = title, highlight = true, show_lines = true)
table.add_column("File Name")
table.add_column("Methods")
atom.file.whereNot(_.name("<unknown>")).foreach { f =>
atom.file.whereNot(_.name("<(unknown|includes)>")).foreach { f =>
table.add_row(
f.name,
f.method.filterNot(m =>
Expand Down
2 changes: 1 addition & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set version = "1.0.4" %}
{% set version = "1.0.5" %}

package:
name: chen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object FileDefaults:
val SOURCE_FILE_EXTENSIONS: Set[String] = Set(C_EXT, CC_EXT, CPP_EXT)

val HEADER_FILE_EXTENSIONS: Set[String] =
Set(C_HEADER_EXT, CPP_HEADER_EXT, OTHER_HEADER_EXT, ".h.in")
Set(C_HEADER_EXT, CPP_HEADER_EXT, OTHER_HEADER_EXT, ".h.in", ".tmh")

private val CPP_FILE_EXTENSIONS = Set(CC_EXT, CPP_EXT, CPP_HEADER_EXT, ".ccm", ".cxxm", ".c++m")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,24 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
)

private def PY_REQUEST_PATTERNS = Array(".*views.py:<module>.*")
private def C_REQUEST_PATTERNS = Array(
"Routes::(Post|Get|Delete|Head|Options|Put).*",
"API_CALL",
"API_CALL_ASYNC",
"ENDPOINT",
"ENDPOINT_ASYNC",
"ENDPOINT_INTERCEPTOR",
"ENDPOINT_INTERCEPTOR_ASYNC",
"registerHandler",
"PATH_ADD",
"ADD_METHOD_TO",
"ADD_METHOD_VIA_REGEX",
"WS_PATH_ADD",
"svr\\.(Post|Get|Delete|Head|Options|Put)"
)

private def containsRegex(str: String) =
Pattern.quote(str) == str || str.contains("*") || str.contains("(") || str.contains(")")
Pattern.quote(str) != str || str.contains("*") || str.contains("(") || str.contains(")")

private val BOM_JSON_FILE = ".*(bom|cdx).json"

Expand Down Expand Up @@ -82,6 +97,14 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
dstGraph
)
)
if language == Languages.NEWC || language == Languages.C
then
C_REQUEST_PATTERNS
.foreach(p =>
atom.method.fullName(p).parameter.newTagNode("framework-input").store()(
dstGraph
)
)
components.foreach { comp =>
val PURL_TYPE = "purl"
val compPurl = comp.hcursor.downField(PURL_TYPE).as[String].getOrElse("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,44 @@ class EasyTagsPass(atom: Cpg) extends CpgPass(atom):
if language == Languages.NEWC || language == Languages.C
then
atom.method.internal.name("main").parameter.newTagNode("cli-source").store()(dstGraph)
atom.method.internal.name("wmain").parameter.newTagNode("cli-source").store()(dstGraph)
atom.method.external.name("(cuda|curl_|BIO_).*").parameter.newTagNode(
"library-call"
).store()(
dstGraph
)
atom.method.external.name("DriverEntry").parameter.newTagNode("driver-source").store()(
dstGraph
)
atom.method.external.name("WdfDriverCreate").parameter.newTagNode(
"driver-source"
).store()(dstGraph)
atom.method.external.name("OnDeviceAdd").parameter.newTagNode(
"driver-source"
).store()(dstGraph)
atom.method.external.fullName(
"(Aws|Azure|google|cloud)(::|\\.).*"
).parameter.newTagNode(
"cloud"
).store()(dstGraph)
atom.method.external.fullName("(CDevice|CDriver)(::|\\.).*").parameter.newTagNode(
"device-driver"
).store()(dstGraph)
atom.method.external.fullName(
"(Windows|WEX|WDMAudio|winrt|wilEx)(::|\\.).*"
).parameter.newTagNode("windows").store()(dstGraph)
atom.method.external.fullName("(RpcServer)(::|\\.).*").parameter.newTagNode(
"rpc"
).store()(
dstGraph
)
atom.method.external.fullName(
"(Pistache|Http|Rest|oatpp|HttpClient|HttpRequest|WebSocketClient|HttpResponse|drogon|chrono|httplib)(::|\\.).*"
).parameter.newTagNode(
"http"
).store()(
dstGraph
)
end if
end run
end EasyTagsPass
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 = "1.0.4"
version = "1.0.5"
description = "Code Hierarchy Exploration Net (chen)"
authors = ["Team AppThreat <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 88bbf81

Please sign in to comment.