diff options
Diffstat (limited to 'miasm/loader')
| -rw-r--r-- | miasm/loader/new_cstruct.py | 6 | ||||
| -rw-r--r-- | miasm/loader/pe.py | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/miasm/loader/new_cstruct.py b/miasm/loader/new_cstruct.py index ec591aa8..16c947a5 100644 --- a/miasm/loader/new_cstruct.py +++ b/miasm/loader/new_cstruct.py @@ -4,6 +4,7 @@ from __future__ import print_function import re import struct +from miasm.core.utils import force_bytes from future.utils import PY3, viewitems, with_metaclass type2realtype = {} @@ -213,9 +214,10 @@ class CStruct(with_metaclass(Cstruct_Metaclass, object)): if cpt == None: if value == None: o = struct.calcsize(fmt) * b"\x00" + elif ffmt.endswith('s'): + new_value = force_bytes(value) + o = struct.pack(self.sex + fmt, new_value) else: - if isinstance(value, str): - value = value.encode() o = struct.pack(self.sex + fmt, value) else: o = b"" diff --git a/miasm/loader/pe.py b/miasm/loader/pe.py index e8208424..cd5d9370 100644 --- a/miasm/loader/pe.py +++ b/miasm/loader/pe.py @@ -267,7 +267,7 @@ class DescName(CStruct): return name, off + len(name) + 1 def sets(self, value): - return bytes(value) + b"\x00" + return force_bytes(value) + b"\x00" class ImportByName(CStruct): |