Skip to content
AppThreatPublic

About

atom is a novel intermediate representation for applications and a standalone tool that is powered by chen.

Topics

Resources

Security policy

Stars

107 stars

Watchers

2 watching

Forks

Repository files navigation

atom (⚛)

atom turns an application into a graph of its code, with types, calls and data flows resolved, and answers questions about it: which libraries the code actually uses and where, whether attacker-controlled data can reach a dangerous call, which endpoints it serves, and where C and C++ code can overrun memory. It is a command-line tool and an intermediate representation, built on the chen code analysis library.

OWASP cdxgen runs atom to add usage, call-site and reachability evidence to the SBOMs it generates, and OWASP dep-scan uses that evidence to decide which vulnerabilities are reachable.

SBOM npm GitHub Downloads (all assets, all releases)

atom 4.0 is built on chen 4.0. It adds the callsites slice for every language, the memory-safety command for C and C++, a C and C++ frontend built on the EDG front end, support for vendored code, CycloneDX BOM input, and faster and more deterministic slicing. What is new in atom 4.0 lists the changes and what consumers of atom's output need to know.

What atom does

Command What it writes
atom (no command) An atom file (app.atom): the code property graph, optionally with data dependencies.
usages The usages slice: how each object, call and type is used inside every method. cdxgen's evidence of library use.
callsites One record per use of an imported module, class or header, at the position of the use, with the package it belongs to.
reachables Flows from tagged sources (framework inputs, environment, files) to tagged sinks (SQL, commands, network, crypto), with the packages they pass through.
data-flow Data-flow slices between definitions and uses.
memory-safety Memory-safety findings for C and C++ (bounds, lifetimes, integer widths, allocation state) as JSON or SARIF.
parsedeps The dependencies a project declares, from its build files and imports.
export The graph as GraphML, GraphSON, GEXF, DOT, Neo4j CSV, or JSON arrays for graph neural networks.
algorithms Graph algorithms over the call graph: centrality, cycles, dominators, paths and more.

The slices specification and the lessons describe each output in detail.

Languages

Language -l Notes
C and C++ c, cpp With the Eclipse CDT parser (default) or the EDG front end (--c-frontend edg, needs edga 0.4.0). Compilation databases, headers and preprocessed .i files (h, i). See C/C++ frontends.
Java java Java 8 to Java 26 syntax, Lombok, and the encoding the build declares. Spring, JAX-RS, Micronaut, servlets, Vert.x, gRPC, JDBC/JPA/MyBatis, AI SDKs, MCP tools, cloud SDKs, messaging and JNI/FFM boundaries are tagged automatically.
JVM bytecode jar, jimple JARs and class directories. Reads JDK classes from an installed JDK 8 or later.
Android apk, dex APKs and split bundles (.apkm, .apks, .xapk). Needs the Android SDK (ANDROID_HOME or --android-sdk) or the container image.
JavaScript and TypeScript js, ts JavaScript, TypeScript and Flow, Vue, Svelte and SvelteKit, and Astro components. Needs astgen from atom-parsetools 2.x (1.x also works).
Python python Python 3 up to 3.15.
PHP php PHP 7.0 to 8.5, limited 5.x. Needs PHP 7.4 or later and phpastgen from atom-parsetools.
Ruby ruby Ruby 1.8 to 4.0 syntax. Needs rbastgen from atom-parsetools and a Ruby 3.4 or 4.0 runtime.
Scala scala Work in progress.

Installation

atom needs Java 23 or later, except for the native images. The parsers for JavaScript, TypeScript, PHP and Ruby come from the @appthreat/atom-parsetools npm package.

npm

npm install -g @appthreat/atom @appthreat/atom-parsetools --ignore-scripts
atom --version

atom --version prints the atom, chen, atom-parsetools and parsa versions. atom-parsetools 2.x installs parsa, its native type map writer, as an optional npm package for the host's platform. On Linux x86_64 (glibc and musl), Linux ARM64, macOS ARM64 and Windows x86_64, @appthreat/atom installs the native image; on other platforms it runs the JVM distribution.

For reachables and package URLs, generate a CycloneDX SBOM with cdxgen and pass it with --bom-file, or leave it in the project directory. JavaScript reachables also work without one.

npm install -g @cdxgen/cdxgen --omit=optional --ignore-scripts

Native images

Each release carries native images built with GraalVM, each with a .sha512 file: atom-amd64 and atom-arm64 for Linux, atom-linux-musl-amd64 for musl, atom-darwin-arm64 for macOS on Apple silicon, and atom.exe for Windows x86_64.

curl -LO https://github.com/AppThreat/atom/releases/latest/download/atom-amd64
chmod +x atom-amd64
./atom-amd64 --help
curl -LO https://github.com/AppThreat/atom/releases/latest/download/atom.exe
.\atom.exe --help

The JVM bytecode languages (jar, jimple, android, apk, dex, scala, tasty, sbt) read the JDK classes from an installed JDK 8 or later. The native image looks in --jdk-path, ATOM_JAVA_HOME, JAVA_HOME, JDK_HOME, the java on PATH and common install locations, in that order. Without a JDK the atom is still built, with the JDK types left as phantoms, and atom prints a notice. The native images do not bundle astgen, phpastgen or rbastgen: install @appthreat/atom-parsetools for those.

Containers

docker run --rm -v /tmp:/tmp -v $HOME:$HOME -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom -l java -o /app/app.atom /app

ghcr.io/appthreat/atom and ghcr.io/appthreat/atom-sle include atom-parsetools, PHP, Ruby, the Android SDK, a C++ compiler and edga, so every language and both C/C++ frontends work out of the box. The atom-ruby, atom-ruby3, atom-alpine-ruby and atom-alpine-ruby3 images target Ruby projects. All images are built for amd64 and arm64.

Quick start

