-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Problem
I am trying to import a binary with a niche architecture that is not
auto-detected by Ghidra, in headless and in UI mode:
INFO No load spec found for import file: main (ProgramLoader)
ERROR The ProgramLoader could not successfully load file://main with the provided import parameters. Please ensure that any specified processor/cspec arguments are compatible with the loader that is used during import and try again. (HeadlessAnalyzer)
The headless Ghidra script supports the -processor <language-id>
flag, so I
wanted to pass that via CTADL's -A
flag. However, I was not able to pass
the -processor
properly.
Things I tried:
-A -processor <my-language-id>
-A -processor -A <my-language-id>
-A "-processor" -A <my-language-id>
-A "-processor,<my-language-id>
- Using
--argument-passthrough
instead of-A
(just in case, but it
shouldn't matter) -A "-processor <my-language-id>"
The first few result in this error:
ctadl import: error: argument -A/--argument-passthrough: expected one argument
The last one successfully passes the argument to analyzeHeadlessBigMem
, but
it doesn't actually do anything, as it is surrounded in quotes and considered
one argument to the analyzeHeadlessBigMem
script:
~/ghidra_12.0_DEV/support/launch.sh fg jdk Ghidra-Headless 40G '-XX:ParallelGCThreads=4 -XX:CICompilerCount=4 ' ghidra.app.util.headless.AnalyzeHeadless /tmp/ctadl-6aoindul/ghidra_headless headless -import main -deleteProject -postScript ExportPCodeForCTADL.java ctadl-output/facts -scriptPath ~/.venv/lib/python3.12/site-packages/ctadl/souffle-logic/pcode '-processor <my-language-id>'
Ultimately I hard-coded the argument in the analyzeHeadlessBigMem
script,
which worked as expected.
Possible solution
A possible solution is to change the parser in the ctadl
Python script to
collect the remainder of arguments for -A
:
parser_add_argument_wrapper(
parser,
"-A",
"--argument-passthrough",
nargs=argparse.REMAINDER,
metavar="<arg>",
help="Passthrough args for the underlying fact generator. All subsequent args will be passed to the fact generator.",
)
This would allow a user to do something like this:
ctadl import -o ctadl-output pcode main -A -processor <my-language-id>
The change works for my use case, but in the event -A
is in a script used in
its original way for multiple arguments (action="append"
) this would cause
issues.