--
You received this message because you are subscribed to the Google Groups "Construct" group.
To unsubscribe from this group and stop receiving emails from it, send an email to construct3+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
def unpack_wstring(buffer, offset):
end = buffer.find("\x00\x00", offset)
if end - 2 <= offset:
return ""
length = end - offset
try:
return buffer[offset:offset + length].decode("utf16").partition("\x00")[0]
except UnicodeDecodeError:
return buffer[offset:offset + length + 1].decode("utf16").partition("\x00")[0]
class UTF16CString(Construct):
def _parse(self, stream, context):
contents = stream.getvalue()
accessed_files = []
offset = context.path_offsets
for i in range(context.path_count):
path = unpack_wstring(contents, offset)
length = (len(path) * 2) + 2
offset += length
accessed_files.append(path)
if offset > context.path_offsets + context.size:
break
return accessed_files