Skip to content

Commit

Permalink
Merge remote-tracking branch
Browse files Browse the repository at this point in the history
'origin/GP-2094_ghidra1_RegisterValueStore_SQUASHED' (Closes NationalSecurityAgency#4259)
  • Loading branch information
ryanmkurtz committed Jun 7, 2022
2 parents d575bdb + 3bc1989 commit 04da5d1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,26 +624,9 @@ private InstructionDB addInstruction(Address address, Address endAddr,

Register contextReg = contextMgr.getBaseContextRegister();
if (contextReg != Register.NO_CONTEXT) {
try {
RegisterValue contextValue = context.getRegisterValue(contextReg);
Address start = address;
if (SystemUtilities.isEqual(contextValue,
contextMgr.getDefaultValue(contextReg, start))) {
contextMgr.setValue(contextReg, start, endAddr, null);
}
else {
// Do not save non-flowing context beyond
RegisterValue ctx = contextValue;
if (contextMgr.hasNonFlowingContext() && !start.equals(endAddr)) {
contextMgr.setRegisterValue(start, start, ctx);
ctx = contextMgr.getFlowValue(ctx);
start = start.next();
}
contextMgr.setRegisterValue(start, endAddr, ctx);
}
}
catch (ContextChangeException e) {
throw new AssertException(e.getMessage()); // Unexpected
RegisterValue contextValue = context.getRegisterValue(contextReg);
if (contextValue != null && contextValue.hasAnyValue()) {
saveInstructionContext(address, endAddr, contextValue);
}
}

Expand All @@ -665,6 +648,31 @@ private InstructionDB addInstruction(Address address, Address endAddr,
return inst;
}

private void saveInstructionContext(Address address, Address endAddr,
RegisterValue contextValue) {
try {
Address start = address;
Register contextReg = contextValue.getRegister();
if (SystemUtilities.isEqual(contextValue,
contextMgr.getDefaultValue(contextReg, start))) {
contextMgr.setValue(contextReg, start, endAddr, null);
}
else {
// Do not save non-flowing context beyond
RegisterValue ctx = contextValue;
if (contextMgr.hasNonFlowingContext() && !start.equals(endAddr)) {
contextMgr.setRegisterValue(start, start, ctx);
ctx = contextMgr.getFlowValue(ctx);
start = start.next();
}
contextMgr.setRegisterValue(start, endAddr, ctx);
}
}
catch (ContextChangeException e) {
throw new AssertException(e.getMessage()); // Unexpected
}
}

RegisterValue getOriginalPrototypeContext(InstructionPrototype prototype,
Register baseContextReg) throws NoValueException {
return protoMgr.getOriginalPrototypeContext(prototype, baseContextReg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ public void setValue(Address start, Address end, RegisterValue newValue) {
// Ensure that transaction is open to avoid delayed error condition
rangeMap.checkWritableState();
}
rangeWriteCacheValue = newValue;
rangeWriteCacheMin = start;
rangeWriteCacheMax = end;
synchronized (this) {
rangeWriteCacheValue = newValue;
rangeWriteCacheMin = start;
rangeWriteCacheMax = end;
}
return;
}

Expand Down Expand Up @@ -230,21 +232,27 @@ public void clearValue(Address start, Address end, Register register) {

/**
* Returns the RegisterValue (value and mask) associated with the given address.
* @param register register (base or child) for which context value should be returned
* @param address the address at which to get the RegisterValue.
* @return the RegisterValue
*/
public RegisterValue getValue(Register register, Address address) {

if (rangeWriteCacheValue != null && address.compareTo(rangeWriteCacheMin) >= 0 &&
address.compareTo(rangeWriteCacheMax) <= 0) {
return rangeWriteCacheValue.getRegisterValue(register);
}

RegisterValue value = null;
byte[] bytes = rangeMap.getValue(address);
if (bytes == null) {
return null;
if (bytes != null) {
value = new RegisterValue(register, bytes);
}

synchronized (this) {
if (rangeWriteCacheValue != null && address.compareTo(rangeWriteCacheMin) >= 0 &&
address.compareTo(rangeWriteCacheMax) <= 0) {
value = value != null ? value.combineValues(rangeWriteCacheValue)
: rangeWriteCacheValue;
return value.getRegisterValue(register);
}
}
return new RegisterValue(register, bytes);
return value;
}

/**
Expand Down

0 comments on commit 04da5d1

Please sign in to comment.