mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-2027 Allow for join Varnodes in splitOutMergeGroup
This commit is contained in:
parent
4b600847eb
commit
cedcfbb321
2 changed files with 38 additions and 40 deletions
|
@ -406,7 +406,7 @@ public class HighFunction extends PcodeSyntaxTree {
|
||||||
// need to separate out first use versus mapped use. When the high local is written
|
// need to separate out first use versus mapped use. When the high local is written
|
||||||
// to database, these issues will be resolved at that point.
|
// to database, these issues will be resolved at that point.
|
||||||
sym = localSymbols.newMappedSymbol(0, highloc.getName(), highloc.getDataType(),
|
sym = localSymbols.newMappedSymbol(0, highloc.getName(), highloc.getDataType(),
|
||||||
new VariableStorage(func.getProgram(), vn), vn.getPCAddress(), -1);
|
buildStorage(vn), vn.getPCAddress(), -1);
|
||||||
reslocal = new HighLocal(highloc.getDataType(), vn, null, vn.getPCAddress(), sym);
|
reslocal = new HighLocal(highloc.getDataType(), vn, null, vn.getPCAddress(), sym);
|
||||||
|
|
||||||
resremain = highloc; // Keep remaining varnodes in old high
|
resremain = highloc; // Keep remaining varnodes in old high
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
private PcodeDataTypeManager datatypeManager;
|
private PcodeDataTypeManager datatypeManager;
|
||||||
private HashMap<Integer, Varnode> refmap; // Obtain varnode by id
|
private HashMap<Integer, Varnode> refmap; // Obtain varnode by id
|
||||||
private HashMap<Integer, PcodeOp> oprefmap; // Obtain op by SequenceNumber unique id
|
private HashMap<Integer, PcodeOp> oprefmap; // Obtain op by SequenceNumber unique id
|
||||||
private HashMap<Integer,VariableStorage> joinmap; // logical map of joined objects
|
private HashMap<Integer, VariableStorage> joinmap; // logical map of joined objects
|
||||||
private int joinAllocate; // next offset to be allocated in join map
|
private int joinAllocate; // next offset to be allocated in join map
|
||||||
private PcodeOpBank opbank;
|
private PcodeOpBank opbank;
|
||||||
private VarnodeBank vbank;
|
private VarnodeBank vbank;
|
||||||
|
@ -53,7 +53,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
joinAllocate = 0;
|
joinAllocate = 0;
|
||||||
opbank = new PcodeOpBank();
|
opbank = new PcodeOpBank();
|
||||||
vbank = new VarnodeBank();
|
vbank = new VarnodeBank();
|
||||||
bblocks = new ArrayList<PcodeBlockBasic>();
|
bblocks = new ArrayList<>();
|
||||||
uniqId = 0;
|
uniqId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
joinAllocate = 0;
|
joinAllocate = 0;
|
||||||
vbank.clear();
|
vbank.clear();
|
||||||
opbank.clear();
|
opbank.clear();
|
||||||
bblocks = new ArrayList<PcodeBlockBasic>();
|
bblocks = new ArrayList<>();
|
||||||
uniqId = 0;
|
uniqId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,12 +106,13 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
* @param addr join address associated with pieces
|
* @param addr join address associated with pieces
|
||||||
*
|
*
|
||||||
* @return the VariableStorage associated with xml
|
* @return the VariableStorage associated with xml
|
||||||
* @throws PcodeXMLException
|
* @throws PcodeXMLException for improperly formatted XML
|
||||||
* @throws InvalidInputException
|
* @throws InvalidInputException if the pieces are not valid storage locations
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public VariableStorage readXMLVarnodePieces(XmlElement el, Address addr) throws PcodeXMLException, InvalidInputException {
|
public VariableStorage readXMLVarnodePieces(XmlElement el, Address addr)
|
||||||
ArrayList<Varnode> list = new ArrayList<Varnode>();
|
throws PcodeXMLException, InvalidInputException {
|
||||||
|
ArrayList<Varnode> list = new ArrayList<>();
|
||||||
int index = 1;
|
int index = 1;
|
||||||
String nextPiece = "piece" + index;
|
String nextPiece = "piece" + index;
|
||||||
while (el.hasAttribute(nextPiece)) {
|
while (el.hasAttribute(nextPiece)) {
|
||||||
|
@ -125,11 +126,13 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
return allocateJoinStorage(addr.getOffset(), pieces);
|
return allocateJoinStorage(addr.getOffset(), pieces);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VariableStorage allocateJoinStorage(long offset,Varnode[] pieces) throws InvalidInputException {
|
private VariableStorage allocateJoinStorage(long offset, Varnode[] pieces)
|
||||||
|
throws InvalidInputException {
|
||||||
VariableStorage storage;
|
VariableStorage storage;
|
||||||
try {
|
try {
|
||||||
storage = new VariableStorage(datatypeManager.getProgram(),pieces);
|
storage = new VariableStorage(datatypeManager.getProgram(), pieces);
|
||||||
} catch (InvalidInputException e) {
|
}
|
||||||
|
catch (InvalidInputException e) {
|
||||||
storage = null;
|
storage = null;
|
||||||
}
|
}
|
||||||
if (storage == null) {
|
if (storage == null) {
|
||||||
|
@ -146,23 +149,23 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
sz += piece.getSize();
|
sz += piece.getSize();
|
||||||
}
|
}
|
||||||
Address uniqaddr = addrFactory.getUniqueSpace().getAddress(0x20000000);
|
Address uniqaddr = addrFactory.getUniqueSpace().getAddress(0x20000000);
|
||||||
storage = new VariableStorage(datatypeManager.getProgram(),uniqaddr,sz);
|
storage = new VariableStorage(datatypeManager.getProgram(), uniqaddr, sz);
|
||||||
}
|
}
|
||||||
Integer offObject;
|
Integer offObject;
|
||||||
int roundsize = (storage.size() + 15) & 0xfffffff0;
|
int roundsize = (storage.size() + 15) & 0xfffffff0;
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
offObject = new Integer(joinAllocate);
|
offObject = Integer.valueOf(joinAllocate);
|
||||||
joinAllocate += roundsize;
|
joinAllocate += roundsize;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
offObject = new Integer((int)offset);
|
offObject = Integer.valueOf((int) offset);
|
||||||
offset += roundsize;
|
offset += roundsize;
|
||||||
if (offset > joinAllocate) {
|
if (offset > joinAllocate) {
|
||||||
joinAllocate = (int)offset;
|
joinAllocate = (int) offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (joinmap == null) {
|
if (joinmap == null) {
|
||||||
joinmap = new HashMap<Integer,VariableStorage>();
|
joinmap = new HashMap<>();
|
||||||
}
|
}
|
||||||
joinmap.put(offObject, storage);
|
joinmap.put(offObject, storage);
|
||||||
return storage;
|
return storage;
|
||||||
|
@ -172,20 +175,25 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
if (joinmap == null) {
|
if (joinmap == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return joinmap.get(new Integer((int)offset));
|
return joinmap.get(Integer.valueOf((int) offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VariableStorage buildStorage(Varnode vn) throws InvalidInputException {
|
public VariableStorage buildStorage(Varnode vn) throws InvalidInputException {
|
||||||
Address addr = vn.getAddress();
|
Address addr = vn.getAddress();
|
||||||
if (addr.getAddressSpace().getType() == AddressSpace.TYPE_VARIABLE) {
|
if (addr.getAddressSpace().getType() == AddressSpace.TYPE_VARIABLE) {
|
||||||
return findJoinStorage(addr.getOffset());
|
VariableStorage store = findJoinStorage(addr.getOffset());
|
||||||
|
if (store == null) {
|
||||||
|
throw new InvalidInputException(
|
||||||
|
"Missing description of pieces for a varnode in the join address space");
|
||||||
|
}
|
||||||
|
return store;
|
||||||
}
|
}
|
||||||
return new VariableStorage(datatypeManager.getProgram(),vn);
|
return new VariableStorage(datatypeManager.getProgram(), vn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an iterator for all Varnodes in the tree ordered by Address
|
* @return an iterator for all Varnodes in the tree ordered by Address
|
||||||
*/
|
*/
|
||||||
public Iterator<VarnodeAST> locRange() {
|
public Iterator<VarnodeAST> locRange() {
|
||||||
return vbank.locRange();
|
return vbank.locRange();
|
||||||
|
@ -278,15 +286,6 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
return opbank.findOp(sq);
|
return opbank.findOp(sq);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @return the varnode bank for this syntax tree
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public VarnodeBank getVbank() {
|
|
||||||
return vbank;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<PcodeBlockBasic> getBasicBlocks() {
|
public ArrayList<PcodeBlockBasic> getBasicBlocks() {
|
||||||
return bblocks;
|
return bblocks;
|
||||||
}
|
}
|
||||||
|
@ -321,7 +320,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Varnode createFromStorage(Address addr,VariableStorage storage, int logicalSize) {
|
public Varnode createFromStorage(Address addr, VariableStorage storage, int logicalSize) {
|
||||||
Varnode[] pieces = storage.getVarnodes();
|
Varnode[] pieces = storage.getVarnodes();
|
||||||
|
|
||||||
// This is the most common case, 1 piece, and address is pulled from the piece
|
// This is the most common case, 1 piece, and address is pulled from the piece
|
||||||
|
@ -337,10 +336,12 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
long joinoffset = joinAllocate; // Next available offset
|
long joinoffset = joinAllocate; // Next available offset
|
||||||
storage = allocateJoinStorage(-1, pieces); // is allocated from JOIN space
|
storage = allocateJoinStorage(-1, pieces); // is allocated from JOIN space
|
||||||
addr = AddressSpace.VARIABLE_SPACE.getAddress(joinoffset);
|
addr = AddressSpace.VARIABLE_SPACE.getAddress(joinoffset);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
storage = allocateJoinStorage(addr.getOffset(), pieces);
|
storage = allocateJoinStorage(addr.getOffset(), pieces);
|
||||||
}
|
}
|
||||||
} catch (InvalidInputException e) {
|
}
|
||||||
|
catch (InvalidInputException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Varnode vn = newVarnode(logicalSize, addr);
|
Varnode vn = newVarnode(logicalSize, addr);
|
||||||
|
@ -359,7 +360,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildVarnodeRefs() {
|
private void buildVarnodeRefs() {
|
||||||
refmap = new HashMap<Integer, Varnode>((int) (1.5 * vbank.size()));
|
refmap = new HashMap<>((int) (1.5 * vbank.size()));
|
||||||
Iterator<?> iter = vbank.locRange(); // Iterate over all varnodes
|
Iterator<?> iter = vbank.locRange(); // Iterate over all varnodes
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
VarnodeAST vn = (VarnodeAST) iter.next();
|
VarnodeAST vn = (VarnodeAST) iter.next();
|
||||||
|
@ -410,7 +411,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildOpRefs() {
|
private void buildOpRefs() {
|
||||||
oprefmap = new HashMap<Integer, PcodeOp>((int) (1.5 * opbank.size()));
|
oprefmap = new HashMap<>((int) (1.5 * opbank.size()));
|
||||||
Iterator<?> iter = opbank.allOrdered();
|
Iterator<?> iter = opbank.allOrdered();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
PcodeOp op = (PcodeOp) iter.next();
|
PcodeOp op = (PcodeOp) iter.next();
|
||||||
|
@ -447,8 +448,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOutput(PcodeOp op, Varnode vn) {
|
public void setOutput(PcodeOp op, Varnode vn) {
|
||||||
if (vn == op.getOutput())
|
if (vn == op.getOutput()) {
|
||||||
{
|
|
||||||
return; // Output already set to this
|
return; // Output already set to this
|
||||||
}
|
}
|
||||||
if (op.getOutput() != null) {
|
if (op.getOutput() != null) {
|
||||||
|
@ -464,8 +464,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
|
|
||||||
public void unSetOutput(PcodeOp op) {
|
public void unSetOutput(PcodeOp op) {
|
||||||
Varnode vn = op.getOutput();
|
Varnode vn = op.getOutput();
|
||||||
if (vn == null)
|
if (vn == null) {
|
||||||
{
|
|
||||||
return; // Nothing to do
|
return; // Nothing to do
|
||||||
}
|
}
|
||||||
op.setOutput(null);
|
op.setOutput(null);
|
||||||
|
@ -473,8 +472,7 @@ public class PcodeSyntaxTree implements PcodeFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInput(PcodeOp op, Varnode vn, int slot) {
|
public void setInput(PcodeOp op, Varnode vn, int slot) {
|
||||||
if (slot >= op.getNumInputs())
|
if (slot >= op.getNumInputs()) {
|
||||||
{
|
|
||||||
op.setInput(null, slot); // Expand number of inputs as necessary
|
op.setInput(null, slot); // Expand number of inputs as necessary
|
||||||
}
|
}
|
||||||
if (op.getInput(slot) != null) {
|
if (op.getInput(slot) != null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue