summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXusheng <xusheng@vector35.com>2023-08-02 13:50:10 +0800
committerXusheng <xusheng@vector35.com>2023-08-02 13:50:10 +0800
commitded699dfc4d5e149c8ad4daf467adac1f94e5822 (patch)
tree90ccc582b428fe9ee70550ccd684ca01aa2bda79
parent7cce661170870b35e5b8b982f670ea5b5f878a32 (diff)
Fix cannot run Python script when the file contains non-ASCII characters. Fix https://github.com/Vector35/binaryninja-api/issues/4460
-rw-r--r--python/scriptingprovider.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py
index 5dfb7075..0a0f9ffa 100644
--- a/python/scriptingprovider.py
+++ b/python/scriptingprovider.py
@@ -1141,7 +1141,7 @@ from binaryninja import *
if not os.path.exists(filename) and os.path.isfile(filename):
return ScriptingProviderExecuteResult.InvalidScriptInput # TODO: maybe this isn't the best result to use?
try:
- with open(filename, 'r') as fp:
+ with open(filename, 'rb') as fp:
file_contents = fp.read()
except IOError:
# File was not readable or something went horribly wrong
@@ -1150,7 +1150,7 @@ from binaryninja import *
if len(file_contents) == 0:
return ScriptingProviderExecuteResult.SuccessfulScriptExecution
- _code = code.compile_command(file_contents, filename, 'exec')
+ _code = code.compile_command(file_contents.decode('utf-8'), filename, 'exec')
self.interpreter.locals['__file__'] = filename
self.interpreter.locals['__name__'] = '__main__'
self.interpreter.execute(_code)