Java Code Examples for ghidra.program.model.symbol.RefType#UNCONDITIONAL_CALL

The following examples show how to use ghidra.program.model.symbol.RefType#UNCONDITIONAL_CALL . 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: LabelFieldFactoryTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void createOffcutFunctionReference(Function function, Address fromAddress) {

		Address entryPoint = function.getEntryPoint();
		Address oneByteOff = entryPoint.add(1);

		AddMemRefCmd addRefCmd = new AddMemRefCmd(fromAddress, oneByteOff,
			RefType.UNCONDITIONAL_CALL, SourceType.ANALYSIS, 0);

		RemoveAllReferencesCmd removeRefsCmd = new RemoveAllReferencesCmd(fromAddress);

		int ID = program.startTransaction("Test - Create Reference");
		try {
			removeRefsCmd.applyTo(program);
			addRefCmd.applyTo(program);
		}
		finally {
			program.endTransaction(ID, true);
		}

		program.flushEvents();
		waitForPostedSwingRunnables();
	}
 
Example 2
Source File: OperandFieldFactoryTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void createOffcutFunctionReference(Function function, Address fromAddress) {

		Address entryPoint = function.getEntryPoint();
		Address oneByteOff = entryPoint.add(1);

		AddMemRefCmd addRefCmd = new AddMemRefCmd(fromAddress, oneByteOff,
			RefType.UNCONDITIONAL_CALL, SourceType.ANALYSIS, 0);

		RemoveAllReferencesCmd removeRefsCmd = new RemoveAllReferencesCmd(fromAddress);

		int ID = program.startTransaction("Test - Create Reference");
		try {
			removeRefsCmd.applyTo(program);
			addRefCmd.applyTo(program);
		}
		finally {
			program.endTransaction(ID, true);
		}

		program.flushEvents();
		waitForPostedSwingRunnables();
	}
 
Example 3
Source File: ConstructorInfo.java    From ghidra with Apache License 2.0 5 votes vote down vote up
FlowType getFlowType() {
	switch (flowFlags) {					// Convert flags to a standard flowtype
		case 0:
		case BRANCH_TO_END:
			return RefType.FALL_THROUGH;
		case CALL:
			return RefType.UNCONDITIONAL_CALL;
		case CALL | BRANCH_TO_END:
			return RefType.CONDITIONAL_CALL;			// This could be wrong but doesn't matter much
		case CALL_INDIRECT:
			return RefType.COMPUTED_CALL;
		case CALL_INDIRECT | BRANCH_TO_END:			// This could be COMPUTED_CONDITIONAL?
			return RefType.COMPUTED_CALL;
		case BRANCH_INDIRECT | NO_FALLTHRU:
			return RefType.COMPUTED_JUMP;
		case BRANCH_INDIRECT | NO_FALLTHRU | BRANCH_TO_END:
			// This should be COMPUTED_CONDITONAL_JUMP but this doesn't exist
			// so we make it a fall thru so the disassembler can continue the flow
			return RefType.FALL_THROUGH;
		case RETURN | NO_FALLTHRU:
			return RefType.TERMINATOR;
		case RETURN | NO_FALLTHRU | BRANCH_TO_END:
			return RefType.CONDITIONAL_TERMINATOR;
		case JUMPOUT:
			return RefType.CONDITIONAL_JUMP;
		case JUMPOUT | NO_FALLTHRU:
			return RefType.UNCONDITIONAL_JUMP;
		case JUMPOUT | NO_FALLTHRU | BRANCH_TO_END:
			return RefType.CONDITIONAL_JUMP;
		case NO_FALLTHRU:
			return RefType.TERMINATOR;
		case BRANCH_TO_END | JUMPOUT:
			return RefType.CONDITIONAL_JUMP;
		case NO_FALLTHRU | BRANCH_TO_END:
			return RefType.FALL_THROUGH;
		default:
			break;
	}
	return RefType.INVALID;
}
 
Example 4
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
FlowType[] followOnlyComputedCalls() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.CONDITIONAL_CALL, RefType.UNCONDITIONAL_CALL,
			RefType.COMPUTED_JUMP, RefType.CONDITIONAL_JUMP, RefType.UNCONDITIONAL_JUMP,
			RefType.INDIRECTION };
	return flowsNotToFollow;
}
 
Example 5
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
FlowType[] followOnlyConditionalCalls() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.COMPUTED_CALL, RefType.UNCONDITIONAL_CALL,
			RefType.COMPUTED_JUMP, RefType.CONDITIONAL_JUMP, RefType.UNCONDITIONAL_JUMP,
			RefType.INDIRECTION };
	return flowsNotToFollow;
}
 
