-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·91 lines (66 loc) · 2.11 KB
/
build.py
File metadata and controls
executable file
·91 lines (66 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2020-2026 Binarly
import pathlib
import subprocess
import click
ROOT_DIR = pathlib.Path(__file__).resolve().parent
def cmake_build(source_dir: pathlib.Path, idasdk: str, hexrays_sdk: str | None = None):
build_dir = pathlib.Path(source_dir) / "build"
build_dir.mkdir(exist_ok=True)
command = ["cmake", str(source_dir), f"-DIdaSdk_ROOT_DIR={idasdk}"]
if hexrays_sdk is not None:
click.secho("HexRays analysis is enabled", fg="green")
command.append(f"-DHexRaysSdk_ROOT_DIR={hexrays_sdk}")
subprocess.run(command, cwd=build_dir, check=True)
subprocess.run(
["cmake", "--build", ".", "--config", "Release", "--parallel"],
cwd=build_dir,
check=True,
)
def resolve_hexrays_sdk(
idasdk: str, hexrays_sdk: str | None, no_hexrays: bool
) -> str | None:
if no_hexrays:
return None
return hexrays_sdk if hexrays_sdk else idasdk
def hexrays_options(f):
f = click.option(
"--hexrays_sdk",
"hexrays_sdk",
type=str,
default=None,
help="Path to hexrays_sdk directory (default: IDASDK).",
)(f)
f = click.option(
"--no-hexrays",
"no_hexrays",
is_flag=True,
default=False,
help="Disable HexRays analysis.",
)(f)
return f
@click.group()
def cli():
pass
@cli.command()
@hexrays_options
@click.argument("idasdk")
def build_plugin(idasdk: str, hexrays_sdk: str, no_hexrays: bool):
"""Build plugin."""
hrs = resolve_hexrays_sdk(idasdk, hexrays_sdk, no_hexrays)
cmake_build(ROOT_DIR / "plugin", idasdk, hexrays_sdk=hrs)
@cli.command()
@click.argument("idasdk")
def build_loader(idasdk: str):
"""Build loader."""
cmake_build(ROOT_DIR / "loader", idasdk)
@cli.command()
@hexrays_options
@click.argument("idasdk")
def build_all(idasdk: str, hexrays_sdk: str, no_hexrays: bool):
"""Build plugin and loader."""
hrs = resolve_hexrays_sdk(idasdk, hexrays_sdk, no_hexrays)
cmake_build(ROOT_DIR, idasdk, hexrays_sdk=hrs)
if __name__ == "__main__":
cli()