Skip to content

Commit add037f

Browse files
authored
CdxPass improvements for JS (#119)
* Update packages Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com> * Update eclipse cdt plugin Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com> * Update eclipse cdt plugin Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com> * Improve Cdx JS tagging. Fixes #117 Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com> * Track proto assign and no-proto for js Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com> * Track http-client and http-endpoint for js Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com> --------- Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
1 parent 09b24b2 commit add037f

File tree

14 files changed

+130
-36
lines changed

14 files changed

+130
-36
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "chen"
22
ThisBuild / organization := "io.appthreat"
3-
ThisBuild / version := "2.4.2"
3+
ThisBuild / version := "2.4.3"
44
ThisBuild / scalaVersion := "3.6.2"
55

66
val cpgVersion = "1.0.1"

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"downloadUrl": "https://github.com/AppThreat/chen",
88
"issueTracker": "https://github.com/AppThreat/chen/issues",
99
"name": "chen",
10-
"version": "2.4.2",
10+
"version": "2.4.3",
1111
"description": "Code Hierarchy Exploration Net (chen) is an advanced exploration toolkit for your application source code and its dependency hierarchy.",
1212
"applicationCategory": "code-analysis",
1313
"keywords": [

meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% set version = "2.4.2" %}
1+
{% set version = "2.4.3" %}
22

33
package:
44
name: chen

platform/frontends/c2cpg/build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ dependsOn(Projects.semanticcpg, Projects.dataflowengineoss % Test, Projects.x2cp
44

55
libraryDependencies ++= Seq(
66
"org.scala-lang.modules" %% "scala-parallel-collections" % Versions.scalaParallel,
7-
"org.eclipse.platform" % "org.eclipse.equinox.common" % "3.20.0",
8-
"org.eclipse.platform" % "org.eclipse.core.resources" % "3.22.100" excludeAll(
7+
"org.eclipse.platform" % "org.eclipse.equinox.common" % "3.20.100",
8+
"org.eclipse.platform" % "org.eclipse.core.resources" % "3.22.200" excludeAll(
99
ExclusionRule(organization = "com.ibm.icu", name = "icu4j"),
1010
ExclusionRule(organization = "org.eclipse.platform", name = "org.eclipse.jface"),
1111
ExclusionRule(organization = "org.eclipse.platform", name = "org.eclipse.jface.text")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
org.eclipse.cdt jars were downloaded from
22

3-
https://download.eclipse.org/tools/cdt/releases/12.0/cdt-12.0.0/plugins/
3+
https://download.eclipse.org/tools/cdt/releases/12.1/cdt-12.1.0/plugins/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
about_resource: org.eclipse.cdt.core_9.1.0.202505200054.jar
2+
name: Eclipse CDT Core
3+
version: 9.1.0.202505200054
4+
homepage_url: http://eclipse.org/cdt
5+
download_url: https://www.eclipse.org/downloads/download.php?file=/tools/cdt/releases/12.1/cdt-12.1.0/plugins/org.eclipse.cdt.core_9.1.0.202505200054.jar
6+
license_expression: EPL-2.0
7+
licenses:
8+
- key: EPL-2.0
9+
name: Eclipse Public License 2.0
10+
file: LICENSE
11+
url: https://github.com/eclipse-cdt/cdt/blob/main/LICENSE
12+
spdx_license_key: EPL-2.0
13+
copyright: Copyright (c) The Eclipse Foundation.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f690b0ceb11465e23b8112e70a60d4263144bb8efe7e6f6a2119ce46ec1e94f7c7451919c348ed819a47dbb919fc4c881aa4c11cd0b7b2dba7d33f0baedd88c4 org.eclipse.cdt.core_9.1.0.202505200054.jar

platform/frontends/jssrc2cpg/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ libraryDependencies ++= Seq(
1111
"io.appthreat" %% "cpg2" % Versions.cpg,
1212
"com.lihaoyi" %% "upickle" % Versions.upickle,
1313
"com.typesafe" % "config" % "1.4.3",
14-
"com.michaelpollmeier" % "versionsort" % "1.0.13",
14+
"com.michaelpollmeier" % "versionsort" % "1.0.17",
1515
"org.scalatest" %% "scalatest" % Versions.scalatest % Test
1616
)
1717

platform/frontends/x2cpg/src/main/scala/io/appthreat/x2cpg/passes/taggers/CdxPass.scala

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,17 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
120120
if language == Languages.JAVA || language == Languages.JAVASRC then
121121
bpkg = bpkg.split("\\.").take(PKG_NS_SIZE).mkString(".").concat(
122122
".*"
123-
)
124-
bpkg =
125-
bpkg.replace(File.separator, Pattern.quote(File.separator))
123+
).replace(File.separator, Pattern.quote(File.separator))
126124
if language == Languages.JSSRC || language == Languages.JAVASCRIPT
127125
then
128-
bpkg = s".*${bpkg}.*"
129-
bpkg =
130-
bpkg.replace(File.separator, Pattern.quote(File.separator))
126+
bpkg = bpkg.replace(File.separator, Pattern.quote(File.separator))
131127
if language == Languages.PYTHON || language == Languages.PYTHONSRC
132128
then bpkg = toPyModuleForm(bpkg)
133129
if language == Languages.RUBYSRC
134130
then bpkg = toRubyModuleForm(bpkg)
135131
if language == Languages.PHP
136132
then
137-
bpkg = bpkg.replaceAll("""\\""", """\\\\""")
138-
bpkg = s"""$bpkg.*"""
133+
bpkg = bpkg.replace("\\", "\\\\").concat(".*")
139134
if bpkg.nonEmpty && !donePkgs.contains(bpkg) then
140135
donePkgs.put(bpkg, true)
141136
// Ruby
@@ -240,15 +235,44 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
240235
)
241236
if language == Languages.JSSRC || language == Languages.JAVASCRIPT
242237
then
243-
atom.call.code(bpkg).argument.newTagNode(
238+
atom.method.name(bpkg).external.newTagNode(
244239
compPurl
245240
).store()(dstGraph)
246-
atom.identifier.code(bpkg).newTagNode(compPurl).store()(
247-
dstGraph
248-
)
249-
atom.identifier.code(bpkg).inCall.newTagNode(
241+
atom.method.name(bpkg).external.parameter.newTagNode(
250242
compPurl
251243
).store()(dstGraph)
244+
atom.method.name(bpkg).external.callIn(NoResolve).argument.newTagNode(
245+
compPurl
246+
).store()(dstGraph)
247+
if bpkg.contains(File.separator) then
248+
val segments = bpkg.split(Pattern.quote(File.separator))
249+
val truncated = segments.take(2).mkString(File.separator)
250+
val re_variant = s".*${truncated}.*"
251+
atom.method.fullName(re_variant).external.newTagNode(
252+
compPurl
253+
).store()(dstGraph)
254+
atom.method.fullName(re_variant).external.parameter.newTagNode(
255+
compPurl
256+
).store()(dstGraph)
257+
atom.method.fullName(re_variant).external.callIn(NoResolve).argument.newTagNode(
258+
compPurl
259+
).store()(dstGraph)
260+
if compType != "library" then
261+
atom.method.fullName(re_variant).external.parameter.newTagNode(
262+
compType
263+
).store()(dstGraph)
264+
atom.method.fullName(re_variant).external.callIn(NoResolve).argument.newTagNode(
265+
compType
266+
).store()(dstGraph)
267+
end if
268+
if compType != "library" then
269+
atom.method.name(bpkg).external.parameter.newTagNode(
270+
compType
271+
).store()(dstGraph)
272+
atom.method.name(bpkg).external.callIn(NoResolve).argument.newTagNode(
273+
compType
274+
).store()(dstGraph)
275+
end if
252276
if language == Languages.PYTHON || language == Languages.PYTHONSRC
253277
then
254278
atom.call.where(
@@ -285,17 +309,6 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
285309
atom.method.fullName(bpkg).newTagNode(compType).store()(
286310
dstGraph
287311
)
288-
if language == Languages.JSSRC || language == Languages.JAVASCRIPT
289-
then
290-
atom.call.code(bpkg).argument.newTagNode(
291-
compType
292-
).store()(dstGraph)
293-
atom.identifier.code(bpkg).newTagNode(
294-
compType
295-
).store()(dstGraph)
296-
atom.identifier.code(bpkg).inCall.newTagNode(
297-
compType
298-
).store()(dstGraph)
299312
if language == Languages.PYTHON || language == Languages.PYTHONSRC
300313
then
301314
atom.call.where(

0 commit comments

Comments
 (0)