Improved support for Unicode Strings inside and ENCODED_STRING value

* In those cases where a list of items was parsed, there were some inconsistencies
* Should address https://github.com/CoreSecurity/impacket/issues/304
* Further testing is needed to be sure we're not breaking anything else.
This commit is contained in:
asolino
2017-08-15 17:54:16 -03:00
parent 23be93ed82
commit 3e0938ef28
2 changed files with 16 additions and 10 deletions
+7 -2
View File
@@ -76,14 +76,19 @@ if __name__ == '__main__':
pEnum = iEnum.Next(0xffffffff,1)[0]
record = pEnum.getProperties()
if printHeader is True:
print '|',
print '|',
for col in record:
print '%s |' % col,
print
printHeader = False
print '|',
for key in record:
print '%s |' % record[key]['value'],
if type(record[key]['value']) is list:
for item in record[key]['value']:
print item,
print ' |',
else:
print '%s |' % record[key]['value'],
print
except Exception, e:
#import traceback
+9 -8
View File
@@ -136,26 +136,27 @@ class ENCODED_STRING(Structure):
# Let's first check the commonHdr
self.fromString(data)
self.structure = ()
self.isUnicode = False
if len(data) > 1:
if self['Encoded_String_Flag'] == 0:
self.structure += self.tascii
# Let's search for the end of the string
index = data[1:].find('\x00')
data = data[:index+1+1]
self.fromString(data)
else:
self.structure = self.tunicode
# index = data[1:].find('\x00\x00')
# data = data[:index+1+2]
self.fromString(data)
try:
self['Character'] = self['Character'].decode('utf-16le')
except UnicodeDecodeError:
pass
self.isUnicode = True
self.fromString(data)
else:
self.structure = self.tascii
self.data = None
def __getitem__(self, key):
if key == 'Character' and self.isUnicode:
return self.fields['Character'].decode('utf-16le')
return Structure.__getitem__(self, key)
# 2.2.8 DecServerName
DEC_SERVER_NAME = ENCODED_STRING