# the graph, with data dependencies
atom -l java --with-data-deps -o app.atom .
# how the code uses its libraries
atom usages -l python -o app.atom -s usages.json .
# every use of an imported module, with its package (BOM from cdxgen)
atom callsites -l js --bom-file bom.json -o app.atom -s callsites.json .
# reachable flows from inputs to sinks, for a web review
atom reachables --profile appsec -l python -o app.atom -s reachables.json .
# memory-safety findings for C, using the build's compilation database
atom memory-safety -l c --compile-commands build --format sarif -o app.atom -s findings.sarif .

CLI usage

Usage: atom [parsedeps|data-flow|usages|callsites|reachables|memory-safety|export|algorithms] [options] [input]

  -o, --output <value>     output filename. Default app.⚛ or app.atom in windows
  -s, --slice-outfile <value>
                           export intra-procedural slices as json
  -l, --language <value>   source language
  --frontend-args <value>  Advanced frontend configuration: comma-separated key=value pairs, where a list value keeps its own commas. Repeatable. E.g. --frontend-args defines=DEBUG,NDEBUG,only-ast-cache=true
  --frontend-args-keys     Print the supported --frontend-args keys for the selected language (-l) and exit.
  --exclude <value>        Comma-separated files/folders to exclude (relative to input or absolute).
  --exclude-regex <value>  Regex of file paths to exclude during analysis.
  --no-ast-cache           Disable the on-disk AST cache for this run (default: enabled).
  --cache-dir <value>      Directory for the AST cache (default: <input>/.chen).
  --schema-check           Enable early schema validation during AST creation.
  --no-dummy-types         Disable placeholder dummy types during type propagation.
  --type-prop-iterations <value>
                           Maximum iterations of type propagation (applies to supported frontends).
  --cache <value>          Cache mode: all (default) | none | no-ast | no-cpg | no-astgen | no-summary.
  --perf-report <value>    Opt-in per-stage performance report: pass a file path to have atom append NDJSON lines (wall ms, applying-thread CPU ms / allocated MB) for every frontend, pass, dataflow and slicing stage. Separate analysis from verification timing with it.
  --parse-report <value>   Opt-in per-file parse report: pass a file path to have atom write one JSON document naming every file the frontends left out or only partly read, with the outcome (unparsed, dropped, partial), the stage and the parser's reason. Separate a broken project from a quietly incomplete one with it. Written even when the run fails.
  --cpp-standard <value>   C/C++ standard, e.g. c++17, c++20. (C/C++ only)
  --define <value>         Define a preprocessor name. Repeatable. (C/C++ only)
  --auto-defines           Run a macro census first and define the build-option macros (CONFIG_*, ENABLE_*, template-declared) that hide #if code. Opt-in: it changes what is analysed. (C/C++ only)
  --suggest-defines <file>
                           Write the macro census to <file>.json and a reviewable --macro-files header to <file>.h, then exit; with --auto-defines, write it and continue. (C/C++ only)
  --include-path <value>   Header include path. Repeatable. (C/C++ only)
  --compile-commands <file|dir>
                           Parse the translation units of a JSON compilation database (compile_commands.json, or a directory holding one) with their own flags. (C/C++ only)
  --compile-commands-only  With --compile-commands, parse only the database's translation units. (C/C++ only)
  --c-build-contexts <first|all>
                           With a compilation database that compiles one file more than once: analyse the first entry's build context (first, the default) or every distinct one (all, a function whose body differs keeps one copy per context). (C/C++ only)
  --c-isolate              Parse each translation unit in a worker process of its own; a unit whose worker exits, hangs or runs out of memory is reported with the reason and retried once in a fresh worker. (C/C++ only)
  --c-frontend <cdt|edg|edg-fallback>
                           The C/C++ frontend: cdt (default, the Eclipse CDT parser), edg (the EDG front end, through the edga exporter), or edg-fallback (edg, with cdt for the files edga cannot export). (C/C++ only)
  --edga-path <file>       The edga binary for the edg frontends (default: EDGA_PATH, then the PATH). (C/C++ only)
  --delombok-mode <value>  Delombok strategy: no-delombok|default|types-only|run-delombok. (Java only)
  --jdk-path <value>       JDK used to resolve builtin Java types. (Java, JVM bytecode and Scala)
  --fetch-deps             Fetch dependency jars for extra type information. (Java only)
  --no-build-tools         Never run the project's build tools: no Maven or Gradle dependency fetch and no delombok for Java sources, and no scalasem (sbt) for Scala. Overrides --fetch-deps, --delombok-mode and the same keys from --frontend-args or a config file.
  --ts-types <value>       Resolve types from TypeScript declarations (default: true). (JS/TS only)
  --flow                   Enable Flow mode. (JS only)
  --venv-dir <value>       Virtual-environment directory (default: .venv). (Python only)
  --ignore-paths <value>   Comma-separated paths to ignore from analysis. (Python only)
  --android-sdk <value>    Path to android.jar, a platform directory holding it, or an SDK directory. (Jimple/Android only)
  --app-prefix <value>     Application package of a bytecode input; repeatable. Replaces the boundary the APK or jar manifest would give, and the jar's package prefixes. (Jimple only)
  --external-paths <value>
                           Regular expression of vendored input paths (third_party/, a copied single-header library); matched files are parsed as always but their methods and types are marked external, and uses of them from the project become callsites records. The match is relative to the input root, with / as separator, and begins at a path segment (third_party does not match src/not_third_party). A BOM given with --bom-file or --bom-dir marks the directories of its components (cdx:vendored:path) the same way. (Not for bytecode inputs.)
  --solver-depth <value>   Recursive jar unpacking depth (default: 1). (Jimple/Scala only)
  --full-resolver          Enable whole-program, transitive call resolution. (Jimple/Scala only)
  --php-ini <value>        php.ini path for the PHP parser. (PHP only)
  --disable-type-stubs     Disable type-stub based type recovery. (Ruby only)
  --with-data-deps         generate the atom with data-dependencies - defaults to `false`
  --remove-atom            do not persist the atom file - defaults to `false`
  -x, --export-atom        export the atom file with data-dependencies to graphml - defaults to `false`
  --reuse-atom             reuse existing atom file - defaults to `false`. The memory-safety command reuses an atom any command built: when the atom carries no memory-safety overlay tags, the overlay runs over the loaded graph in memory and the atom file itself is not changed.
  --export-dir <value>     export directory. Default: atom-exports
  --export-format <value>  export format graphml or dot. Default: graphml
  --config <value>         path to a JSON config file with frontend options and settings for the export and algorithms commands. An empty file sets nothing.
  --project-config         read atom.json, .atom/atom.json or .atom/config.json from the input directory when --config is not given. Off by default, since that file comes from the analysed project.
  --memory-api-config <value>
                           path to a JSON file (memory-apis.json schema) merged over the built-in memory-API inventory by API name, declaring in-house wrappers or platform argument roles. (C/C++ only)
  --validation-config <value>
                           path to a JSON file declaring validators/sanitisers (chennai.json schema). Reachable flows passing through a declared sanitiser are dropped for its categories.
  --bom-file <value>       the project's CycloneDX BOM or VDR, e.g. from cdxgen. Reachables takes package purls and component tags from it; without it or --bom-dir, a BOM in the input directory is used.
  --bom-dir <value>        a directory of CycloneDX BOMs: every *bom*.json, *.cdx.json and *.vdr.json under it is used as with --bom-file.
  --file-filter <value>    the name of the source file to generate slices from. Uses regex.
  --method-name-filter <value>
                           filters in slices that go through specific methods by names. Uses regex.
  --method-parameter-filter <value>
                           filters in slices that go through methods with specific types on the method parameters. Uses regex.
  --method-annotation-filter <value>
                           filters in slices that go through methods with specific annotations on the methods. Uses regex.
  --max-num-def <value>    maximum number of definitions in per-method data flow calculation - defaults to 2000
  --legacy-dataflow        use the classic data-flow engine and disable mini-graph fragment caching. By default atom uses the faster, lower-allocation Flux engine with fragment caching enabled.
  input                    source file or directory
