From f59fbb02fe79585632f79876f5684633785a2404 Mon Sep 17 00:00:00 2001 From: "gergely.erdelyi" Date: Mon, 19 Jan 2009 20:38:59 +0000 Subject: [PATCH] Added rudimentary support for the new interactive command-line in IDA 5.4 --- python.cpp | 38 ++++++++++++++++++++++++++++++++++++++ swig/idaapi.i | 1 + 2 files changed, 39 insertions(+) diff --git a/python.cpp b/python.cpp index 1ea7cfe..289329b 100644 --- a/python.cpp +++ b/python.cpp @@ -379,6 +379,38 @@ void enable_extlang_python(bool enable) } } +/* Execute a line in the Python CLI */ +bool idaapi IDAPython_cli_execute_line(const char *line) +{ + PyRun_SimpleString(line); + return true; +} + +cli_t cli_python = + { + sizeof(cli_t), + 0, + "Python", + "Python - IDAPython plugin", + "Enter any Python expression", + IDAPython_cli_execute_line, + NULL, + NULL + }; + +/* Control the Python CLI status */ +void enable_python_cli(bool enable) +{ + if (enable) + { + install_command_interpreter(&cli_python); + } + else + { + remove_command_interpreter(&cli_python); + } +} + /* Initialize the Python environment */ bool IDAPython_Init(void) { @@ -491,6 +523,9 @@ bool IDAPython_Init(void) /* Register a RunPythonStatement() function for IDC */ set_idc_func("RunPythonStatement", idc_runpythonstatement, idc_runpythonstatement_args); + /* Enable the CLI by default */ + enable_python_cli(true); + initialized = 1; return true; @@ -505,6 +540,9 @@ void IDAPython_Term(void) del_menu_item("File/Python command..."); del_menu_item("View/Open subviews/Python Scripts"); + /* Remove the CLI */ + enable_python_cli(false); + /* Remove the extlang */ register_extlang(NULL); diff --git a/swig/idaapi.i b/swig/idaapi.i index d2e27b5..ca9b9fc 100644 --- a/swig/idaapi.i +++ b/swig/idaapi.i @@ -129,4 +129,5 @@ idainfo *get_inf_structure(void) %inline { void enable_extlang_python(bool enable); + void enable_python_cli(bool enable); }