ghidra.app.cmd.register.SetRegisterCmd Java Examples

The following examples show how to use ghidra.app.cmd.register.SetRegisterCmd. 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: RegisterEvent.java    From gdbghidra with MIT License 6 votes vote down vote up
public static void handleEvent(RegisterEvent registerEvent, Program currentProgram, ProgramPlugin plugin, ProgramLocation currentLocation) {
	var register = currentProgram.getRegister(registerEvent.getName());
	if(register == null) {
		register = currentProgram.getRegister(registerEvent.getName().toUpperCase());
		if(register == null) {
			System.err.println("[GDBGHIDRA] Error unknown register: "+registerEvent.getName()+"\n");
			return;
		}
	}
	var address = currentLocation.getAddress();
	var cmd = new CompoundCmd("Set Register Values");
	var regCmd = new SetRegisterCmd(
			register, 
			address, 
			address,
			registerEvent.getValue());
	cmd.add(regCmd);
	plugin.getTool().execute(cmd, currentProgram);
}
 
Example #2
Source File: JavaLoader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void setAlignmentInfo(Program program, AddressSet set) {
	AddressIterator addressIterator = set.getAddresses(true);
	int alignmentValue = 3;
	while (addressIterator.hasNext()) {
		Address address = addressIterator.next();
		SetRegisterCmd cmd = new SetRegisterCmd(alignmentReg, address, address,
			BigInteger.valueOf(alignmentValue));
		cmd.applyTo(program);
		if (alignmentValue == 0) {
			alignmentValue = 3;
		}
		else {
			alignmentValue--;
		}
	}
}
 
Example #3
Source File: RegisterValuesPanel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void deleteSelectedRanges() {
	CompoundCmd cmd = new CompoundCmd("Delete Register Value Ranges");
	int[] rows = table.getSelectedRows();
	boolean containsDefaultValues = false;
	for (int row : rows) {
		RegisterValueRange rvr = model.values.get(row);
		if (rvr.isDefault()) {
			containsDefaultValues = true;
		}
		cmd.add(new SetRegisterCmd(selectedRegister, rvr.getStartAddress(), rvr.getEndAddress(),
			null));
	}
	if (containsDefaultValues) {
		int result = OptionDialog.showOptionDialog(table, "Warning",
			"The selected ranges " +
				"contain default values that can't be deleted.\n  Do you want to continue?",
			"Yes", OptionDialog.WARNING_MESSAGE);
		if (result == OptionDialog.CANCEL_OPTION) {
			return;
		}
	}
	if (cmd.size() > 0) {
		tool.execute(cmd, currentProgram);
	}
}
 
Example #4
Source File: RegisterPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void deleteRegisterValueRange(ListingActionContext context) {
	RegisterTransitionFieldLocation location =
		(RegisterTransitionFieldLocation) context.getLocation();
	Register register = location.getRegister();
	Address addr = location.getAddress();
	ProgramContext programContext = context.getProgram().getProgramContext();
	AddressRangeIterator it = programContext.getRegisterValueAddressRanges(register);
	while (it.hasNext()) {
		AddressRange range = it.next();
		if (range.contains(addr)) {
			Command cmd = new SetRegisterCmd(register, range.getMinAddress(),
				range.getMaxAddress(), null);
			if (!tool.execute(cmd, context.getProgram())) {
				Msg.showError(this, tool.getToolFrame(), "Register Context Error",
					cmd.getStatusMsg());
			}
			return;
		}
	}
}
 
Example #5
Source File: RegisterPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void applyRegisterValues(Program program, Register register, BigInteger value,
		AddressSetView addressSet) {
	if (program == null || addressSet.isEmpty()) {
		return;
	}

	CompoundCmd cmd = new CompoundCmd("Set Register Values");
	for (AddressRange range : addressSet) {
		SetRegisterCmd regCmd =
			new SetRegisterCmd(register, range.getMinAddress(), range.getMaxAddress(), value);
		cmd.add(regCmd);
	}
	if (!tool.execute(cmd, program)) {
		Msg.showError(this, tool.getToolFrame(), "Register Context Error", cmd.getStatusMsg());
	}
}
 
Example #6
Source File: RegisterValuesPanel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void updateValue(Address start, Address end, Address newStart, Address newEnd,
		BigInteger newValue) {
	CompoundCmd cmd = new CompoundCmd("Update Register Range");
	Command cmd1 = new SetRegisterCmd(selectedRegister, start, end, null);
	Command cmd2 = new SetRegisterCmd(selectedRegister, newStart, newEnd, newValue);
	cmd.add(cmd1);
	cmd.add(cmd2);
	tool.execute(cmd, currentProgram);

}
 
Example #7
Source File: RegisterPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected void deleteRegisterValueAtFunction(ListingActionContext context) {
	RegisterFieldLocation location = (RegisterFieldLocation) context.getLocation();
	Register register = location.getRegister();
	Address addr = location.getAddress();
	Command cmd = new SetRegisterCmd(register, addr, addr, null);
	if (!tool.execute(cmd, context.getProgram())) {
		Msg.showError(this, tool.getToolFrame(), "Register Context Error", cmd.getStatusMsg());
	}
}
 
Example #8
Source File: ObjectiveC1_Utilities.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * If needed, sets the TMode bit at the specified address.
 */
public static void setThumbBit(ObjectiveC1_State state, Address address) {
	if (state.thumbCodeLocations.contains(address)) {
		Register tmodeRegister = state.program.getLanguage().getRegister("TMode");
		if (tmodeRegister != null) {
			Command c =
				new SetRegisterCmd(tmodeRegister, address, address, BigInteger.valueOf(1));
			c.applyTo(state.program);
		}
	}
}
 
Example #9
Source File: ClearTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearRegisters() throws Exception {

	assertTrue(program.getListing().getFunctions(true).hasNext());

	assertTrue(cb.goToField(addr("0x10022cc"), "Bytes", 0, 4));
	ProgramContext context = program.getProgramContext();
	Register ax = context.getRegister("ax");
	SetRegisterCmd cmd =
		new SetRegisterCmd(ax, addr("0x10022cc"), addr("0x10022ce"), BigInteger.valueOf(5));
	applyCmd(program, cmd);

	assertTrue(context.hasValueOverRange(ax, BigInteger.valueOf(5),
		new AddressSet(addr("0x10022cc"))));

	performAction(clearWithOptionsAction, cb.getProvider(), false);
	ClearDialog cd = waitForDialogComponent(ClearDialog.class);
	turnOffOption(COMMENTS_CHECK_BOX_TEXT, cd);
	turnOffOption("Properties", cd);
	turnOffOption("Bookmarks", cd);
	turnOffOption("Functions", cd);
	turnOffOption("Equates", cd);
	turnOffOption("Code", cd);
	turnOffOption("Symbols", cd);

	okOnClearDialog();

	assertTrue(!context.hasValueOverRange(ax, BigInteger.valueOf(5),
		new AddressSet(addr("0x10022cc"))));
	undo(program);
	assertTrue(context.hasValueOverRange(ax, BigInteger.valueOf(5),
		new AddressSet(addr("0x10022cc"))));
}
 
Example #10
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 #11
Source File: RegisterPluginScreenShots.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void set(String registerName, Address start, Address end, int value) {
	Register register = program.getRegister(registerName);
	SetRegisterCmd regCmd = new SetRegisterCmd(register, start, end, BigInteger.valueOf(value));
	tool.execute(regCmd, program);
	waitForBusyTool(tool);
}