Command: parsedeps
Extract dependencies from the build file and imports
Command: data-flow [options]
Extract backward data-flow slices
  --slice-depth <value>    the max depth to traverse the DDG for the data-flow slice - defaults to 7.
  --sink-filter <value>    filters on the sink's `code` property. Uses regex.
Command: usages [options]
Extract local variable and parameter usages
  --min-num-calls <value>  the minimum number of calls required for a usage slice - defaults to 1.
  --include-source         includes method source code in the slices - defaults to false.
  --extract-endpoints      extract http endpoints and convert to openapi format using atom-tools - defaults to false.
  --also-callsites <value>
                           also write the callsites slice to the given path: the atom is built and tagged once for both slices.
Command: callsites
Extract one record per use of an imported module, class or header, for every language atom reads
Command: reachables [options]
Extract reachable data-flow slices based on automated framework tags
  --source-tag <value>     source tag - defaults to framework-input. Comma-separated values allowed.
  --sink-tag <value>       sink tag - defaults to framework-output. Comma-separated values allowed.
  --slice-depth <value>    the max depth to traverse the DDG during reverse reachability - defaults to 7.
  --include-crypto         includes crypto library flows - defaults to false.
  --profile <value>        reduce false positives with a flow-filtering profile: appsec, generic. Defaults to generic (no extra filtering).
Command: memory-safety [options]
Run the memory-safety overlay and write findings (rule, cwe, kind, confidence, flow) as JSON or SARIF. With --reuse-atom the overlay runs over the loaded graph when the reused atom carries no overlay tags; the atom file itself is not changed.
  --min-confidence <value>
                           drop findings below this confidence: high, medium or low. Defaults to keeping all.
  --format <value>         output format: json or sarif (SARIF 2.1.0). Default: json.
  --include-system-headers
                           keep findings located in a file outside the analysed directory, such as a header from a system include directory. They are dropped by default; kept ones print their absolute path.
  --memory-api-profiles <value>
                           which declared memory-API library profiles the overlay applies: auto selects per translation unit by the headers it includes, none turns profiles off, or a comma list of profile names forces exactly those. Default: auto. (C/C++ only)
Command: export [options]
Export the atom to a graph format (dot, graphml, gexf, graphson, neo4jcsv, gnn)
  --format <value>         export format: dot, graphml, gexf, graphson, neo4jcsv or gnn
  --scope <value>          export scope: whole or methods. Default: whole
  --out <value>            output directory. Default: atom-exports
Command: algorithms [options]
Run a graph algorithm over the atom and write the result as JSON
  --type <value>           algorithm: scc, toposort, dominators, paths, centrality, lowest-common-ancestors, dependency-sequencer, union-find, heap-walker, or context-sensitive-paths
  --source <value>         source method full-name pattern for the paths algorithm. Uses regex.
  --target <value>         target method full-name pattern for the paths algorithm. Uses regex.
  --max-depth <value>      maximum path depth for the paths algorithm
  --version                print the versions of atom, chen, atom-parsetools and parsa, then exit
  --help                   display this help message

Call sites

callsites writes one record per use of an imported module, class, function or header: where it is (file, line, col), what was used (module, path, kind such as call, new, ref, extends, import, decorator or macro), how atom found out (via: binding, type, name or macro), whether it is a runtime built-in, and the package URL it belongs to (purl). It works for JavaScript and TypeScript, Python, Java source, PHP, Ruby, JVM bytecode and C and C++. Package URLs come from a BOM (--bom-file, --bom-dir) or the project's lock files and installed packages, depending on the language. The output is byte-identical across runs.

