Unverified Commit 44a194f7 by Melvin Klimke Committed by GitHub

- Fixed issue #169 (#171)

parent 41088680
...@@ -214,11 +214,16 @@ public class PcodeExtractor extends GhidraScript { ...@@ -214,11 +214,16 @@ public class PcodeExtractor extends GhidraScript {
*/ */
protected Boolean iteratePcode() { protected Boolean iteratePcode() {
int numberOfPcodeOps = PcodeBlockData.ops.length; int numberOfPcodeOps = PcodeBlockData.ops.length;
int previousPcodeIndex = 0;
Boolean intraInstructionJumpOccured = false; Boolean intraInstructionJumpOccured = false;
PcodeBlockData.pcodeIndex = 0; PcodeBlockData.pcodeIndex = 0;
for(PcodeOp op : PcodeBlockData.ops) { for(PcodeOp op : PcodeBlockData.ops) {
PcodeBlockData.pcodeOp = op; PcodeBlockData.pcodeOp = op;
String mnemonic = PcodeBlockData.pcodeOp.getMnemonic(); String mnemonic = PcodeBlockData.pcodeOp.getMnemonic();
if (previousPcodeIndex < PcodeBlockData.pcodeIndex -1) {
numberOfPcodeOps++;
}
previousPcodeIndex = PcodeBlockData.pcodeIndex;
if (JumpProcessing.jumps.contains(mnemonic) || PcodeBlockData.pcodeOp.getOpcode() == PcodeOp.UNIMPLEMENTED) { if (JumpProcessing.jumps.contains(mnemonic) || PcodeBlockData.pcodeOp.getOpcode() == PcodeOp.UNIMPLEMENTED) {
intraInstructionJumpOccured = JumpProcessing.processJump(mnemonic, numberOfPcodeOps); intraInstructionJumpOccured = JumpProcessing.processJump(mnemonic, numberOfPcodeOps);
} else { } else {
......
...@@ -45,7 +45,7 @@ public final class JumpProcessing { ...@@ -45,7 +45,7 @@ public final class JumpProcessing {
return processJumpInPcodeBlock(mnemonic, numberOfPcodeOps, currentBlock); return processJumpInPcodeBlock(mnemonic, numberOfPcodeOps, currentBlock);
} }
processJumpAtEndOfPcodeBlocks(mnemonic, numberOfPcodeOps, currentBlock); processJumpAtEndOfPcodeBlocks(mnemonic, currentBlock);
return false; return false;
} }
...@@ -53,13 +53,12 @@ public final class JumpProcessing { ...@@ -53,13 +53,12 @@ public final class JumpProcessing {
/** /**
* *
* @param mnemonic: pcode mnemonic * @param mnemonic: pcode mnemonic
* @param numberOfPcodeOps: number of pcode instruction in pcode block
* @param currentBlock: current block term * @param currentBlock: current block term
* *
* Process jumps at the end of pcode blocks * Process jumps at the end of pcode blocks
* If it is a return block, the call return address is changed to the current block * If it is a return block, the call return address is changed to the current block
*/ */
private static void processJumpAtEndOfPcodeBlocks(String mnemonic, int numberOfPcodeOps, Term<Blk> currentBlock) { private static void processJumpAtEndOfPcodeBlocks(String mnemonic, Term<Blk> currentBlock) {
// Case 1: jump at the end of pcode group but not end of ghidra generated block. Create a block for the next assembly instruction. // Case 1: jump at the end of pcode group but not end of ghidra generated block. Create a block for the next assembly instruction.
if(PcodeBlockData.instructionIndex < PcodeBlockData.numberOfInstructionsInBlock - 1 && PcodeBlockData.instruction.getDelaySlotDepth() == 0) { if(PcodeBlockData.instructionIndex < PcodeBlockData.numberOfInstructionsInBlock - 1 && PcodeBlockData.instruction.getDelaySlotDepth() == 0) {
PcodeBlockData.blocks.add(TermCreator.createBlkTerm(PcodeBlockData.instruction.getFallThrough().toString(), null)); PcodeBlockData.blocks.add(TermCreator.createBlkTerm(PcodeBlockData.instruction.getFallThrough().toString(), null));
......
...@@ -348,7 +348,11 @@ public class TermCreator { ...@@ -348,7 +348,11 @@ public class TermCreator {
callString = "unimplemented"; callString = "unimplemented";
call = new Call(null, createLabel(PcodeBlockData.instruction.getFallThrough()), callString); call = new Call(null, createLabel(PcodeBlockData.instruction.getFallThrough()), callString);
} else { } else {
call = new Call(createLabel(null), createLabel(PcodeBlockData.instruction.getFallThrough())); if (PcodeBlockData.instruction.getFallThrough() == null) {
call = new Call(createLabel(null));
} else {
call = new Call(createLabel(null), createLabel(PcodeBlockData.instruction.getFallThrough()));
}
} }
return call; return call;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment