-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWideChar.py
More file actions
executable file
·30 lines (26 loc) · 876 Bytes
/
WideChar.py
File metadata and controls
executable file
·30 lines (26 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from Peach.transformer import Transformer
class WideChar(Transformer):
"""Transform a normal string into a wchar string.
Does not convert unicode into wchar strings or anything super fancy.
"""
def realEncode(self, data):
try:
return data.encode("utf-16le")
except Exception as e:
pass
ret = ""
for c in data:
ret += c + "\0"
return ret
def realDecode(self, data):
try:
return str(data.decode("utf-16le"))
except Exception as e:
pass
ret = ""
for i in range(0, len(data), 2):
ret += data[i]
return ret