atom callsites -l python --bom-file bom.json -o app.atom -s callsites.json .
atom usages -l js --also-callsites callsites.json -o app.atom -s usages.json .

usages --also-callsites writes both slices from one process. Code in vendored directories (--external-paths third_party, or the directories a BOM records as vendored) is treated as a dependency, and uses of it become call sites. Lesson 9 describes the records for each language.

Memory safety

memory-safety runs chen's memory-safety overlay over a C or C++ atom and reports out-of-bounds access and overlapping copies, use after free and after scope, null dereference, uninitialised reads, integer narrowing, overflow, shifts and division, format strings, and check-then-use races. Each finding has a rule id, a CWE, a confidence and the flow that leads to it, as JSON or SARIF 2.1.0 (--format sarif). --min-confidence high|medium|low drops weaker findings, and --memory-api-config declares in-house allocation and copy wrappers. Both C/C++ frontends work; the EDG frontend gives the overlay more resolved facts. See C/C++ frontends.

Reachability profiles

The default reachables run is deliberately broad: it reports every flow from a tagged source to a tagged sink. For a focused review you can apply a profile with --profile, which post-filters the flows in a generic, tag-driven way that works across all languages.

atom reachables --profile appsec -o app.atom -s reachables.json -l python .

Profiles do two things:

  • Neutraliser barriers: a flow that passes through a call (or a call to a method) carrying a neutraliser tag is dropped. This builds on the validator/sanitiser handling above and adds declassification barriers such as ORM reads.
  • Source restriction: a profile may narrow the source tags considered. An explicit --source-tag always overrides this.
Profile Behaviour
generic (default) No additional filtering.
appsec Web/API review. Drops flows neutralised by validation, sanitization, sanitizer, encode or db-read (ORM reads), and restricts sources to web-facing inputs (framework-input, framework-route, framework, service-ingress), so CLI and driver sources are excluded.

The db-read barrier is what removes the bulk of object-identity false positives: when a request only supplies the primary key to an ORM accessor (e.g. get_object_or_404), the value read back is stored data, not live request input, so flows that merely pass through such a read are pruned.

Profiles are extensible. A profile is a ReachabilityProfile (name, neutraliser tags, optional source override) registered in io.appthreat.atom.slicing; add an entry to the registry to define your own.

Validators and sanitisers

Reachable flows that pass through a genuine validation or sanitisation routine are usually not real findings. You can declare such routines in a JSON file and pass it with --validation-config. atom tags every call to a declared method as a sanitiser and drops reachable flows that pass through one, scoped to the sink categories the sanitiser covers.

The file uses the same schema as chennai.json. sanitizers and validators are treated identically; categories is optional and, when omitted, the sanitiser covers every flow:

{
  "sanitizers": [
    {
      "name": "owasp-encode",
      "methods": ["org\\.owasp\\.encoder\\.Encode\\..*"],
      "categories": ["http"]
    },
    {
      "name": "sql-escape",
      "methods": [".*escapeSql.*"],
      "categories": ["sql"]
    }
  ],
  "validators": [{ "name": "bean-validation", "methods": [".*\\.validate"] }]
}

methods entries are matched against each call's method full name (treated as a regular expression when they contain regex characters, otherwise as an exact match). categories are matched against the tags on a flow's sink, so an HTML encoder declared for http does not suppress an SQL-injection flow.

atom reachables --validation-config validators.json -o app.atom -s reachables.json -l java .

The declarations can also be embedded in the project's chennai.json instead of passed on the command line. For programmatic use, the dataflow engine exposes passesThrough / doesNotPassThrough on a flow iterator, taking a simple node predicate.

Data-flow engine

atom computes data dependencies with the Flux engine (Flow-Lattice Update eXecutor) by default: a low-allocation, reaching-definitions solver that produces the same REACHING_DEF edges as the classic engine while using far less memory and GC time on large (e.g. bundled/transpiled JavaScript) methods. Per-file mini-graph (fragment) AST caching is also enabled by default, so unchanged files are restored from a .chen cache instead of being re-parsed.

Pass --legacy-dataflow to fall back to the classic engine and disable fragment caching (useful for A/B comparisons or troubleshooting). Caching can also be controlled independently via the -Dchen.cache.disabled=true system property.

Storage compression (-Dodb.storage.compression)

On large codebases the graph overflows the heap and unused nodes are spilled to disk; the spill/save path runs on a single thread, so the compressor it uses can dominate generation and slicing time. Choose it with a system property (no rebuild needed):

atom ... -Dodb.storage.compression=none|lzf|deflate
  • deflate (default): slowest but produces the smallest .atom; the default because atom file size matters most on large codebases.
  • lzf: fast compression; best for large graphs that overflow the heap, where DEFLATE dominates generation/slicing time.
  • none: no compression; fastest spill, largest .atom.

The compressor is recorded per chunk, so atoms written with any mode remain readable under any other (an lzf atom loads fine under the deflate default). Giving the JVM more heap (-Xmx) also reduces spilling: the cheapest win is to not overflow at all.

Method flow summaries

The reachables command builds a context-independent flow summary for each method before running the backward query. A summary records which parameters of a method reach its return value or its output parameters. The reachables engine uses these summaries to skip cross-call work that provably carries no taint, for example exploring an argument that the callee never writes, or descending into a callee whose return value can carry no taint. The pruning only removes empty work, so the reported flows are identical to a run without summaries.

Method flow summaries are part of the default Flux bundle: there is no separate flag. They are enabled whenever the Flux engine is used (the default) and turned off only by --legacy-dataflow, which also reverts to the classic data-flow engine.

