Merge remote-tracking branch 'origin/caheckman_BaseSpaceID'

This commit is contained in:
ghidra1 2020-07-01 16:14:23 -04:00
commit 9af174f9fe
28 changed files with 172 additions and 126 deletions

View file

@ -544,7 +544,7 @@ public class FlowArrowPlugin extends Plugin implements MarginProvider, OptionsCh
if (bottomAddr != null) {
AddressSpace testSpace = bottomAddr.getAddressSpace();
validState = (program.getAddressFactory().getAddressSpace(
testSpace.getUniqueSpaceID()) == testSpace);
testSpace.getSpaceID()) == testSpace);
}
}

View file

@ -175,7 +175,7 @@ public abstract class AbstractScalarOperandHover extends AbstractConfigurableHov
AddressSpace space = factory.getDefaultAddressSpace();
Address asAddress;
try {
asAddress = factory.getAddress(space.getBaseSpaceID(), scalarLong);
asAddress = factory.getAddress(space.getSpaceID(), scalarLong);
}
catch (AddressOutOfBoundsException ex) {
asAddress = null; // Constant doesn't make sense as an address

View file

@ -1,6 +1,5 @@
/* ###
* 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.
@ -306,7 +305,7 @@ abstract class AbstractDwarfEHDecoder implements DwarfEHDecoder {
long offset = decode(context);
return addrFactory.getAddress(ram.getBaseSpaceID(), offset);
return addrFactory.getAddress(ram.getSpaceID(), offset);
}
/**
@ -370,7 +369,7 @@ abstract class AbstractDwarfEHDecoder implements DwarfEHDecoder {
}
if (isIndirect) {
Address toDeref = prog.getAddressFactory().getAddress(ram.getBaseSpaceID(), val);
Address toDeref = prog.getAddressFactory().getAddress(ram.getSpaceID(), val);
val = ptrval(prog, toDeref);
}

View file

@ -95,7 +95,7 @@ public class LSDAHeader extends GccAnalysisClass {
AddressFactory addrFactory = program.getAddressFactory();
AddressSpace ram = addrFactory.getDefaultAddressSpace();
return addrFactory.getAddress(ram.getBaseSpaceID(), offset);
return addrFactory.getAddress(ram.getSpaceID(), offset);
}
private Address createLPStartPointer(Address addr) throws MemoryAccessException {

View file

@ -602,7 +602,7 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc
Address address = loc.getAddress();
AddressSpace locAddressSpace = address.getAddressSpace();
AddressSpace programAddressSpace =
program.getAddressFactory().getAddressSpace(locAddressSpace.getUniqueSpaceID());
program.getAddressFactory().getAddressSpace(locAddressSpace.getSpaceID());
if (programAddressSpace != locAddressSpace) {
FieldLocation compatibleLocation =
getFieldLocationForDifferingAddressSpaces(loc, program);

View file

@ -72,7 +72,7 @@ public class AddressIndexMapConverter extends AddressIndexMap {
private Address getMapAddress(Address addr) {
AddressSpace locAddressSpace = addr.getAddressSpace();
AddressSpace programAddressSpace =
mapProgram.getAddressFactory().getAddressSpace(locAddressSpace.getUniqueSpaceID());
mapProgram.getAddressFactory().getAddressSpace(locAddressSpace.getSpaceID());
Address mapAddress = (programAddressSpace == locAddressSpace) ? addr
: SimpleDiffUtility.getCompatibleAddress(otherProgram, addr, mapProgram);
return mapAddress;

View file

@ -212,7 +212,7 @@ public class SymbolicPropogator {
ProgramContext newSpaceContext = new ProgramContextImpl(programContext.getRegisters());
VarnodeContext newContext = new VarnodeContext(program, newValueContext, newSpaceContext);
newContext.setDebug(debug);
int constantSpaceID = program.getAddressFactory().getConstantSpace().getBaseSpaceID();
int constantSpaceID = program.getAddressFactory().getConstantSpace().getSpaceID();
// copy any current registers with values into the context
Register[] regWithVals = programContext.getRegistersWithValues();
for (Register regWithVal : regWithVals) {
@ -834,7 +834,7 @@ public class SymbolicPropogator {
val1 = vContext.getValue(in[0], evaluator);
lval1 = vContext.getConstant(val1, evaluator);
vt = vContext.getVarnode(
minInstrAddress.getAddressSpace().getBaseSpaceID(), lval1, 0);
minInstrAddress.getAddressSpace().getSpaceID(), lval1, 0);
makeReference(vContext, instruction, ptype, -1, vt,
instruction.getFlowType(), monitor);
}
@ -889,7 +889,7 @@ public class SymbolicPropogator {
!refs[0].getToAddress().equals(target)) {
makeReference(vContext, instruction, Reference.MNEMONIC,
// Use target in case location has shifted (external...)
target.getAddressSpace().getBaseSpaceID(),
target.getAddressSpace().getSpaceID(),
target.getAddressableWordOffset(), val1.getSize(),
instruction.getFlowType(), ptype, true, monitor);
}
@ -1848,7 +1848,7 @@ public class SymbolicPropogator {
pcodeType, constant, 0, reftype);
if (newTarget != null) {
makeReference(vContext, instruction, Reference.MNEMONIC,
newTarget.getAddressSpace().getBaseSpaceID(), newTarget.getOffset(),
newTarget.getAddressSpace().getSpaceID(), newTarget.getOffset(),
0, reftype, pcodeType, false, monitor);
return;
}
@ -2050,7 +2050,7 @@ public class SymbolicPropogator {
// if only one memory space, no overlays, just return default space
if (memorySpaces.size() == 1) {
return defaultSpace.getUniqueSpaceID();
return defaultSpace.getSpaceID();
}
int realMemSpaceCnt = 0; // count of real memory spaces that could contain the target
@ -2069,7 +2069,7 @@ public class SymbolicPropogator {
// if this instruction is in an overlay space overlaying the default space, change the default space
if (instrSpace.isOverlaySpace() &&
instrSpace.getBaseSpaceID() == defaultSpace.getUniqueSpaceID()) {
((OverlayAddressSpace) instrSpace).getBaseSpaceID() == defaultSpace.getSpaceID()) {
defaultSpace = instrSpace;
}
@ -2109,17 +2109,17 @@ public class SymbolicPropogator {
// if only one memory space held a valid value, use it
if (containingMemSpaceCnt == 1 && containingAddr != null) {
return containingAddr.getAddressSpace().getUniqueSpaceID();
return containingAddr.getAddressSpace().getSpaceID();
}
if (symbolTargetCnt == 1 && symbolTarget != null) {
return symbolTarget.getAddressSpace().getUniqueSpaceID();
return symbolTarget.getAddressSpace().getSpaceID();
}
// nothing to lead to one space or the other, and code/data spaces are not the same
if (realMemSpaceCnt != 1 && !defaultSpacesAreTheSame) {
return -1;
}
return defaultSpace.getUniqueSpaceID();
return defaultSpace.getSpaceID();
}
/**

View file

@ -989,7 +989,7 @@ public class VarnodeContext implements ProcessorContext {
}
BigInteger spaceVal = getTranslatedSpaceValue(reg, fromAddr, toAddr);
if (spaceVal != null) {
if (addrFactory.getConstantSpace().getBaseSpaceID() != spaceVal.intValue()) {
if (addrFactory.getConstantSpace().getSpaceID() != spaceVal.intValue()) {
return null;
}
}
@ -1224,7 +1224,7 @@ public class VarnodeContext implements ProcessorContext {
if (regSpace == null) {
regSpace = ((OffsetAddressFactory) addrFactory).createNewOffsetSpace(name);
}
spaceID = regSpace.getBaseSpaceID();
spaceID = regSpace.getSpaceID();
return spaceID;
}
@ -1242,7 +1242,7 @@ public class VarnodeContext implements ProcessorContext {
throws NotFoundException {
// degenerate case, don't need to know the value
if (val1.equals(val2)) {
return createVarnode(0, addrFactory.getConstantSpace().getBaseSpaceID(),
return createVarnode(0, addrFactory.getConstantSpace().getSpaceID(),
val1.getSize());
}
int spaceID = val1.getSpace();
@ -1430,7 +1430,7 @@ public class VarnodeContext implements ProcessorContext {
}
public boolean isSymbolicSpace(AddressSpace space) {
int spaceID = space.getUniqueSpaceID();
int spaceID = space.getSpaceID();
return OffsetAddressFactory.isSymbolSpace(spaceID);
}

View file

@ -1,6 +1,5 @@
/* ###
* 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.
@ -204,7 +203,7 @@ public class TableEntry extends Switch {
return null;
}
AddressFactory addrFactory = program.getAddressFactory();
if (addrFactory.getDefaultAddressSpace().getUniqueSpaceID() != inputValues[0].getOffset()) {
if (addrFactory.getDefaultAddressSpace().getSpaceID() != inputValues[0].getOffset()) {
// TableEntryAddress class assumes default address space for tables
return null;
}

View file

@ -174,11 +174,11 @@ public class OverlayAddressSpaceTest extends AbstractGhidraHeadedIntegrationTest
AddressSpace nonOverlaySpace = space3Address.getAddressSpace();
Assert.assertNotEquals(overlaySpace, nonOverlaySpace);
int overlayBaseID = overlaySpace.getBaseSpaceID();
int spaceBaseID = space1.getBaseSpaceID();
int overlayBaseID = ((OverlayAddressSpace) overlaySpace).getBaseSpaceID();
int spaceBaseID = space1.getSpaceID();
assertEquals(overlayBaseID, spaceBaseID);
int nonBaseID = nonOverlaySpace.getBaseSpaceID();
int nonBaseID = nonOverlaySpace.getSpaceID();
Assert.assertNotEquals(overlayBaseID, nonBaseID);
}

View file

@ -15,8 +15,7 @@
*/
package ghidra.util.state;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.math.BigInteger;
@ -281,30 +280,30 @@ public class ContextStateTest extends AbstractGhidraHeadedIntegrationTest {
new Varnode[] { regEAX, new Varnode(addrFactory.getConstantAddress(16), 4) }, regEBX);
VarnodeOperation addEAX16op = new VarnodeOperation(addEAX16, addEAX16.getInputs());
state1.store(addrFactory.getDefaultAddressSpace().getUniqueSpaceID(), addEAX16op,
state1.store(addrFactory.getDefaultAddressSpace().getSpaceID(), addEAX16op,
new Varnode(addrFactory.getConstantAddress(0x12345678), 4), 4);
assertEquals(new Varnode(addrFactory.getConstantAddress(0x12345678), 4),
state1.get(addrFactory.getDefaultAddressSpace().getUniqueSpaceID(), addEAX16op, 4));
state1.get(addrFactory.getDefaultAddressSpace().getSpaceID(), addEAX16op, 4));
assertEquals(new Varnode(addrFactory.getConstantAddress(0x345678), 3),
state1.get(addrFactory.getDefaultAddressSpace().getUniqueSpaceID(), addEAX16op, 3));
state1.get(addrFactory.getDefaultAddressSpace().getSpaceID(), addEAX16op, 3));
assertEquals(new Varnode(addrFactory.getConstantAddress(0x5678), 2),
state1.get(addrFactory.getDefaultAddressSpace().getUniqueSpaceID(), addEAX16op, 2));
state1.get(addrFactory.getDefaultAddressSpace().getSpaceID(), addEAX16op, 2));
assertEquals(new Varnode(addrFactory.getConstantAddress(0x78), 1),
state1.get(addrFactory.getDefaultAddressSpace().getUniqueSpaceID(), addEAX16op, 1));
state1.get(addrFactory.getDefaultAddressSpace().getSpaceID(), addEAX16op, 1));
PcodeOp addEAX18 = new PcodeOp(addr(1000), 0, PcodeOp.INT_ADD,
new Varnode[] { regEAX, new Varnode(addrFactory.getConstantAddress(18), 4) }, regEBX);
VarnodeOperation addEAX18op = new VarnodeOperation(addEAX18, addEAX18.getInputs());
assertEquals(new Varnode(addrFactory.getConstantAddress(0x1234), 2),
state1.get(addrFactory.getDefaultAddressSpace().getUniqueSpaceID(), addEAX18op, 2));
state1.get(addrFactory.getDefaultAddressSpace().getSpaceID(), addEAX18op, 2));
assertEquals(new Varnode(addrFactory.getConstantAddress(0x34), 1),
state1.get(addrFactory.getDefaultAddressSpace().getUniqueSpaceID(), addEAX18op, 1));
state1.get(addrFactory.getDefaultAddressSpace().getSpaceID(), addEAX18op, 1));
}

