Skip to content

Commit c975c6c

Browse files
author
Willi Ballenthin
committed
views: better handle unicode
1 parent 583d947 commit c975c6c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Evtx/Views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
18+
import sys
1819
import string
1920

2021
from .Nodes import RootNode
@@ -153,7 +154,10 @@ def rec(root_node):
153154
f = _make_template_xml_view(root_node, cache=cache)
154155
subs_strs = []
155156
for sub in root_node.fast_substitutions():
156-
if isinstance(sub, str):
157+
# ugly hack for supporting is-string on py2 and py3
158+
if sys.version_info < (3, ) and isinstance(sub, basestring):
159+
subs_strs.append(sub)
160+
elif sys.version_info >= (3, ) and isinstance(sub, str):
157161
subs_strs.append(sub)
158162
elif isinstance(sub, RootNode):
159163
subs_strs.append(rec(sub))

scripts/evtxdump.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
from Evtx.Views import evtx_file_xml_view
2727

2828

29+
def ascii(s):
30+
return s.encode('ascii', 'replace').decode('ascii')
31+
32+
2933
def main():
3034
parser = argparse.ArgumentParser(
3135
description="Dump a binary EVTX file into XML.")
@@ -42,7 +46,7 @@ def main():
4246
print("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>")
4347
print("<Events>")
4448
for xml, record in evtx_file_xml_view(fh):
45-
print(xml)
49+
print(ascii(xml))
4650
print("</Events>")
4751

4852
if __name__ == "__main__":

0 commit comments

Comments
 (0)