about summary refs log tree commit diff stats
path: root/miasm/core/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm/core/utils.py')
-rw-r--r--miasm/core/utils.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/miasm/core/utils.py b/miasm/core/utils.py
index 7667a656..37248c40 100644
--- a/miasm/core/utils.py
+++ b/miasm/core/utils.py
@@ -81,10 +81,16 @@ def printable(string):
 
 
 def force_bytes(value):
-    try:
-        return value.encode()
-    except AttributeError:
+    if isinstance(value, bytes):
         return value
+    if not isinstance(value, str):
+        return value
+    out = []
+    for c in value:
+        c = ord(c)
+        assert c < 0x100
+        out.append(c)
+    return bytes(out)
 
 
 def force_str(value):