private static void copyByteRange(Memory toMem, Memory fromMem, AddressRange range)
			throws MemoryAccessException {

// TODO: Addresses from one program cannot be used with another program (e.g., overlays)
// TODO: Should be using AddressTranslator (see DiffUtility.getCompatibleAddressRange)
// TODO: Method relies too heavily on caller limiting range to valid initialized memory in both programs

		// Copy the bytes for this range
		int length = 0;
		Address writeAddress = range.getMinAddress();
		for (long len = range.getLength(); len > 0; len -= length) {
			length = (int) Math.min(len, Integer.MAX_VALUE);
			byte[] srcBytes = new byte[length];

			// NOTE: problems will arise if srcLen != length
			int srcLen = fromMem.getBytes(writeAddress, srcBytes);
			byte[] destBytes = new byte[srcLen];
			if (toMem.getBytes(writeAddress, destBytes) != srcLen ||
				!Arrays.equals(destBytes, 0, srcLen, srcBytes, 0, srcLen)) {
				// only copy bytes if they differ
				toMem.setBytes(writeAddress, srcBytes, 0, srcLen);
			}
			if (len > length) {
				writeAddress = writeAddress.add(length);
			}
		}
	}
Copies the bytes to one program memory from another for the specified 
address range.
@param toMem program memory that the bytes are copied to.
@param fromMem program memory the bytes are copied from.
@param range the address range to be copied.
The addresses in this range are derived from the program associated with the "to memory".

@throws MemoryAccessException if bytes can't be copied.
Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramMemoryUtil.java