il2cpp-ghidrah 0.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. il2cpp_ghidrah-0.1.5/LICENSE +21 -0
  2. il2cpp_ghidrah-0.1.5/PKG-INFO +187 -0
  3. il2cpp_ghidrah-0.1.5/README.md +175 -0
  4. il2cpp_ghidrah-0.1.5/pyproject.toml +25 -0
  5. il2cpp_ghidrah-0.1.5/setup.cfg +4 -0
  6. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/__init__.py +3 -0
  7. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/__main__.py +3 -0
  8. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/cli.py +146 -0
  9. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/config.py +46 -0
  10. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/generators.py +167 -0
  11. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/ghidra.py +140 -0
  12. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/ghidra_scripts/ghidraUnityMetadata.py +96 -0
  13. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/ghidra_scripts/ghidra_with_struct_headless.py +610 -0
  14. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/ghidra_scripts/parse_header_headless.py +214 -0
  15. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/inputs.py +393 -0
  16. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/installation.py +160 -0
  17. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/pipeline.py +221 -0
  18. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/process.py +75 -0
  19. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah/selection.py +56 -0
  20. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah.egg-info/PKG-INFO +187 -0
  21. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah.egg-info/SOURCES.txt +24 -0
  22. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah.egg-info/dependency_links.txt +1 -0
  23. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah.egg-info/entry_points.txt +2 -0
  24. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah.egg-info/requires.txt +1 -0
  25. il2cpp_ghidrah-0.1.5/src/il2cpp_ghidrah.egg-info/top_level.txt +1 -0
  26. il2cpp_ghidrah-0.1.5/tests/test_cli.py +295 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 il2cpp-ghidrah contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: il2cpp-ghidrah
