String determineFillerValue(Listing listing) {

		FunctionIterator iterator = listing.getFunctions(true);
		HashMap<String, Integer> patterns = new HashMap<>();

		while (iterator.hasNext()) {

			// Get undefined byte immediately following function
			Function function = iterator.next();
			Address maxAddress = function.getBody().getMaxAddress();
			Data undefinedData = listing.getUndefinedDataAt(maxAddress.next());
			if (undefinedData == null) {
				// No undefined filler bytes found, keep going to next function
				continue;
			}

			// Add filler to hash
			String pattern = ProgramUtilities.getByteCodeString(undefinedData);
			if ("??".equals(pattern)) {
				continue;
			}

			if (patterns.containsKey(pattern)) {
				int value = patterns.get(pattern);
				patterns.put(pattern, value + 1);
			}
			else {
				patterns.put(pattern, 1);
			}
		}

		if (patterns.isEmpty()) {
			return null;
		}

		// Decide that filler value is the one with the greatest count				
		String filler = getMostFrequentFillValue(patterns);

		return filler;
	}
This function tries to determine the fill value used by the current program.
The byte value occurring most is the winner.

@return filler value
@throws Exception
Ghidra/Features/Base/src/main/java/ghidra/app/analyzers/CondenseFillerBytesAnalyzer.java