mirror of
https://github.com/cemu-project/idapython.git
synced 2024-11-24 10:09:20 +01:00
python.cpp: Indentation consistency and misc formatting fixes
This commit is contained in:
parent
260c813f05
commit
ef9921587b
50
python.cpp
50
python.cpp
@ -147,16 +147,13 @@ static error_t idaapi idc_runpythonstatement(idc_value_t *argv, idc_value_t *res
|
||||
return eOk;
|
||||
}
|
||||
|
||||
|
||||
/* QuickFix for the FILE* incompatibility problem */
|
||||
int ExecFile(const char *FileName)
|
||||
{
|
||||
PyObject* PyFileObject = PyFile_FromString((char*)FileName, "r");
|
||||
|
||||
if (!PyFileObject)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PyRun_SimpleFile(PyFile_AsFile(PyFileObject), FileName) == 0)
|
||||
{
|
||||
@ -203,9 +200,7 @@ void IDAPython_RunScript(char *script)
|
||||
int i;
|
||||
|
||||
if (script)
|
||||
{
|
||||
scriptpath = script;
|
||||
}
|
||||
else
|
||||
{
|
||||
scriptpath = askfile_c(0, "*.py", "Python file to run");
|
||||
@ -220,15 +215,10 @@ void IDAPython_RunScript(char *script)
|
||||
for (i=0; scriptpath[i]; i++)
|
||||
{
|
||||
if (scriptpath[i] == '\\')
|
||||
{
|
||||
slashpath[i] = '/';
|
||||
}
|
||||
else
|
||||
{
|
||||
slashpath[i] = scriptpath[i];
|
||||
}
|
||||
}
|
||||
|
||||
slashpath[i] = '\0';
|
||||
|
||||
/* Add the script't path to sys.path */
|
||||
@ -239,13 +229,10 @@ void IDAPython_RunScript(char *script)
|
||||
|
||||
/* Error handling */
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_Print();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Execute Python statement(s) from an editor window */
|
||||
/* Default hotkey: Alt-8 */
|
||||
void IDAPython_RunStatement(void)
|
||||
@ -258,9 +245,7 @@ void IDAPython_RunStatement(void)
|
||||
|
||||
/* Fetch the previous statement */
|
||||
if (history.supval(IDAPYTHON_DATA_STATEMENT, statement, sizeof(statement)) == -1)
|
||||
{
|
||||
statement[0] = '\0';
|
||||
}
|
||||
|
||||
if (asktext(sizeof(statement), statement, statement, "Enter Python expressions"))
|
||||
{
|
||||
@ -311,11 +296,9 @@ void IDAPython_ScriptBox(void)
|
||||
{
|
||||
/* Print the exception info */
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool idaapi IDAPython_Menu_Callback(void *ud)
|
||||
{
|
||||
@ -345,11 +328,9 @@ static void handle_python_error(char *errbuf, size_t errbufsize)
|
||||
Py_XDECREF(ptraceback);
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert return value from Python to IDC or report about an error */
|
||||
static bool return_python_result(idc_value_t *rv,
|
||||
@ -378,9 +359,7 @@ static bool return_python_result(idc_value_t *rv,
|
||||
{
|
||||
rv->str = (char *)qalloc(PyString_Size(result)+1);
|
||||
if (!rv->str)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
qstrncpy(rv->str, PyString_AsString(result), MAXSTR);
|
||||
rv->vtype = VT_STR;
|
||||
Py_XDECREF(result);
|
||||
@ -458,16 +437,13 @@ bool idaapi IDAPython_extlang_run(const char *name,
|
||||
case VT_LONG:
|
||||
pa = PyInt_FromLong(args[i].num);
|
||||
break;
|
||||
|
||||
case VT_STR:
|
||||
pa = PyString_FromString(args[i].str);
|
||||
break;
|
||||
|
||||
case VT_FLOAT:
|
||||
ieee_realcvt(&dresult, (ushort *)args[i].e, 013);
|
||||
pa = PyFloat_FromDouble(dresult);
|
||||
break;
|
||||
|
||||
default:
|
||||
qsnprintf(errbuf, errbufsize, "arg#%d has wrong type %d", i, args[i].vtype);
|
||||
return false;
|
||||
@ -584,14 +560,10 @@ cli_t cli_python =
|
||||
void enable_python_cli(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
install_command_interpreter(&cli_python);
|
||||
}
|
||||
else
|
||||
{
|
||||
remove_command_interpreter(&cli_python);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize the Python environment */
|
||||
@ -604,9 +576,7 @@ bool IDAPython_Init(void)
|
||||
|
||||
/* Already initialized? */
|
||||
if (initialized == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Check for the presence of essential files */
|
||||
initialized = 0;
|
||||
@ -615,11 +585,8 @@ bool IDAPython_Init(void)
|
||||
result &= CheckFile("init.py");
|
||||
result &= CheckFile("idaapi.py");
|
||||
result &= CheckFile("idautils.py");
|
||||
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef __LINUX__
|
||||
/* Export symbols from libpython to resolve imported module deps */
|
||||
@ -651,7 +618,6 @@ bool IDAPython_Init(void)
|
||||
VER_PATCH,
|
||||
VER_STATUS,
|
||||
VER_SERIAL);
|
||||
|
||||
PyRun_SimpleString(tmp);
|
||||
|
||||
#if IDP_INTERFACE_VERSION >= 75
|
||||
@ -676,11 +642,8 @@ bool IDAPython_Init(void)
|
||||
/* Batch-mode operation: */
|
||||
/* A script specified on the command line is run */
|
||||
options = (char *)get_plugin_options("IDAPython");
|
||||
|
||||
if (options)
|
||||
{
|
||||
IDAPython_RunScript(options);
|
||||
}
|
||||
|
||||
/* Add menu items for all the functions */
|
||||
/* Different paths are used for the GUI version */
|
||||
@ -689,31 +652,27 @@ bool IDAPython_Init(void)
|
||||
(menu_item_callback_t *)IDAPython_Menu_Callback,
|
||||
(void *)IDAPYTHON_RUNSTATEMENT);
|
||||
|
||||
/* Add Load Python file menu item*/
|
||||
result = add_menu_item("File/Load file/IDC file...", "P~y~thon file...",
|
||||
"Alt-9", SETMENU_APP,
|
||||
(menu_item_callback_t *)IDAPython_Menu_Callback,
|
||||
(void *)IDAPYTHON_RUNFILE);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
add_menu_item("File/IDC command...", "P~y~thon file...",
|
||||
"Alt-9", SETMENU_APP,
|
||||
(menu_item_callback_t *)IDAPython_Menu_Callback,
|
||||
(void *)IDAPYTHON_RUNFILE);
|
||||
}
|
||||
|
||||
/* Add View Python Scripts menu item*/
|
||||
result = add_menu_item("View/Open subviews/Show strings", "Python S~c~ripts",
|
||||
"Alt-7", SETMENU_APP,
|
||||
(menu_item_callback_t *)IDAPython_Menu_Callback,
|
||||
(void *)IDAPYTHON_SCRIPTBOX);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
add_menu_item("View/Open subviews/Problems", "Python S~c~ripts",
|
||||
"Alt-7", SETMENU_APP,
|
||||
(menu_item_callback_t *)IDAPython_Menu_Callback,
|
||||
(void *)IDAPYTHON_SCRIPTBOX);
|
||||
}
|
||||
|
||||
/* Register a RunPythonStatement() function for IDC */
|
||||
set_idc_func("RunPythonStatement", idc_runpythonstatement, idc_runpythonstatement_args);
|
||||
@ -825,17 +784,12 @@ plugin_t PLUGIN = {
|
||||
IDP_INTERFACE_VERSION,
|
||||
0, // plugin flags
|
||||
init, // initialize
|
||||
|
||||
term, // terminate. this pointer may be NULL.
|
||||
|
||||
run, // invoke plugin
|
||||
|
||||
comment, // long comment about the plugin
|
||||
// it could appear in the status line
|
||||
// or as a hint
|
||||
|
||||
help, // multiline help about the plugin
|
||||
|
||||
wanted_name, // the preferred short name of the plugin
|
||||
wanted_hotkey // the preferred hotkey to run the plugin
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user