public MemoryBlock createMemoryBlockFromMemoryState(String name, final Address start,
			final int length, boolean overlay, TaskMonitor monitor) throws MemoryConflictException,
			AddressOverflowException, CancelledException, LockException, DuplicateNameException {

		if (emulator.isExecuting()) {
			throw new IllegalStateException("Emulator must be paused to access memory state");
		}

		InputStream memStateStream = new InputStream() {

			private MemoryState memState = emulator.getMemState();

			private byte[] buffer = new byte[1024];
			private long nextBufferOffset = start.getOffset();
			private int bytesRemaining = length;
			private int bufferPos = buffer.length;

			@Override
			public int read() throws IOException {

				if (bytesRemaining <= 0) {
					return -1;
				}

				if (bufferPos == buffer.length) {
					int size = Math.min(buffer.length, bytesRemaining);
					memState.getChunk(buffer, start.getAddressSpace(), nextBufferOffset, size,
						false);
					nextBufferOffset += buffer.length;
					bufferPos = 0;
				}

				byte b = buffer[bufferPos++];
				--bytesRemaining;
				return b;
			}
		};

		MemoryBlock block;
		boolean success = false;
		int txId = program.startTransaction("Create Memory Block");
		try {
			block = program.getMemory()
					.createInitializedBlock(name, start, memStateStream, length,
						monitor, overlay);
			success = true;
		}
		finally {
			program.endTransaction(txId, success);
		}
		return block;
	}
Create a new initialized memory block using the current emulator memory state

@param name block name
@param start start address of the block
@param length the size of the block
@param overlay if true, the block will be created as an OVERLAY which means that a new
           overlay address space will be created and the block will have a starting address
           at the same offset as the given start address parameter, but in the new address
           space.
@param monitor
@return new memory block
@throws LockException if exclusive lock not in place (see haveLock())
@throws MemoryConflictException if the new block overlaps with a previous block
@throws AddressOverflowException if the start is beyond the address space
@throws CancelledException user cancelled operation
@throws DuplicateNameException
Ghidra/Framework/Emulation/src/main/java/ghidra/app/emulator/EmulatorHelper.java