def return_characters(data: bytes) -> bytes:
    """
    Characters that are used for telegram control are replaced with others
    so that it is easier to parse the message over the wire.
    Final character is never replaced.
    This function returns them to their original form.

    '\x1b\x0e' -> '\x0d'
    '\x1b\x1b' -> '\x1b'
    '\x1b\x0f' -'\x8d'

    It is important to only do one pass as the first pass can result in new combinations
    of escape sequence. Ex '\x1b\x1b\x0e' -> '\x1b\x0e'
    """
    in_data = bytearray(data)
    out = bytearray()
    while in_data:
        byte = in_data.pop(0)

        if byte == 0x1B:
            next_byte = in_data.pop(0)
            if next_byte == 0x0E:
                out.append(0x0D)
            elif next_byte == 0x1B:
                out.append(0x1B)
            elif next_byte == 0x0F:
                out.append(0x8D)
            else:
                out.append(byte)
                out.append(next_byte)
        else:
            out.append(byte)

    return bytes(out)