Init
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.address.AddressSpace;
|
||||
import ghidra.program.model.mem.Memory;
|
||||
import ghidra.program.model.mem.MemoryBlock;
|
||||
import ghidra.program.model.symbol.SourceType;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* MapAIS.java — Ghidra headless preScript. Creates one memory block per
|
||||
* AIS section of ic300_1.bin at its DDR load address, marks the AIS
|
||||
* entry point. Paths are hardcoded (see tools/ais_unpack.py output).
|
||||
*/
|
||||
public class MapAIS extends GhidraScript {
|
||||
|
||||
static final String UNPACK = "/tmp/ais-unpack";
|
||||
// {name, addrHex, len, file}
|
||||
static final String[][] SEGS = {
|
||||
{"ais0", "C7074630", "464", "ais_sect0_addrC7074630.bin"},
|
||||
{"ais1", "C7074800", "211712", "ais_sect1_addrC7074800.bin"},
|
||||
{"ais2", "C70A8300", "10444", "ais_sect2_addrC70A8300.bin"},
|
||||
{"ais3", "C70AABD0", "12", "ais_sect3_addrC70AABD0.bin"},
|
||||
{"ais4", "C70AABE0", "12", "ais_sect4_addrC70AABE0.bin"},
|
||||
{"ais5", "C70AABF0", "3396", "ais_sect5_addrC70AABF0.bin"},
|
||||
{"ais6", "C70AF000", "512", "ais_sect6_addrC70AF000.bin"},
|
||||
{"ais7", "C70AF4E8", "260", "ais_sect7_addrC70AF4E8.bin"},
|
||||
{"ais8", "C70AF5EC", "112", "ais_sect8_addrC70AF5EC.bin"},
|
||||
{"ais9", "C70AF660", "3896", "ais_sect9_addrC70AF660.bin"},
|
||||
};
|
||||
static final String ENTRY = "C70A28A0";
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
AddressSpace space = currentProgram.getAddressFactory()
|
||||
.getDefaultAddressSpace();
|
||||
Memory mem = currentProgram.getMemory();
|
||||
for (String[] s : SEGS) {
|
||||
Address addr = space.getAddress(s[1]);
|
||||
if (mem.getBlock(addr) != null) {
|
||||
println("[MapAIS] " + s[0] + " already mapped, skip");
|
||||
continue;
|
||||
}
|
||||
File f = new File(UNPACK + "/" + s[3]);
|
||||
long len = Long.parseLong(s[2]);
|
||||
try {
|
||||
mem.createInitializedBlock(s[0], addr, f, len,
|
||||
"ais_unpack", "", false);
|
||||
MemoryBlock blk = mem.getBlock(addr);
|
||||
blk.setRead(true);
|
||||
blk.setWrite(false);
|
||||
blk.setExecute(true);
|
||||
println("[MapAIS] mapped " + s[0] + " " + s[1]
|
||||
+ " len=" + len);
|
||||
}
|
||||
catch (Exception e) {
|
||||
println("[MapAIS] FAILED " + s[0] + ": " + e);
|
||||
}
|
||||
}
|
||||
Address entry = space.getAddress(ENTRY);
|
||||
currentProgram.getSymbolTable().addExternalEntryPoint(entry);
|
||||
createLabel(entry, "ais_entry", true, SourceType.IMPORTED);
|
||||
disassemble(entry);
|
||||
createFunction(entry, "ais_entry");
|
||||
println("[MapAIS] entry " + ENTRY + " marked");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user