Summaries are persisted in two ways: as CPG-native flow-summary tags on each METHOD node (so they serialize with the atom and are reused for free when the atom is reused/cached), and as a flowsummary-<fingerprint>.json sidecar next to the atom for runs that do not carry the tags. The fingerprint changes when any method body changes. The summary caches, like the other caches, can be turned off with -Dchen.cache.disabled=true.

atom reachables -o app.atom -s reachables.json -l java .

Export and algorithms commands

The export and algorithms commands work on an .atom file. If the file given with -o already exists it is reused; otherwise atom builds it from the input first, so there is no separate build step to remember.

export writes the graph in one of several formats. Use --scope whole for the entire atom or --scope methods to write one file per method (every format except neo4jcsv supports the per-method scope). The gnn format writes parallel id, label and edge arrays as JSON for machine-learning pipelines.

atom export -l python --format graphml --scope whole -o app.atom --out exports app.py
atom export -l python --format gnn --scope methods -o app.atom --out gnn-out app.py

algorithms runs a graph algorithm and writes the result to the slice output file as JSON:

  • centrality ranks methods in the call graph by PageRank and in-degree.
  • scc reports strongly connected components, which flags recursion in the call graph.
  • toposort returns a callee-before-caller ordering of methods. Recursive methods are grouped into stages (each flagged as recursive) so the ordering works even when the call graph has cycles.
  • dominators writes the control-flow dominator tree of each method.
  • paths finds paths between a source and target method selected by regular expression.
  • lowest-common-ancestors finds the lowest common callers of methods matching --source. Use case: locating common routing dispatchers or entry gates in security audits.
  • dependency-sequencer sequences method call dependencies into parallelizable execution stages. Use case: parallelizing inter-procedural summary calculations.
  • union-find groups methods into independent connected components of the call graph. Use case: discovering isolated modules/codebases for refactoring or microservice separation.
  • heap-walker traverses the AST of a method matching --source in stack-safe DFS order. Use case: memory-safe control flow and structure analysis on deep or generated ASTs.
  • context-sensitive-paths finds call-stack matching paths from --source to --target. Use case: precise data-flow/reachability tracing without false paths across call sites.
atom algorithms -l python --type centrality -o app.atom -s centrality.json app.py
atom algorithms -l python --type paths --source '.*main$' --target '.*helper$' -o app.atom -s paths.json app.py

Verbose or repeatable parameters can be supplied with --config <file>, a JSON file. Command-line flags override values from the file. For example, an algorithms config file:

{
  "type": "paths",
  "source": ".*main$",
  "target": ".*helper$",
  "maxDepth": 20,
  "out": "paths.json"
}

Sample Invocations

Generate an atom

# Compile java project
atom -o app.atom -l java .
atom -o app.atom -l jar <jar file>
export ANDROID_HOME=<path to android sdk>
atom -o app.atom -l apk <apk file>

Split bundles are also supported. A .apkm, .apks, or .xapk file is unpacked automatically and the apks that carry dalvik bytecode are analysed.

export ANDROID_HOME=<path to android sdk>
atom -o app.atom -l apk <apkm file>

When slicing an Android apk, atom runs the chen Android tagger passes over the code property graph. These passes attach semantic tags to the flows in a reachable slice, including personally identifiable information such as pii-email and pii-device-id, regulated data such as pci-dss, gdpr, and phi-medical, secrets, third party trackers tagged as tracker, and network direction tagged as service-egress, service-ingress, and on-device-ai. atom-tools consumes these tags to attribute reachable services and to enrich the CycloneDX SBOM produced by blint.

Create reachables slice for a java project.

cd <path to repo>
cdxgen -t java --deep -o bom.json .
atom reachables -o app.atom -s reachables.json -l java .

Pass the argument --reuse-atom to slice based on an existing atom file.

atom reachables --reuse-atom -o app.atom -s reachables.json -l java .

Example with container-based invocation.

docker run --rm -v /tmp:/tmp -v $HOME:$HOME -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom reachables -l java -o /app/app.atom -s /app/reachables.slices.json /app
# podman run --rm -v /tmp:/tmp -v $HOME:$HOME -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom reachables -l java -o /app/app.atom -s /app/reachables.slices.json /app

Create usages slice for a java project.

atom usages -o app.atom --slice-outfile usages.json -l java .

Example for a Ruby 4 project with container-based invocation.

docker run --rm -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom usages -l ruby -o /app/app.atom -s /app/usages.slices.json /app
# podman run --rm -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom usages -l ruby -o /app/app.atom -s /app/usages.slices.json /app

Pass the argument --platform=linux/amd64, if you face issues with Java or Ruby builds on arm64 architecture.

docker run --rm --platform=linux/amd64 -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom usages -l ruby -o /app/app.atom -s /app/usages.slices.json /app
# podman run --rm --platform=linux/amd64 -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom usages -l ruby -o /app/app.atom -s /app/usages.slices.json /app

For Ruby 4, there is an alpine-based version available.

docker run --rm -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/appthreat/atom-alpine-ruby atom usages --extract-endpoints -l ruby -o /app/app.atom -s /app/usages.slices.json /app
# podman run --rm -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/appthreat/atom-alpine-ruby atom usages --extract-endpoints -l ruby -o /app/app.atom -s /app/usages.slices.json /app

Ruby 3 variant is also available for alpine.

docker run --rm -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/appthreat/atom-alpine-ruby3 atom usages --extract-endpoints -l ruby -o /app/app.atom -s /app/usages.slices.json /app
# podman run --rm -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/appthreat/atom-alpine-ruby3 atom usages --extract-endpoints -l ruby -o /app/app.atom -s /app/usages.slices.json /app

Create data-flow slice for a java project.

atom data-flow -o app.atom --slice-outfile df.json -l java .

Learn more about slices or view some samples

Extract HTTP endpoints in openapi format using atom-tools

atom can automatically invoke atom-tools convert command to extract http endpoints from the usages slices. Pass the argument --extract-endpoints to enable this feature.

