Skip to main content

Code Hierarchy Exploration Net (chen)

Project description

chen

Code Hierarchy Exploration Net (chen) is an advanced exploration toolkit for your application source code and its dependency hierarchy. This repo contains the source code for chen library and an advanced REPL console called chennai (chen not AI).

SBOM

Requirements

  • Java >= 21
  • Python >= 3.10
  • Node.js >= 20 (To run atom)
  • Minimum 16GB RAM

Getting started

chen container image has everything needed to get started.

Jupyter notebook with docker compose

Use the docker compose from this repo to try chennai with Jupyter Notebook.

git clone https://github.com/AppThreat/chen
cd chen
docker compose up

Use the controls in Jupyter to interact with the cells. For a preview via github click here

Jupyter console Jupyter console

Interactive console

To start the interactive console, run chennai command.

docker run --rm -v /tmp:/tmp -v $HOME:$HOME -v $(pwd):/app:rw -it ghcr.io/appthreat/chen chennai

Chennai server mode

chennai could also be run as an HTTP server.

docker run --rm -v /tmp:/tmp -v $HOME:$HOME -v $(pwd):/app:rw -p 8080:8080 -it ghcr.io/appthreat/chen chennai --server

Defaults:

  • Port 8080
  • Username chenadmin
  • Password chenpassword

Local Installation

# Install atom-parsetools and cdxgen
sudo npm install -g @appthreat/atom-parsetools@1.1.3 @cyclonedx/cdxgen --omit=optional

# Install chen from pypi
pip install appthreat-chen

To download the chen distribution.

chen --download

To generate custom graphs and models with atom for data science, download the scientific pack which installs support for the PyTorch ecosystem. conda is recommended for the best experience.

chen --download --with-science

Once the download finishes, the command will display the download location along with the environment variables that need to be set to invoke chennai console. Example output below:

[21:53:36] INFO     To run chennai console, add the following environment variables to your .zshrc or .bashrc:
export JAVA_OPTS="-Xmx16G"
export JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8 -Djna.library.path=<lib dir>"
export SCALAPY_PYTHON_LIBRARY=python3.12
export CHEN_HOME=/home/user/.local/share/chen
export PATH=$PATH:/home/user/.local/share/chen/platform:/home/user/.local/share/chen/platform/bin:

It is important to set these environment variables without which the console commands would fail with errors.

Running the console

Type chennai to launch the console.

chennai
 _                          _   _   _   _  __
/  |_   _  ._  ._   _. o   |_  / \ / \ / \  / |_|_
\_ | | (/_ | | | | (_| |   |_) \_/ \_/ \_/ /    |


Version: 0.0.7
Type `help` to begin


chennai>

Sample commmands

Help command

chennai> help
val res0: Helper = Welcome to the interactive help system. Below you find a table of all available
top-level commands. To get more detailed help on a specific command, just type

`help.<command>`.

Try `help.importCode` to begin with.
_______________________________________________________________________________________________________________________________________________________________
command          | description                                                               | example                                                       |
=============================================================================================================================================================|
annotations      | List annotations                                                          | annotations                                                   |
callTree         | Show call tree for the given method                                       | callTree(method full name)                                    |
close            | Close project by name                                                     | close(projectName)                                            |
declarations     | List declarations                                                         | declarations                                                  |
distance         | Show graph edit distance from the source method to the comparison methods | distance(source method iterator, comparison method iterators) |
exit             | Exit the REPL                                                             |                                                               |
files            | List files                                                                | files                                                         |
importAtom       | Create new project from existing atom                                     | importAtom("app.atom")                                        |
importCode       | Create new project from code                                              | importCode("example.jar")                                     |
imports          | List imports                                                              | imports                                                       |
methods          | List methods                                                              | methods('Methods', includeCalls=true, tree=true)              |
sensitive        | List sensitive literals                                                   | sensitive                                                     |
showSimilar      | Show methods similar to the given method                                  | showSimilar(method full name)                                 |
summary          | Display summary information                                               | summary                                                       |
reachables       | Show reachable flows from a source to sink. Default source: framework-input and sink: framework-output | reachables                       |
cryptos          | Show reachable flows from a source to sink. Default source: crypto-algorithm and sink: crypto-generate | cryptos                          |

Refer to the documentation site to learn more about the commands.

Languages supported

  • C/C++
  • H (C/C++ Header and pre-processed .i files alone)
  • Java (Requires compilation)
  • Jar
  • Android APK (Requires Android SDK. Set the environment variable ANDROID_HOME or use the container image.)
  • JavaScript
  • TypeScript
  • Flow
  • Python
  • Python (Supports 3.x to 3.13)
  • PHP (Requires PHP >= 7.4. Supports PHP 7.0 to 8.4 with limited support for PHP 5.x)
  • Ruby (Requires Ruby 3.4.7. Supports Ruby 1.8 - 3.4.x syntax)

Troubleshooing

Commands throw errors in chennai console

You might see errors like this in chennai console.

chennai> help
-- [E006] Not Found Error: -----------------------------------------------------
1 |help
  |^^^^
  |Not found: help
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | The identifier for `help` is not bound, that is,
  | no declaration for this identifier can be found.
  | That can happen, for example, if `help` or its declaration has either been
  | misspelt or if an import is missing.
   -----------------------------------------------------------------------------
1 error found

This error is mostly due to missing python .so (linux), .dll (windows) or .dylib (mac) file. Ensure the environment variables below are set correctly.

  • SCALAPY_PYTHON_LIBRARY - Use values such as python3.10, python3.11 based on the version installed. On Windows, there are no dots. Eg: python312
  • JAVA_TOOL_OPTIONS - jna.library.path must be set to the python lib directory
  • SCALAPY_PYTHON_PROGRAMNAME - Path to Python executable in case of virtual environments (Usually not required)

Origin of chen

chen is a fork of the popular joern project. We deviate from the joern project in the following ways:

  • Keep the CPG implementation at 1.0 based on the original paper.
  • Make code analysis accessible by adding first-class integration with Python and frameworks such as NetworkX and PyTorch.
  • Enable broader hierarchical analysis (Application + Dependency + Container + OS layer + Cloud + beyond)

We don't intend for bug-to-bug compatibility and often rewrite patches to suit our needs. We also do not bring features and passes that do not add value for hierarchical analysis.

License

Apache-2.0

Enterprise support

Enterprise support including custom language development and integration services is available via AppThreat Ltd.

Sponsors

YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of YourKit Java Profiler, YourKit .NET Profiler, and YourKit YouMonitor.

YourKit logo

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

appthreat_chen-2.5.20.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

appthreat_chen-2.5.20-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file appthreat_chen-2.5.20.tar.gz.

File metadata

  • Download URL: appthreat_chen-2.5.20.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for appthreat_chen-2.5.20.tar.gz
Algorithm Hash digest
SHA256 a6dce0dc70ff67a6867c3dc3541ad8fbd8d0c6767bcb16a3da3cf7f37e846895
MD5 188e3e42f0f4e5ddca1241936fe8ed30
BLAKE2b-256 be4d6045673fd73f0b281d60c22f213d8a1ebc07bb41fce4187333df0e1e3abc

See more details on using hashes here.

Provenance

The following attestation bundles were made for appthreat_chen-2.5.20.tar.gz:

Publisher: release.yml on AppThreat/chen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file appthreat_chen-2.5.20-py3-none-any.whl.

File metadata

  • Download URL: appthreat_chen-2.5.20-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for appthreat_chen-2.5.20-py3-none-any.whl
Algorithm Hash digest
SHA256 3c691e565a8074ae3755aee3cb7f0d2898f5d45e377e99847e050c16b31e1a5a
MD5 6ee4f21f033d20edcb0e7b8185a30976
BLAKE2b-256 7614b4c454e77f9c3146c230bd1b3d8f9223f7dbb9ed7a0e4c43486e6e1d6355

See more details on using hashes here.

Provenance

The following attestation bundles were made for appthreat_chen-2.5.20-py3-none-any.whl:

Publisher: release.yml on AppThreat/chen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page