diff --git a/.gitignore b/.gitignore index 99225cf..abdad38 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ build/* *.gdb_history decomp2dbg/decompilers decomp2dbg/d2d.py +decompilers/*/.gradle/ +decompilers/*/build/ +decompilers/*/dist/ diff --git a/decompilers/d2d_ghidra/src/main/java/decomp2dbg/D2DGhidraServerAPI.java b/decompilers/d2d_ghidra/src/main/java/decomp2dbg/D2DGhidraServerAPI.java index 0fd4b95..a497f47 100644 --- a/decompilers/d2d_ghidra/src/main/java/decomp2dbg/D2DGhidraServerAPI.java +++ b/decompilers/d2d_ghidra/src/main/java/decomp2dbg/D2DGhidraServerAPI.java @@ -6,6 +6,9 @@ import ghidra.app.decompiler.ClangLine; import ghidra.app.decompiler.PrettyPrinter; +import ghidra.app.util.bin.MemoryByteProvider; +import ghidra.app.util.bin.format.elf.ElfException; +import ghidra.app.util.bin.format.elf.ElfHeader; import ghidra.program.model.listing.Function; import ghidra.program.model.symbol.Symbol; import ghidra.program.model.symbol.SymbolType; @@ -323,4 +326,33 @@ public Map enums() { this.server.plugin.enumCache = resp; return resp; } + + public Map elf_info() { + if(!this.server.plugin.elfInfoCache.isEmpty()) + return this.server.plugin.elfInfoCache; + + Map elf_info = new HashMap<>(); + + var program = this.server.plugin.getCurrentProgram(); + var provider = new MemoryByteProvider(program.getMemory(), program.getMinAddress()); + ElfHeader header = null; + try { + header = new ElfHeader(provider, null); + } + catch (ElfException e) { + elf_info.put("error", e.toString()); + return elf_info; + } + + elf_info.put("flags", "0x" + Integer.toHexString(header.e_flags())); + elf_info.put("machine", (int) header.e_machine()); + elf_info.put("is_big_endian", header.isBigEndian()); + elf_info.put("is_32_bit", header.is32Bit()); + elf_info.put("image_base", "0x" + Long.toHexString(program.getMinAddress().getOffset())); + elf_info.put("name", program.getName()); + elf_info.put("error", ""); + + this.server.plugin.elfInfoCache = elf_info; + return elf_info; + } } diff --git a/decompilers/d2d_ghidra/src/main/java/decomp2dbg/D2DPlugin.java b/decompilers/d2d_ghidra/src/main/java/decomp2dbg/D2DPlugin.java index 6569d73..77083ef 100644 --- a/decompilers/d2d_ghidra/src/main/java/decomp2dbg/D2DPlugin.java +++ b/decompilers/d2d_ghidra/src/main/java/decomp2dbg/D2DPlugin.java @@ -57,6 +57,7 @@ public class D2DPlugin extends ProgramPlugin implements DomainObjectListener { public Map typeAliasCache; public Map unionCache; public Map enumCache; + public Map elfInfoCache; public D2DPlugin(PluginTool tool) { super(tool); @@ -74,6 +75,7 @@ public D2DPlugin(PluginTool tool) { typeAliasCache = new HashMap<>(); unionCache = new HashMap<>(); enumCache = new HashMap<>(); + elfInfoCache = new HashMap<>(); } @Override