Skip to content

Commit

Permalink
Updated processing of meta.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJokiv committed Nov 8, 2020
1 parent 3298996 commit 0af23f2
Showing 1 changed file with 46 additions and 62 deletions.
108 changes: 46 additions & 62 deletions ghidra_scripts/TransferEfiFilesToProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,63 @@
//@UEFI

import ghidra.app.util.headless.HeadlessScript;
import ghidra.program.model.data.DataTypeManager;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.mem.MemoryBlock;
import ghidra.util.Msg;
import org.json.JSONObject;

public class TransferEfiFilesToProject extends HeadlessScript {

@Override
protected void run() throws Exception {
String folderName = null;

this.setHeadlessImportDirectory(null);
String[] args = getScriptArgs();
if (args.length < 1)
return;
if (this.isRunningHeadless()) {
MemoryBlock childSmiBlock = this.getMemoryBlock("childSmi");
MemoryBlock regInterBlock = this.getMemoryBlock("regInterrupt");
this.setHeadlessImportDirectory(null);
String[] args = getScriptArgs();
if (args.length < 1)
return;
setHeadlessContinuationOption(HeadlessContinuationOption.CONTINUE);

if (childSmiBlock != null) {
folderName = "ChildInterrupts";
print("ChildInterrupt found");
}
else {
print("No ChildInterrupt in module!");
}
if (regInterBlock != null) {
byte[] raw = new byte[(int) regInterBlock.getSize()];
regInterBlock.getBytes(regInterBlock.getStart(), raw);
String str = new String(raw);
str = str.substring(1, str.length() - 1);
MemoryBlock metaBlock = this.getMemoryBlock("metaBlock");
if(metaBlock != null) {
byte[] raw = new byte[(int) metaBlock.getSize()];
try {
metaBlock.getBytes(metaBlock.getStart(), raw);
} catch (MemoryAccessException e) {
Msg.info(this, "Can't read metaBlock");
e.printStackTrace();
return;
}
String metaStr = new String(raw);
JSONObject meta = new JSONObject(metaStr);
JSONObject interrupts = meta.getJSONObject("interrupts");
JSONObject childSmi = interrupts.getJSONObject("child");
JSONObject swSmi = interrupts.getJSONObject("swSmi");
JSONObject hwSmi = interrupts.getJSONObject("hwSmi");


String[] regInter = str.split("[, =]");
for (int i = 0; i < regInter.length; i++) {
switch (regInter[i]) {
case ("gpiHandler"):
case ("ichnHandler"):
case ("ioTrapHandler"):
case ("periodicTimerHandler"):
case ("pwrButtonHandler"):
case ("sxHandler"):
case ("usbHandler"):
case ("standbyButtonHandler"):
case ("pchTcoHandler"):
case ("pchPcieHandler"):
case ("pchAcpiHandler"):
case ("pchGpioUnlockHandler"):
case ("pchHandler"):
case ("pchEspiHandler"):
case ("acpiEnHandler"):
case ("acpiDisHandler"):
if (folderName == null || folderName.equalsIgnoreCase("UnknownInterrupts"))
folderName = "HwInterrupts";
print("HwInterrupt found");
break;
case ("Unknown"):
if (folderName == null)
folderName = "UnknownInterrupts";
print("UnknownInterrupt found");
break;
case ("swSmiHandler"):
folderName = "SwInterrupts";
print("SwInterrupt found");
break;
}
if (folderName.compareTo("SwInterrupts") == 0)
break;
if (!hwSmi.isEmpty()) {
folderName = "HwSmi";
print("HwSmi found");
}
else {
print("HwSmi is missing from the module!");
}
if (!childSmi.isEmpty()) {
folderName = "ChildInter";
print("ChildSmi found");
} else {
print("ChildInter is missing from the module!");
}
if (!swSmi.isEmpty()) {
folderName = "SwSmi";
print("SwSmi found");
} else {
print("SwSmi is missing from the module!");
}
}
else {
print("No Sw/HwItterupts in module!");
}

if (folderName != null) {
this.setHeadlessImportDirectory(args[0] + "/" + folderName);
if (folderName != null) {
this.setHeadlessImportDirectory(args[0] + "/" + folderName);
}
}
}
}
Expand Down

0 comments on commit 0af23f2

Please sign in to comment.