Use InjectPayload for segment ops

This commit is contained in:
caheckman 2019-08-29 14:17:02 -04:00
parent 06de0d46a0
commit 4c3289f09f
7 changed files with 93 additions and 132 deletions

View file

@ -227,51 +227,19 @@
</optional>
</define>
<define name="segment_op_type">
<attribute name="code">
<choice>
<value type="string">INT_ZEXT</value>
<value type="string">INT_LEFT</value>
<value type="string">INT_AND</value>
</choice>
</attribute>
<optional>
<attribute name="value"/>
</optional>
<optional>
<attribute name="slot"/>
</optional>
</define>
<define name="segmentop_type">
<element name="segmentop">
<attribute name="space"/>
<optional> <attribute name="userop"/> </optional>
<optional> <attribute name="baseinsize"/> </optional>
<optional> <attribute name="innerinsize"/> </optional>
<optional> <attribute name="farpointer"/> </optional>
<element name="pcode">
<ref name="pcode_type"/>
</element>
<optional>
<attribute name="force">
<ref name="boolean_type"/>
</attribute>
<element name="constresolve">
<ref name="varnode_tags_type"/>
</element>
</optional>
<interleave>
<zeroOrMore>
<element name="baseop">
<ref name="segment_op_type"/>
</element>
</zeroOrMore>
<zeroOrMore>
<element name="innerop">
<ref name="segment_op_type"/>
</element>
</zeroOrMore>
<optional>
<element name="constresolve">
<ref name="varnode_tags_type"/>
</element>
</optional>
</interleave>
</element>
</define>

View file

@ -599,6 +599,29 @@ public class SleighLanguage implements Language {
}
}
private void parseSegmentOp(XmlElement el, XmlPullParser parser) {
String name = el.getAttribute("userop");
if (name == null) {
name = "segment";
}
name = name + "_pcode";
String source = "pspec: " + getLanguageID().getIdAsString();
if (parser.peek().isStart()) {
if (parser.peek().getName().equals("pcode")) {
InjectPayloadSleigh payload =
new InjectPayloadSleigh(name, InjectPayload.EXECUTABLEPCODE_TYPE, source);
if (additionalInject == null) {
additionalInject = new ArrayList<>();
}
payload.restoreXml(parser);
additionalInject.add(payload);
}
}
while (parser.peek().isStart()) {
parser.discardSubTree();
}
}
private void read(XmlPullParser parser) {
Set<String> registerDataSet = new HashSet<>();
@ -775,9 +798,7 @@ public class SleighLanguage implements Language {
}
}
else if (element.getName().equals("segmentop")) {
while (parser.peek().isStart()) {
parser.discardSubTree();
}
parseSegmentOp(element, parser);
}
// get rid of the end tag of whatever we started with at the top of the while
parser.end(element);

View file

@ -163,29 +163,30 @@ public class BasicCompilerSpec implements CompilerSpec {
language.getProperty(GhidraLanguagePropertyKeys.PCODE_INJECT_LIBRARY_CLASS);
if (classname == null) {
pcodeInject = new PcodeInjectLibrary(language); // This is the default implementation
return;
}
try {
Class<?> c = Class.forName(classname);
if (!PcodeInjectLibrary.class.isAssignableFrom(c)) {
else {
try {
Class<?> c = Class.forName(classname);
if (!PcodeInjectLibrary.class.isAssignableFrom(c)) {
Msg.error(this,
"Language " + language.getLanguageID() + " does not specify a valid " +
GhidraLanguagePropertyKeys.PCODE_INJECT_LIBRARY_CLASS);
throw new RuntimeException(classname + " does not implement interface " +
PcodeInjectLibrary.class.getName());
}
Class<? extends PcodeInjectLibrary> injectLibraryClass =
(Class<? extends PcodeInjectLibrary>) c;
Constructor<? extends PcodeInjectLibrary> constructor =
injectLibraryClass.getConstructor(SleighLanguage.class);
pcodeInject = constructor.newInstance(language);
}
catch (Exception e) {
Msg.error(this,
"Language " + language.getLanguageID() + " does not specify a valid " +
GhidraLanguagePropertyKeys.PCODE_INJECT_LIBRARY_CLASS);
throw new RuntimeException(classname + " does not implement interface " +
PcodeInjectLibrary.class.getName());
throw new RuntimeException("Failed to instantiate " + classname + " for language " +
language.getLanguageID(), e);
}
Class<? extends PcodeInjectLibrary> injectLibraryClass =
(Class<? extends PcodeInjectLibrary>) c;
Constructor<? extends PcodeInjectLibrary> constructor =
injectLibraryClass.getConstructor(SleighLanguage.class);
pcodeInject = constructor.newInstance(language);
}
catch (Exception e) {
Msg.error(this, "Language " + language.getLanguageID() + " does not specify a valid " +
GhidraLanguagePropertyKeys.PCODE_INJECT_LIBRARY_CLASS);
throw new RuntimeException(
"Failed to instantiate " + classname + " for language " + language.getLanguageID(),
e);
}
List<InjectPayloadSleigh> additionalInject = language.getAdditionalInject();
if (additionalInject != null) {