mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
7f65b1117a
This pipe is executed during the Lift step and populates the model with all the required primitive types.
99 lines
3.1 KiB
Python
99 lines
3.1 KiB
Python
from tempfile import NamedTemporaryFile
|
|
|
|
from .commands_registry import Command, commands_registry, Options
|
|
from .revng import run_revng_command
|
|
from .support import log_error
|
|
|
|
|
|
class LiftCommand(Command):
|
|
def __init__(self):
|
|
super().__init__(("lift",), "revng lift wrapper")
|
|
|
|
def register_arguments(self, parser):
|
|
parser.add_argument("input", type=str, nargs=1, help="Input binary to be lifted")
|
|
parser.add_argument("output", type=str, nargs=1, help="Output module path")
|
|
parser.add_argument("--record-asm", action="store_true")
|
|
parser.add_argument("--record-ptc", action="store_true")
|
|
parser.add_argument("--external", action="store_true")
|
|
parser.add_argument("--base", type=str)
|
|
parser.add_argument("--entry", type=str)
|
|
parser.add_argument("--debug-info", type=str)
|
|
parser.add_argument("--import-debug-info", type=str, action="append", default=[])
|
|
|
|
def run(self, options: Options):
|
|
if options.remaining_args:
|
|
log_error("Unknown arguments passed in")
|
|
return 1
|
|
|
|
args = options.parsed_args
|
|
|
|
arg_or_empty = (
|
|
lambda args, name: [f"--{name}={args.__dict__[name]}"] if args.__dict__[name] else []
|
|
)
|
|
|
|
with NamedTemporaryFile(
|
|
suffix=".yml", delete=not options.keep_temporaries
|
|
) as model, NamedTemporaryFile(
|
|
suffix=".ll", delete=not options.keep_temporaries
|
|
) as model_in_module:
|
|
# Run revng model import args.input
|
|
run_revng_command(
|
|
[
|
|
"model",
|
|
"import",
|
|
"binary",
|
|
args.input[0],
|
|
"-o",
|
|
model.name,
|
|
]
|
|
+ [f"--import-debug-info={value}" for value in args.import_debug_info]
|
|
+ arg_or_empty(args, "base")
|
|
+ arg_or_empty(args, "entry"),
|
|
options,
|
|
)
|
|
|
|
run_revng_command(
|
|
[
|
|
"model",
|
|
"opt",
|
|
"--add-primitive-types",
|
|
model.name,
|
|
"-o",
|
|
model.name,
|
|
],
|
|
options,
|
|
)
|
|
|
|
run_revng_command(
|
|
[
|
|
"model",
|
|
"inject",
|
|
model.name,
|
|
"/dev/null",
|
|
"-o",
|
|
model_in_module.name,
|
|
],
|
|
options,
|
|
)
|
|
|
|
run_revng_command(
|
|
[
|
|
"opt",
|
|
model_in_module.name,
|
|
"-o",
|
|
args.output[0],
|
|
"-load-binary",
|
|
f"-binary-path={args.input[0]}",
|
|
"-lift",
|
|
]
|
|
+ arg_or_empty(args, "external")
|
|
+ arg_or_empty(args, "record_asm")
|
|
+ arg_or_empty(args, "record_ptc"),
|
|
options,
|
|
)
|
|
|
|
# TODO: annotate IR
|
|
|
|
|
|
commands_registry.register_command(LiftCommand())
|