pip install atom-tools
atom usages --extract-endpoints -o app.atom --slice-outfile usages.json -l java .

A file called openapi.json would be created with the endpoints information. Use the environment variable ATOM_TOOLS_OPENAPI_FILENAME to customize the filename.

ATOM_TOOLS_OPENAPI_FILENAME=openapi.json atom usages --extract-endpoints -o app.atom --slice-outfile usages.json -l ruby .

Container-based invocation:

docker run --rm -v /tmp:/tmp -e ATOM_TOOLS_OPENAPI_FILENAME=openapi.json -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom usages --extract-endpoints -l ruby -o /app/app.atom -s /app/usages.slices.json /app
# podman run --rm -v /tmp:/tmp -e ATOM_TOOLS_OPENAPI_FILENAME=openapi.json -v $(pwd):/app:rw -t ghcr.io/appthreat/atom atom usages --extract-endpoints -l ruby -o /app/app.atom -s /app/usages.slices.json /app

Export atom to graphml or dot format

It is possible to export each method along with data dependencies in an atom to graphml or dot format. Pass --export-atom (-x) to enable this feature.

atom -o app.atom -l java --export-atom --export-dir <export dir> <path to application>

The resulting graphml files could be imported into Neo4j or NetworkX for further analysis. Use the argument --export-format for dot format.

atom -o app.atom -l java --export-atom --export-format dot --export-dir <export dir> <path to application>

In dot format, individual representations such as ast, cdg, and cfg would also get exported.

To also compute and include data-dependency graph (DDG) information in the exported files, pass --with-data-deps

atom -o app.atom -l java --export-atom --export-dir <export dir> --with-data-deps <path to application>

Environment variables

Variable Description
CHEN_IGNORE_DIRS Comma-separated list of directories to ignore for every language frontend.
CHEN_IGNORE_TEST_DIRS Set to true to ignore common test directories (test, tests, mocks) for every language frontend.
CHEN_C_IGNORE_DIRS Comma-separated list of additional directories to ignore for the C/C++ and header frontends.
CHEN_CPP_IGNORE_DIRS Comma-separated list of additional directories to ignore for the C++ frontend.
CHEN_JAVA_IGNORE_DIRS Comma-separated list of additional directories to ignore for the Java source frontend.
CHEN_JIMPLE_IGNORE_DIRS Comma-separated list of directories to ignore for the Jimple/JAR/Android/APK/DEX frontend.
CHEN_SCALA_IGNORE_DIRS Comma-separated list of directories to ignore for the Scala frontend.
CHEN_JAVASCRIPT_IGNORE_DIRS Comma-separated list of directories to ignore for the JavaScript, TypeScript, and Flow frontend.
CHEN_JS_IGNORE_DIRS Alias for JavaScript, TypeScript, and Flow ignored directories.
CHEN_TYPESCRIPT_IGNORE_DIRS Alias for TypeScript and Flow ignored directories.
CHEN_PYTHON_IGNORE_DIRS Comma-separated list of directories to ignore for Python. If unset, Atom uses Python's default ignored directories.
CHEN_PHP_IGNORE_DIRS Comma-separated list of additional directories to ignore for the PHP frontend.
CHEN_RUBY_IGNORE_DIRS Comma-separated list of additional directories to ignore for the Ruby frontend.
CHEN_JIMPLE_JDK_CLASSES Where the JVM bytecode frontends read JDK classes from: auto (default: the running JVM, or an installed JDK in the native image), image (always an installed JDK), platform (the running JVM) or none. Also -Dchen.jimple.jdk-classes.
CHEN_DELOMBOK_MODE Delombok mode for the Java frontend (no-delombok, default, types-only, run-delombok).
CHEN_INCLUDE_PATH Include directories for the C frontend. Separate paths with : or ; (only ; on Windows).
CHEN_ASTGEN_OUT Existing astgen output directory. Improves performance for JavaScript, TypeScript, and Flow during repeated invocations by reusing existing AST json data.
EDGA_PATH The edga binary for --c-frontend edg and edg-fallback, when --edga-path is not given. Otherwise edga is looked up on PATH.
ASTGEN_TYPES Type map engine for astgen 2.x: native (parsa, the TypeScript 7 engine) or ts6. The astgen-types frontend argument sets it for a run.
ASTGEN_NATIVE_BIN Path to parsa, the native type map writer of atom-parsetools 2.x, when it is not found next to astgen.
ANDROID_HOME Android SDK directory, used to find android.jar for APK, DEX and split-bundle inputs when --android-sdk is not given.
GEM_HOME, BUNDLE_PATH Where installed gems are found, for package URLs in the Ruby callsites slice.
GRADLE_USER_HOME Gradle cache used, with the local Maven repository, to attribute JVM bytecode callsites to packages. Nothing is downloaded.
ATOM_CONFIG_FILE JSON config file for frontend options and the export and algorithms commands, when --config is not given.
ATOM_TOOLS_OPENAPI_FORMAT OpenAPI format for atom-tools. Default: openapi3.1.0; alternative: openapi3.0.1.
ATOM_TOOLS_WORK_DIR Working directory for atom-tools. Defaults to atom input path.
ATOM_SCALASEM_WORK_DIR Working directory for scalasem. Defaults to atom input path.
ATOM_SCALASEM_REUSE Set to true to reuse an existing scalasem version 2 report of the same project instead of running scalasem again.
ATOM_SCALASEM_SLICES_FILE scalasem report path; a relative path resolves against the scalasem work directory. When unset, the report is written beside the -s slices file, else beside the -o atom file, else into the input path.
ATOM_JVM_ARGS Overrides the JVM arguments, including heap memory values, constructed by the atom Node.js wrapper.
ATOM_JAVA_HOME Java 23 or above to be used by atom.
ATOM_TIMEOUT Maximum run time in milliseconds, enforced by the atom Node.js wrapper: atom is stopped with SIGTERM, then SIGKILL, and the wrapper exits with status 124.
ATOM_KILL_GRACE_MS How long the wrapper waits after SIGTERM before it kills atom with SIGKILL. Default: 10000.
ATOM_PARENT_PID Supervising process id; cdxgen sets its own. The wrapper stops atom when it exits, and passes its own id on, so atom exits if the wrapper is killed.
PHP_CMD Overrides the PHP command used by the PHP frontend.
PHP_PARSER_BIN Overrides the php-parse command used by the PHP frontend.
SCALA_CMD Overrides the scala command.
SCALAC_CMD Overrides the scalac command used by the scala frontend.
ASTGEN_IGNORE_DIRS Comma-separated list of directories to ignore by the JavaScript astgen pre-processor command.
ASTGEN_IGNORE_FILE_PATTERN File pattern to ignore by the JavaScript astgen pre-processor command.
ASTGEN_INCLUDE_NODE_MODULES_BUNDLES Also include source code from node_modules directory. Makes the flows more complete at the cost of increased memory use.
JAVA_CMD Overrides the java command.
RUBY_CMD Overrides the Ruby command used by the rbastgen wrapper.
ATOM_RUBY_HOME Ruby installation directory for the rbastgen wrapper, when Ruby is not on PATH.
RUBY_ASTGEN_BIN Path to the ruby_ast_gen script that the rbastgen wrapper runs. The simplest way to test a generator build.
RBASTGEN_PATH Path to the rbastgen executable itself, overriding the one on PATH; the rbastgen.path system property takes precedence.

