Java Code Examples for ghidra.program.model.address.Address#isVariableAddress()

The following examples show how to use ghidra.program.model.address.Address#isVariableAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OldVariableStorageManagerDB.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private OldVariableStorage getVariableStorage(Address variableAddr) throws IOException {
	if (!variableAddr.isVariableAddress()) {
		throw new IllegalArgumentException();
	}
	if (lastNamespaceCacheID != -1) {
		OldVariableStorage varStore = variableAddrLookupCache.get(variableAddr);
		if (varStore != null) {
			return varStore;
		}
	}
	Record rec = adapter.getRecord(variableAddr.getOffset());
	if (rec == null) {
		return null;
	}
	cacheNamespaceStorage(rec.getLongValue(OldVariableStorageDBAdapter.NAMESPACE_ID_COL));
	return variableAddrLookupCache.get(variableAddr);
}
 
Example 2
Source File: VariableStorageManagerDB.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private MyVariableStorage getMyVariableStorage(Address variableAddr) throws IOException {
	if (!variableAddr.isVariableAddress()) {
		throw new IllegalArgumentException("Address is not a VariableAddress: " + variableAddr);
	}
	MyVariableStorage varStore = cache.get(variableAddr.getOffset());
	if (varStore != null) {
		return varStore;
	}
	Record rec = adapter.getRecord(variableAddr.getOffset());
	if (rec == null) {
		return null;
	}
	varStore = new MyVariableStorage(cache, rec);
	cacheMap.put(varStore.getLongHash(), varStore);
	return varStore;
}
 
Example 3
Source File: VariableStorageManagerDB.java    From ghidra with Apache License 2.0 6 votes vote down vote up
List<Varnode> getStorageVarnodes(Address variableAddr) throws IOException {
	if (!variableAddr.isVariableAddress()) {
		throw new IllegalArgumentException();
	}
	Record rec = adapter.getRecord(variableAddr.getOffset());
	if (rec == null) {
		return null;
	}
	try {
		return VariableStorage.getVarnodes(program.getAddressFactory(),
			rec.getString(VariableStorageDBAdapter.STORAGE_COL));
	}
	catch (InvalidInputException e) {
		Msg.error(this, "Invalid variable storage: " + e.getMessage());
	}
	return null;
}
 
Example 4
Source File: AbstractReferenceHover.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected ProgramLocation getPreviewLocation(Program program, ProgramLocation pLoc,
		Address toAddress) {
	if (toAddress == null || pLoc == null) {
		return null;
	}

	ProgramLocation location = gotoHelper.getLocation(program, pLoc.getAddress(), toAddress);
	if (location != null) {
		return location;
	}

	if (pLoc instanceof OperandFieldLocation && toAddress.isVariableAddress()) {
		OperandFieldLocation opLoc = (OperandFieldLocation) pLoc;
		ReferenceManager refMgr = program.getReferenceManager();
		Reference ref =
			refMgr.getReference(opLoc.getAddress(), toAddress, opLoc.getOperandIndex());
		if (ref != null) {
			Variable var = refMgr.getReferencedVariable(ref);
			if (var != null) {
				return new VariableNameFieldLocation(program, var, 0);
			}
		}
	}
	return null;
}
 
Example 5
Source File: StackEditorProvider.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean inCurrentFunction(DomainObjectChangeRecord record) {
	if (!(record instanceof ProgramChangeRecord)) {
		return false;
	}

	if (function == null) {
		return false; // not sure if this can happen
	}

	ProgramChangeRecord programChangeRecord = (ProgramChangeRecord) record;
	Object affectedValue = programChangeRecord.getObject();
	if (affectedValue instanceof Symbol) {
		Address address = ((Symbol) affectedValue).getAddress();
		if (address.isVariableAddress()) {
			Symbol s = (Symbol) affectedValue;
			return s.getParentNamespace() == function;
		}
	}
	else if (affectedValue instanceof Function) {
		Address changedEntry = ((Function) affectedValue).getEntryPoint();
		if (changedEntry.equals(function.getEntryPoint())) {
			return true;
		}
	}

	return false;
}
 
Example 6
Source File: SymbolType.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isValidAddress(Program program, Address symbolAddress) {
	return symbolAddress.isVariableAddress();
}
 
Example 7
Source File: SymbolType.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isValidAddress(Program program, Address symbolAddress) {
	return symbolAddress.isVariableAddress();
}
 
Example 8
Source File: SymbolType.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isValidAddress(Program program, Address symbolAddress) {
	return symbolAddress.isVariableAddress();
}
 
Example 9
Source File: AddressBasedLocation.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private static String buildStringRepresentation(Program program, Address address,
		Reference reference, ShowBlockName showBlockName) {
	if (address == null) {
		return "<NULL>";
	}
	if (address.getAddressSpace().getType() == AddressSpace.TYPE_NONE) {
		return ""; // NO_ADDRESS or EXT_FROM_ADDRESS not rendered
	}
	if (address.isExternalAddress()) {
		return getExternalAddressRepresentation(program, address);
	}
	if (address.isVariableAddress()) {
		return getVariableAddressRepresentation();
	}
	if (address.isStackAddress()) {
		return getStackAddressRepresentation(address);
	}
	if (address.isConstantAddress()) {
		return getConstantAddressRepresentation(address);
	}
	if (address.isRegisterAddress()) {
		return getRegisterAddressRepresentation(program, address);
	}

	// Handle all other spaces (e.g., memory, other, overlays, hash, etc.)
	String addrStr;
	if (reference != null && reference.isOffsetReference()) {
		OffsetReference offsetRef = (OffsetReference) reference;
		long offset = offsetRef.getOffset();
		boolean neg = (offset < 0);
		Address baseAddr = offsetRef.getBaseAddress();
		addrStr = baseAddr.toString() + (neg ? "-" : "+") + "0x" +
			Long.toHexString(neg ? -offset : offset);
	}
	else if (reference != null && reference.isShiftedReference()) {
		// TODO: unsure of rendering which has never really been addressed
		// TODO: shifted references have never addressed concerns related to
		// addressable unit size
		ShiftedReference shiftedRef = (ShiftedReference) reference;
		StringBuilder buf = new StringBuilder();
		buf.append(address.toString());
		buf.append("(0x");
		buf.append(Long.toHexString(shiftedRef.getValue()));
		buf.append("<<");
		buf.append(Long.toString(shiftedRef.getShift()));
		buf.append(")");
		addrStr = buf.toString();
	}
	else {
		addrStr = address.toString();
	}

	if (showBlockName != ShowBlockName.NEVER) {
		Memory mem = program.getMemory();
		MemoryBlock toBlock = mem.getBlock(address);
		if (toBlock != null && showBlockName == ShowBlockName.NON_LOCAL && reference != null &&
			toBlock.equals(mem.getBlock(reference.getFromAddress()))) {
			toBlock = null;
		}
		if (toBlock != null) {
			addrStr = toBlock.getName() + "::" + addrStr;
		}
	}

	return addrStr;
}