mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
Merge remote-tracking branch 'origin/caheckman_MultiplyCorners'
This commit is contained in:
commit
d5a5f80d29
7 changed files with 222 additions and 50 deletions
|
@ -38,24 +38,37 @@ public class VarnodeBank {
|
|||
/*
|
||||
* Compare objects by location, size, then definition
|
||||
*/
|
||||
@Override
|
||||
public int compare(VarnodeAST v1, VarnodeAST v2) {
|
||||
int cmp = v1.getAddress().compareTo(v2.getAddress());
|
||||
if (cmp!=0)
|
||||
if (cmp!=0) {
|
||||
return cmp;
|
||||
if (v1.getSize() != v2.getSize())
|
||||
}
|
||||
if (v1.getSize() != v2.getSize()) {
|
||||
return (v1.getSize() < v2.getSize() ? -1 : 1);
|
||||
}
|
||||
if (v1.isInput()) {
|
||||
if (v2.isInput()) return 0;
|
||||
if (v2.isInput()) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (v2.isInput()) return 1;
|
||||
if (v2.isInput()) {
|
||||
return 1;
|
||||
}
|
||||
if (v1.getDef() != null) {
|
||||
if (v2.getDef()==null) return -1;
|
||||
if (v2.getDef()==null) {
|
||||
return -1;
|
||||
}
|
||||
return v1.getDef().getSeqnum().compareTo(v2.getDef().getSeqnum());
|
||||
}
|
||||
if (v2.getDef()!=null) return 1;
|
||||
if (v2.getDef()!=null) {
|
||||
return 1;
|
||||
}
|
||||
// Reaching this point guarantees both Varnodes are free
|
||||
if (v1.getUniqueId() == v2.getUniqueId()) return 0;
|
||||
if (v1.getUniqueId() == v2.getUniqueId()) {
|
||||
return 0;
|
||||
}
|
||||
return (v1.getUniqueId()<v2.getUniqueId() ? -1 : 1);
|
||||
}
|
||||
}
|
||||
|
@ -65,23 +78,37 @@ public class VarnodeBank {
|
|||
/*
|
||||
* Compare by definition then location and size
|
||||
*/
|
||||
@Override
|
||||
public int compare(VarnodeAST v1, VarnodeAST v2) {
|
||||
int comp;
|
||||
if (v1.isInput()) {
|
||||
if (!v2.isInput()) return -1;
|
||||
if (!v2.isInput()) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (v1.getDef() != null) {
|
||||
if (v2.isInput()) return 1;
|
||||
if (v2.isFree()) return -1;
|
||||
if (v2.isInput()) {
|
||||
return 1;
|
||||
}
|
||||
if (v2.isFree()) {
|
||||
return -1;
|
||||
}
|
||||
comp = v1.getDef().getSeqnum().compareTo(v2.getDef().getSeqnum());
|
||||
if (comp != 0) return comp;
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
comp = v1.getAddress().compareTo(v2.getAddress());
|
||||
if (comp != 0) return comp;
|
||||
if (v1.getSize() != v2.getSize())
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
if (v1.getSize() != v2.getSize()) {
|
||||
return (v1.getSize() < v2.getSize() ? -1 : 1);
|
||||
}
|
||||
if (v1.isFree()) { // Both Varnodes must be free, compare uniqId
|
||||
if (v1.getUniqueId()==v2.getUniqueId()) return 0;
|
||||
if (v1.getUniqueId()==v2.getUniqueId()) {
|
||||
return 0;
|
||||
}
|
||||
return (v1.getUniqueId() < v2.getUniqueId() ? -1 : 1);
|
||||
}
|
||||
return 0;
|
||||
|
@ -149,8 +176,12 @@ public class VarnodeBank {
|
|||
}
|
||||
|
||||
public Varnode setInput(Varnode vn) {
|
||||
if (!vn.isFree()) return null;
|
||||
if (vn.isConstant()) return null;
|
||||
if (!vn.isFree()) {
|
||||
return null;
|
||||
}
|
||||
if (vn.isConstant()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
VarnodeAST vn1 = (VarnodeAST)vn;
|
||||
locTree.remove(vn1);
|
||||
|
@ -160,8 +191,12 @@ public class VarnodeBank {
|
|||
}
|
||||
|
||||
public Varnode setDef(Varnode vn,PcodeOp op) {
|
||||
if (!vn.isFree()) return null;
|
||||
if (vn.isConstant()) return null;
|
||||
if (!vn.isFree()) {
|
||||
return null;
|
||||
}
|
||||
if (vn.isConstant()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
VarnodeAST vn1 = (VarnodeAST)vn;
|
||||
locTree.remove(vn1);
|
||||
|
@ -177,9 +212,8 @@ public class VarnodeBank {
|
|||
public Iterator<VarnodeAST> locRange(AddressSpace spaceid) {
|
||||
VarnodeAST searchvn1 = new VarnodeAST(spaceid.getAddress(0),0,0);
|
||||
searchvn1.setInput(true);
|
||||
VarnodeAST searchvn2 = new VarnodeAST(spaceid.getAddress(Long.MAX_VALUE),0,0);
|
||||
searchvn2.setInput(true);
|
||||
return locTree.subSet(searchvn1,searchvn2).iterator();
|
||||
VarnodeAST searchvn2 = new VarnodeAST(spaceid.getMaxAddress(), Integer.MAX_VALUE, 0);
|
||||
return locTree.subSet(searchvn1, searchvn2).iterator();
|
||||
}
|
||||
|
||||
public Iterator<VarnodeAST> locRange(Address addr) {
|
||||
|
@ -206,11 +240,17 @@ public class VarnodeBank {
|
|||
Iterator<VarnodeAST> iter = locTree.tailSet(searchvn).iterator();
|
||||
for(;iter.hasNext();) {
|
||||
VarnodeAST vn = iter.next();
|
||||
if (vn.getSize()!=sz) break;
|
||||
if (!vn.getAddress().equals(addr)) break;
|
||||
if (vn.getSize()!=sz) {
|
||||
break;
|
||||
}
|
||||
if (!vn.getAddress().equals(addr)) {
|
||||
break;
|
||||
}
|
||||
PcodeOp op2 = vn.getDef();
|
||||
if ((op2!=null)&&(op2.getSeqnum().getTarget().equals(pc))) {
|
||||
if ((uniq==-1)||(op2.getSeqnum().getTime()==uniq)) return vn;
|
||||
if ((uniq==-1)||(op2.getSeqnum().getTime()==uniq)) {
|
||||
return vn;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -222,8 +262,9 @@ public class VarnodeBank {
|
|||
Iterator<VarnodeAST> iter = locTree.tailSet(searchvn).iterator();
|
||||
if (iter.hasNext()) {
|
||||
VarnodeAST vn = iter.next();
|
||||
if (vn.isInput() && (vn.getSize()==sz) && vn.getAddress().equals(addr))
|
||||
if (vn.isInput() && (vn.getSize()==sz) && vn.getAddress().equals(addr)) {
|
||||
return vn;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue