mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
Merge remote-tracking branch 'origin/GP-2587_InjectionErrorHandling'
This commit is contained in:
commit
fece9ce5f7
9 changed files with 240 additions and 206 deletions
|
@ -20,8 +20,10 @@ import java.io.IOException;
|
|||
import ghidra.app.plugin.processors.sleigh.PcodeEmit;
|
||||
import ghidra.app.plugin.processors.sleigh.SleighLanguage;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.mem.MemoryAccessException;
|
||||
import ghidra.program.model.pcode.Encoder;
|
||||
import ghidra.program.model.pcode.PcodeOp;
|
||||
import ghidra.util.exception.NotFoundException;
|
||||
import ghidra.xml.XmlParseException;
|
||||
import ghidra.xml.XmlPullParser;
|
||||
|
||||
|
@ -122,8 +124,13 @@ public interface InjectPayload {
|
|||
* Given a context, send the p-code payload to the emitter
|
||||
* @param context is the context for injection
|
||||
* @param emit is the object accumulating the final p-code
|
||||
* @throws MemoryAccessException for problems establishing the injection context
|
||||
* @throws IOException for problems while emitting the injection p-code
|
||||
* @throws UnknownInstructionException if there is no underlying instruction being injected
|
||||
* @throws NotFoundException if an expected aspect of the injection is not present in context
|
||||
*/
|
||||
public void inject(InjectContext context, PcodeEmit emit);
|
||||
public void inject(InjectContext context, PcodeEmit emit) throws MemoryAccessException,
|
||||
IOException, UnknownInstructionException, NotFoundException;
|
||||
|
||||
/**
|
||||
* A convenience function wrapping the inject method, to produce the final set
|
||||
|
@ -131,8 +138,13 @@ public interface InjectPayload {
|
|||
* @param program is the Program for which injection is happening
|
||||
* @param con is the context for injection
|
||||
* @return the array of PcodeOps
|
||||
* @throws MemoryAccessException for problems establishing the injection context
|
||||
* @throws IOException for problems while emitting the injection p-code
|
||||
* @throws UnknownInstructionException if there is no underlying instruction being injected
|
||||
* @throws NotFoundException if an expected aspect of the injection is not present in context
|
||||
*/
|
||||
public PcodeOp[] getPcode(Program program, InjectContext con);
|
||||
public PcodeOp[] getPcode(Program program, InjectContext con) throws MemoryAccessException,
|
||||
IOException, UnknownInstructionException, NotFoundException;
|
||||
|
||||
/**
|
||||
* @return true if the injected p-code falls thru
|
||||
|
|
|
@ -27,7 +27,9 @@ import ghidra.app.plugin.processors.sleigh.template.*;
|
|||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.address.AddressFactory;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.mem.MemoryAccessException;
|
||||
import ghidra.program.model.pcode.*;
|
||||
import ghidra.util.exception.NotFoundException;
|
||||
import ghidra.util.xml.SpecXmlUtils;
|
||||
import ghidra.xml.*;
|
||||
|
||||
|
@ -163,22 +165,19 @@ public class InjectPayloadSleigh implements InjectPayload {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inject(InjectContext context, PcodeEmit emit) {
|
||||
public void inject(InjectContext context, PcodeEmit emit) throws UnknownInstructionException,
|
||||
MemoryAccessException, IOException, NotFoundException {
|
||||
ParserWalker walker = emit.getWalker();
|
||||
try {
|
||||
walker.snippetState();
|
||||
setupParameters(context, walker);
|
||||
emit.build(pcodeTemplate, -1);
|
||||
}
|
||||
catch (Exception e) { // Should not be happening in a CallFixup
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
walker.snippetState();
|
||||
setupParameters(context, walker);
|
||||
emit.build(pcodeTemplate, -1);
|
||||
emit.resolveRelatives();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PcodeOp[] getPcode(Program program, InjectContext con) {
|
||||
public PcodeOp[] getPcode(Program program, InjectContext con)
|
||||
throws UnknownInstructionException, MemoryAccessException, IOException,
|
||||
NotFoundException {
|
||||
SleighParserContext protoContext =
|
||||
new SleighParserContext(con.baseAddr, con.nextAddr, con.refAddr, con.callAddr);
|
||||
ParserWalker walker = new ParserWalker(protoContext);
|
||||
|
@ -333,29 +332,36 @@ public class InjectPayloadSleigh implements InjectPayload {
|
|||
/**
|
||||
* Verify that the storage locations passed -con- match the restrictions for this payload
|
||||
* @param con is InjectContext containing parameter storage locations
|
||||
* @throws NotFoundException for expected aspects of the context that are not present
|
||||
*/
|
||||
private void checkParameterRestrictions(InjectContext con, Address addr) {
|
||||
private void checkParameterRestrictions(InjectContext con, Address addr)
|
||||
throws NotFoundException {
|
||||
int insize = (con.inputlist == null) ? 0 : con.inputlist.size();
|
||||
if (inputlist.length != insize) {
|
||||
throw new SleighException(
|
||||
"Input parameters do not match injection specification: " + source);
|
||||
throw new NotFoundException(
|
||||
"Input parameters do not match specification " + name + " in\n" + source);
|
||||
}
|
||||
for (int i = 0; i < inputlist.length; ++i) {
|
||||
int sz = inputlist[i].getSize();
|
||||
if (sz != 0 && sz != con.inputlist.get(i).getSize()) {
|
||||
throw new SleighException(
|
||||
"Input parameter size does not match injection specification: " + source);
|
||||
throw new NotFoundException(
|
||||
"Input parameter size does not match specification " + name + " in\n" + source);
|
||||
}
|
||||
}
|
||||
int outsize = (con.output == null) ? 0 : con.output.size();
|
||||
if (output.length != outsize) {
|
||||
throw new SleighException("Output does not match injection specification: " + source);
|
||||
if (outsize == 0) {
|
||||
throw new NotFoundException(
|
||||
"Output expected by specification " + name + " in\n" + source);
|
||||
}
|
||||
throw new NotFoundException(
|
||||
"Output not expected by specification " + name + " in\n" + source);
|
||||
}
|
||||
for (int i = 0; i < output.length; ++i) {
|
||||
int sz = output[i].getSize();
|
||||
if (sz != 0 && sz != con.output.get(i).getSize()) {
|
||||
throw new SleighException(
|
||||
"Output size does not match injection specification: " + source);
|
||||
throw new NotFoundException(
|
||||
"Output size does not match specification " + name + " in\n" + source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -365,9 +371,10 @@ public class InjectPayloadSleigh implements InjectPayload {
|
|||
* @param con is the InjectContext containing storage locations
|
||||
* @param walker is the sleigh parser state object
|
||||
* @throws UnknownInstructionException if there are too many parameters for the parser
|
||||
* @throws NotFoundException for expected aspects of the context that are not present
|
||||
*/
|
||||
private void setupParameters(InjectContext con, ParserWalker walker)
|
||||
throws UnknownInstructionException {
|
||||
throws UnknownInstructionException, NotFoundException {
|
||||
checkParameterRestrictions(con, walker.getAddr());
|
||||
for (int i = 0; i < inputlist.length; ++i) {
|
||||
walker.allocateOperand();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue