private boolean exportModifiedBytes(File file, FileBytes fileBytes, Program program,
			TaskMonitor monitor) throws IOException {

		// Write source program's file bytes to a temp file.
		// This is done to ensure a random access write failure doesn't corrupt a file the user 
		// might be overwriting.
		File tempFile = Application.createTempFile("ghidra_export_", null);
		try (OutputStream out = new FileOutputStream(tempFile, false)) {
			FileUtilities.copyStreamToStream(new FileBytesInputStream(fileBytes, true), out,
				monitor);
		}
		
		// Undo relocations in the temp file.
		// NOTE: not all relocations are file-backed, and some are only partially file-backed.
		try (RandomAccessFile fout = new RandomAccessFile(tempFile, "rw")) {
			Iterable<Relocation> relocs = () -> program.getRelocationTable().getRelocations();
			Memory memory = program.getMemory();
			for (Relocation reloc : relocs) {
				if (reloc.getStatus() != Relocation.Status.APPLIED &&
					reloc.getStatus() != Relocation.Status.APPLIED_OTHER) {
					continue;
				}
				Address addr = reloc.getAddress();
				AddressSourceInfo addrSourceInfo = memory.getAddressSourceInfo(addr);
				if (addrSourceInfo == null) {
					continue;
				}
				long offset = addrSourceInfo.getFileOffset();
				if (offset >= 0) {
					MemoryBlockSourceInfo memSourceInfo = addrSourceInfo.getMemoryBlockSourceInfo();
					byte[] bytes = reloc.getBytes();
					if (bytes != null) {
						int len = Math.min(bytes.length,
							(int) memSourceInfo.getMaxAddress().subtract(addr) + 1);
						fout.seek(offset);
						fout.write(bytes, 0, len);
					}
				}
			}
		}
		catch (Exception e) {
			if (!tempFile.delete()) {
				log.appendMsg("Failed to delete malformed file: " + tempFile);
			}
			log.appendException(e);
			return false;
		}
		
		// Success...it is safe to move the temp file to desired output file
		Path from = Paths.get(tempFile.toURI());
		Path to = Paths.get(file.toURI());
		Files.move(from, to, StandardCopyOption.REPLACE_EXISTING);
		return true;
	}
Exports the modified {@link FileBytes}

@param file The file to export to
@param fileBytes The {@link FileBytes} to export
@param program The program to export
@param monitor The monitor
@return True if the export succeeded; otherwise, false
@throws IOException If there was IO-related error during the export
Ghidra/Features/Base/src/main/java/ghidra/app/util/exporter/OriginalFileExporter.java