diff options
| author | KyleMiles <krm504@nyu.edu> | 2018-07-13 19:23:31 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2018-07-13 19:25:15 -0400 |
| commit | 2c7f443ce0b3d92ea44acb440c1891344eacc6d4 (patch) | |
| tree | 2b792808b858de83d7f2b90040b023534a4455a6 /python/generator.cpp | |
| parent | b460b9495a91897d9f8ed192c148e5afc366fb59 (diff) | |
Python2/3 String Compatibility Fix
Diffstat (limited to 'python/generator.cpp')
| -rw-r--r-- | python/generator.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/python/generator.cpp b/python/generator.cpp index 2da856ff..afc77254 100644 --- a/python/generator.cpp +++ b/python/generator.cpp @@ -198,13 +198,9 @@ int main(int argc, char* argv[]) fprintf(out, "\t_base_path = os.path.join(os.path.dirname(__file__), \"..\", \"..\")\n"); fprintf(out, "\tcore = ctypes.CDLL(os.path.join(_base_path, \"binaryninjacore.dll\"))\n"); fprintf(out, "else:\n"); - fprintf(out, "\traise Exception(\"OS not supported\")\n\n"); + fprintf(out, "\traise Exception(\"OS not supported\")\n\n\n"); - fprintf(out, "def cstr(arg):\n"); - fprintf(out, "\tif isinstance(arg, str):\n"); - fprintf(out, "\t\treturn arg.encode('charmap')\n"); - fprintf(out, "\telse:\n"); - fprintf(out, "\t\treturn arg\n\n"); + fprintf(out, "from binaryninja import cstr, pyNativeStr\n\n\n"); // Create type objects fprintf(out, "# Type definitions\n"); @@ -226,8 +222,8 @@ int main(int argc, char* argv[]) (arg.type->GetChildType()->GetWidth() == 1) && (arg.type->GetChildType()->IsSigned())) { - fprintf(out, "\t@property\n\tdef %s(self):\n\t\treturn self._%s.decode('charmap')\n", arg.name.c_str(), arg.name.c_str()); - fprintf(out, "\t@%s.setter\n\tdef %s(self, value):\n\t\tself._%s = value.encode('charmap')\n", arg.name.c_str(), arg.name.c_str(), arg.name.c_str()); + fprintf(out, "\t@property\n\tdef %s(self):\n\t\treturn pyNativeStr(self._%s)\n", arg.name.c_str(), arg.name.c_str()); + fprintf(out, "\t@%s.setter\n\tdef %s(self, value):\n\t\tself._%s = cstr(value)\n", arg.name.c_str(), arg.name.c_str(), arg.name.c_str()); stringField = true; } } @@ -423,7 +419,7 @@ int main(int argc, char* argv[]) } else fprintf(out, "\tresult = %s(*args)\n", funcName.c_str()); - fprintf(out, "\tstring = str(ctypes.cast(result, ctypes.c_char_p).value.decode('charmap'))\n"); + fprintf(out, "\tstring = str(pyNativeStr(ctypes.cast(result, ctypes.c_char_p).value))\n"); fprintf(out, "\tBNFreeString(result)\n"); fprintf(out, "\treturn string\n"); } |