View file

@ -23,6 +23,8 @@
//
//@category Search
import java.util.*;
import generic.jar.ResourceFile;
import ghidra.app.decompiler.*;
import ghidra.app.decompiler.component.DecompilerUtils;
@ -43,8 +45,6 @@ import ghidra.util.UndefinedFunction;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.InvalidInputException;
import java.util.*;
public class ShowConstantUse extends GhidraScript {
private DecompInterface decomplib;
DecompileResults lastResults = null;
@ -143,9 +143,9 @@ public class ShowConstantUse extends GhidraScript {
if (f == null) {
Reference[] referencesFrom =
currentProgram.getReferenceManager().getReferencesFrom(faddr);
for (int i = 0; i < referencesFrom.length; i++) {
if (referencesFrom[i].isExternalReference()) {
faddr = referencesFrom[i].getToAddress();
for (Reference element : referencesFrom) {
if (element.isExternalReference()) {
faddr = element.getToAddress();
f = currentProgram.getFunctionManager().getFunctionAt(faddr);
if (f != null) {
break;
@ -437,8 +437,7 @@ public class ShowConstantUse extends GhidraScript {
keys = constLocs.keySet();
Address[] keyArray = keys.toArray(new Address[0]);
Arrays.sort(keyArray);
for (int i = 0; i < keyArray.length; i++) {
Address loc = keyArray[i];
for (Address loc : keyArray) {
Long constant = constLocs.get(loc);
tableChooserDialog.add(new ConstUseLocation(currentProgram, loc, constant, null));
}
@ -872,7 +871,7 @@ public class ShowConstantUse extends GhidraScript {
if (def.getInput(0).isConstant() && def.getInput(1).isConstant()) {
long space = def.getInput(0).getOffset();
long offset = def.getInput(1).getOffset();
if (space != funcEntry.getAddressSpace().getBaseSpaceID()) {
if (space != funcEntry.getAddressSpace().getSpaceID()) {
break;
}
try {

View file

@ -127,7 +127,7 @@ public class FunctionSignatureDecompilerHover extends AbstractConfigurableHover
AddressFactory factory = program.getAddressFactory();
AddressSpace space = factory.getDefaultAddressSpace();
try {
Address asAddress = factory.getAddress(space.getBaseSpaceID(), scalarLong);
Address asAddress = factory.getAddress(space.getSpaceID(), scalarLong);
Function function = program.getListing().getFunctionAt(asAddress);
if (function != null) {
String content = ToolTipUtils.getToolTipText(function, false);

View file

@ -77,7 +77,7 @@ public class PEUtil {
try {
int addrAsInt = memory.getInt(addr);
Address pointedToAddr =
addressFactory.getAddress(defaultSpace.getBaseSpaceID(), addrAsInt);
addressFactory.getAddress(defaultSpace.getSpaceID(), addrAsInt);
return memory.contains(pointedToAddr);
}
catch (MemoryAccessException e) {
@ -92,7 +92,7 @@ public class PEUtil {
try {
int addrAsInt = memory.getInt(addr);
Address pointedToAddr =
addressFactory.getAddress(defaultSpace.getBaseSpaceID(), addrAsInt);
addressFactory.getAddress(defaultSpace.getSpaceID(), addrAsInt);
if (memory.contains(pointedToAddr)) {
GuidInfo guidInfo = GuidUtil.getKnownGuid(program, pointedToAddr);
if (guidInfo != null) {

View file

@ -1,6 +1,5 @@
/* ###
* 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.
@ -16,11 +15,14 @@
*/
package ghidra.app.plugin.processors.generic;
import ghidra.program.model.address.*;
import ghidra.program.model.mem.MemBuffer;
import ghidra.program.model.pcode.*;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.*;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.mem.MemBuffer;
import ghidra.program.model.pcode.PcodeOp;
import ghidra.program.model.pcode.Varnode;
/**
*
@ -50,7 +52,7 @@ public class BinaryExpression implements OperandValue, ExpressionValue {
right = r;
wordSize = c.getSize()/8;
// wordMask = c.getMaxOffset();
spaceID = c.getBaseSpaceID();
spaceID = c.getSpaceID();
constantSpace = c;
switch (opType) {
case ADD:
@ -65,11 +67,12 @@ public class BinaryExpression implements OperandValue, ExpressionValue {
}
public void setSpace(AddressSpace space) {
spaceID = space.getBaseSpaceID();
spaceID = space.getSpaceID();
wordSize = space.getSize()/8;
// wordMask = space.getMaxOffset();
}
@Override
public int length(MemBuffer buf,int off) throws Exception {
int leftLen = left.length(buf,off);
int rightLen = right.length(buf, off);
@ -77,10 +80,12 @@ public class BinaryExpression implements OperandValue, ExpressionValue {
return (leftLen > rightLen ? leftLen : rightLen);
}
@Override
public ConstructorInfo getInfo(MemBuffer buf, int off) throws Exception {
return new ConstructorInfo(length(buf,off),0);
}
@Override
public long longValue(MemBuffer buf, int off) throws Exception {
long l = left.longValue(buf, off);
@ -98,9 +103,12 @@ public class BinaryExpression implements OperandValue, ExpressionValue {
}
}
@Override
public String toString(MemBuffer buf, int off) throws Exception {
long val = longValue(buf, off);
if (val >= 0) return "0x" + Long.toString(val,16);
if (val >= 0) {
return "0x" + Long.toString(val,16);
}
return "-0x" + Long.toString(-val,16);
}
@ -113,6 +121,7 @@ public class BinaryExpression implements OperandValue, ExpressionValue {
right.linkRelativeOffsets(opHash);
}
@Override
public Handle getHandle(Position position, int off) throws Exception {
long val = /* wordMask & */ longValue(position.buffer(),off);
Address a = constantSpace.getAddress(val);
@ -120,10 +129,12 @@ public class BinaryExpression implements OperandValue, ExpressionValue {
return new Handle(v,spaceID,wordSize);
}
@Override
public Handle getHandle(ArrayList<PcodeOp> pcode, Position position, int off) throws Exception {
return getHandle(position,off); // a binary expression never has any associated pcode
}
@Override
public void getAllHandles(ArrayList<Handle> handles,Position position,int off) throws Exception {
handles.add(getHandle(position,off));
}
@ -131,6 +142,7 @@ public class BinaryExpression implements OperandValue, ExpressionValue {
/* (non-Javadoc)
* @see ghidra.app.plugin.processors.generic.OperandValue#toList(java.util.ArrayList, ghidra.program.model.mem.MemBuffer, int)
*/
@Override
public void toList(ArrayList<Handle> list, Position position, int off) throws Exception {
list.add(getHandle(position, off));
}
@ -138,6 +150,7 @@ public class BinaryExpression implements OperandValue, ExpressionValue {
/* (non-Javadoc)
* @see ghidra.app.plugin.processors.generic.OperandValue#getSize()
*/
@Override
public int getSize() {
return wordSize * 8;
}

View file

@ -15,11 +15,11 @@
*/
package ghidra.app.plugin.processors.generic;
import ghidra.program.model.address.Address;
import java.io.Serializable;
import java.util.HashMap;
import ghidra.program.model.address.Address;
/**
*
*/
@ -101,7 +101,7 @@ public class ConstantTemplate implements Serializable {
case JUMP_CODESPACE:
Address addr = position.buffer().getAddress();
return addr.getAddressSpace().getBaseSpaceID();
return addr.getAddressSpace().getSpaceID();
default: // Should never reach here
return 0;
@ -114,8 +114,9 @@ public class ConstantTemplate implements Serializable {
* @return long
*/
public long resolve(HashMap<Object, Handle> handles, Position position, int off) throws Exception {
if (type == HANDLE)
if (type == HANDLE) {
return handles.get(op).getLong(select1,select2);
}
return resolve(position,off);
}
@ -126,14 +127,26 @@ public class ConstantTemplate implements Serializable {
@Override
public boolean equals(Object o) {
if (o.getClass() != ConstantTemplate.class) return false;
if (o.getClass() != ConstantTemplate.class) {
return false;
}
ConstantTemplate ct = (ConstantTemplate) o;
if (ct.hashCode() != hashCode) return false;
if (ct.type() != type) return false;
if (ct.hashCode() != hashCode) {
return false;
}
if (ct.type() != type) {
return false;
}
if (type == HANDLE) {
if (!ct.operand().equals(op)) return false;
if (ct.select1() != select1) return false;
if (ct.select2() != select2) return false;
if (!ct.operand().equals(op)) {
return false;
}
if (ct.select1() != select1) {
return false;
}
if (ct.select2() != select2) {
return false;
}
}
return true;

View file

@ -498,7 +498,7 @@ public abstract class PcodeEmit {
dyncache[2].size = incache[i].size;
AddressSpace spc = generatePointer(vn, dyncache[1]);
dyncache[0].space = const_space;
dyncache[0].offset = spc.getBaseSpaceID();
dyncache[0].offset = spc.getSpaceID();
dyncache[0].size = 4; // Size of spaceid
dump(startAddress, PcodeOp.LOAD, dyncache, 2, dyncache[2]);
numOps += 1;
@ -529,7 +529,7 @@ public abstract class PcodeEmit {
dyncache[2].size = outcache.size;
AddressSpace spc = generatePointer(outvn, dyncache[1]);
dyncache[0].space = const_space;
dyncache[0].offset = spc.getBaseSpaceID();
dyncache[0].offset = spc.getSpaceID();
dyncache[0].size = 4; // Size of spaceid;
dump(startAddress, PcodeOp.STORE, dyncache, 3, null);
numOps += 1;
@ -738,7 +738,7 @@ public abstract class PcodeEmit {
AddressSpace space = uniqueFactory.getAddressFactory().getAddressSpace(spaceId);
if (space.isOverlaySpace()) {
space = ((OverlayAddressSpace) space).getOverlayedSpace();
in[0].offset = space.getBaseSpaceID();
in[0].offset = space.getSpaceID();
}
}
for (int i = 0; i < isize; ++i) {

View file

@ -96,14 +96,16 @@ public class ConstTpl {
}
public boolean isConstSpace() {
if (type == SPACEID)
if (type == SPACEID) {
return (value_spaceid.getType() == AddressSpace.TYPE_CONSTANT);
}
return false;
}
public boolean isUniqueSpace() {
if (type == SPACEID)
if (type == SPACEID) {
return (value_spaceid.getType() == AddressSpace.TYPE_UNIQUE);
}
return false;
}
@ -140,32 +142,38 @@ public class ConstTpl {
case J_CURSPACE_SIZE:
return walker.getCurSpace().getPointerSize();
case J_CURSPACE:
return walker.getCurSpace().getBaseSpaceID();
return walker.getCurSpace().getSpaceID();
case HANDLE: {
FixedHandle hand = walker.getFixedHandle(handle_index);
switch (select) {
case V_SPACE:
if (hand.offset_space == null)
return hand.space.getBaseSpaceID();
return hand.temp_space.getBaseSpaceID();
if (hand.offset_space == null) {
return hand.space.getSpaceID();
}
return hand.temp_space.getSpaceID();
case V_OFFSET:
if (hand.offset_space == null)
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.getType() != AddressSpace.TYPE_CONSTANT) { // If we are not a constant
if (hand.offset_space == null)
{
return hand.offset_offset + (value_real & 0xffff); // Adjust offset by truncation amount
}
return hand.temp_offset + (value_real & 0xffff);
}
// If we are a constant, shift by the truncation amount
long val;
if (hand.offset_space == null)
if (hand.offset_space == null) {
val = hand.offset_offset;
else
}
else {
val = hand.temp_offset;
}
val >>= 8 * (value_real >> 16);
return val;
}
@ -175,7 +183,7 @@ public class ConstTpl {
case REAL:
return value_real;
case SPACEID:
return value_spaceid.getBaseSpaceID();
return value_spaceid.getSpaceID();
}
return 0; // Should never reach here
}
@ -188,8 +196,9 @@ public class ConstTpl {
FixedHandle hand = walker.getFixedHandle(handle_index);
switch (select) {
case V_SPACE:
if (hand.offset_space == null)
if (hand.offset_space == null) {
return hand.space;
}
return hand.temp_space;
default:
break;
@ -272,18 +281,22 @@ public class ConstTpl {
type = HANDLE;
handle_index = (short) SpecXmlUtils.decodeInt(el.getAttribute("val"));
String selstr = el.getAttribute("s");
if (selstr.equals("space"))
if (selstr.equals("space")) {
select = V_SPACE;
else if (selstr.equals("offset"))
}
else if (selstr.equals("offset")) {
select = V_OFFSET;
else if (selstr.equals("size"))
}
else if (selstr.equals("size")) {
select = V_SIZE;
}
else if (selstr.equals("offset_plus")) {
select = V_OFFSET_PLUS;
value_real = SpecXmlUtils.decodeLong(el.getAttribute("plus"));
}
else
else {
throw new SleighException("Bad handle selector");
}
}
else if (typestr.equals("start")) {
type = J_START;
@ -317,8 +330,9 @@ public class ConstTpl {
else if (typestr.equals("flowdest_size")) {
type = J_FLOWDEST_SIZE;
}
else
else {
throw new SleighException("Bad xml for ConstTpl");
}
parser.end(el);
}

View file

@ -117,7 +117,7 @@ public class ProgramAddressFactory extends DefaultAddressFactory {
@Override
public Address getAddress(int spaceID, long offset) {
Address addr = super.getAddress(spaceID, offset);
if (addr == null && spaceID == stackSpace.getUniqueSpaceID()) {
if (addr == null && spaceID == stackSpace.getSpaceID()) {
return stackSpace.getAddress(offset);
}
return addr;

View file

@ -282,9 +282,13 @@ abstract class AbstractAddressSpace implements AddressSpace {
public long subtract(Address addr1, Address addr2) {
AddressSpace space1 = addr1.getAddressSpace();
AddressSpace space2 = addr2.getAddressSpace();
if (!addr1.getAddressSpace().equals(addr2.getAddressSpace())) {
if (!space1.equals(space2)) {
// if the two spaces are actually based in the same space, calculate the offset
if (space1.getBaseSpaceID() != space2.getBaseSpaceID()) {
int base1 = space1.isOverlaySpace() ? ((OverlayAddressSpace) space1).getBaseSpaceID()
: space1.getSpaceID();
int base2 = space2.isOverlaySpace() ? ((OverlayAddressSpace) space2).getBaseSpaceID()
: space2.getSpaceID();
if (base1 != base2) {
throw new IllegalArgumentException("Address are in different spaces " +
addr1.getAddressSpace().getName() + " != " + addr2.getAddressSpace().getName());
}
@ -478,8 +482,9 @@ abstract class AbstractAddressSpace implements AddressSpace {
return minAddress;
}
private int compareToOverlaySpace(AddressSpace overlaySpace) {
int baseCompare = getBaseSpaceID() - overlaySpace.getBaseSpaceID();
private int compareAsOverlaySpace(AddressSpace overlaySpace) {
int baseCompare = ((OverlayAddressSpace) this).getBaseSpaceID() -
((OverlayAddressSpace) overlaySpace).getBaseSpaceID();
if (baseCompare == 0) {
long otherMinOffset = overlaySpace.getMinAddress().getOffset();
if (minOffset == otherMinOffset) {
@ -498,7 +503,7 @@ abstract class AbstractAddressSpace implements AddressSpace {
if (isOverlaySpace()) {
if (space.isOverlaySpace()) {
// Both spaces are overlay spaces
return compareToOverlaySpace(space);
return compareAsOverlaySpace(space);
}
// I'm an overlay, other space is NOT an overlay
return 1;
@ -519,7 +524,7 @@ abstract class AbstractAddressSpace implements AddressSpace {
// source within a list/set of addresses from a second source.
return 0;
}
int c = getBaseSpaceID() - space.getBaseSpaceID();
int c = getSpaceID() - space.getSpaceID();
if (c == 0) {
c = getClass().getName().compareTo(space.getClass().getName());
}
@ -557,12 +562,7 @@ abstract class AbstractAddressSpace implements AddressSpace {
}
@Override
public int getBaseSpaceID() {
return spaceID;
}
@Override
public int getUniqueSpaceID() {
public int getSpaceID() {
return spaceID;
}

View file

@ -111,9 +111,7 @@ public interface AddressSpace extends Comparable<AddressSpace> {
*
* @return space ID
*/
int getBaseSpaceID();
int getUniqueSpaceID();
int getSpaceID();
/** Returns the number of bits that are used to form the address. Thus
* the maximum offset for this address space will be 2^size-1.

View file

@ -71,7 +71,7 @@ public class DefaultAddressFactory implements AddressFactory {
this.defaultSpace = space;
}
spaceNameTable.put(space.getName(), space);
spaceLookup.put(space.getUniqueSpaceID(), space);
spaceLookup.put(space.getSpaceID(), space);
if (space.getType() == AddressSpace.TYPE_CONSTANT) {
constantSpace = space;
}
@ -270,7 +270,7 @@ public class DefaultAddressFactory implements AddressFactory {
@Override
public long getIndex(Address addr) {
AddressSpace space = addr.getAddressSpace();
int id = space.getUniqueSpaceID();
int id = space.getSpaceID();
if (spaceLookup.get(id) == null) {
spaceLookup.put(id, space);
}
@ -385,7 +385,7 @@ public class DefaultAddressFactory implements AddressFactory {
}
spaces.add(space);
spaceNameTable.put(space.getName(), space);
spaceLookup.put(space.getUniqueSpaceID(), space);
spaceLookup.put(space.getSpaceID(), space);
if (space.isMemorySpace()) {
memoryAddressSet.addRange(space.getMinAddress(), space.getMaxAddress());
@ -415,7 +415,7 @@ public class DefaultAddressFactory implements AddressFactory {
if (deletedSpace != null) {
spaces.remove(deletedSpace);
spaceNameTable.remove(deletedSpace.getName());
spaceLookup.remove(deletedSpace.getUniqueSpaceID());
spaceLookup.remove(deletedSpace.getSpaceID());
if (deletedSpace.getType() == AddressSpace.TYPE_RAM ||
deletedSpace.getType() == AddressSpace.TYPE_CODE) {
memoryAddressSet.deleteRange(deletedSpace.getMinAddress(),

View file

@ -96,8 +96,12 @@ public class OverlayAddressSpace extends AbstractAddressSpace {
public long subtract(Address addr1, Address addr2) {
AddressSpace space1 = addr1.getAddressSpace();
AddressSpace space2 = addr2.getAddressSpace();
if (space1.equals(this)) space1 = originalSpace;
if (space2.equals(this)) space2 = originalSpace;
if (space1.equals(this)) {
space1 = originalSpace;
}
if (space2.equals(this)) {
space2 = originalSpace;
}
if (!space1.equals(space2)) {
throw new IllegalArgumentException("Address are in different spaces " +
addr1.getAddressSpace().getName() + " != " + addr2.getAddressSpace().getName());
@ -204,9 +208,11 @@ public class OverlayAddressSpace extends AbstractAddressSpace {
return new GenericAddress(originalSpace, addr.getOffset());
}
@Override
/**
* @return the ID of the address space underlying this space
*/
public int getBaseSpaceID() {
return originalSpace.getBaseSpaceID();
return originalSpace.getSpaceID();
}
@Override

View file

@ -50,7 +50,7 @@ public class Varnode {
public Varnode(Address a, int sz) {
address = a;
AddressSpace space = address.getAddressSpace();
spaceID = space.getBaseSpaceID();
spaceID = space.getSpaceID();
size = sz;
offset = address.getOffset();
}
@ -127,7 +127,7 @@ public class Varnode {
* @return true if this varnode contains the specified address
*/
public boolean contains(Address address) {
if (spaceID != address.getAddressSpace().getUniqueSpaceID()) {
if (spaceID != address.getAddressSpace().getSpaceID()) {
return false;
}
if (isConstant() || isUnique() || isHash()) {
@ -193,7 +193,7 @@ public class Varnode {
}
for (AddressRange range : set.getAddressRanges()) {
Address minAddr = range.getMinAddress();
if (minAddr.getAddressSpace().getUniqueSpaceID() != spaceID) {
if (minAddr.getAddressSpace().getSpaceID() != spaceID) {
continue;
}
Address maxAddr = range.getMaxAddress();
@ -244,7 +244,7 @@ public class Varnode {
}
public boolean isHash() {
return spaceID == AddressSpace.HASH_SPACE.getUniqueSpaceID();
return spaceID == AddressSpace.HASH_SPACE.getSpaceID();
}
/**
@ -588,7 +588,7 @@ public class Varnode {
String localName = el.getName();
if (localName.equals("spaceid")) {
AddressSpace spc = addrFactory.getAddressSpace(el.getAttribute("name"));
int spaceid = spc.getBaseSpaceID();
int spaceid = spc.getSpaceID();
spc = addrFactory.getConstantSpace();
return spc.getAddress(spaceid);
}
@ -613,7 +613,7 @@ public class Varnode {
AddressFactory addrFactory) {
if (localName.equals("spaceid")) {
AddressSpace spc = addrFactory.getAddressSpace(attr.getValue("name"));
int spaceid = spc.getBaseSpaceID();
int spaceid = spc.getSpaceID();
spc = addrFactory.getConstantSpace();
return spc.getAddress(spaceid);
}
@ -658,7 +658,7 @@ public class Varnode {
if (nameend >= 0) {
AddressSpace spc =
addrfactory.getAddressSpace(addrstring.substring(attrstart, nameend));
int spaceid = spc.getBaseSpaceID();
int spaceid = spc.getSpaceID();
spc = addrfactory.getConstantSpace();
return spc.getAddress(spaceid);
}

View file

@ -550,7 +550,7 @@ public class RefTypeFactory {
}
}
else if (op.getOpcode() == PcodeOp.LOAD) {
if (memAddr.getAddressSpace().getUniqueSpaceID() == inputs[0].getOffset() &&
if (memAddr.getAddressSpace().getSpaceID() == inputs[0].getOffset() &&
(memOffset == inputs[1].getOffset() || inputs[1].equals(offsetVarnode))) {
if (refType != null && refType.isWrite()) {
return RefType.READ_WRITE;

View file

@ -300,16 +300,22 @@ public class SimpleDiffUtility {
Program otherProgram) {
AddressSpace otherSpace =
otherProgram.getAddressFactory().getAddressSpace(addrSpace.getName());
if (otherSpace != null && otherSpace.getType() == addrSpace.getType() &&
otherSpace.getBaseSpaceID() == addrSpace.getBaseSpaceID()) {
if (otherSpace.isOverlaySpace()) {
long addrOffset = addrSpace.getMinAddress().getOffset();
long otherOffset = otherSpace.getMinAddress().getOffset();
if (addrOffset != otherOffset) {
return null; // Overlays didn't begin at same address.
if (otherSpace != null && otherSpace.getType() == addrSpace.getType()) {
int id = addrSpace.isOverlaySpace() ? ((OverlayAddressSpace) addrSpace).getBaseSpaceID()
: addrSpace.getSpaceID();
int otherid =
otherSpace.isOverlaySpace() ? ((OverlayAddressSpace) otherSpace).getBaseSpaceID()
: otherSpace.getSpaceID();
if (id == otherid) {
if (otherSpace.isOverlaySpace()) {
long addrOffset = addrSpace.getMinAddress().getOffset();
long otherOffset = otherSpace.getMinAddress().getOffset();
if (addrOffset != otherOffset) {
return null; // Overlays didn't begin at same address.
}
}
return otherSpace;
}
return otherSpace;
}
return null;
}

View file

@ -111,9 +111,9 @@ public class InjectPayloadJavaParameters implements InjectPayload {
}
AddressSpace paramSpace = program.getAddressFactory().getAddressSpace("parameterSpace");
int paramSpaceID = paramSpace.getBaseSpaceID();
int paramSpaceID = paramSpace.getSpaceID();
AddressSpace lva = program.getAddressFactory().getAddressSpace("localVariableArray");
int lvaID = lva.getBaseSpaceID();
int lvaID = lva.getSpaceID();
AddressSpace constant = program.getAddressFactory().getConstantSpace();
PcodeOp[] resOps = new PcodeOp[1 + 3*numOps];

View file

@ -318,7 +318,7 @@ public class MipsAddressAnalyzer extends ConstantPropagationAnalyzer {
}
}
symEval.makeReference(context, lastSetInstr, -1,
instr.getMinAddress().getAddressSpace().getBaseSpaceID(),
instr.getMinAddress().getAddressSpace().getSpaceID(),
unsignedValue, 1, RefType.DATA, PcodeOp.UNIMPLEMENTED, true,
monitor);
if (localGPAssumptionValue == null) {