From 5a5baa7bcd2827114f93819d0ae70a8b9df45d97 Mon Sep 17 00:00:00 2001 From: Clement Rouault Date: Fri, 17 Nov 2017 15:14:10 +0100 Subject: [PATCH] Add ctypes_generation extended structs _LSA_UNICODE_STRING.py --- .../extended_structs/_LSA_UNICODE_STRING.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py diff --git a/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py b/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py new file mode 100644 index 0000000..04d5f0b --- /dev/null +++ b/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py @@ -0,0 +1,19 @@ +INITIAL_LSA_UNICODE_STRING = _LSA_UNICODE_STRING + +class _LSA_UNICODE_STRING(INITIAL_LSA_UNICODE_STRING): + @property + def str(self): + """The python string of the LSA_UNICODE_STRING object + + :type: :class:`unicode` + """ + if not self.Length: + return "" + if getattr(self, "_target", None) is not None: #remote ctypes :D -> TRICKS OF THE YEAR + raw_data = self._target.read_memory(self.Buffer, self.Length) + return raw_data.decode("utf16") + size = self.Length / 2 + return (ctypes.c_wchar * size).from_address(self.Buffer)[:] + + def __repr__(self): + return """<{0} "{1}" at {2}>""".format(type(self).__name__, self.str, hex(id(self))) \ No newline at end of file