mirror of
https://github.com/siemens-mobile-hacks/GhidraMCP.git
synced 2026-11-25 23:57:13 +00:00
import_file: add block_name, file_offset and length for Raw Binary
Ghidra parses these loader options as hex, so the values are converted.
This commit is contained in:
parent
8241933a7c
commit
c554d9e922
2 changed files with 14 additions and 2 deletions
|
|
@ -100,6 +100,9 @@ final class ProjectTools {
|
|||
.optString("compiler", "", "Compiler spec ID, e.g. default (default: auto)")
|
||||
.optString("loader", "", "Loader name, e.g. \"Raw Binary\" or \"Executable and Linking Format (ELF)\"")
|
||||
.optString("base_address", "", "Image base / load address (loader option), e.g. 0x8000000")
|
||||
.optString("block_name", "", "Raw Binary: name of the memory block (Ghidra default: ram)")
|
||||
.optInteger("file_offset", 0, "Raw Binary: first byte of the file to load")
|
||||
.optInteger("length", 0, "Raw Binary: number of bytes to load (0 = to the end of the file)")
|
||||
.optBoolean("open", true, "Open the imported program in the background")
|
||||
.handler(a -> importFile(a));
|
||||
|
||||
|
|
@ -473,6 +476,10 @@ final class ProjectTools {
|
|||
String v = base.trim();
|
||||
b.addLoaderArg("-loader-baseAddr", v.startsWith("0x") || v.startsWith("0X") ? v.substring(2) : v);
|
||||
}
|
||||
String blockName = a.str("block_name");
|
||||
if (blockName != null && !blockName.isBlank()) b.addLoaderArg("-loader-blockName", blockName.trim());
|
||||
if (a.integer("file_offset") > 0) b.addLoaderArg("-loader-fileOffset", Integer.toHexString(a.integer("file_offset")));
|
||||
if (a.integer("length") > 0) b.addLoaderArg("-loader-length", Integer.toHexString(a.integer("length")));
|
||||
MessageLog log = new MessageLog();
|
||||
b.log(log);
|
||||
Object consumer = this;
|
||||
|
|
|
|||
|
|
@ -244,17 +244,22 @@ def project(c):
|
|||
c.check("import_file", "import_file",
|
||||
{"file_path": THUMB_O, "folder": "/e2e", "name": "thumb_import"},
|
||||
expect=["Imported thumb.o as /e2e/thumb_import", "ARM", "Opened in the background"])
|
||||
c.check("imported program is current", "get_current_program", expect=["thumb_import"])
|
||||
c.call("delete_project_file", path="/e2e/blob_raw", confirm=True)
|
||||
c.check("import_file raw binary loader", "import_file",
|
||||
{"file_path": THUMB_O, "folder": "/e2e", "name": "blob_raw", "loader": "Raw Binary",
|
||||
"language": "ARM:LE:32:Cortex", "base_address": "0x8000000", "open": False},
|
||||
"language": "ARM:LE:32:Cortex", "base_address": "0x8000000", "block_name": "flash",
|
||||
"file_offset": 16, "length": 64, "open": False},
|
||||
expect=["Imported thumb.o as /e2e/blob_raw", "Format: Raw Binary", "ARM:LE:32:Cortex"])
|
||||
c.call("open_program", path="/e2e/blob_raw")
|
||||
c.check("raw import block name/offset/length", "list_segments", {"program": "/e2e/blob_raw"},
|
||||
regex=[r"^flash: 0?8000000 - 0?800003f size=0x40 "])
|
||||
c.call("close_program", program="/e2e/blob_raw")
|
||||
c.check("import_file unknown loader", "import_file", {"file_path": THUMB_O, "loader": "Nope"},
|
||||
error=True, expect=["Unknown loader", "Raw Binary"])
|
||||
c.check("delete raw import", "delete_project_file", {"path": "/e2e/blob_raw", "confirm": True})
|
||||
c.check("import_file missing", "import_file", {"file_path": "/nonexistent.bin"}, error=True,
|
||||
expect=["File not found"])
|
||||
c.check("imported program is current", "get_current_program", expect=["thumb_import"])
|
||||
c.check("imported program not analyzed", "get_program_info", {"program": "/e2e/thumb_import"},
|
||||
expect=["Analysis: not analyzed"])
|
||||
c.check("open_program mode=tool headless", "open_program",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue