protected void applyPatch(AddressRange rng, byte[] encoded)
			throws MemoryAccessException, CodeUnitInsertionException {
		Program program = getProgram();
		Address address = getAddress();
		Data data = getData();
		DataType dt = data.getBaseDataType();

		int oldLength = data.getLength();
		if (encoded.length != oldLength) {
			program.getListing().clearCodeUnits(address, rng.getMaxAddress(), false);
		}
		program.getMemory().setBytes(address, encoded);
		if (encoded.length != oldLength) {
			program.getListing().createData(address, dt, encoded.length);
		}
	}
A context menu action to patch data at the current address
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/assembler/PatchDataAction.java