about summary refs log tree commit diff stats
path: root/miasm/loader/new_cstruct.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2020-04-29 11:52:26 +0200
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2020-04-30 17:19:44 +0200
commit8f691c21c4bb0aff342471c57b2045ac604f6c91 (patch)
treeb9bd834f7ad85ab64e6647e9541fd85e73606dc8 /miasm/loader/new_cstruct.py
parentdd2ee1a0810b7bfc78050510a19d93347c86a6ac (diff)
downloadfocaccia-miasm-8f691c21c4bb0aff342471c57b2045ac604f6c91.tar.gz
focaccia-miasm-8f691c21c4bb0aff342471c57b2045ac604f6c91.zip
Loader: Fix force_bytes
Diffstat (limited to 'miasm/loader/new_cstruct.py')
-rw-r--r--miasm/loader/new_cstruct.py6
1 files changed, 4 insertions, 2 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""