Advanced Configuration

For complex projects you may need to pass granular configuration options to the underlying language frontend. You can achieve this using the --frontend-args flag.

This flag accepts a comma-separated list of key-value pairs in the format key=value, and may be given more than once. A list value keeps its own commas (includes=/a,/b).

Usage

--frontend-args key1=value1,key2=value2,key3=value3

Supported Arguments (C/C++)

The following arguments are supported when --language is c, cpp or c++, and by the header-only modes h, hpp and i. atom -l c --frontend-args-keys lists every key with its default.

Key Type Description Example
defines List Preprocessor definitions. defines=DEBUG,VERSION=2
includes List Additional header include paths (alias: include-paths). includes=/opt/a/include,/opt/b
include-files List Header files to include in every translation unit. include-files=config.h
macro-files List Files whose macro definitions apply to every translation unit. macro-files=build/defs.h
cpp-standard String The C++ standard version to use. cpp-standard=c++17
compile-commands String A JSON compilation database (or a directory holding compile_commands.json): each translation unit is parsed with its own flags, and only its units and the project's headers are parsed. compile-commands=build
compile-commands-only Boolean With compile-commands, parse only the database's translation units. compile-commands-only=true
auto-defines Boolean Run the macro census and define the build-option macros it finds before parsing. auto-defines=true
macro-census String Write the macro census to <file>.json and <file>.h. macro-census=/tmp/census
include-auto-discovery Boolean Ask gcc and clang for the system include paths and guess the project's include dirs. include-auto-discovery=true
function-bodies Boolean Parse function bodies (default true). function-bodies=false
parse-inactive-code Boolean Parse code within disabled preprocessor blocks (e.g., inside #if 0). parse-inactive-code=true
with-image-locations Boolean Create image locations (explains how a name made it into the translation unit). with-image-locations=true
enable-ast-cache Boolean Cache parsed ASTs to disk to speed up later runs on unchanged files (default true). enable-ast-cache=false
ast-cache-dir String Directory to store cached AST files. Defaults to .chen in the input directory. ast-cache-dir=/tmp/cache
only-ast-cache Boolean Only generate AST cache files and exit. Useful for large projects to avoid OOM. only-ast-cache=true

Note: Boolean values must be passed as the strings true or false. A list value keeps its own commas: --frontend-args includes=/a,/b,cpp-standard=c++17 sets two include paths and the standard.

Supported Arguments (JavaScript and TypeScript)

Key Type Description Example
astgen-types Enum Type map engine for astgen 2.x: native (parsa, the TypeScript 7 engine) or ts6. An unknown value is reported and ignored. astgen-types=ts6

atom -l js --frontend-args-keys lists every key for the language with its default.

Supported Arguments (Python)

The following arguments are supported when --language is set to py or python. The python-deps family controls how installed dependencies (from the virtual environment) enter the graph - from none at all to the whole dependency tree with method bodies:

Key Type Description Example
venv-dir String Virtual-environment directory. Defaults to .venv. venv-dir=/opt/venv
ignore-paths List Paths to ignore from analysis. ignore-paths=build,dist
requirements-txt String Requirements file name. requirements-txt=requirements.txt
strict-parse Boolean Fail the run when any statement fails to parse (errors are always summarized). strict-parse=true
python-deps Enum Dependency treatment: none (default) | stubs (signature-only, external) | summaries (stubs + flow summaries) | full (whole dependency tree with bodies, external for attribution, explorable by the engine; opt-in, trades build cost for accuracy). python-deps=summaries
python-deps-rounds Int Transitive import-closure rounds for python-deps=stubs|summaries only (full ingests everything, unbounded). Default 2 - the imported distributions' own modules; raise to 3-4 for deeper chains. python-deps-rounds=3
typeshed-dir String Typeshed checkout (with a stdlib/ subtree) for python-deps stubs/summaries/full (full ingests stdlib signatures). Falls back to $CHEN_TYPESHED_DIR. typeshed-dir=/opt/typeshed

Note: With python-deps=full, reachables stays scoped to the project's own code: a flow whose source lives in library code is a fact about the library, not a finding about the analyzed project, so it is explored but not reported. A flow that merely traverses library code (project source -> library -> project sink) survives.

Examples

1. Setting C++ Standard and Defines Generate an atom for a C++ project using C++17.

atom -l c++ -o app.atom \
  --frontend-args cpp-standard=c++17,defines=NDEBUG,VERSION=2 \
  ./my-cpp-project

2. Handling Custom Include Paths If your project relies on headers located outside the source tree:

atom -l c -o app.atom \
  --frontend-args includes=/usr/local/include,/opt/mylib/include \
  ./src

3. Parsing Inactive Code To include code hidden behind preprocessor directives (like #ifdef WINDOWS when running on Linux):

atom -l c -o app.atom --frontend-args parse-inactive-code=true ./src

4. Large Projects: Two-Stage Generation (Memory Optimization) For very large C/C++ codebases, generating the full graph in one pass might consume too much memory. You can split the process into two stages using the AST cache.

Stage 1: Generate AST Cache Only This parses files one by one and saves their ASTs to disk (./src/.chen by default), keeping memory usage low.

atom -l c -o app.atom --frontend-args only-ast-cache=true,ast-cache-dir=/tmp/cache ./src

Stage 2: Generate Atom from Cache Run the command again with caching enabled. It will load the pre-computed ASTs from disk, significantly speeding up graph creation.

atom -l c -o app.atom --frontend-args enable-ast-cache=true,ast-cache-dir=/tmp/cache ./src

atom Specification

The intermediate representation used by atom is available under the same open-source license (MIT). The specification is available in protobuf, markdown, and html formats.

The current specification version is 1.0.0

Generating atom files

atom files (app.⚛ or app.atom) are zip files with serialized protobuf data. atom cli is the preferred approach to generate these files. It is possible to author a generator tool from scratch using the proto specification. We offer a sample in Python for interested users. We also offer proto bindings in additional languages which can be found here.

Example code snippet for generating an atom in python.

# Create a method fullname property
methodFullName = atom.CpgStructNodeProperty(
    name=atom.NodePropertyName.FULL_NAME, value=atom.PropertyValue("main")
)

# Create a method node with the fullname property
method = atom.CpgStructNode(
    key=1, type=atom.NodeType.METHOD, property=[methodFullName]
)

# Create an atom with a single node
atom_struct = atom.CpgStruct(node=[method])

# Create an atom (app.atom) by serializing this data into a zip file
with ZipFile("app.atom", "w") as zip_file:
    zip_file.writestr("cpg.proto", bytes(atom_struct))

Developing and contributing

atom builds with sbt 2 and JDK 23 or later (CI uses JDK 25), and needs Node.js for the parsers and the npm wrapper. chen, cpg2 and overflowdb2 come from GitHub Packages, so the build needs a GITHUB_TOKEN that can read packages.

export GITHUB_TOKEN=$(gh auth token)
sbt "clean; stage; scalafmt; testFull; createDistribution"
cd wrapper/nodejs
bash build.sh && sudo npm install -g .

Tests that need an external tool cancel themselves without it: astgen, phpastgen and rbastgen from atom-parsetools, PHP, and edga (EDGA_PATH) for the EDG frontend.

Testing Ruby against a specific rbastgen

Ruby support depends on the external ruby_ast_gen generator, which atom's Ruby frontend runs as a subprocess. There are two layers, and which knob to use depends on which one you are replacing:

  • rbastgen (from atom-parsetools) is a Node wrapper. It runs the bundled ruby_ast_gen script under a Ruby interpreter, so RUBY_ASTGEN_BIN points it at a different generator checkout - the simplest way to test a generator branch:

    RUBY_ASTGEN_BIN=/path/to/ruby_ast_gen/exe/ruby_ast_gen sbt test

    RUBY_CMD and ATOM_RUBY_HOME select the interpreter the wrapper uses; it needs Ruby 3.4.x or 4.0.x.

  • RBASTGEN_PATH (or -Drbastgen.path=) replaces the rbastgen executable itself, for a generator that is not driven by that wrapper. Because atom loads the Ruby frontend in-process it would otherwise inherit whatever rbastgen is first on PATH:

    RBASTGEN_PATH=/path/to/rbastgen sbt test
    sbt -Drbastgen.path=/path/to/rbastgen test

Both work for any chen-based tool and for atom at runtime. The end-to-end Ruby suite (RubyAtomWorkflowTests - atom generation, usage slicing and data-flow slicing over a small Ruby project) needs a generator implementing the 2.x JSON contract and cancels itself when the reachable one is older or unusable, rather than reporting assertion failures. A generator that fails to parse produces an empty atom, not an error, so check the reported version first if Ruby slices come back empty.

Using atom with chennai

chennai is the recommended query interface for working with atom.

chennai> importAtom("/home/almalinux/work/sandbox/apollo/app.atom")

atom-tools

atom-tools works with atom's slices: it converts usages slices to OpenAPI, and filters, queries and validates slices.

Troubleshooting

atom file is incomplete for large JS/TS projects

astgen might require a generous heap of memory for large JavaScript projects, especially flow projects. Use the environment variable NODE_OPTIONS to increase the memory available.

export NODE_OPTIONS="--expose-gc --max-old-space-size=16288"

For large projects such as React 19, astgen requires over 80 GB of heap memory! Use the environment variable CHEN_ASTGEN_OUT to make atom and chen, reuse any existing directory containing astgen generated json and typemap files.

To improve the accuracy further, include source code from the node_modules directory by setting ASTGEN_INCLUDE_NODE_MODULES_BUNDLES.

export ASTGEN_INCLUDE_NODE_MODULES_BUNDLES=true
export ASTGEN_IGNORE_DIRS=""

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

License

MIT

About

atom is a novel intermediate representation for applications and a standalone tool that is powered by chen.

Topics

Resources

Security policy

Stars

107 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages