Java Code Examples for ghidra.program.model.address.AddressSpace#TYPE_CONSTANT

The following examples show how to use ghidra.program.model.address.AddressSpace#TYPE_CONSTANT . 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: HandleTpl.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public void fix(FixedHandle hand, ParserWalker walker) {
	if (ptrspace.getType() == ConstTpl.REAL) {
		// The export is unstarred, but this doesn't mean
		// the varnode being exported isn't dynamic
		space.fillinSpace(hand, walker);
		hand.size = (int) size.fix(walker);
		ptroffset.fillinOffset(hand, walker);
	}
	else {
		hand.space = space.fixSpace(walker);
		hand.size = (int) size.fix(walker);
		hand.offset_offset = ptroffset.fix(walker);
		hand.offset_space = ptrspace.fixSpace(walker);
		if (hand.offset_space.getType() == AddressSpace.TYPE_CONSTANT) {
			hand.offset_space = null;	// Could have been, but wasn't
			hand.offset_offset *= hand.space.getAddressableUnitSize();
			hand.offset_offset = hand.space.truncateOffset(hand.offset_offset);
		}
		else {
			hand.offset_size = (int) ptrsize.fix(walker);
			hand.temp_space = temp_space.fixSpace(walker);
			hand.temp_offset = temp_offset.fix(walker);
		}
	}
}
 
Example 2
Source File: HandleTpl.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public void fixPrintPiece(FixedHandle hand, ParserWalker walker, int handleIndex) {
	if (!hand.fixable)
		return;
	if (hand.space.getType() != AddressSpace.TYPE_CONSTANT) {
		hand.fixable = false;
		return;
	}
	if (space.getType() == ConstTpl.SPACEID) {
		if (space.isUniqueSpace()) {
			hand.fixable = false;
			return;
		}
	}
	if (ptroffset.getType() == ConstTpl.HANDLE && ptroffset.getHandleIndex() == handleIndex) {
		hand.space = space.fixSpace(walker);
		hand.offset_offset = hand.space.getAddressableUnitSize() * hand.offset_offset;
		hand.size = (int) size.fix(walker);
	}
	else {
		hand.fixable = false;
	}
}
 
Example 3
Source File: SleighDebugLogger.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void dumpFinalGlobalSets() throws MemoryAccessException {
	SleighParserContext protoContext = prototype.getParserContext(buf, context);
	ParserWalker walker = new ParserWalker(protoContext);
	Iterator<ContextSet> contextCommits = protoContext.getContextCommits();
	while (contextCommits.hasNext()) {
		ContextSet set = contextCommits.next();
		walker.subTreeState(set.point);
		FixedHandle hand = new FixedHandle();
		// FIXME: review after Chris has checked the SleighParserContext.applyCommits method
		set.sym.getFixedHandle(hand, walker);
		// TODO: this is a hack. Addresses that are computed end up in the
		// constant space and we must factor-in the wordsize.
		long offset = hand.offset_offset;
		AddressSpace curSpace = buf.getAddress().getAddressSpace();
		if (hand.space.getType() == AddressSpace.TYPE_CONSTANT) {
			offset = offset * curSpace.getAddressableUnitSize();
		}
		Address address = curSpace.getAddress(offset);
		dumpGlobalSet(set.point, set.num, set.mask, set.value, address);
	}
}
 
Example 4
Source File: FixedHandle.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public Varnode getStaticVarnode() {
	if (space == null) {
		return null;
	}
	if (offset_space != null && offset_space.getType() != AddressSpace.TYPE_CONSTANT) {
		return null;
	}
	return new Varnode(space.getAddress(offset_offset), size);
}
 
Example 5
Source File: SleighDebugLogger.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Dump fixed handle associated with a constructor symbol to the log.
 * NOTE: Method has no affect unless constructed with VERBOSE logging mode.
 * @param name
 * @param definingSymbol
 * @param pos
 * @param subState
 * @param language
 * @throws MemoryAccessException
 */
void dumpFixedHandle(String name, TripleSymbol definingSymbol, ParserWalker walker,
		Language language) throws MemoryAccessException {

	if (!isVerboseEnabled()) {
		return;
	}

	append(name);
	append(": ");

	FixedHandle hand = new FixedHandle();
	definingSymbol.getFixedHandle(hand, walker);

	if (hand.space.getType() == AddressSpace.TYPE_CONSTANT) {
		append("constant ");
		try {
			Scalar s = new Scalar(8 * hand.size, hand.offset_offset);
			append(s.toString(16, false, false, "0x", ""));
		}
		catch (Exception e) {
			append("Bad Value: " + e.getMessage());
		}
	}
	else {
		Address addr = hand.space.getAddress(hand.offset_offset);
		Register reg = language.getRegister(addr, hand.size);
		if (reg != null) {
			append("register ");
			append(reg.getName());
		}
		else {
			append("memory ");
			append(addr.toString(true));
		}
	}
	append(" (size:");
	append(Integer.toString(hand.size));
	append(")\n");
}
 
Example 6
Source File: ConstTpl.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public boolean isConstSpace() {
	if (type == SPACEID)
		return (value_spaceid.getType() == AddressSpace.TYPE_CONSTANT);
	return false;
}
 
Example 7
Source File: ConstTpl.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public long fix(ParserWalker walker) {
	switch (type) {
		case J_START:
			return walker.getAddr().getOffset();
		case J_NEXT:
			return walker.getNaddr().getOffset();
		case J_FLOWREF:
			return walker.getFlowRefAddr().getOffset();
		case J_FLOWREF_SIZE:
			return walker.getFlowRefAddr().getAddressSpace().getPointerSize();
		case J_FLOWDEST:
			return walker.getFlowDestAddr().getOffset();
		case J_FLOWDEST_SIZE:
			return walker.getFlowDestAddr().getAddressSpace().getPointerSize();
		case J_CURSPACE_SIZE:
			return walker.getCurSpace().getPointerSize();
		case J_CURSPACE:
			return walker.getCurSpace().getBaseSpaceID();
		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();
				case V_OFFSET:
					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)
						val = hand.offset_offset;
					else
						val = hand.temp_offset;
					val >>= 8 * (value_real >> 16);
					return val;
			}
			break;
		}
		case J_RELATIVE:
		case REAL:
			return value_real;
		case SPACEID:
			return value_spaceid.getBaseSpaceID();
	}
	return 0;			// Should never reach here
}
 
Example 8
Source File: Handle.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public boolean isConstant() {
	int type = AddressSpace.ID_TYPE_MASK & spaceID;
	return (type == AddressSpace.TYPE_CONSTANT);
}