Metadata-Version: 2.4
Name: applescript-tools
Version: 3.0.0
Summary: Tools for analyzing AppleScript malware: decompiler, disassembler, emulator
Author: pberba
License-Expression: MIT
Project-URL: Homepage, https://github.com/pberba/applescript-tools
Project-URL: Documentation, https://github.com/pberba/applescript-tools/tree/main/docs
Project-URL: Changelog, https://github.com/pberba/applescript-tools/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/pberba/applescript-tools/issues
Keywords: applescript,osascript,decompiler,disassembler,emulator,malware-analysis,macos
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Information Technology
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Disassemblers
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: applescript_tools/disassembler/LICENSE
Requires-Dist: tomli>=1.1; python_version < "3.11"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Provides-Extra: zip
Requires-Dist: pyzipper; extra == "zip"
Dynamic: license-file

# applescript-tools

Tools for analysing AppleScript malware, including run-only scripts, without
a Mac VM. They install one command, `osatool` (Python package
`applescript_tools`):

- **`osatool decompile`** turns compiled, run-only `.scpt` files back into
  source; see the
  [blog post](https://pberba.github.io/security/2025/12/14/decompiling-run-only-applescripts/)
  for how it works.
- **`osatool disassemble`** prints a compiled script's bytecode. It's built
  on a vendored copy of
  [Jinmo/applescript-disassembler](https://github.com/Jinmo/applescript-disassembler),
  which the decompiler also uses to load scripts.
- **`osatool emulate`** triages a sample: it emulates the script with a
  fake Mac and reports the commands it runs, what it downloads and uploads,
  the files it reads and drops, and the IOCs. Nothing is executed.
- **An offline compiler** (`applescript_tools.compiler`) parses
  AppleScript source into the same AST, so source text and compiled
  scripts are handled alike, on any OS.

## Installation

```shell
pip install applescript-tools
```

Python 3.10 or later, on any OS. For the latest from GitHub:
`pip install git+https://github.com/pberba/applescript-tools`. Or, from a
checkout, with uv:

```shell
git clone https://github.com/pberba/applescript-tools
cd applescript-tools
uv sync
uv run osatool --help
```

## Triage a sample

```shell
osatool emulate ~/Downloads/<sha256>.zip   # a VirusTotal/MalwareBazaar zip (password "infected"), read in memory
```

The report is the files the script drops and its IOCs: every shell command,
URLs, domains, files written and read, apps. A `warning:` line says when the
script used something the emulator has no model for. `-v` adds the trace of
what it did, in order, and the list of what isn't emulated, and `-vv` the
decoded strings, the questions nothing answered and the next steps for this
sample. Typically:

```shell
osatool emulate sample.zip -v                             # with the trace
osatool emulate sample.zip --brute-force --assume-files   # past anti-VM checks, into a stealer's target list
osatool emulate sample.zip --answers a.toml --update-answers   # unanswered questions go in a.toml as "?"…
# …replace the ones you know, and run it again
osatool emulate sample.zip -i                             # or answer on the terminal
```

See [docs/emulator.md](https://github.com/pberba/applescript-tools/blob/main/docs/emulator.md).

## Decompile or disassemble a script

```shell
osatool decompile sample.scpt > sample.applescript   # also sample zips and JXA
osatool disassemble sample.scpt                      # the bytecode
```

The decompiled output compiles, and recompiles to the same bytecode as the
original. See [docs/decompiler.md](https://github.com/pberba/applescript-tools/blob/main/docs/decompiler.md) and
[docs/disassembler.md](https://github.com/pberba/applescript-tools/blob/main/docs/disassembler.md).

### Demo

```shell
osacompile -x -o demo/demo_runonly.scpt demo/demo_source.applescript   # compile run-only
osadecompile demo/demo_runonly.scpt                                    # errOSASourceNotAvailable (-1756)
osatool decompile demo/demo_runonly.scpt > demo/demo_output.out
osatool emulate demo/demo_runonly.scpt -k
```

## Before applescript-tools

This project was `applescript-decompiler`. The old names keep working: the
commands `applescript_decompile`, `applescript_disassemble` and
`applescript_emulate`, and the imports `applescript_decompiler.*`, which are
the same modules as `applescript_tools.*`.

## Documentation

| Tool | Docs |
| --- | --- |
| `osatool emulate` | [emulator.md](https://github.com/pberba/applescript-tools/blob/main/docs/emulator.md): triage, the report, getting further, options · [answers-file.md](https://github.com/pberba/applescript-tools/blob/main/docs/answers-file.md): answering what the emulator can't, changing the fake Mac · [brute-force.md](https://github.com/pberba/applescript-tools/blob/main/docs/brute-force.md): how `--brute-force` explores both sides of `if`s · [emulation-model.md](https://github.com/pberba/applescript-tools/blob/main/docs/emulation-model.md): what's modelled, limits, where IOCs come from, code layout |
| `osatool decompile` | [decompiler.md](https://github.com/pberba/applescript-tools/blob/main/docs/decompiler.md): usage, and how decompilation works · [scripting-dictionaries.md](https://github.com/pberba/applescript-tools/blob/main/docs/scripting-dictionaries.md): adding app dictionaries |
| `osatool disassemble` | [disassembler.md](https://github.com/pberba/applescript-tools/blob/main/docs/disassembler.md) |
| offline compiler | [compiler.md](https://github.com/pberba/applescript-tools/blob/main/docs/compiler.md): parsing source text without `osacompile` |
| the Python library | [library-usage.md](https://github.com/pberba/applescript-tools/blob/main/docs/library-usage.md) |
| development | [development.md](https://github.com/pberba/applescript-tools/blob/main/docs/development.md): setup · [testing.md](https://github.com/pberba/applescript-tools/blob/main/docs/testing.md): tests, fixtures, debugging a decompilation |
