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.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/miasm/core/utils.py b/miasm/core/utils.py
index 9856d4f2..7667a656 100644
--- a/miasm/core/utils.py
+++ b/miasm/core/utils.py
@@ -1,4 +1,5 @@
 from __future__ import print_function
+import sys
 from builtins import range
 import struct
 import inspect
@@ -86,6 +87,21 @@ def force_bytes(value):
         return value
 
 
+def force_str(value):
+    if isinstance(value, str):
+        return value
+    elif isinstance(value, bytes):
+        out = ""
+        for i in range(len(value)):
+            # For Python2/Python3 compatibility
+            c = ord(value[i:i+1])
+            out += chr(c)
+        value = out
+    else:
+        raise ValueError("Unsupported type")
+    return value
+
+
 def iterbytes(string):
     for i in range(len(string)):
         yield string[i:i+1]