Skip to content

Commit 46e1cc5

Browse files
committed
feat: remove joern integration
1 parent 4472790 commit 46e1cc5

File tree

2 files changed

+1
-100
lines changed

2 files changed

+1
-100
lines changed

scubatrace/function.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from tree_sitter import Node
99

1010
from . import language as lang
11-
from .call import Call
1211
from .identifier import Identifier
1312
from .statement import BlockStatement, Statement
1413

@@ -21,16 +20,10 @@ class Function(BlockStatement):
2120
A function in the source code.
2221
"""
2322

24-
def __init__(
25-
self, node: Node, file: File | BlockStatement, joern_id: str | None = None
26-
):
23+
def __init__(self, node: Node, file: File | BlockStatement):
2724
super().__init__(node, file)
28-
self.joern_id = joern_id
2925
self._is_build_cfg = False
3026

31-
self.callers_joern: list[Call] = []
32-
self.callees_joern: list[Call] = []
33-
3427
@staticmethod
3528
def create(node: Node, parent: File | BlockStatement):
3629
"""
@@ -106,9 +99,6 @@ def __str__(self) -> str:
10699
f'"{self.name.replace("::", "--")} ({self.file.name}\\:{self.start_line})"'
107100
)
108101

109-
def set_joernid(self, joern_id: str):
110-
self.joern_id = joern_id
111-
112102
@property
113103
def signature(self) -> str:
114104
"""

scubatrace/project.py

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
from scubalspy.scubalspy_config import ScubalspyConfig
1212
from scubalspy.scubalspy_logger import ScubalspyLogger
1313

14-
from . import joern
1514
from . import language as lang
16-
from .call import Call
1715
from .file import File
1816
from .function import Function, FunctionDeclaration
1917
from .parser import Parser
@@ -98,26 +96,9 @@ def __init__(
9896
path: str,
9997
language: type[lang.Language],
10098
enable_lsp: bool = True,
101-
enable_joern: bool = False,
10299
):
103100
self.path = path
104101
self.language = language
105-
if enable_joern:
106-
if language == lang.C:
107-
joern_language = joern.Language.C
108-
elif language == lang.JAVA:
109-
joern_language = joern.Language.JAVA
110-
elif language == lang.PYTHON:
111-
joern_language = joern.Language.PYTHON
112-
elif language == lang.JAVASCRIPT:
113-
joern_language = joern.Language.JAVASCRIPT
114-
else:
115-
raise ValueError("Joern unsupported language")
116-
self.joern = joern.Joern(
117-
path,
118-
joern_language,
119-
)
120-
self.joern.export_with_preprocess()
121102
if enable_lsp:
122103
self.start_lsp()
123104

@@ -160,13 +141,6 @@ def start_lsp(self):
160141
atexit.register(os.remove, self.conf_file)
161142
self.lsp.sync_start_server()
162143

163-
def close(self):
164-
if "joern" in self.__dict__:
165-
self.joern.close()
166-
167-
def __exit__(self, exc_type, exc_value, traceback):
168-
self.close()
169-
170144
@property
171145
def abspath(self) -> str:
172146
"""
@@ -289,69 +263,6 @@ def callgraph(self) -> nx.MultiDiGraph:
289263
cg = self.__build_callgraph(entry)
290264
return cg
291265

292-
@cached_property
293-
def callgraph_joern(self) -> nx.MultiDiGraph:
294-
if self.joern is None:
295-
raise ValueError("Joern is not enabled for this project.")
296-
joern_cg = self.joern.callgraph
297-
cg = nx.MultiDiGraph()
298-
for node in joern_cg.nodes:
299-
if joern_cg.nodes[node]["NODE_TYPE"] != "METHOD":
300-
continue
301-
if joern_cg.nodes[node]["IS_EXTERNAL"] == "true":
302-
continue
303-
func = self.search_function(
304-
joern_cg.nodes[node]["FILENAME"],
305-
int(joern_cg.nodes[node]["LINE_NUMBER"]),
306-
)
307-
if func is None:
308-
continue
309-
func.set_joernid(node)
310-
cg.add_node(
311-
func,
312-
label=func.dot_text,
313-
)
314-
for u, v, data in joern_cg.edges(data=True):
315-
if joern_cg.nodes[u]["NODE_TYPE"] != "METHOD":
316-
continue
317-
if joern_cg.nodes[v]["NODE_TYPE"] != "METHOD":
318-
continue
319-
320-
# search by joern_id
321-
src_func: Function | None = None
322-
dst_func: Function | None = None
323-
for node in cg.nodes:
324-
if node.joern_id == u:
325-
src_func = node
326-
if node.joern_id == v:
327-
dst_func = node
328-
if src_func is None or dst_func is None:
329-
continue
330-
if src_func == dst_func:
331-
continue
332-
src_func.callees_joern.append(
333-
Call(
334-
src_func,
335-
dst_func,
336-
int(data["LINE_NUMBER"]),
337-
int(data["COLUMN_NUMBER"]),
338-
)
339-
)
340-
dst_func.callers_joern.append(
341-
Call(
342-
src_func,
343-
dst_func,
344-
int(data["LINE_NUMBER"]),
345-
int(data["COLUMN_NUMBER"]),
346-
)
347-
)
348-
cg.add_edge(
349-
src_func,
350-
dst_func,
351-
**data,
352-
)
353-
return cg
354-
355266
def export_callgraph(self, output_path: str):
356267
"""
357268
Exports the call graph of the project to a DOT file.

0 commit comments

Comments
 (0)