Example 6
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
FlowType[] followOnlyComputedJumps() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.COMPUTED_CALL, RefType.CONDITIONAL_CALL,
			RefType.UNCONDITIONAL_CALL, RefType.CONDITIONAL_JUMP, RefType.UNCONDITIONAL_JUMP,
			RefType.INDIRECTION };
	return flowsNotToFollow;
}
 
Example 7
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
FlowType[] followOnlyConditionalJumps() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.COMPUTED_CALL, RefType.CONDITIONAL_CALL,
			RefType.UNCONDITIONAL_CALL, RefType.COMPUTED_JUMP, RefType.UNCONDITIONAL_JUMP,
			RefType.INDIRECTION };
	return flowsNotToFollow;
}
 
Example 8
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
FlowType[] followOnlyUnconditionalJumps() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.COMPUTED_CALL, RefType.CONDITIONAL_CALL,
			RefType.UNCONDITIONAL_CALL, RefType.COMPUTED_JUMP, RefType.CONDITIONAL_JUMP,
			RefType.INDIRECTION };
	return flowsNotToFollow;
}
 
Example 9
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
FlowType[] followOnlyPointers() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.COMPUTED_CALL, RefType.CONDITIONAL_CALL,
			RefType.UNCONDITIONAL_CALL, RefType.COMPUTED_JUMP, RefType.CONDITIONAL_JUMP,
			RefType.UNCONDITIONAL_JUMP };
	return flowsNotToFollow;
}
 
Example 10
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
FlowType[] followNoFlows() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.COMPUTED_CALL, RefType.CONDITIONAL_CALL,
			RefType.UNCONDITIONAL_CALL, RefType.COMPUTED_JUMP, RefType.CONDITIONAL_JUMP,
			RefType.UNCONDITIONAL_JUMP, RefType.INDIRECTION };
	return flowsNotToFollow;
}
 
Example 11
Source File: SleighInstructionPrototype.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private static FlowType convertFlowFlags(int flowFlags) {

		if ((flowFlags & LABEL) != 0)
			flowFlags |= BRANCH_TO_END;
		flowFlags &= ~(CROSSBUILD | LABEL);
		// NOTE: If prototype has cross-build, flow must be determined dynamically
		switch (flowFlags) { // Convert flags to a standard flowtype
			case 0:
			case BRANCH_TO_END:
				return RefType.FALL_THROUGH;
			case CALL:
				return RefType.UNCONDITIONAL_CALL;
			case CALL | NO_FALLTHRU | RETURN:
				return RefType.CALL_TERMINATOR;
			case CALL_INDIRECT | NO_FALLTHRU | RETURN:
				return RefType.COMPUTED_CALL_TERMINATOR;
			case CALL | BRANCH_TO_END:
				return RefType.CONDITIONAL_CALL; // This could be wrong but doesn't matter much
			case CALL | NO_FALLTHRU | JUMPOUT:
				return RefType.COMPUTED_JUMP;
			case CALL | NO_FALLTHRU | BRANCH_TO_END | RETURN:
				return RefType.UNCONDITIONAL_CALL;
			case CALL_INDIRECT:
				return RefType.COMPUTED_CALL;
			case BRANCH_INDIRECT | NO_FALLTHRU:
				return RefType.COMPUTED_JUMP;
			case BRANCH_INDIRECT | BRANCH_TO_END:
			case BRANCH_INDIRECT | NO_FALLTHRU | BRANCH_TO_END:
			case BRANCH_INDIRECT | JUMPOUT | NO_FALLTHRU | BRANCH_TO_END:
				return RefType.CONDITIONAL_COMPUTED_JUMP;
			case CALL_INDIRECT | BRANCH_TO_END:
			case CALL_INDIRECT | NO_FALLTHRU | BRANCH_TO_END:
				return RefType.CONDITIONAL_COMPUTED_CALL;
			case RETURN | NO_FALLTHRU:
				return RefType.TERMINATOR;
			case RETURN | BRANCH_TO_END:
			case RETURN | NO_FALLTHRU | BRANCH_TO_END:
				return RefType.CONDITIONAL_TERMINATOR;
			case JUMPOUT:
				return RefType.CONDITIONAL_JUMP;
			case JUMPOUT | NO_FALLTHRU:
				return RefType.UNCONDITIONAL_JUMP;
			case JUMPOUT | NO_FALLTHRU | BRANCH_TO_END:
				return RefType.CONDITIONAL_JUMP;
			case JUMPOUT | NO_FALLTHRU | RETURN:
				return RefType.JUMP_TERMINATOR;
			case JUMPOUT | NO_FALLTHRU | BRANCH_INDIRECT:
				return RefType.COMPUTED_JUMP; //added for tableswitch in jvm
			case BRANCH_INDIRECT | NO_FALLTHRU | RETURN:
				return RefType.JUMP_TERMINATOR;
			case NO_FALLTHRU:
				return RefType.TERMINATOR;
			case BRANCH_TO_END | JUMPOUT:
				return RefType.CONDITIONAL_JUMP;
			case NO_FALLTHRU | BRANCH_TO_END:
				return RefType.FALL_THROUGH;
			default:
				break;
		}
		return RefType.INVALID;
	}
 
Example 12
Source File: SleighInstructionPrototype.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private RefType getStaticOperandRefType(Varnode var, PcodeOp[] pcode) {
	if (var.isConstant()) {
		return RefType.DATA;
	}
	boolean isRead = false;
	boolean isWrite = false;
	for (PcodeOp element : pcode) {
		Varnode[] inputs = element.getInputs();
		switch (element.getOpcode()) {

			case PcodeOp.BRANCHIND:
			case PcodeOp.CALLIND:
			case PcodeOp.RETURN:
				if (inputs[0].equals(var)) {
					return RefType.INDIRECTION;
				}
				break;

			case PcodeOp.BRANCH:
				if (inputs[0].equals(var)) {
					return RefType.UNCONDITIONAL_JUMP;
				}
				break;

			case PcodeOp.CBRANCH:
				if (inputs[0].equals(var)) {
					return RefType.CONDITIONAL_JUMP;
				}
				break;

			case PcodeOp.CALL:
				if (inputs[0].equals(var)) {
					return RefType.UNCONDITIONAL_CALL;
				}
				break;

		}
		if (!var.isUnique()) {
			if (var.equals(element.getOutput())) {
				isWrite = true;
			}
			for (Varnode input : element.getInputs()) {
				if (var.equals(input)) {
					isRead = true;
				}
			}
		}
	}
	if (isRead && isWrite) {
		return RefType.READ_WRITE;
	}
	if (isRead) {
		return RefType.READ;
	}
	if (isWrite) {
		return RefType.WRITE;
	}
	return RefType.DATA;
}
 
Example 13
Source File: SleighInstructionPrototype.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private RefType getDynamicOperandRefType(FixedHandle hand, PcodeOp[] pcode) {
	Varnode offset = hand.getDynamicOffset();
	Varnode staticAddr = hand.getStaticVarnode();
	Varnode temp = hand.getDynamicTemp();
	boolean isRead = false;
	boolean isWrite = false;
	for (PcodeOp element : pcode) {
		Varnode[] inputs = element.getInputs();
		switch (element.getOpcode()) {

			case PcodeOp.LOAD:
				if (temp.equals(element.getOutput())) {
					isRead = true;
				}
				break;

			case PcodeOp.STORE:
				if (offset.equals(inputs[1]) && temp.equals(inputs[2])) {
					isWrite = true;
				}
				break;

			case PcodeOp.BRANCHIND:
			case PcodeOp.CALLIND:
			case PcodeOp.RETURN:
				if (inputs[0].equals(temp) || inputs[0].equals(staticAddr)) {
					return RefType.INDIRECTION;
				}
				break;

			case PcodeOp.BRANCH:
				if (inputs[0].equals(staticAddr)) {
					return RefType.UNCONDITIONAL_JUMP;
				}
				break;

			case PcodeOp.CBRANCH:
				if (inputs[0].equals(staticAddr)) {
					return RefType.CONDITIONAL_JUMP;
				}
				break;

			case PcodeOp.CALL:
				if (inputs[0].equals(staticAddr)) {
					return RefType.UNCONDITIONAL_CALL;
				}
				break;

		}
	}
	if (isRead && isWrite) {
		return RefType.READ_WRITE;
	}
	if (isRead) {
		return RefType.READ;
	}
	if (isWrite) {
		return RefType.WRITE;
	}
	return RefType.DATA;
}
 
Example 14
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
FlowType[] followConditionalAndUnconditionalJumps() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.COMPUTED_CALL, RefType.CONDITIONAL_CALL,
			RefType.UNCONDITIONAL_CALL, RefType.COMPUTED_JUMP, RefType.INDIRECTION };
	return flowsNotToFollow;
}
 
Example 15
Source File: AbstractFollowFlowTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
FlowType[] followAllJumps() {
	FlowType[] flowsNotToFollow =
		new FlowType[] { RefType.COMPUTED_CALL, RefType.CONDITIONAL_CALL,
			RefType.UNCONDITIONAL_CALL, RefType.INDIRECTION };
	return flowsNotToFollow;
}