mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-22 03:01:55 +08:00
GP-2480 pcodeCPort dead code cleanup. This package is never used for
emitting pcode which is handled by parallel implementation in package 'ghidra.app.plugin.processors.sleigh'
This commit is contained in:
-302
@@ -1,302 +0,0 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.pcodeCPort.context;
|
||||
|
||||
import generic.stl.IteratorSTL;
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.app.plugin.processors.sleigh.SleighException;
|
||||
import ghidra.pcodeCPort.address.Address;
|
||||
import ghidra.pcodeCPort.globalcontext.ContextCache;
|
||||
import ghidra.pcodeCPort.slghsymbol.*;
|
||||
import ghidra.pcodeCPort.space.AddrSpace;
|
||||
import ghidra.pcodeCPort.translate.BadDataError;
|
||||
|
||||
public class ParserContext {
|
||||
public enum ContextState {
|
||||
uninitialized, disassembly, pcode;
|
||||
}
|
||||
|
||||
private ContextState parsestate;
|
||||
private AddrSpace const_space;
|
||||
private byte[] buf = new byte[16]; // Pointer to instruction bit stream
|
||||
private int[] context; // Pointer to local context
|
||||
private int contextsize; // Number of entries in context array
|
||||
private ContextCache contcache; // Interface for getting/setting context
|
||||
private VectorSTL<ContextSet> contextcommit = new VectorSTL<ContextSet>();
|
||||
private Address addr; // Address of start of instruction
|
||||
private Address naddr; // Address of next instruction
|
||||
private VectorSTL<ConstructState> state = new VectorSTL<ConstructState>(); // Current resolved
|
||||
// instruction
|
||||
ConstructState base_state;
|
||||
private ConstructState point; // Current substate
|
||||
private boolean outofband;
|
||||
private int oob_offset;
|
||||
private int alloc; // Number of ConstructState's allocated
|
||||
private int delayslot; // delayslot depth
|
||||
|
||||
public void dispose() {
|
||||
if (context != null) {
|
||||
context = null;
|
||||
}
|
||||
}
|
||||
|
||||
private ConstructState getState(int index) {
|
||||
ConstructState constructState = state.get(index);
|
||||
if (constructState == null) {
|
||||
constructState = new ConstructState();
|
||||
state.set(index, constructState);
|
||||
}
|
||||
return constructState;
|
||||
}
|
||||
|
||||
public void setAddr(Address ad) {
|
||||
addr = ad;
|
||||
}
|
||||
|
||||
public void setNaddr(Address ad) {
|
||||
naddr = ad;
|
||||
}
|
||||
|
||||
public void clearCommits() {
|
||||
contextcommit.clear();
|
||||
}
|
||||
|
||||
public Address getAddr() {
|
||||
return addr;
|
||||
}
|
||||
|
||||
public Address getNaddr() {
|
||||
return naddr;
|
||||
}
|
||||
|
||||
public AddrSpace getCurSpace() {
|
||||
return addr.getSpace();
|
||||
}
|
||||
|
||||
public AddrSpace getConstSpace() {
|
||||
return const_space;
|
||||
}
|
||||
|
||||
public void setContextWord(int i, int val, int mask) {
|
||||
context[i] = (context[i] & (~mask)) | (mask & val);
|
||||
}
|
||||
|
||||
public void loadContext() {
|
||||
contcache.getContext(addr, context);
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return base_state.length;
|
||||
}
|
||||
|
||||
public void setDelaySlot(int val) {
|
||||
delayslot = val;
|
||||
}
|
||||
|
||||
public int getDelaySlot() {
|
||||
return delayslot;
|
||||
}
|
||||
|
||||
public ParserContext(ContextCache ccache) {
|
||||
parsestate = ContextState.uninitialized;
|
||||
contcache = ccache;
|
||||
if (ccache != null) {
|
||||
contextsize = ccache.getDatabase().getContextSize();
|
||||
context = new int[contextsize];
|
||||
}
|
||||
else {
|
||||
contextsize = 0;
|
||||
context = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void resize(VectorSTL<ConstructState> list, int newsize) {
|
||||
while (list.size() < newsize) {
|
||||
list.push_back(new ConstructState());
|
||||
}
|
||||
while (list.size() > newsize) {
|
||||
list.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getBuffer() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
public void initialize(int maxstate, int maxparam, AddrSpace spc) {
|
||||
const_space = spc;
|
||||
resize(state, maxstate);
|
||||
getState(0).parent = null;
|
||||
for (int i = 0; i < maxstate; ++i) {
|
||||
resize(getState(i).resolve, maxparam);
|
||||
}
|
||||
base_state = getState(0);
|
||||
}
|
||||
|
||||
public ContextState getParserState() {
|
||||
return parsestate;
|
||||
}
|
||||
|
||||
public void setParserState(ContextState st) {
|
||||
parsestate = st;
|
||||
}
|
||||
|
||||
public void deallocateState(ParserWalkerChange walker) {
|
||||
alloc = 1;
|
||||
walker.context = this;
|
||||
walker.baseState();
|
||||
}
|
||||
|
||||
public void allocateOperand(int i, ParserWalkerChange walker) {
|
||||
ConstructState opstate = state.get(alloc++);
|
||||
opstate.parent = walker.point;
|
||||
opstate.ct = null;
|
||||
walker.point.resolve.set(i, opstate);
|
||||
walker.breadcrumb[walker.depth++] += 1;
|
||||
walker.point = opstate;
|
||||
walker.breadcrumb[walker.depth] = 0;
|
||||
}
|
||||
|
||||
public int getInstructionBytes(int bytestart, int size, int off) {
|
||||
// Get bytes from the instruction stream into an int
|
||||
// (assuming big endian format)
|
||||
off += bytestart;
|
||||
if (off >= 16) {
|
||||
throw new BadDataError("Instruction is using more than 16 bytes");
|
||||
}
|
||||
int res = 0;
|
||||
for (int i = 0; i < size; ++i) {
|
||||
res <<= 8;
|
||||
res |= buf[i + off];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int getInstructionBits(int startbit, int size, int off) {
|
||||
off += (startbit / 8);
|
||||
if (off >= 16) {
|
||||
throw new BadDataError("Instruction is using more than 16 bytes");
|
||||
}
|
||||
startbit = startbit % 8;
|
||||
int bytesize = (startbit + size - 1) / 8 + 1;
|
||||
int res = 0;
|
||||
for (int i = 0; i < bytesize; ++i) {
|
||||
res <<= 8;
|
||||
res |= buf[i + off];
|
||||
}
|
||||
res <<= 8 * (4 - bytesize) + startbit; // Move starting bit to highest position
|
||||
res >>= 8 * 4 - size; // Shift to bottom of intm
|
||||
return res;
|
||||
}
|
||||
|
||||
// Get bytes from context into a intm
|
||||
// Assume request is within a intm
|
||||
public int getContextBytes(int bytestart, int size) {
|
||||
int res = context[bytestart / 4];
|
||||
res <<= (bytestart % 4) * 8;
|
||||
res >>>= (4 - size) * 8;
|
||||
return res;
|
||||
}
|
||||
|
||||
public int getContextBits(int startbit, int size) {
|
||||
int res = context[startbit / (8 * 4)]; // Get intm containing highest bit
|
||||
res <<= (startbit % (8 * 4)); // Shift startbit to highest position
|
||||
res >>>= (8 * 4 - size);
|
||||
return res;
|
||||
}
|
||||
|
||||
// set the offset into instruction bytes (for
|
||||
// future calls into getInstructionBytes) without
|
||||
// disturbing the tree walk
|
||||
public void setOffsetOutOfBand(Constructor c, int index) {
|
||||
outofband = true;
|
||||
ConstructState pt = point;
|
||||
while (pt.ct != c) {
|
||||
if (pt == getState(0)) {
|
||||
return;
|
||||
}
|
||||
pt = pt.parent;
|
||||
}
|
||||
OperandSymbol sym = c.getOperand(index);
|
||||
int i = sym.getOffsetBase();
|
||||
// if i<0, i.e. the offset of the operand is constructor relative
|
||||
// its possible that the branch corresponding to the operand
|
||||
// has not been constructed yet. Context expressions are
|
||||
// evaluated BEFORE the constructors branches are created.
|
||||
// So we have to construct the offset explicitly.
|
||||
if (i < 0) {
|
||||
oob_offset = pt.offset + sym.getRelativeOffset();
|
||||
}
|
||||
else {
|
||||
oob_offset = pt.resolve.get(index).offset;
|
||||
}
|
||||
}
|
||||
|
||||
public void addCommit(TripleSymbol sym, int num, int mask, boolean flow, ConstructState point) {
|
||||
contextcommit.push_back(new ContextSet());
|
||||
ContextSet set = contextcommit.back();
|
||||
|
||||
set.sym = sym;
|
||||
set.point = point; // This is the current state
|
||||
set.num = num;
|
||||
set.mask = mask;
|
||||
set.value = context[num] & mask;
|
||||
set.flow = flow;
|
||||
}
|
||||
|
||||
public void applyCommits() {
|
||||
if (contextcommit.empty()) {
|
||||
return;
|
||||
}
|
||||
ParserWalker walker = new ParserWalker(this);
|
||||
walker.baseState();
|
||||
|
||||
IteratorSTL<ContextSet> iter;
|
||||
for (iter = contextcommit.begin(); !iter.isEnd(); iter.increment()) {
|
||||
TripleSymbol sym = iter.get().sym;
|
||||
Address addr = null;
|
||||
if (sym.getType() == symbol_type.operand_symbol) {
|
||||
// The value for an OperandSymbol is probabably already
|
||||
// calculated, we just need to find the right
|
||||
// tree node of the state
|
||||
int i = ((OperandSymbol) sym).getIndex();
|
||||
FixedHandle h = (iter.get().point.resolve.get(i).hand);
|
||||
addr = new Address(h.space, h.offset_offset);
|
||||
}
|
||||
else {
|
||||
FixedHandle hand = new FixedHandle();
|
||||
sym.getFixedHandle(hand, walker);
|
||||
addr = new Address(hand.space, hand.offset_offset);
|
||||
}
|
||||
// Commit context change
|
||||
contcache.setContext(addr, iter.get().num, iter.get().mask, iter.get().value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns primary flow reference destination address for instruction or null
|
||||
*/
|
||||
public Address getFlowRefAddr() {
|
||||
throw new SleighException("Flow reference (inst_ref) is undefined at " + getAddr());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns original flow destination address for instruction or null
|
||||
*/
|
||||
public Address getFlowDestAddr() {
|
||||
throw new SleighException("Flow destination (inst_dest) is undefined at " + getAddr());
|
||||
}
|
||||
}
|
||||
-160
@@ -1,160 +0,0 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.pcodeCPort.context;
|
||||
|
||||
import ghidra.pcodeCPort.address.Address;
|
||||
import ghidra.pcodeCPort.slghsymbol.Constructor;
|
||||
import ghidra.pcodeCPort.slghsymbol.OperandSymbol;
|
||||
import ghidra.pcodeCPort.space.AddrSpace;
|
||||
|
||||
public class ParserWalker {
|
||||
// A class for walking the ParserContext
|
||||
private ParserContext const_context;
|
||||
protected ConstructState point; // The current node being visited
|
||||
protected int depth; // Depth of the current node
|
||||
protected int[] breadcrumb; // Path of operands from root
|
||||
|
||||
public ParserWalker(ParserContext c) {
|
||||
const_context = c;
|
||||
breadcrumb = new int[32];
|
||||
}
|
||||
|
||||
public ParserContext getParserContext() {
|
||||
return const_context;
|
||||
}
|
||||
|
||||
public void baseState() {
|
||||
point = const_context.base_state;
|
||||
depth = 0;
|
||||
breadcrumb[0] = 0;
|
||||
}
|
||||
|
||||
public void setOutOfBandState(Constructor ct, int index, ConstructState tempstate,
|
||||
ParserWalker otherwalker) {
|
||||
// Initialize walker for future calls into getInstructionBytes assuming -ct- is the current position in the walk
|
||||
ConstructState pt = otherwalker.point;
|
||||
int curdepth = otherwalker.depth;
|
||||
while (pt.ct != ct) {
|
||||
if (curdepth <= 0) {
|
||||
return;
|
||||
}
|
||||
curdepth -= 1;
|
||||
pt = pt.parent;
|
||||
}
|
||||
OperandSymbol sym = ct.getOperand(index);
|
||||
int i = sym.getOffsetBase();
|
||||
// if i<0, i.e. the offset of the operand is constructor relative
|
||||
// its possible that the branch corresponding to the operand
|
||||
// has not been constructed yet. Context expressions are
|
||||
// evaluated BEFORE the constructors branches are created.
|
||||
// So we have to construct the offset explicitly.
|
||||
if (i < 0) {
|
||||
tempstate.offset = pt.offset + sym.getRelativeOffset();
|
||||
}
|
||||
else {
|
||||
tempstate.offset = pt.resolve.get(index).offset;
|
||||
}
|
||||
|
||||
tempstate.ct = ct;
|
||||
tempstate.length = pt.length;
|
||||
point = tempstate;
|
||||
depth = 0;
|
||||
breadcrumb[0] = 0;
|
||||
}
|
||||
|
||||
public boolean isState() {
|
||||
return (point != null);
|
||||
}
|
||||
|
||||
public void pushOperand(int i) {
|
||||
breadcrumb[depth++] = i + 1;
|
||||
point = point.resolve.get(i);
|
||||
breadcrumb[depth] = 0;
|
||||
}
|
||||
|
||||
public void popOperand() {
|
||||
point = point.parent;
|
||||
depth -= 1;
|
||||
}
|
||||
|
||||
public int getOffset(int i) {
|
||||
if (i < 0) {
|
||||
return point.offset;
|
||||
}
|
||||
ConstructState op = point.resolve.get(i);
|
||||
return op.offset + op.length;
|
||||
}
|
||||
|
||||
public Constructor getConstructor() {
|
||||
return point.ct;
|
||||
}
|
||||
|
||||
public int getOperand() {
|
||||
return breadcrumb[depth];
|
||||
}
|
||||
|
||||
public FixedHandle getParentHandle() {
|
||||
return point.hand;
|
||||
}
|
||||
|
||||
public FixedHandle getFixedHandle(int i) {
|
||||
return point.resolve.get(i).hand;
|
||||
}
|
||||
|
||||
public AddrSpace getCurSpace() {
|
||||
return const_context.getCurSpace();
|
||||
}
|
||||
|
||||
public AddrSpace getConstSpace() {
|
||||
return const_context.getConstSpace();
|
||||
}
|
||||
|
||||
public Address getAddr() {
|
||||
return const_context.getAddr();
|
||||
}
|
||||
|
||||
public Address getNaddr() {
|
||||
return const_context.getNaddr();
|
||||
}
|
||||
|
||||
public Address getFlowRefAddr() {
|
||||
return const_context.getFlowRefAddr();
|
||||
}
|
||||
|
||||
public Address getFlowDestAddr() {
|
||||
return const_context.getFlowDestAddr();
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return const_context.getLength();
|
||||
}
|
||||
|
||||
public int getInstructionBytes(int byteoff, int numbytes) {
|
||||
return const_context.getInstructionBytes(byteoff, numbytes, point.offset);
|
||||
}
|
||||
|
||||
public int getContextBytes(int byteoff, int numbytes) {
|
||||
return const_context.getContextBytes(byteoff, numbytes);
|
||||
}
|
||||
|
||||
public int getInstructionBits(int startbit, int size) {
|
||||
return const_context.getInstructionBits(startbit, size, point.offset);
|
||||
}
|
||||
|
||||
public int getContextBits(int startbit, int size) {
|
||||
return const_context.getContextBits(startbit, size);
|
||||
}
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.pcodeCPort.context;
|
||||
|
||||
import ghidra.pcodeCPort.slghsymbol.Constructor;
|
||||
|
||||
public class ParserWalkerChange extends ParserWalker {
|
||||
// Extension to walker that allows for on the fly modifications to tree
|
||||
ParserContext context;
|
||||
|
||||
public ParserWalkerChange(ParserContext c) {
|
||||
super(c);
|
||||
context = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParserContext getParserContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public ConstructState getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
public void setOffset(int off) {
|
||||
point.offset = off;
|
||||
}
|
||||
|
||||
public void setConstructor(Constructor c) {
|
||||
point.ct = c;
|
||||
}
|
||||
|
||||
public void setCurrentLength(int len) {
|
||||
point.length = len;
|
||||
}
|
||||
|
||||
public void calcCurrentLength(int length, int numopers) {
|
||||
// Calculate the length of the current constructor
|
||||
// state assuming all its operands are constructed
|
||||
length += point.offset; // Convert relative length to absolute length
|
||||
for (int i = 0; i < numopers; ++i) {
|
||||
ConstructState subpoint = point.resolve.get(i);
|
||||
int sublength = subpoint.length + subpoint.offset;
|
||||
// Since subpoint->offset is an absolute offset
|
||||
// (relative to beginning of instruction) sublength
|
||||
if (sublength > length) {
|
||||
length = sublength;
|
||||
}
|
||||
}
|
||||
point.length = length - point.offset; // Convert back to relative length
|
||||
}
|
||||
}
|
||||
+7
-135
@@ -20,13 +20,10 @@ import java.io.PrintStream;
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.error.LowlevelError;
|
||||
import ghidra.pcodeCPort.space.AddrSpace;
|
||||
import ghidra.pcodeCPort.space.spacetype;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.pcodeCPort.utils.AddrSpaceToIdSymmetryMap;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
|
||||
public class ConstTpl {
|
||||
@@ -41,6 +38,7 @@ public class ConstTpl {
|
||||
handle,
|
||||
j_start,
|
||||
j_next,
|
||||
j_next2,
|
||||
j_curspace,
|
||||
j_curspace_size,
|
||||
spaceid,
|
||||
@@ -198,138 +196,6 @@ public class ConstTpl {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long fix(ParserWalker walker) {
|
||||
// Get the value of the ConstTpl in context
|
||||
// NOTE: if the property is dynamic this returns the property
|
||||
// of the temporary storage
|
||||
switch (type) {
|
||||
case j_start:
|
||||
return walker.getAddr().getOffset(); // Fill in starting address placeholder with real address
|
||||
case j_next:
|
||||
return walker.getNaddr().getOffset(); // Fill in next address placeholder with real address
|
||||
case j_curspace_size:
|
||||
return walker.getCurSpace().getAddrSize();
|
||||
case j_curspace:
|
||||
return AddrSpaceToIdSymmetryMap.getID(walker.getCurSpace());
|
||||
case handle: {
|
||||
FixedHandle hand = walker.getFixedHandle(handle_index);
|
||||
switch (select) {
|
||||
case v_space:
|
||||
if (hand.offset_space == null) {
|
||||
return AddrSpaceToIdSymmetryMap.getID(hand.space);
|
||||
}
|
||||
return AddrSpaceToIdSymmetryMap.getID(hand.temp_space);
|
||||
case v_offset:
|
||||
if (hand.offset_space == null) {
|
||||
return hand.offset_offset;
|
||||
}
|
||||
return hand.temp_offset;
|
||||
case v_size:
|
||||
return hand.size;
|
||||
case v_offset_plus:
|
||||
if (hand.space != walker.getConstSpace()) { // If we are not a constant
|
||||
if (hand.offset_space == null) {
|
||||
return hand.offset_offset + (value_real&0xffff);
|
||||
}
|
||||
return hand.temp_offset + (value_real&0xffff);
|
||||
}
|
||||
// If we are a constant, return a shifted value
|
||||
long val;
|
||||
if (hand.offset_space == null)
|
||||
val = hand.offset_offset;
|
||||
else
|
||||
val = hand.temp_offset;
|
||||
val >>= 8 * (value_real >> 16);
|
||||
return val;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case j_relative:
|
||||
case real:
|
||||
return value_real;
|
||||
case spaceid:
|
||||
return AddrSpaceToIdSymmetryMap.getID(spaceid);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0; // Should never reach here
|
||||
}
|
||||
|
||||
// Get the value of the ConstTpl in context
|
||||
// when we know it is a space
|
||||
public AddrSpace fixSpace(ParserWalker walker) {
|
||||
// Get the value of the ConstTpl in context
|
||||
// when we know it is a space
|
||||
switch (type) {
|
||||
case j_curspace:
|
||||
return walker.getCurSpace();
|
||||
case handle: {
|
||||
FixedHandle hand = walker.getFixedHandle(handle_index);
|
||||
switch (select) {
|
||||
case v_space:
|
||||
if (hand.offset_space == null) {
|
||||
return hand.space;
|
||||
}
|
||||
return hand.temp_space;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case spaceid:
|
||||
return spaceid;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
throw new LowlevelError("ConstTpl is not a spaceid as expected");
|
||||
}
|
||||
|
||||
// Fill in the space portion of a FixedHandle, base on this ConstTpl
|
||||
public void fillinSpace(FixedHandle hand, ParserWalker walker) {
|
||||
switch (type) {
|
||||
case j_curspace:
|
||||
hand.space = walker.getCurSpace();
|
||||
return;
|
||||
case handle: {
|
||||
FixedHandle otherhand = walker.getFixedHandle(handle_index);
|
||||
switch (select) {
|
||||
case v_space:
|
||||
hand.space = otherhand.space;
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case spaceid:
|
||||
hand.space = spaceid;
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
throw new LowlevelError("ConstTpl is not a spaceid as expected");
|
||||
}
|
||||
|
||||
// Fillin the offset portion of a FixedHandle, based on this ConstTpl
|
||||
// If the offset value is dynamic, indicate this in the handle
|
||||
// we don't just fill in the temporary variable offset
|
||||
// we assume hand.space is already filled in
|
||||
public void fillinOffset(FixedHandle hand, ParserWalker walker) {
|
||||
if (type == const_type.handle) {
|
||||
FixedHandle otherhand = walker.getFixedHandle(handle_index);
|
||||
hand.offset_space = otherhand.offset_space;
|
||||
hand.offset_offset = otherhand.offset_offset;
|
||||
hand.offset_size = otherhand.offset_size;
|
||||
hand.temp_space = otherhand.temp_space;
|
||||
hand.temp_offset = otherhand.temp_offset;
|
||||
}
|
||||
else {
|
||||
hand.offset_space = null;
|
||||
hand.offset_offset = fix(walker);
|
||||
hand.offset_offset &= hand.space.getMask();
|
||||
}
|
||||
}
|
||||
|
||||
private void copyIntoMe(ConstTpl other) {
|
||||
type = other.type;
|
||||
spaceid = other.spaceid;
|
||||
@@ -434,6 +300,9 @@ public class ConstTpl {
|
||||
case j_next:
|
||||
s.append("next\"/>");
|
||||
break;
|
||||
case j_next2:
|
||||
s.append("next2\"/>");
|
||||
break;
|
||||
case j_curspace:
|
||||
s.append("curspace\"/>");
|
||||
break;
|
||||
@@ -485,6 +354,9 @@ public class ConstTpl {
|
||||
else if (typestring.equals("next")) {
|
||||
type = const_type.j_next;
|
||||
}
|
||||
else if (typestring.equals("next2")) {
|
||||
type = const_type.j_next2;
|
||||
}
|
||||
else if (typestring.equals("curspace")) {
|
||||
type = const_type.j_curspace;
|
||||
}
|
||||
|
||||
+4
-34
@@ -16,18 +16,15 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.semantics;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.space.AddrSpace;
|
||||
import ghidra.pcodeCPort.space.spacetype;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.space.AddrSpace;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
|
||||
public class HandleTpl {
|
||||
|
||||
private ConstTpl space;
|
||||
@@ -114,33 +111,6 @@ public class HandleTpl {
|
||||
// Build handle to thing being pointed at by -vn-
|
||||
}
|
||||
|
||||
public void fix(FixedHandle hand, ParserWalker walker) {
|
||||
if (ptrspace.getType() == ConstTpl.const_type.real) {
|
||||
// The export is unstarred, but this doesn't mean the varnode
|
||||
// being exported isn't dynamic
|
||||
space.fillinSpace(hand, walker);
|
||||
hand.size = (int) size.fix(walker);
|
||||
ptroffset.fillinOffset(hand, walker);
|
||||
}
|
||||
else {
|
||||
hand.space = space.fixSpace(walker);
|
||||
hand.size = (int) size.fix(walker);
|
||||
hand.offset_offset = ptroffset.fix(walker);
|
||||
hand.offset_space = ptrspace.fixSpace(walker);
|
||||
if (hand.offset_space.getType() == spacetype.IPTR_CONSTANT) {
|
||||
// Handle could have been dynamic but wasn't
|
||||
hand.offset_space = null;
|
||||
hand.offset_offset <<= hand.space.getScale();
|
||||
hand.offset_offset &= hand.space.getMask();
|
||||
}
|
||||
else {
|
||||
hand.offset_size = (int) ptrsize.fix(walker);
|
||||
hand.temp_space = temp_space.fixSpace(walker);
|
||||
hand.temp_offset = temp_offset.fix(walker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changeHandleIndex(VectorSTL<Integer> handmap) {
|
||||
space.changeHandleIndex(handmap);
|
||||
size.changeHandleIndex(handmap);
|
||||
|
||||
-7
@@ -18,7 +18,6 @@ package ghidra.pcodeCPort.semantics;
|
||||
|
||||
import generic.stl.IteratorSTL;
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.translate.UnimplError;
|
||||
|
||||
// SLEIGH specific pcode generator
|
||||
@@ -27,8 +26,6 @@ public abstract class PcodeBuilder {
|
||||
private int labelbase;
|
||||
private int labelcount;
|
||||
|
||||
protected ParserWalker walker;
|
||||
|
||||
protected abstract void dump(OpTpl op);
|
||||
|
||||
public PcodeBuilder(int lbcnt) {
|
||||
@@ -42,10 +39,6 @@ public abstract class PcodeBuilder {
|
||||
return labelbase;
|
||||
}
|
||||
|
||||
public ParserWalker getCurrentWalker() {
|
||||
return walker;
|
||||
}
|
||||
|
||||
public abstract void appendBuild(OpTpl bld, int secnum);
|
||||
|
||||
public abstract void appendCrossBuild(OpTpl bld, int secnum);
|
||||
|
||||
-13
@@ -21,8 +21,6 @@ import java.util.List;
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl.const_type;
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl.v_field;
|
||||
import ghidra.pcodeCPort.space.spacetype;
|
||||
@@ -129,17 +127,6 @@ public class VarnodeTpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isDynamic(ParserWalker walker) {
|
||||
if (offset.getType() != ConstTpl.const_type.handle) {
|
||||
return false;
|
||||
}
|
||||
// Technically we should probably check all three
|
||||
// ConstTpls for dynamic handles, but in all cases
|
||||
// if there is any dynamic piece then the offset is
|
||||
FixedHandle hand = walker.getFixedHandle(offset.getHandleIndex());
|
||||
return (hand.offset_space != null);
|
||||
}
|
||||
|
||||
public int transfer(VectorSTL<HandleTpl> params) {
|
||||
boolean doesOffsetPlus = false;
|
||||
int handleIndex=0;
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class AndExpression extends BinaryExpression {
|
||||
|
||||
public AndExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class AndExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval & rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
+5
-11
@@ -16,16 +16,15 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
public class ConstantValue extends PatternValue {
|
||||
|
||||
long val;
|
||||
@@ -39,11 +38,6 @@ public class ConstantValue extends PatternValue {
|
||||
val = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenPattern genMinPattern(VectorSTL<TokenPattern> ops) {
|
||||
return new TokenPattern(location);
|
||||
|
||||
+4
-18
@@ -16,17 +16,16 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.pcodeCPort.utils.Utils;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class ContextField extends PatternValue {
|
||||
|
||||
private int startbit, endbit;
|
||||
@@ -80,19 +79,6 @@ public class ContextField extends PatternValue {
|
||||
shift = 7 - (endbit % 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long res = ExpressUtils.getContextBytes(pos, startbyte, endbyte);
|
||||
res >>>= shift;
|
||||
if (signbit) {
|
||||
res = Utils.zzz_sign_extend(res, endbit - startbit);
|
||||
}
|
||||
else {
|
||||
res = Utils.zzz_zero_extend(res, endbit - startbit);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "cf:{" + startbit + "," + endbit + "," + startbyte + "," + endbyte + "," + shift +
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class DivExpression extends BinaryExpression {
|
||||
|
||||
public DivExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class DivExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval / rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
+4
-10
@@ -16,26 +16,20 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
public class EndInstructionValue extends PatternValue {
|
||||
|
||||
public EndInstructionValue(Location location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
return (pos.getNaddr().getOffset() >>> pos.getNaddr().getSpace().getScale());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenPattern genMinPattern(VectorSTL<TokenPattern> ops) {
|
||||
return new TokenPattern(location);
|
||||
|
||||
-46
@@ -17,55 +17,9 @@
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.Utils;
|
||||
|
||||
public class ExpressUtils {
|
||||
|
||||
// Build a long from the instruction bytes
|
||||
static long getInstructionBytes(ParserWalker pos, int bytestart, int byteend, boolean bigendian) {
|
||||
long res = 0;
|
||||
|
||||
int size = byteend - bytestart + 1;
|
||||
int tmpsize = size;
|
||||
while (tmpsize >= 4) {
|
||||
int tmp = pos.getInstructionBytes(bytestart, 4);
|
||||
res <<= 32;
|
||||
res |= tmp;
|
||||
bytestart += 4;
|
||||
tmpsize -= 4;
|
||||
}
|
||||
if (tmpsize > 0) {
|
||||
int tmp = pos.getInstructionBytes(bytestart, tmpsize);
|
||||
res <<= 8 * tmpsize;
|
||||
res |= tmp;
|
||||
}
|
||||
if (!bigendian) {
|
||||
res = Utils.byte_swap(res, size);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Build a intb from the context bytes
|
||||
static long getContextBytes(ParserWalker pos, int bytestart, int byteend) {
|
||||
long res = 0;
|
||||
|
||||
int size = byteend - bytestart + 1;
|
||||
while (size >= 4) {
|
||||
int tmp = pos.getContextBytes(bytestart, 4);
|
||||
res <<= 32;
|
||||
res |= tmp;
|
||||
bytestart += 4;
|
||||
size = byteend - bytestart + 1;
|
||||
}
|
||||
if (size > 0) {
|
||||
int tmp = pos.getContextBytes(bytestart, size);
|
||||
res <<= 8 * size;
|
||||
res |= tmp;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static boolean advance_combo(VectorSTL<Long> val, VectorSTL<Long> min, VectorSTL<Long> max) {
|
||||
int i = 0;
|
||||
while (i < val.size()) {
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class LeftShiftExpression extends BinaryExpression {
|
||||
|
||||
public LeftShiftExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class LeftShiftExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval << rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
+2
-9
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class MinusExpression extends UnaryExpression {
|
||||
|
||||
public MinusExpression(Location location) {
|
||||
@@ -33,12 +32,6 @@ public class MinusExpression extends UnaryExpression {
|
||||
super(location, u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long val = getUnary().getValue(pos);
|
||||
return -val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long val = getUnary().getSubValue(replace, listpos);
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class MultExpression extends BinaryExpression {
|
||||
|
||||
public MultExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class MultExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval * rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
+2
-9
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class NotExpression extends UnaryExpression {
|
||||
|
||||
public NotExpression(Location location) {
|
||||
@@ -33,12 +32,6 @@ public class NotExpression extends UnaryExpression {
|
||||
super(location, u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long val = getUnary().getValue(pos);
|
||||
return ~val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long val = getUnary().getSubValue(replace, listpos);
|
||||
|
||||
+1
-23
@@ -20,7 +20,7 @@ import java.io.PrintStream;
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.*;
|
||||
import ghidra.pcodeCPort.context.SleighError;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghsymbol.*;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
@@ -79,28 +79,6 @@ public class OperandValue extends PatternValue {
|
||||
throw new SleighError("Operand used in pattern expression", ct.location);
|
||||
}
|
||||
|
||||
// Get the value of an operand when it is used in
|
||||
// an expression.
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
OperandSymbol sym = ct.getOperand(index);
|
||||
PatternExpression patexp = sym.getDefiningExpression();
|
||||
if (patexp == null) {
|
||||
TripleSymbol defsym = sym.getDefiningSymbol();
|
||||
if (defsym != null) {
|
||||
patexp = defsym.getPatternExpression();
|
||||
}
|
||||
if (patexp == null) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
ConstructState tempstate = new ConstructState();
|
||||
ParserWalker newwalker = new ParserWalker(pos.getParserContext());
|
||||
newwalker.setOutOfBandState(ct, index, tempstate, pos);
|
||||
long res = patexp.getValue(newwalker);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
OperandSymbol sym = ct.getOperand(index);
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class OrExpression extends BinaryExpression {
|
||||
|
||||
public OrExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class OrExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval | rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
+8
-8
@@ -16,16 +16,15 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
public abstract class PatternExpression {
|
||||
public final Location location;
|
||||
|
||||
@@ -39,8 +38,6 @@ public abstract class PatternExpression {
|
||||
refcount = 0;
|
||||
}
|
||||
|
||||
public abstract long getValue(ParserWalker pos);
|
||||
|
||||
public abstract TokenPattern genMinPattern(VectorSTL<TokenPattern> ops);
|
||||
|
||||
public abstract void listValues(VectorSTL<PatternValue> list);
|
||||
@@ -91,6 +88,9 @@ public abstract class PatternExpression {
|
||||
else if (nm.equals("end_exp")) {
|
||||
res = new EndInstructionValue(null);
|
||||
}
|
||||
else if (nm.equals("next2_exp")) {
|
||||
res = new Next2InstructionValue(null);
|
||||
}
|
||||
else if (nm.equals("plus_exp")) {
|
||||
res = new PlusExpression(null);
|
||||
}
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class PlusExpression extends BinaryExpression {
|
||||
|
||||
public PlusExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class PlusExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval + rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class RightShiftExpression extends BinaryExpression {
|
||||
|
||||
public RightShiftExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class RightShiftExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval >>> rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
+4
-10
@@ -16,26 +16,20 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
public class StartInstructionValue extends PatternValue {
|
||||
|
||||
public StartInstructionValue(Location location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
return (pos.getAddr().getOffset() >> pos.getAddr().getSpace().getScale());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenPattern genMinPattern(VectorSTL<TokenPattern> ops) {
|
||||
return new TokenPattern(location);
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class SubExpression extends BinaryExpression {
|
||||
|
||||
public SubExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class SubExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval - rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
+4
-20
@@ -16,18 +16,17 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.context.Token;
|
||||
import ghidra.pcodeCPort.translate.Translate;
|
||||
import ghidra.pcodeCPort.utils.Utils;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class TokenField extends PatternValue {
|
||||
|
||||
private Token tok;
|
||||
@@ -77,21 +76,6 @@ public class TokenField extends PatternValue {
|
||||
shift = bitstart % 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) { // Construct value given specific
|
||||
// instruction stream
|
||||
long res = ExpressUtils.getInstructionBytes(pos, bytestart, byteend, bigendian);
|
||||
|
||||
res >>>= shift;
|
||||
if (signbit) {
|
||||
res = Utils.zzz_sign_extend(res, bitend - bitstart);
|
||||
}
|
||||
else {
|
||||
res = Utils.zzz_zero_extend(res, bitend - bitstart);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenPattern genPattern(long val) { // Generate corresponding pattern if the
|
||||
// value is forced to be val
|
||||
|
||||
+2
-10
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpatexpress;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.MutableInt;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class XorExpression extends BinaryExpression {
|
||||
|
||||
public XorExpression(Location location) {
|
||||
@@ -33,13 +32,6 @@ public class XorExpression extends BinaryExpression {
|
||||
super(location, l, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue(ParserWalker pos) {
|
||||
long leftval = getLeft().getValue(pos);
|
||||
long rightval = getRight().getValue(pos);
|
||||
return leftval ^ rightval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSubValue(VectorSTL<Long> replace, MutableInt listpos) {
|
||||
long leftval = getLeft().getSubValue(replace, listpos); // Must be left first
|
||||
|
||||
-13
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpattern;
|
||||
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
|
||||
@@ -63,17 +61,6 @@ public class CombinePattern extends DisjointPattern {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(ParserWalker pos) {
|
||||
if (!instr.isMatch(pos)) {
|
||||
return false;
|
||||
}
|
||||
if (!context.isMatch(pos)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alwaysTrue() {
|
||||
return (context.alwaysTrue() && instr.alwaysTrue());
|
||||
|
||||
-7
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpattern;
|
||||
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
|
||||
@@ -60,11 +58,6 @@ public class ContextPattern extends DisjointPattern {
|
||||
public void shiftInstruction(int sa) {
|
||||
} // do nothing
|
||||
|
||||
@Override
|
||||
public boolean isMatch(ParserWalker pos) {
|
||||
return maskvalue.isContextMatch(pos, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alwaysTrue() {
|
||||
return maskvalue.alwaysTrue();
|
||||
|
||||
-7
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpattern;
|
||||
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
|
||||
@@ -70,11 +68,6 @@ public class InstructionPattern extends DisjointPattern {
|
||||
maskvalue.shift(sa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(ParserWalker pos) {
|
||||
return maskvalue.isInstructionMatch(pos, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alwaysTrue() {
|
||||
return maskvalue.alwaysTrue();
|
||||
|
||||
+3
-14
@@ -16,16 +16,15 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpattern;
|
||||
|
||||
import generic.stl.IteratorSTL;
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.IteratorSTL;
|
||||
import generic.stl.VectorSTL;
|
||||
|
||||
public class OrPattern extends Pattern {
|
||||
|
||||
private VectorSTL<DisjointPattern> orlist = new VectorSTL<DisjointPattern>();
|
||||
@@ -71,16 +70,6 @@ public class OrPattern extends Pattern {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(ParserWalker pos) {
|
||||
for (int i = 0; i < orlist.size(); ++i) {
|
||||
if (orlist.get(i).isMatch(pos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// This isn't quite right because different branches
|
||||
// may cover the entire gamut
|
||||
@Override
|
||||
|
||||
-4
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghpattern;
|
||||
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
@@ -37,8 +35,6 @@ public abstract class Pattern {
|
||||
|
||||
public abstract Pattern commonSubPattern(Pattern b, int sa);
|
||||
|
||||
public abstract boolean isMatch(ParserWalker pos); // Does this pattern match context
|
||||
|
||||
public abstract int numDisjoint();
|
||||
|
||||
public abstract DisjointPattern getDisjoint(int i);
|
||||
|
||||
-31
@@ -23,7 +23,6 @@ import org.jdom.Element;
|
||||
|
||||
import generic.stl.IteratorSTL;
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.utils.Utils;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
|
||||
@@ -364,36 +363,6 @@ public class PatternBlock {
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean isInstructionMatch(ParserWalker pos, int off) {
|
||||
if (nonzerosize <= 0) {
|
||||
return (nonzerosize == 0);
|
||||
}
|
||||
off += offset;
|
||||
for (int i = 0; i < maskvec.size(); ++i) {
|
||||
int data = pos.getInstructionBytes(off, 4);
|
||||
if ((maskvec.get(i) & data) != valvec.get(i)) {
|
||||
return false;
|
||||
}
|
||||
off += 4;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isContextMatch(ParserWalker pos, int off) {
|
||||
if (nonzerosize <= 0) {
|
||||
return (nonzerosize == 0);
|
||||
}
|
||||
off += offset;
|
||||
for (int i = 0; i < maskvec.size(); ++i) {
|
||||
int data = pos.getContextBytes(off, 4);
|
||||
if ((maskvec.get(i) & data) != valvec.get(i)) {
|
||||
return false;
|
||||
}
|
||||
off += 4;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<pat_block ");
|
||||
s.append("offset=\"");
|
||||
|
||||
+1
-67
@@ -22,7 +22,7 @@ import org.jdom.Element;
|
||||
|
||||
import generic.stl.IteratorSTL;
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.*;
|
||||
import ghidra.pcodeCPort.context.SleighError;
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl.const_type;
|
||||
import ghidra.pcodeCPort.semantics.ConstructTpl;
|
||||
import ghidra.pcodeCPort.semantics.HandleTpl;
|
||||
@@ -129,13 +129,6 @@ public class Constructor {
|
||||
return namedtempl.size();
|
||||
}
|
||||
|
||||
public void applyContext(ParserWalkerChange pos) {
|
||||
IteratorSTL<ContextChange> iter = context.begin();
|
||||
for (; !iter.isEnd(); iter.increment()) {
|
||||
iter.get().apply(pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void markSubtableOperands(VectorSTL<Integer> check) {
|
||||
// Adjust -check- so it has one entry for every operand, a 0 if it is a subtable, a 2 if it is not
|
||||
check.resize(operands.size(), 0);
|
||||
@@ -296,65 +289,6 @@ public class Constructor {
|
||||
namedtempl.set(id, tpl);
|
||||
}
|
||||
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
IteratorSTL<String> piter;
|
||||
for (piter = printpiece.begin(); !piter.isEnd(); piter.increment()) {
|
||||
if (piter.get().charAt(0) == '\n') {
|
||||
int index = piter.get().charAt(1) - 'A';
|
||||
operands.get(index).print(s, pos);
|
||||
}
|
||||
else {
|
||||
s.append(piter.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void printMnemonic(PrintStream s, ParserWalker pos) {
|
||||
if (flowthruindex != -1) {
|
||||
TripleSymbol definingSymbol = operands.get(flowthruindex).getDefiningSymbol();
|
||||
if (definingSymbol instanceof SubtableSymbol) {
|
||||
pos.pushOperand(flowthruindex);
|
||||
pos.getConstructor().printMnemonic(s, pos);
|
||||
pos.popOperand();
|
||||
return;
|
||||
}
|
||||
}
|
||||
int endind = (firstwhitespace == -1) ? printpiece.size() : firstwhitespace;
|
||||
for (int i = 0; i < endind; ++i) {
|
||||
if (printpiece.get(i).charAt(0) == '\n') {
|
||||
int index = printpiece.get(i).charAt(1) - 'A';
|
||||
operands.get(index).print(s, pos);
|
||||
}
|
||||
else {
|
||||
s.append(printpiece.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void printBody(PrintStream s, ParserWalker pos) {
|
||||
if (flowthruindex != -1) {
|
||||
TripleSymbol sym = operands.get(flowthruindex).getDefiningSymbol();
|
||||
if (sym instanceof SubtableSymbol) {
|
||||
pos.pushOperand(flowthruindex);
|
||||
pos.getConstructor().printBody(s, pos);
|
||||
pos.popOperand();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (firstwhitespace == -1) {
|
||||
return; // Nothing to print after firstwhitespace
|
||||
}
|
||||
for (int i = firstwhitespace + 1; i < printpiece.size(); ++i) {
|
||||
if (printpiece.get(i).charAt(0) == '\n') {
|
||||
int index = printpiece.get(i).charAt(1) - 'A';
|
||||
operands.get(index).print(s, pos);
|
||||
}
|
||||
else {
|
||||
s.append(printpiece.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Allow for user to force extra space at end of printing
|
||||
public void removeTrailingSpace() {
|
||||
if ((!printpiece.empty()) && (printpiece.back().equals(" "))) {
|
||||
|
||||
+2
-5
@@ -16,13 +16,12 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import ghidra.pcodeCPort.context.ParserWalkerChange;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
|
||||
// Change to context command
|
||||
public abstract class ContextChange {
|
||||
|
||||
@@ -35,8 +34,6 @@ public abstract class ContextChange {
|
||||
|
||||
public abstract void restoreXml(Element el, SleighBase trans);
|
||||
|
||||
public abstract void apply(ParserWalkerChange pos);
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
|
||||
+3
-10
@@ -16,14 +16,13 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import ghidra.pcodeCPort.context.ParserWalkerChange;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.utils.*;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.utils.*;
|
||||
|
||||
public class ContextCommit extends ContextChange {
|
||||
|
||||
private TripleSymbol sym;
|
||||
@@ -49,12 +48,6 @@ public class ContextCommit extends ContextChange {
|
||||
mask = m.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ParserWalkerChange pos) {
|
||||
pos.getParserContext().addCommit(sym, num, mask, flow, pos.getPoint());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<commit");
|
||||
|
||||
+4
-12
@@ -16,18 +16,17 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalkerChange;
|
||||
import ghidra.pcodeCPort.context.SleighError;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.*;
|
||||
import ghidra.pcodeCPort.utils.*;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class ContextOp extends ContextChange {
|
||||
public final Location location;
|
||||
|
||||
@@ -58,13 +57,6 @@ public class ContextOp extends ContextChange {
|
||||
patexp.layClaim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ParserWalkerChange pos) {
|
||||
int val = (int) patexp.getValue(pos); // Get our value based on context
|
||||
val <<= shift;
|
||||
pos.getParserContext().setContextWord(num, val, mask);
|
||||
}
|
||||
|
||||
// Throw an exception if the PatternExpression is not valid
|
||||
@Override
|
||||
public void validate() {
|
||||
|
||||
-23
@@ -22,10 +22,8 @@ import java.util.List;
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.*;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.error.LowlevelError;
|
||||
import ghidra.pcodeCPort.slghpattern.DisjointPattern;
|
||||
import ghidra.pcodeCPort.translate.BadDataError;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
|
||||
public class DecisionNode {
|
||||
@@ -356,27 +354,6 @@ public class DecisionNode {
|
||||
}
|
||||
}
|
||||
|
||||
Constructor resolve(ParserWalker pos) {
|
||||
if (bitsize == 0) { // The node is terminal
|
||||
IteratorSTL<Pair<DisjointPattern, Constructor>> iter;
|
||||
for (iter = list.begin(); !iter.isEnd(); iter.increment()) {
|
||||
if (iter.get().first.isMatch(pos)) {
|
||||
return iter.get().second;
|
||||
}
|
||||
}
|
||||
throw new BadDataError(pos.getAddr().getShortcut() + pos.getAddr().toString() +
|
||||
": Unable to resolve constructor");
|
||||
}
|
||||
int val;
|
||||
if (contextdecision) {
|
||||
val = pos.getContextBits(startbit, bitsize);
|
||||
}
|
||||
else {
|
||||
val = pos.getInstructionBits(startbit, bitsize);
|
||||
}
|
||||
return children.get(val).resolve(pos);
|
||||
}
|
||||
|
||||
void saveXml(PrintStream s) {
|
||||
s.append("<decision");
|
||||
s.append(" number=\"");
|
||||
|
||||
+4
-21
@@ -16,8 +16,10 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl;
|
||||
import ghidra.pcodeCPort.semantics.VarnodeTpl;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
@@ -26,10 +28,6 @@ import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.space.AddrSpace;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class EndSymbol extends SpecificSymbol {
|
||||
private AddrSpace const_space;
|
||||
private PatternExpression patexp;
|
||||
@@ -72,21 +70,6 @@ public class EndSymbol extends SpecificSymbol {
|
||||
return new VarnodeTpl(location, spc, off, sz_zero);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker pos) {
|
||||
hand.space = pos.getCurSpace();
|
||||
hand.offset_space = null;
|
||||
hand.offset_offset = pos.getNaddr().getOffset(); // Get starting address of next instruction
|
||||
hand.size = hand.space.getAddrSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
long val = pos.getNaddr().getOffset();
|
||||
s.append("0x");
|
||||
s.append(Long.toHexString(val));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<end_sym");
|
||||
|
||||
+4
-19
@@ -16,18 +16,16 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl;
|
||||
import ghidra.pcodeCPort.semantics.VarnodeTpl;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.space.AddrSpace;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
// Another name for zero pattern/value
|
||||
public class EpsilonSymbol extends PatternlessSymbol {
|
||||
|
||||
@@ -47,19 +45,6 @@ public class EpsilonSymbol extends PatternlessSymbol {
|
||||
return symbol_type.epsilon_symbol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker pos) {
|
||||
hand.space = const_space;
|
||||
hand.offset_space = null; // Not a dynamic value
|
||||
hand.offset_offset = 0;
|
||||
hand.size = 0; // Cannot provide size
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
s.append('0');
|
||||
}
|
||||
|
||||
@Override
|
||||
public VarnodeTpl getVarnode() {
|
||||
return new VarnodeTpl(location, new ConstTpl(const_space), new ConstTpl(
|
||||
|
||||
-20
@@ -15,11 +15,6 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import ghidra.pcodeCPort.address.Address;
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl;
|
||||
import ghidra.pcodeCPort.semantics.VarnodeTpl;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
@@ -49,15 +44,6 @@ public class FlowDestSymbol extends SpecificSymbol {
|
||||
return symbol_type.start_symbol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker walker) {
|
||||
Address refAddr = walker.getFlowDestAddr();
|
||||
hand.space = const_space;
|
||||
hand.offset_space = null;
|
||||
hand.offset_offset = refAddr.getOffset();
|
||||
hand.size = refAddr.getAddrSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VarnodeTpl getVarnode() {
|
||||
ConstTpl spc = new ConstTpl(const_space);
|
||||
@@ -66,10 +52,4 @@ public class FlowDestSymbol extends SpecificSymbol {
|
||||
return new VarnodeTpl(location, spc, off, sz_zero);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
long val = pos.getFlowDestAddr().getOffset();
|
||||
s.append("0x");
|
||||
s.print(Long.toHexString(val));
|
||||
}
|
||||
}
|
||||
|
||||
-20
@@ -15,11 +15,6 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import ghidra.pcodeCPort.address.Address;
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl;
|
||||
import ghidra.pcodeCPort.semantics.VarnodeTpl;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
@@ -50,15 +45,6 @@ public class FlowRefSymbol extends SpecificSymbol {
|
||||
return symbol_type.start_symbol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker walker) {
|
||||
Address refAddr = walker.getFlowRefAddr();
|
||||
hand.space = const_space;
|
||||
hand.offset_space = null;
|
||||
hand.offset_offset = refAddr.getOffset();
|
||||
hand.size = refAddr.getAddrSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VarnodeTpl getVarnode() {
|
||||
ConstTpl spc = new ConstTpl(const_space);
|
||||
@@ -67,10 +53,4 @@ public class FlowRefSymbol extends SpecificSymbol {
|
||||
return new VarnodeTpl(location, spc, off, sz_zero);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
long val = pos.getFlowRefAddr().getOffset();
|
||||
s.append("0x");
|
||||
s.print(Long.toHexString(val));
|
||||
}
|
||||
}
|
||||
|
||||
-23
@@ -22,11 +22,9 @@ import java.util.List;
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternValue;
|
||||
import ghidra.pcodeCPort.translate.BadDataError;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
public class NameSymbol extends ValueSymbol {
|
||||
@@ -56,32 +54,11 @@ public class NameSymbol extends ValueSymbol {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor resolve(ParserWalker pos) {
|
||||
if (!tableisfilled) {
|
||||
int ind = (int) patval.getValue(pos);
|
||||
if ((ind >= nametable.size()) || (ind < 0) || (nametable.get(ind).length() == 0)) {
|
||||
throw new BadDataError(
|
||||
"No corresponding entry in nametable <" + getName() + ">, index=" + ind);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public symbol_type getType() {
|
||||
return symbol_type.name_symbol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos)
|
||||
|
||||
{
|
||||
int ind = (int) patval.getValue(pos);
|
||||
// ind is already checked to be in range by the resolve routine
|
||||
s.print(nametable.get(ind));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<name_sym");
|
||||
|
||||
+1
-31
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import ghidra.pcodeCPort.context.*;
|
||||
import ghidra.pcodeCPort.context.SleighError;
|
||||
import ghidra.pcodeCPort.semantics.VarnodeTpl;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.OperandValue;
|
||||
@@ -168,11 +168,6 @@ public class OperandSymbol extends SpecificSymbol {
|
||||
return new VarnodeTpl(location, hand, false); // Possible dynamic handle
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hnd, ParserWalker pos) {
|
||||
hnd = pos.getFixedHandle(hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
if (triple != null) {
|
||||
@@ -181,31 +176,6 @@ public class OperandSymbol extends SpecificSymbol {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
pos.pushOperand(getIndex());
|
||||
if (triple != null) {
|
||||
if (triple.getType() == symbol_type.subtable_symbol) {
|
||||
pos.getConstructor().print(s, pos);
|
||||
}
|
||||
else {
|
||||
triple.print(s, pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
long val = defexp.getValue(pos);
|
||||
if (val >= 0) {
|
||||
s.append("0x");
|
||||
s.append(Long.toHexString(val));
|
||||
}
|
||||
else {
|
||||
s.append("-0x");
|
||||
s.append(Long.toHexString(-val));
|
||||
}
|
||||
}
|
||||
pos.popOperand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectLocalValues(ArrayList<Long> results) {
|
||||
if (triple != null) {
|
||||
|
||||
+4
-21
@@ -16,8 +16,10 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl;
|
||||
import ghidra.pcodeCPort.semantics.VarnodeTpl;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
@@ -26,10 +28,6 @@ import ghidra.pcodeCPort.slghpatexpress.StartInstructionValue;
|
||||
import ghidra.pcodeCPort.space.AddrSpace;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class StartSymbol extends SpecificSymbol {
|
||||
private AddrSpace const_space;
|
||||
private PatternExpression patexp;
|
||||
@@ -72,21 +70,6 @@ public class StartSymbol extends SpecificSymbol {
|
||||
return new VarnodeTpl(location, spc, off, sz_zero);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker pos) {
|
||||
hand.space = pos.getCurSpace();
|
||||
hand.offset_space = null;
|
||||
hand.offset_offset = pos.getAddr().getOffset(); // Get starting address of instruction
|
||||
hand.size = hand.space.getAddrSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
long val = pos.getAddr().getOffset();
|
||||
s.append("0x");
|
||||
s.print(Long.toHexString(val));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<start_sym");
|
||||
|
||||
+1
-16
@@ -22,7 +22,7 @@ import org.jdom.Element;
|
||||
|
||||
import generic.stl.IteratorSTL;
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.*;
|
||||
import ghidra.pcodeCPort.context.SleighError;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.slghpatexpress.TokenPattern;
|
||||
@@ -58,11 +58,6 @@ public class SubtableSymbol extends TripleSymbol {
|
||||
construct.push_back(ct);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor resolve(ParserWalker pos) {
|
||||
return decisiontree.resolve(pos);
|
||||
}
|
||||
|
||||
public TokenPattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
@@ -80,21 +75,11 @@ public class SubtableSymbol extends TripleSymbol {
|
||||
throw new SleighError("Cannot use subtable in expression", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker pos) {
|
||||
throw new SleighError("Cannot use subtable in expression", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
throw new SleighError("Cannot use subtable in expression", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectLocalValues(ArrayList<Long> results) {
|
||||
for (Constructor curConstruct : construct) {
|
||||
|
||||
-11
@@ -15,11 +15,8 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
@@ -36,20 +33,12 @@ public abstract class TripleSymbol extends SleighSymbol {
|
||||
|
||||
public abstract PatternExpression getPatternExpression();
|
||||
|
||||
public abstract void getFixedHandle(FixedHandle hand, ParserWalker pos);
|
||||
|
||||
public int getSize() {
|
||||
return 0;
|
||||
} // Size out of context
|
||||
|
||||
public abstract void print(PrintStream s, ParserWalker pos);
|
||||
|
||||
public void collectLocalValues(ArrayList<Long> results) {
|
||||
// By default, assume symbol has no local exports
|
||||
}
|
||||
|
||||
public Constructor resolve(ParserWalker pos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-45
@@ -16,22 +16,19 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternValue;
|
||||
import ghidra.pcodeCPort.translate.BadDataError;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternValue;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
public class ValueMapSymbol extends ValueSymbol {
|
||||
private VectorSTL<Long> valuetable = new VectorSTL<Long>();
|
||||
private boolean tableisfilled;
|
||||
@@ -63,41 +60,6 @@ public class ValueMapSymbol extends ValueSymbol {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor resolve(ParserWalker pos) {
|
||||
if (!tableisfilled) {
|
||||
int ind = (int) patval.getValue(pos);
|
||||
if ((ind >= valuetable.size()) || (ind < 0) || (valuetable.get(ind) == 0xBADBEEF)) {
|
||||
throw new BadDataError("No corresponding entry in nametable <" + getName() +
|
||||
">, index=" + ind);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker pos) {
|
||||
int ind = (int) patval.getValue(pos);
|
||||
// The resolve routine has checked that -ind- must be a valid index
|
||||
hand.space = pos.getConstSpace();
|
||||
hand.offset_space = null; // Not a dynamic value
|
||||
hand.offset_offset = valuetable.get(ind);
|
||||
hand.size = 0; // Cannot provide size
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
int ind = (int) patval.getValue(pos);
|
||||
// ind is already checked to be in range by the resolve routine
|
||||
Long val = valuetable.get(ind);
|
||||
if (val >= 0) {
|
||||
s.append("0x").append(Long.toHexString(val));
|
||||
}
|
||||
else {
|
||||
s.append("-0x").append(Long.toHexString(-val));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<valuemap_sym");
|
||||
|
||||
+5
-28
@@ -16,18 +16,16 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import ghidra.pcodeCPort.context.FixedHandle;
|
||||
import ghidra.pcodeCPort.context.ParserWalker;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternValue;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternValue;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
public class ValueSymbol extends FamilySymbol {
|
||||
|
||||
protected PatternValue patval;
|
||||
@@ -65,27 +63,6 @@ public class ValueSymbol extends FamilySymbol {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker pos) {
|
||||
hand.space = pos.getConstSpace();
|
||||
hand.offset_space = null;
|
||||
hand.offset_offset = patval.getValue(pos);
|
||||
hand.size = 0; // Cannot provide size
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
long val = patval.getValue(pos);
|
||||
if (val >= 0) {
|
||||
s.append("0x");
|
||||
s.append(Long.toHexString(val));
|
||||
}
|
||||
else {
|
||||
s.append("-0x");
|
||||
s.append(Long.toHexString(-val));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<value_sym");
|
||||
|
||||
+8
-46
@@ -16,23 +16,20 @@
|
||||
*/
|
||||
package ghidra.pcodeCPort.slghsymbol;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.*;
|
||||
import ghidra.pcodeCPort.pcoderaw.VarnodeData;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternValue;
|
||||
import ghidra.pcodeCPort.translate.BadDataError;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import generic.stl.VectorSTL;
|
||||
import ghidra.pcodeCPort.context.SleighError;
|
||||
import ghidra.pcodeCPort.sleighbase.SleighBase;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternExpression;
|
||||
import ghidra.pcodeCPort.slghpatexpress.PatternValue;
|
||||
import ghidra.pcodeCPort.utils.XmlUtils;
|
||||
import ghidra.sleigh.grammar.Location;
|
||||
|
||||
public class VarnodeListSymbol extends ValueSymbol {
|
||||
|
||||
private VectorSTL<VarnodeSymbol> varnode_table = new VectorSTL<VarnodeSymbol>();
|
||||
@@ -67,32 +64,6 @@ public class VarnodeListSymbol extends ValueSymbol {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor resolve(ParserWalker walker) {
|
||||
if (!tableisfilled) {
|
||||
int ind = (int) patval.getValue(walker);
|
||||
if ((ind < 0) || (ind >= varnode_table.size()) || (varnode_table.get(ind) == null)) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintStream s = new PrintStream(baos);
|
||||
walker.getAddr().printRaw(s);
|
||||
throw new BadDataError(walker.getAddr().getShortcut() + baos.toString() +
|
||||
": No corresponding entry in varnode list");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker pos) {
|
||||
int ind = (int) patval.getValue(pos);
|
||||
// The resolve routine has checked that -ind- must be a valid index
|
||||
VarnodeData fix = varnode_table.get(ind).getFixedVarnode();
|
||||
hand.space = fix.space;
|
||||
hand.offset_space = null; // Not a dynamic value
|
||||
hand.offset_offset = fix.offset;
|
||||
hand.size = fix.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
for (int i = 0; i < varnode_table.size(); ++i) {
|
||||
@@ -104,15 +75,6 @@ public class VarnodeListSymbol extends ValueSymbol {
|
||||
throw new SleighError("No register attached to: " + getName(), getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
int ind = (int) patval.getValue(pos);
|
||||
if (ind >= varnode_table.size()) {
|
||||
throw new SleighError("Value out of range for varnode table", getLocation());
|
||||
}
|
||||
s.append(varnode_table.get(ind).getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<varlist_sym");
|
||||
|
||||
+1
-14
@@ -22,7 +22,7 @@ import org.jdom.Element;
|
||||
|
||||
import generic.util.UnsignedDataUtils;
|
||||
// A global varnode
|
||||
import ghidra.pcodeCPort.context.*;
|
||||
import ghidra.pcodeCPort.context.SleighError;
|
||||
import ghidra.pcodeCPort.pcoderaw.VarnodeData;
|
||||
import ghidra.pcodeCPort.semantics.ConstTpl;
|
||||
import ghidra.pcodeCPort.semantics.VarnodeTpl;
|
||||
@@ -54,11 +54,6 @@ public class VarnodeSymbol extends PatternlessSymbol {
|
||||
return fix.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(PrintStream s, ParserWalker pos) {
|
||||
s.append(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectLocalValues(ArrayList<Long> results) {
|
||||
if (fix.space.getType() == spacetype.IPTR_INTERNAL) {
|
||||
@@ -98,14 +93,6 @@ public class VarnodeSymbol extends PatternlessSymbol {
|
||||
new ConstTpl(ConstTpl.const_type.real, fix.size));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFixedHandle(FixedHandle hand, ParserWalker pos) {
|
||||
hand.space = fix.space;
|
||||
hand.offset_space = null; // Not a dynamic symbol
|
||||
hand.offset_offset = fix.offset;
|
||||
hand.size = fix.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveXml(PrintStream s) {
|
||||
s.append("<varnode_sym");
|
||||
|
||||
Reference in New Issue
Block a user