Import from Base64?

0 votes
asked Dec 21, 2021 by hpux735 (120 points)
Hi!

Is it possible to import Base64 encoded binary directly into the editor?  If not, that would be an awesome feature!

1 Answer

0 votes
answered Feb 17, 2023 by andreas (3,420 points)

Thank you for the suggestion, this can be solved with a script. Simply but the code below in the script editor in a new script of type selection. This means that you first select the bytes that are part of the BASE64 string (in the hex editor), then run the script via the script menu.

~~~~~~~~~~~~~~~~~8<~~~~~~~~~~~~~~~~~
import base64

def processByteRange(byteView, byteArray, bytePos, byteLength):
    # this method processes a sequence of bytes
    """parseByteRange method"""

    data_string = byteView.readString(bytePos, byteLength, "ISO_8859-1")
    data_bytes = data_string.encode('ascii')
    decoded = base64.b64decode(data_bytes)

    byteArray.deleteRange(bytePos, byteLength)

    index = 0
    for base64_char in decoded:
        byteArray.insertByte(bytePos + index, base64_char)
        index += 1

~~~~~~~~~~~~~~~~~8<~~~~~~~~~~~~~~~~~
 

...