From 5ab9b8ca89ffd9cde52411559f8c0280743a56e9 Mon Sep 17 00:00:00 2001 From: prabhu Date: Fri, 23 Jun 2023 22:52:46 +0200 Subject: [PATCH] Tweaks (#43) * Tweaks Signed-off-by: Prabhu Subramanian * Update atom bin dir for windows Signed-off-by: Prabhu Subramanian --------- Signed-off-by: Prabhu Subramanian --- Dockerfile | 2 +- ci/Dockerfile-alma8 | 2 +- ci/Dockerfile-atom | 2 +- cpggen/executor.py | 25 +++++++++++++++++++++---- poetry.lock | 2 +- pyproject.toml | 2 +- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 27ec9cd..fe1ee24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ LABEL maintainer="appthreat" \ org.opencontainers.image.authors="Team AppThreat " \ org.opencontainers.image.source="https://github.com/appthreat/cpggen" \ org.opencontainers.image.url="https://github.com/appthreat/cpggen" \ - org.opencontainers.image.version="1.8.1" \ + org.opencontainers.image.version="1.8.2" \ org.opencontainers.image.vendor="AppThreat" \ org.opencontainers.image.licenses="Apache-2.0" \ org.opencontainers.image.title="cpggen" \ diff --git a/ci/Dockerfile-alma8 b/ci/Dockerfile-alma8 index cefafb8..13854d7 100644 --- a/ci/Dockerfile-alma8 +++ b/ci/Dockerfile-alma8 @@ -4,7 +4,7 @@ LABEL maintainer="appthreat" \ org.opencontainers.image.authors="Team AppThreat " \ org.opencontainers.image.source="https://github.com/appthreat/cpggen" \ org.opencontainers.image.url="https://github.com/appthreat/cpggen" \ - org.opencontainers.image.version="1.8.1" \ + org.opencontainers.image.version="1.8.2" \ org.opencontainers.image.vendor="AppThreat" \ org.opencontainers.image.licenses="Apache-2.0" \ org.opencontainers.image.title="cpggen" \ diff --git a/ci/Dockerfile-atom b/ci/Dockerfile-atom index c4a8a7b..8b9bdb4 100644 --- a/ci/Dockerfile-atom +++ b/ci/Dockerfile-atom @@ -4,7 +4,7 @@ LABEL maintainer="appthreat" \ org.opencontainers.image.authors="Team AppThreat " \ org.opencontainers.image.source="https://github.com/appthreat/cpggen" \ org.opencontainers.image.url="https://github.com/appthreat/cpggen" \ - org.opencontainers.image.version="1.8.1" \ + org.opencontainers.image.version="1.8.2" \ org.opencontainers.image.vendor="AppThreat" \ org.opencontainers.image.licenses="Apache-2.0" \ org.opencontainers.image.title="cpggen" \ diff --git a/cpggen/executor.py b/cpggen/executor.py index fa76377..44de05c 100644 --- a/cpggen/executor.py +++ b/cpggen/executor.py @@ -6,7 +6,7 @@ import sys import tempfile import zipfile -from pathlib import Path +from pathlib import Path, PureWindowsPath import psutil from psutil._common import bytes2human @@ -483,7 +483,19 @@ def exec_tool( if atom_home: atom_bin_dir = os.path.join(atom_home, "bin", "") else: - atom_bin_dir = "/usr/local/bin/" + # Handle the case where the user might have installed atom npm package on windows + # but not set the PATH environment variable + atom_bin_dir = ( + str(Path.home() / "AppData" / "Roaming" / "npm") + if sys.platform == "win32" + else "/usr/local/bin" + ) + atom_bin_dir = os.path.join(atom_bin_dir, "") + if sys.platform == "win32" and os.path.exists(atom_bin_dir): + os.environ["ATOM_BIN_DIR"] = atom_bin_dir + os.environ["PATH"] = ( + os.environ["PATH"] + os.pathsep + atom_bin_dir + os.pathsep + ) # Set joern_home from environment variable # This is required to handle bundled exe mode if ( @@ -583,6 +595,9 @@ def exec_tool( if go_mods: modules = [os.path.dirname(gmod) for gmod in go_mods] for amodule in modules: + # Expand . directory names + if amodule == ".": + amodule = os.path.abspath(amodule) cmd_with_args = cpg_tools_map.get(cpg_cmd_lang) # Fallback to atom if the command doesn't exist if ( @@ -906,11 +921,13 @@ def exec_tool( ) else: LOG.info( - """%s for %s is %s. You can import this in joern using importCpg("%s")""", + """%s for %s is %s.\nTo import this in joern, use importCpg(%r)""", whats_built, tool_lang_simple, cpg_out, - cpg_out, + str(PureWindowsPath(cpg_out)) + if sys.platform == "win32" + else cpg_out, ) with open(manifest_out, mode="w", encoding="utf-8") as mfp: # In case of github action, we need to convert this to relative path diff --git a/poetry.lock b/poetry.lock index e119f64..603bba5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1315,4 +1315,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<3.12" -content-hash = "3495c0891a8fc2500286fdb2615da3f5248815bc3d2737f6f1d646476c577efa" +content-hash = "26d5e693e5754c32c285692c13850529f7186df79c749663bef4ac22544bb9cf" diff --git a/pyproject.toml b/pyproject.toml index 660882e..bf741d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cpggen" -version = "1.8.1" +version = "1.8.2" description = "Generate CPG for multiple languages for code and threat analysis" authors = ["Team AppThreat "] license = "Apache-2.0"