Moved to non-deprecated API to init Python intepreter

This commit is contained in:
Jean-Michel Picod 2022-12-06 18:07:10 +01:00
parent 53b2909f04
commit b487961cbd
2 changed files with 16 additions and 9 deletions

View file

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- Moved to non-deprecated API to initialize Python interpreter (jmichel@)
- Changed `sc upgrade` updated firmware v4.12 (RDV40) (@sentiprox)
- Fixed contact interface / smartcard APDU chaining logic and allow 256 bytes ADPU payload. Need SIM firmware 4.12 to work (@jmichel)
- Fixed `lf hitag dump` - Should now work as described in the command help (@natmchugh)

View file

@ -412,22 +412,28 @@ static int CmdScriptRun(const char *Cmd) {
// hook Proxmark3 API
PyImport_AppendInittab("_pm3", PyInit__pm3);
#endif
Py_Initialize();
PyConfig py_conf;
PyConfig_InitIsolatedConfig(&py_conf);
//int argc, char ** argv
char *argv[128];
int argc = split(arguments, argv);
wchar_t *py_args[argc + 1];
py_args[0] = Py_DecodeLocale(filename, NULL);
for (int i = 0; i < argc; i++) {
py_args[i + 1] = Py_DecodeLocale(argv[i], NULL);
}
argv[0] = filename;
int argc = split(arguments, &argv[1]);
PyConfig_SetBytesArgv(&py_conf, argc + 1, argv);
// Despite being isolated we probably want to allow users to use
// the Python packages they installed on their user directory as well
// as obey env variables.
py_conf.use_environment = 1;
py_conf.user_site_directory = 1;
// Setting this pre-intializes Python implictly which will change the config
PyConfig_SetString(&py_conf, &py_conf.program_name, program);
PySys_SetArgv(argc + 1, py_args);
Py_InitializeFromConfig(&py_conf);
// clean up
PyConfig_Clear(&py_conf);
for (int i = 0; i < argc; ++i) {
free(argv[i]);
free(argv[i + 1]);
}
// setup search paths.