mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-21 19:42:14 +00:00
GP-4967: Corrected issues related to emulator cached block instruction
re-use.
This commit is contained in:
parent
025cc9f702
commit
e8c28c2a84
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package ghidra.pcode.emu;
|
package ghidra.pcode.emu;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import ghidra.app.util.PseudoInstruction;
|
import ghidra.app.util.PseudoInstruction;
|
||||||
import ghidra.pcode.emulate.InstructionDecodeException;
|
import ghidra.pcode.emulate.InstructionDecodeException;
|
||||||
import ghidra.pcode.exec.DecodePcodeExecutionException;
|
import ghidra.pcode.exec.DecodePcodeExecutionException;
|
||||||
@ -73,14 +75,18 @@ public class SleighInstructionDecoder implements InstructionDecoder {
|
|||||||
Disassembler.getDisassembler(language, addrFactory, TaskMonitor.DUMMY, listener);
|
Disassembler.getDisassembler(language, addrFactory, TaskMonitor.DUMMY, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected boolean useCachedInstruction(Address address, RegisterValue context) {
|
||||||
public Instruction decodeInstruction(Address address, RegisterValue context) {
|
if (block == null) {
|
||||||
lastMsg = DEFAULT_ERROR;
|
return false;
|
||||||
if (block != null &&
|
|
||||||
(instruction = (PseudoInstruction) block.getInstructionAt(address)) != null) {
|
|
||||||
return instruction;
|
|
||||||
}
|
}
|
||||||
/*
|
// Always use instruction within last block decoded assuming we flowed from another
|
||||||
|
// instruction within the same block. The block should be null is starting a new flow.
|
||||||
|
instruction = (PseudoInstruction) block.getInstructionAt(address);
|
||||||
|
return instruction != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void parseNewBlock(Address address, RegisterValue context) {
|
||||||
|
/**
|
||||||
* Parse as few instructions as possible. If more are returned, it's because they form a
|
* Parse as few instructions as possible. If more are returned, it's because they form a
|
||||||
* parallel instruction group. In that case, I should not have to worry self-modifying code
|
* parallel instruction group. In that case, I should not have to worry self-modifying code
|
||||||
* within that group, so no need to re-disassemble after each is executed.
|
* within that group, so no need to re-disassemble after each is executed.
|
||||||
@ -91,17 +97,28 @@ public class SleighInstructionDecoder implements InstructionDecoder {
|
|||||||
throw new DecodePcodeExecutionException(lastMsg, address);
|
throw new DecodePcodeExecutionException(lastMsg, address);
|
||||||
}
|
}
|
||||||
instruction = (PseudoInstruction) block.getInstructionAt(address);
|
instruction = (PseudoInstruction) block.getInstructionAt(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Instruction decodeInstruction(Address address, RegisterValue context) {
|
||||||
|
lastMsg = DEFAULT_ERROR;
|
||||||
|
if (!useCachedInstruction(address, context)) {
|
||||||
|
parseNewBlock(address, context);
|
||||||
|
}
|
||||||
lengthWithDelays = computeLength();
|
lengthWithDelays = computeLength();
|
||||||
return instruction;
|
return instruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void branched(Address address) {
|
public void branched(Address address) {
|
||||||
/*
|
/**
|
||||||
* This shouldn't happen in the middle of a parallel instruction group, but in case the
|
* There may be internal branching within a decoded block. Those shouldn't clear the block.
|
||||||
* group modifies itself and jumps back to itself, this will ensure it is re-disassembled.
|
* However, if the cached instruction's context does not match the desired one, assume we're
|
||||||
|
* starting a new block. That check will have to wait for the decode call, though.
|
||||||
*/
|
*/
|
||||||
block = null;
|
if (block.getInstructionAt(address) == null) {
|
||||||
|
block = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@ -66,7 +66,7 @@ public abstract class AbstractBytesPcodeExecutorStatePiece<S extends BytesPcodeE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Memory getMemory() {
|
public Memory getMemory() {
|
||||||
throw new UnsupportedOperationException();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user