ghidra.program.database.code.CodeManager Java Examples

The following examples show how to use ghidra.program.database.code.CodeManager. 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: MemoryMapDB.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void checkRangeForInstructions(Address start, Address end) throws MemoryAccessException {
	CodeManager codeManager = program.getCodeManager();
	Instruction instr = codeManager.getInstructionContaining(start);
	if (instr != null) {
		throw new MemoryAccessException(
			"Memory change conflicts with instruction at " + instr.getMinAddress());
	}
	if (!end.equals(start)) {
		instr = codeManager.getInstructionAfter(start);
		if (instr != null) {
			if (instr.getMinAddress().compareTo(end) <= 0) {
				throw new MemoryAccessException(
					"Memory change conflicts with instruction at " + instr.getMinAddress());
			}
		}
	}
}
 
Example #2
Source File: FixArrayStructReferencesScript.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected void run() throws Exception {
	Data data = getDataAt(currentAddress);
	if (data == null) {
		printerr("no data at " + currentAddress);
		return;
	}
	if (!data.isArray()) {
		printerr("data at " + currentAddress + " is not an array");
		return;
	}
	CodeManager codeManager = ((ProgramDB) currentProgram).getCodeManager();
	int numComponents = data.getNumComponents();
	monitor.setMessage("updating data references in array");
	monitor.initialize(numComponents);
	for (int ii = 0; ii < numComponents; ++ii) {
		if (monitor.isCancelled()) {
			printerr("cancelled");
			return;
		}
		monitor.incrementProgress(1);
		Data component = data.getComponent(ii);
		codeManager.updateDataReferences(component);
	}
}
 
Example #3
Source File: ProgramRegisterContextDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public ProgramRegisterContextDB(DBHandle dbHandle, ErrorHandler errHandler, Language lang,
		CompilerSpec compilerSpec, AddressMap addrMap, Lock lock, int openMode,
		CodeManager codeMgr, TaskMonitor monitor) throws VersionException, CancelledException {

	super(lang.getRegisters());
	this.addrMap = addrMap;
	this.dbHandle = dbHandle;
	this.errorHandler = errHandler;
	this.lock = lock;

	boolean oldContextDataExists = OldProgramContextDB.oldContextDataExists(dbHandle);
	boolean upgrade = oldContextDataExists && !contextDataExists(dbHandle);
	if (openMode != DBConstants.UPGRADE && upgrade) {
		throw new VersionException(true);
	}

	registerValueMap = new HashMap<>();
	defaultRegisterValueMap = new HashMap<>();
	initializeDefaultValues(lang, compilerSpec);
	initializedCurrentValues();

	if (upgrade) {
		upgrade(addrMap, lang, monitor);
	}

	if (openMode == DBConstants.UPGRADE && oldContextDataExists) {
		try {
			OldProgramContextDB.removeOldContextData(dbHandle);
		}
		catch (IOException e) {
			errorHandler.dbError(e);
		}
	}
}
 
Example #4
Source File: ProgramRegisterContextDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void checkContextWrite(Register reg, Address start, Address end)
		throws ContextChangeException {
	if (changing || !reg.getBaseRegister().equals(getBaseContextRegister())) {
		return;
	}
	CodeManager codeManager = program.getCodeManager();
	codeManager.checkContextWrite(start, end);
}
 
Example #5
Source File: GCAnalyzer.java    From Ghidra-GameCube-Loader with Apache License 2.0 5 votes vote down vote up
protected boolean setRegisterValue(String registerName, long defaultValue, Program program, CodeManager cm, AddressSpace addrSpace) {
    Register reg = program.getRegister(registerName);
    Address startAddr = cm.getInstructionAfter(addrSpace.getMinAddress()).getAddress();
    Address endAddr = cm.getInstructionBefore(addrSpace.getMaxAddress()).getAddress();
    Msg.debug(this, String.format("Writing regs to minAddr=0x%08X through maxAddr=0x%08X", startAddr.getUnsignedOffset(), endAddr.getUnsignedOffset()));
    BigInteger val = BigInteger.valueOf(defaultValue);
    var cmd1 = new SetRegisterCmd(reg, startAddr, endAddr, null);
    var cmd2 = new SetRegisterCmd(reg, startAddr, endAddr, val);
    var cmd = new CompoundCmd("Update Register Range");
    cmd.add(cmd1);
    cmd.add(cmd2);
    var result =  cmd.applyTo(program);
    Msg.debug(this, String.format("Reg value: %08X", program.getProgramContext().getRegisterValue(reg, startAddr).getUnsignedValue().longValue()));
    return result;
}
 
Example #6
Source File: ProgramDB.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the CodeManager
 */
public CodeManager getCodeManager() {
	return (CodeManager) managers[CODE_MGR];
}
 
Example #7
Source File: FunctionManagerDB.java    From ghidra with Apache License 2.0 4 votes vote down vote up
CodeManager getCodeManager() {
	return codeMgr;
}
 
Example #8
Source File: SymbolManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
CodeManager getCodeManager() {
	return program.getCodeManager();
}