From ded699dfc4d5e149c8ad4daf467adac1f94e5822 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Wed, 2 Aug 2023 13:50:10 +0800 Subject: Fix cannot run Python script when the file contains non-ASCII characters. Fix https://github.com/Vector35/binaryninja-api/issues/4460 --- python/scriptingprovider.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python/scriptingprovider.py') 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) -- cgit v1.3.1