3
+ Version: 0.1.5
4
+ Summary: Headless Ghidra pipeline for Unity IL2CPP applications
5
+ Author: il2cpp-ghidrah contributors
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: pyghidra<4,>=3.1
11
+ Dynamic: license-file
12
+
13
+ # il2cpp-ghidrah
14
+
15
+ `il2cpp-ghidrah` builds a typed Ghidra project from a Unity IL2CPP application and exports selected classes as C++. Everything runs headlessly; the Ghidra GUI is not opened.
16
+
17
+ ## Requirements
18
+
19
+ - Python 3.9 or newer.
20
+ - PyGhidra 3.1 or newer.
21
+ - Ghidra 12 or newer.
22
+ - [TurboHeader](https://github.com/TeamRocketIst/turboHeader) installed under Ghidra's `Ghidra/Extensions` directory.
23
+ - `Il2CppDumper` and `Cpp2IL`.
24
+
25
+ Generator commands must be available through `PATH`, unless an explicit executable is supplied with the corresponding command option.
26
+
27
+ Set the Ghidra installation:
28
+
29
+ ```sh
30
+ export GHIDRA_INSTALL_DIR=/path/to/ghidra
31
+ ```
32
+
33
+ For a Homebrew installation, use the Ghidra root inside `libexec`:
34
+
35
+ ```sh
36
+ export GHIDRA_INSTALL_DIR="$(brew --prefix ghidra)/libexec"
37
+ ```
38
+
39
+ Add the appropriate `export` command to `~/.zshrc`, `~/.bashrc`, or `~/.bash_profile` to keep it across terminal sessions.
40
+
41
+ You can also pass it with `--ghidra /path/to/ghidra`.
42
+
43
+ ## Installation
44
+
45
+ Use a project-local virtual environment:
46
+
47
+ ```sh
48
+ python3 -m venv .venv
49
+ source .venv/bin/activate
50
+ python -m pip install --upgrade pip
51
+ python -m pip install .
52
+ il2cpp-ghidrah doctor --probe
53
+ ```
54
+
55
+ For an offline installation, activate `.venv` and use the PyGhidra wheels included with Ghidra:
56
+
57
+ ```sh
58
+ python -m pip install --no-index \
59
+ -f "$GHIDRA_INSTALL_DIR/Ghidra/Features/PyGhidra/pypkg/dist" .
60
+ ```
61
+
62
+ For development:
63
+
64
+ ```sh
65
+ python3 -m venv .venv
66
+ source .venv/bin/activate
67
+ python -m pip install -e .
68
+ python -m unittest discover -s tests -v
69
+ ```
70
+
71
+ ## Basic use
72
+
73
+ The documented workflow uses Il2CppDumper with Cpp2IL. Using extracted files is recommended:
74
+
75
+ ```sh
76
+ export UNITY_VERSION=2022.3.62f3 # replace with the application's exact version
77
+ il2cpp-ghidrah run libil2cpp.so -M global-metadata.dat \
78
+ -g dumper -u "$UNITY_VERSION" -o output
79
+ ```
80
+
81
+ Inspect the resolved input and commands without starting Ghidra:
82
+
83
+ ```sh
84
+ il2cpp-ghidrah run libil2cpp.so -M global-metadata.dat \
85
+ -g dumper -u "$UNITY_VERSION" -o output --dry-run --show-commands
86
+ ```
87
+
88
+ Tool output is shown live and also retained under `output/logs/`.
89
+ Decompilation uses eight workers by default. Override it when needed with
90
+ `--decompile-jobs N`, where `N` is from `0` through `12`; `0` selects the legacy sequential path.
91
+
92
+ ## Generators and importers
93
+
94
+ Il2CppDumper creates the header and metadata artifacts, while Cpp2IL creates the DiffableCs class tree. Custom executables can be supplied with `--dumper-command` and `--cpp2il-command`.
95
+
96
+ [TurboHeader](https://github.com/TeamRocketIst/turboHeader) is the default and recommended importer. It is faster than the CParserUtils compatibility path and imports layouts, methods, strings, metadata, and typed relocation slots:
97
+
98
+ ```sh
99
+ il2cpp-ghidrah run game.apk -o out -g dumper --importer turbo -u "$UNITY_VERSION"
100
+ ```
101
+
102
+ The compatibility importer uses the bundled CParserUtils scripts:
103
+
104
+ ```sh
105
+ il2cpp-ghidrah run game.apk -o out -g dumper --importer cparser -u "$UNITY_VERSION"
106
+ ```
107
+
108
+ That flow runs `parse_header_headless.py`, `ghidra_with_struct_headless.py`, and `ghidraUnityMetadata.py`. It imports the header, method signatures, and basic metadata labels, but it does not currently provide TurboHeader's authoritative layouts or complete GOT typing. TurboHeader is still required for the exporter.
109
+
110
+ TurboHeader layout policies are:
111
+
112
+ ```text
113
+ inferred allow header-inferred offsets
114
+ external require type_offsets.json or dump.cs
115
+ authoritative require authoritative layout evidence
116
+ ```
117
+
118
+ The default is `external`. Il2CppDumper supplies `dump.cs`.
119
+
120
+ ## Selection
121
+
122
+ Blacklist known frameworks:
123
+
124
+ ```sh
125
+ il2cpp-ghidrah run game.apk -o out -g dumper -s blacklist -u "$UNITY_VERSION" \
126
+ --ignore-frameworks framework_ignore.txt
127
+ ```
128
+
129
+ Whitelist assemblies:
130
+
131
+ ```sh
132
+ il2cpp-ghidrah run game.apk -o out -g dumper -s whitelist -u "$UNITY_VERSION" \
133
+ -a Assembly-CSharp -a Assembly-CSharp-firstpass
134
+ ```
135
+
136
+ Select individual classes:
137
+
138
+ ```sh
139
+ il2cpp-ghidrah run game.apk -o out -g dumper -u "$UNITY_VERSION" \
140
+ -c MainMenuController -c PlayerController
141
+ ```
142
+
143
+ Export everything:
144
+
145
+ ```sh
146
+ il2cpp-ghidrah run game.apk -o out -g dumper -s all -u "$UNITY_VERSION"
147
+ ```
148
+
149
+ `--classes` accepts a JSON array. `--classes-file` accepts either a JSON array or one class name per line.
150
+
151
+ ## Inputs
152
+
153
+ Prefer extracted files so each tool receives the exact ARM64 binary and metadata selected by you:
154
+
155
+ ```sh
156
+ il2cpp-ghidrah run libil2cpp.so -M global-metadata.dat \
157
+ -g dumper -u "$UNITY_VERSION" -o out
158
+ ```
159
+
160
+ Extracted application directories are also supported:
161
+
162
+ ```sh
163
+ il2cpp-ghidrah run extracted-app/ -g dumper -u "$UNITY_VERSION" -o out
164
+ ```
165
+
166
+ APK, XAPK, APKM, APKS, and ZIP inputs are detected automatically when extracted files are not available:
167
+
168
+ ```sh
169
+ il2cpp-ghidrah run game.apk -g dumper -u "$UNITY_VERSION" -o out
170
+ il2cpp-ghidrah run game.apks -g dumper -u "$UNITY_VERSION" -o out
171
+ ```
172
+
173
+ Cpp2IL forced-file mode requires the exact Unity version. The Dumper flow stops with an error when `--unity` is missing; it never guesses a default version.
174
+
175
+ ## Output
176
+
177
+ ```text
178
+ output/
179
+ ├── artifacts/ il2cpp.h, script.json, offsets, dump.cs
180
+ ├── cpp2il/ DiffableCs class tree
181
+ ├── project/ Ghidra project
182
+ ├── decompiled/ assembly/namespace/class.cpp
183
+ ├── logs/ generation, import, and decompilation logs
184
+ └── run.json configuration and executed commands
185
+ ```
186
+
187
+ The first Ghidra process imports and types the binary. The second reopens the project and exports the requested classes. Automatic whole-program analysis remains disabled in both phases.
@@ -0,0 +1,175 @@
1
+ # il2cpp-ghidrah
2
+
3
+ `il2cpp-ghidrah` builds a typed Ghidra project from a Unity IL2CPP application and exports selected classes as C++. Everything runs headlessly; the Ghidra GUI is not opened.
4
+
5
+ ## Requirements
6
+
7
+ - Python 3.9 or newer.
8
+ - PyGhidra 3.1 or newer.
9
+ - Ghidra 12 or newer.
10
+ - [TurboHeader](https://github.com/TeamRocketIst/turboHeader) installed under Ghidra's `Ghidra/Extensions` directory.
11
+ - `Il2CppDumper` and `Cpp2IL`.
12
+
13
+ Generator commands must be available through `PATH`, unless an explicit executable is supplied with the corresponding command option.
14
+
15
+ Set the Ghidra installation:
16
+
17
+ ```sh
18
+ export GHIDRA_INSTALL_DIR=/path/to/ghidra
19
+ ```
20
+
21
+ For a Homebrew installation, use the Ghidra root inside `libexec`:
22
+
23
+ ```sh
24
+ export GHIDRA_INSTALL_DIR="$(brew --prefix ghidra)/libexec"
25
+ ```
26
+
27
+ Add the appropriate `export` command to `~/.zshrc`, `~/.bashrc`, or `~/.bash_profile` to keep it across terminal sessions.
28
+
29
+ You can also pass it with `--ghidra /path/to/ghidra`.
30
+
31
+ ## Installation
32
+
33
+ Use a project-local virtual environment:
34
+
35
+ ```sh
36
+ python3 -m venv .venv
37
+ source .venv/bin/activate
38
+ python -m pip install --upgrade pip
39
+ python -m pip install .
40
+ il2cpp-ghidrah doctor --probe
41
+ ```
42
+
43
+ For an offline installation, activate `.venv` and use the PyGhidra wheels included with Ghidra:
44
+
45
+ ```sh
46
+ python -m pip install --no-index \
47
+ -f "$GHIDRA_INSTALL_DIR/Ghidra/Features/PyGhidra/pypkg/dist" .
48
+ ```
49
+
50
+ For development:
51
+
52
+ ```sh
53
+ python3 -m venv .venv
54
+ source .venv/bin/activate
55
+ python -m pip install -e .
56
+ python -m unittest discover -s tests -v
57
+ ```
58
+
59
+ ## Basic use
60
+
61
+ The documented workflow uses Il2CppDumper with Cpp2IL. Using extracted files is recommended:
62
+
63
+ ```sh
64
+ export UNITY_VERSION=2022.3.62f3 # replace with the application's exact version
65
+ il2cpp-ghidrah run libil2cpp.so -M global-metadata.dat \
66
+ -g dumper -u "$UNITY_VERSION" -o output
67
+ ```
68
+
69
+ Inspect the resolved input and commands without starting Ghidra:
70
+
71
+ ```sh
72
+ il2cpp-ghidrah run libil2cpp.so -M global-metadata.dat \
73
+ -g dumper -u "$UNITY_VERSION" -o output --dry-run --show-commands
74
+ ```
75
+
76
+ Tool output is shown live and also retained under `output/logs/`.
77
+ Decompilation uses eight workers by default. Override it when needed with
78
+ `--decompile-jobs N`, where `N` is from `0` through `12`; `0` selects the legacy sequential path.
79
+
80
+ ## Generators and importers
81
+
82
+ Il2CppDumper creates the header and metadata artifacts, while Cpp2IL creates the DiffableCs class tree. Custom executables can be supplied with `--dumper-command` and `--cpp2il-command`.
83
+
84
+ [TurboHeader](https://github.com/TeamRocketIst/turboHeader) is the default and recommended importer. It is faster than the CParserUtils compatibility path and imports layouts, methods, strings, metadata, and typed relocation slots:
85
+
86
+ ```sh
87
+ il2cpp-ghidrah run game.apk -o out -g dumper --importer turbo -u "$UNITY_VERSION"
88
+ ```
89
+
90
+ The compatibility importer uses the bundled CParserUtils scripts:
91
+
92
+ ```sh
93
+ il2cpp-ghidrah run game.apk -o out -g dumper --importer cparser -u "$UNITY_VERSION"
94
+ ```
95
+
96
+ That flow runs `parse_header_headless.py`, `ghidra_with_struct_headless.py`, and `ghidraUnityMetadata.py`. It imports the header, method signatures, and basic metadata labels, but it does not currently provide TurboHeader's authoritative layouts or complete GOT typing. TurboHeader is still required for the exporter.
97
+
98
+ TurboHeader layout policies are:
99
+
100
+ ```text
101
+ inferred allow header-inferred offsets
102
+ external require type_offsets.json or dump.cs
103
+ authoritative require authoritative layout evidence
104
+ ```
105
+
106
+ The default is `external`. Il2CppDumper supplies `dump.cs`.
107
+
108
+ ## Selection
109
+
110
+ Blacklist known frameworks:
111
+
112
+ ```sh
113
+ il2cpp-ghidrah run game.apk -o out -g dumper -s blacklist -u "$UNITY_VERSION" \
114
+ --ignore-frameworks framework_ignore.txt
115
+ ```
116
+
117
+ Whitelist assemblies:
118
+
119
+ ```sh
120
+ il2cpp-ghidrah run game.apk -o out -g dumper -s whitelist -u "$UNITY_VERSION" \
121
+ -a Assembly-CSharp -a Assembly-CSharp-firstpass
122
+ ```
123
+
124
+ Select individual classes:
125
+
126
+ ```sh
127
+ il2cpp-ghidrah run game.apk -o out -g dumper -u "$UNITY_VERSION" \
128
+ -c MainMenuController -c PlayerController
129
+ ```
130
+
131
+ Export everything:
132
+
133
+ ```sh
134
+ il2cpp-ghidrah run game.apk -o out -g dumper -s all -u "$UNITY_VERSION"
135
+ ```
136
+
137
+ `--classes` accepts a JSON array. `--classes-file` accepts either a JSON array or one class name per line.
138
+
139
+ ## Inputs
140
+
141
+ Prefer extracted files so each tool receives the exact ARM64 binary and metadata selected by you:
142
+
143
+ ```sh
144
+ il2cpp-ghidrah run libil2cpp.so -M global-metadata.dat \
145
+ -g dumper -u "$UNITY_VERSION" -o out
146
+ ```
147
+
148
+ Extracted application directories are also supported:
149
+
150
+ ```sh
151
+ il2cpp-ghidrah run extracted-app/ -g dumper -u "$UNITY_VERSION" -o out
152
+ ```
153
+
154
+ APK, XAPK, APKM, APKS, and ZIP inputs are detected automatically when extracted files are not available:
155
+
156
+ ```sh
157
+ il2cpp-ghidrah run game.apk -g dumper -u "$UNITY_VERSION" -o out
158
+ il2cpp-ghidrah run game.apks -g dumper -u "$UNITY_VERSION" -o out
159
+ ```
160
+
161
+ Cpp2IL forced-file mode requires the exact Unity version. The Dumper flow stops with an error when `--unity` is missing; it never guesses a default version.
162
+
163
+ ## Output
164
+
165
+ ```text
166
+ output/
167
+ ├── artifacts/ il2cpp.h, script.json, offsets, dump.cs
168
+ ├── cpp2il/ DiffableCs class tree
169
+ ├── project/ Ghidra project
170
+ ├── decompiled/ assembly/namespace/class.cpp
171
+ ├── logs/ generation, import, and decompilation logs
172
+ └── run.json configuration and executed commands
173
+ ```
174
+
175
+ The first Ghidra process imports and types the binary. The second reopens the project and exports the requested classes. Automatic whole-program analysis remains disabled in both phases.
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "il2cpp-ghidrah"
7
+ version = "0.1.5"
8
+ description = "Headless Ghidra pipeline for Unity IL2CPP applications"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "il2cpp-ghidrah contributors" }]
13
+ dependencies = ["pyghidra>=3.1,<4"]
14
+
15
+ [project.scripts]
16
+ il2cpp-ghidrah = "il2cpp_ghidrah.cli:main"
17
+
18
+ [tool.setuptools.packages.find]
19
+ where = ["src"]
20
+
21
+ [tool.setuptools.package-data]
22
+ il2cpp_ghidrah = ["ghidra_scripts/*.py"]
23
+
24
+ [tool.pytest.ini_options]
25
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """Headless Unity IL2CPP to Ghidra pipeline."""
2
+
3
+ __version__ = "0.1.5"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,146 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ from . import __version__
9
+ from .config import RunConfig
10
+ from .installation import doctor
11
+ from .pipeline import run
12
+
13
+
14
+ def _class_list(value: str) -> list[str]:
15
+ try:
16
+ parsed = json.loads(value)
17
+ except json.JSONDecodeError as error:
18
+ raise argparse.ArgumentTypeError(f"invalid JSON class list: {error}") from error
19
+ if not isinstance(parsed, list) or not all(isinstance(item, str) and item.strip() for item in parsed):
20
+ raise argparse.ArgumentTypeError("--classes must be a JSON array of non-empty strings")
21
+ return [item.strip() for item in parsed]
22
+
23
+
24
+ def _classes_file(path: Path) -> list[str]:
25
+ text = path.read_text(encoding="utf-8")
26
+ if path.suffix.lower() == ".json":
27
+ return _class_list(text)
28
+ return [line.split("#", 1)[0].strip() for line in text.splitlines() if line.split("#", 1)[0].strip()]
29
+
30
+
31
+ def _common_tools(parser: argparse.ArgumentParser) -> None:
32
+ parser.add_argument("--ghidra", type=Path, help="Ghidra installation root (or GHIDRA_INSTALL_DIR)")
33
+ parser.add_argument("--il2cpp-command", default="il2cpp")
34
+ parser.add_argument("--dumper-command", default="Il2CppDumper")
35
+ parser.add_argument("--cpp2il-command", default="Cpp2IL")
36
+
37
+
38
+ def parser() -> argparse.ArgumentParser:
39
+ root = argparse.ArgumentParser(prog="il2cpp-ghidrah", description="Headless Ghidra pipeline for Unity IL2CPP")
40
+ root.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
41
+ commands = root.add_subparsers(dest="command", required=True)
42
+
43
+ run_parser = commands.add_parser("run", help="generate artifacts and run targeted Ghidra headlessly")
44
+ run_parser.add_argument("input", type=Path, help="APK/XAPK/APKS/ZIP, extracted directory, or native binary")
45
+ run_parser.add_argument("-o", "--output", type=Path, required=True)
46
+ run_parser.add_argument("-g", "--generator", choices=("auto", "aotopsy", "dumper"), default="auto")
47
+ run_parser.add_argument("--importer", choices=("turbo", "cparser"), default="turbo")
48
+ run_parser.add_argument("-l", "--layout", choices=("inferred", "external", "authoritative"), default="external")
49
+ run_parser.add_argument("-s", "--scope", choices=("whitelist", "blacklist", "all"), default="blacklist")
50
+ run_parser.add_argument("-M", "--metadata", type=Path)
51
+ run_parser.add_argument("-A", "--assets", type=Path)
52
+ run_parser.add_argument("-U", "--unity-data", type=Path)
53
+ run_parser.add_argument("-u", "--unity", "--force-unity-version", dest="unity")
54
+ run_parser.add_argument("--abi", default="arm64-v8a")
55
+ run_parser.add_argument("-a", "--assembly", action="append", default=[])
56
+ run_parser.add_argument("-c", "--class", dest="selected_classes", action="append", default=[])
57
+ run_parser.add_argument("--classes", type=_class_list, default=[])
58
+ run_parser.add_argument("--classes-file", type=Path)
59
+ run_parser.add_argument("--ignore-frameworks", type=Path)
60
+ run_parser.add_argument("--project-name")
61
+ run_parser.add_argument(
62
+ "--decompile-jobs",
63
+ type=int,
64
+ choices=range(13),
65
+ default=8,
66
+ metavar="N",
67
+ help="Ghidra decompiler workers from 0 through 12 (default: 8; 0 uses the legacy sequential path)",
68
+ )
69
+ run_parser.add_argument("--dry-run", action="store_true")
70
+ run_parser.add_argument("--show-commands", action="store_true")
71
+ run_parser.add_argument("--keep-temporary", action="store_true")
72
+ _common_tools(run_parser)
73
+
74
+ doctor_parser = commands.add_parser("doctor", help="verify the headless toolchain installation")
75
+ doctor_parser.add_argument("-g", "--generator", choices=("auto", "aotopsy", "dumper"), default="auto")
76
+ doctor_parser.add_argument("--importer", choices=("turbo", "cparser"), default="turbo")
77
+ doctor_parser.add_argument("--probe", action="store_true", help="initialize Ghidra through PyGhidra")
78
+ doctor_parser.add_argument("--json", action="store_true", dest="json_output")
79
+ _common_tools(doctor_parser)
80
+ return root
81
+
82
+
83
+ def _run(args: argparse.Namespace) -> None:
84
+ classes = [*args.selected_classes, *args.classes]
85
+ if args.classes_file:
86
+ classes.extend(_classes_file(args.classes_file))
87
+ config = RunConfig(
88
+ input_path=args.input,
89
+ output=args.output,
90
+ generator=args.generator,
91
+ layout=args.layout,
92
+ scope=args.scope,
93
+ metadata=args.metadata,
94
+ assets=args.assets,
95
+ unity_data=args.unity_data,
96
+ unity=args.unity,
97
+ abi=args.abi,
98
+ assemblies=tuple(dict.fromkeys(args.assembly)),
99
+ classes=tuple(dict.fromkeys(classes)),
100
+ ignore_frameworks=args.ignore_frameworks,
101
+ ghidra_dir=args.ghidra,
102
+ importer=args.importer,
103
+ project_name=args.project_name,
104
+ il2cpp_command=args.il2cpp_command,
105
+ dumper_command=args.dumper_command,
106
+ cpp2il_command=args.cpp2il_command,
107
+ decompile_jobs=args.decompile_jobs,
108
+ dry_run=args.dry_run,
109
+ show_commands=args.show_commands,
110
+ keep_temporary=args.keep_temporary,
111
+ )
112
+ run(config)
113
+
114
+
115
+ def _doctor(args: argparse.Namespace) -> int:
116
+ checks = doctor(
117
+ args.ghidra,
118
+ importer=args.importer,
119
+ generator=args.generator,
120
+ il2cpp_command=args.il2cpp_command,
121
+ dumper_command=args.dumper_command,
122
+ cpp2il_command=args.cpp2il_command,
123
+ probe=args.probe,
124
+ )
125
+ if args.json_output:
126
+ print(json.dumps([{"name": name, "ok": ok, "detail": detail} for name, ok, detail in checks], indent=2))
127
+ else:
128
+ for name, ok, detail in checks:
129
+ print(f"{'OK' if ok else 'FAIL':4} {name}: {detail}")
130
+ return 0 if all(ok for _, ok, _ in checks) else 1
131
+
132
+
133
+ def main(argv: list[str] | None = None) -> int:
134
+ args = parser().parse_args(argv)
135
+ try:
136
+ if args.command == "run":
137
+ _run(args)
138
+ return 0
139
+ return _doctor(args)
140
+ except (FileNotFoundError, FileExistsError, ValueError, RuntimeError) as error:
141
+ print(f"il2cpp-ghidrah: error: {error}", file=sys.stderr)
142
+ return 2
143
+
144
+
145
+ if __name__ == "__main__":
146
+ raise SystemExit(main())
@@ -0,0 +1,46 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+
6
+
7
+ LAYOUT_POLICIES = {
8
+ "inferred": "allow-inferred",
9
+ "external": "require-external-offsets",
10
+ "authoritative": "require-authoritative",
11
+ }
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class RunConfig:
16
+ input_path: Path
17
+ output: Path
18
+ generator: str = "auto"
19
+ layout: str = "external"
20
+ scope: str = "blacklist"
21
+ metadata: Path | None = None
22
+ assets: Path | None = None
23
+ unity_data: Path | None = None
24
+ unity: str | None = None
25
+ abi: str = "arm64-v8a"
26
+ assemblies: tuple[str, ...] = ()
27
+ classes: tuple[str, ...] = ()
28
+ ignore_frameworks: Path | None = None
29
+ ghidra_dir: Path | None = None
30
+ importer: str = "turbo"
31
+ project_name: str | None = None
32
+ il2cpp_command: str = "il2cpp"
33
+ dumper_command: str = "Il2CppDumper"
34
+ cpp2il_command: str = "Cpp2IL"
35
+ decompile_jobs: int = 8
36
+ dry_run: bool = False
37
+ show_commands: bool = False
38
+ keep_temporary: bool = False
39
+
40
+ def __post_init__(self) -> None:
41
+ if type(self.decompile_jobs) is not int or not 0 <= self.decompile_jobs <= 12:
42
+ raise ValueError("decompile_jobs must be an integer from 0 through 12")
43
+
44
+ @property
45
+ def turbo_policy(self) -> str:
46
+ return LAYOUT_POLICIES[self.layout]