Skip to content

Unable to read any UTF-16 string #155

@knenkne

Description

@knenkne

Hey! I've been using pymem lately and found out that I can't read any UTF-16 strings.
Let's take a look at this byte's representation of Hello string:

UTF-8

0x48 0x65 0x6C 0x6C 0x6F

UTF-16-LE

0x48 0x00 0x65 0x00 0x6C 0x00 0x6C 0x00 0x6F 0x00

As you can see there is empty bytes added in UTF-16 strings and that's how things work, but current solution probably breaks, because of these empty appended bytes:

def read_string(handle, address, byte=50, encoding='UTF-8'):
    buff = read_bytes(handle, address, byte)
    i = buff.find(b'\x00')
    if i != -1:
        buff = buff[:i]
    buff = buff.decode(encoding)
    return buff

May be we can ignore this truncation for UTF-16, what you guys think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions