Skip to content

Code examples

Eduardo Santos edited this page Mar 12, 2026 · 16 revisions

Compile a MAL Language (Legacy)

Compiling a mal-lang in this manner is no longer recommended. Now, it is recommended to load the language directly from .mal files (go to Create a MAL Model) into the mal-toolbox. However, this compilation is still supported.

Prerequisites:

  • Install maltoolbox
  • Create/download a MAL language in .mal file(s)

Compile a MAL Language with malc

Example compile coreLang on ubuntu machine:

# Download coreLang (you can do this without git as well)
git clone https://github.com/mal-lang/coreLang.git

# Move into the coreLang directory
cd coreLang

# Download malc (correct version for your OS can be found on https://github.com/mal-lang/malc/releases)
wget https://github.com/mal-lang/malc/releases/download/release%2F0.2.0/malc_0.2.0-1_amd64.deb

# Install malc
sudo dpkg -i malc_0.2.0-1_amd64.deb

# Compile coreLang (we are in the coreLang root directory)
# This will output org.mal-lang.coreLang-1.0.0.mar which,
# a '.mar'-archive containing the language.
malc src/main/mal/main.mal

Configure MAL-toolbox

MAL-toolbox uses a config file that sets logging and visualizer settings.

To write your own config file, create a file called 'maltoolbox.yml' and place it in the directory from where you are running mal-toolbox. The content of the file should be this:

logging: 
  log_level: INFO
  log_file: "logs/log.txt"
  attackgraph_file: "logs/attackgraph.yml"
  model_file: "logs/model.yml"
  langspec_file: "logs/langspec_file.yml"

You can change log level, log file, and output file paths.

Create a MAL Model

Prerequisites:

  • You have mal-toolbox installed.
  • A MAL language (.mal or .mar-file).

Creating a MAL Model using the mal-gui

  1. Install mal-gui.
  2. Launch mal-gui using the command malgui from the command line and select your language.
  3. Drag and drop the assets you want and create associations between them by SHIFT+Left clicking and dragging from one asset to another.
  4. Export the model to either .yml or .json (you can export scenario files as well, this is for the mal-simulator)

Create a MAL Model programatically using the mal-toolbox package

  1. Load your language using maltoolbox.language.LanguageGraph.
  2. Use the maltoolbox.model.Model class to create a model and add assets.
  3. Add associations to your assets using asset.add_associated_assets.

See how in this tutorial.

Generating an AttackGraph

Prerequisites:

  • MAL Toolbox
  • A MAL language (.mal or .mar-file).
  • A model file (.yml/.json).

Option 1: Using the MAL Toolbox cli

maltoolbox attack-graph generate [options] <model_file> <lang_file>

Example:

### Language given as a .mal
maltoolbox attack-graph generate [options] model.yml main.mal

### Language given as a .mar
maltoolbox attack-graph generate [options] model.yml org.mal-lang.coreLang-1.0.0.mar

This will output the attack-graph (.yml) to the logging directory of mal-toolbox.

The default logging directory is './logs' in the directory where the maltoolbox command is run.

Option 2: Generating an attack graph programatically

Use maltoolbox.attackgraph.create_attack_graph

See how in this tutorial.

Run a simulation

You can refer to the mal-simulator Wiki.