Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 223e4a5

Browse files
author
elias.bachaalany@gmail.com
committed
Applied patches from Hex-Rays:
- added MakeYword - wrap obsolete IDA API functions too, so that old scripts continue to work - added debugger trace related functions in idc.py BUGFIX: IDAPython would fail with a cryptic error message if there was no free space on the current disk BUGFIX: site-packages directory was missing from sys.path BUGFIX: functions for working with additional lines (LineA/LineB etc) were broken BUGFIX: GetFixup* functions from idc.py were broken BUGFIX: IDA could not start if another python27.dll was present in PATH and importing site.py for that Python installation failed BUGFIX: SaveBase() was broken BUGFIX: IDAPython would fail with a cryptic error message if there was no free space on the current disk BUGFIX: IDAPython: site-packages directory was missing from sys.path BUGFIX: IDAPython: functions for working with additional lines (LineA/LineB etc) were broken BUGFIX: IDAPython: GetFixup* functions from idc.py were broken BUGFIX: IDAPython: IDA could not start if another python27.dll was present in PATH and importing site.py for that Python installation failed BUGFIX: IDAPython: SaveBase() was broken BUGFIX: Dbg/Idp hooks automatically unhook when hook object is not referenced anymore note: these patches are already applied in IDAPython that comes with IDA Pro 6.4
1 parent 69d5c83 commit 223e4a5

26 files changed

Lines changed: 501 additions & 123 deletions

python.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#define _SSIZE_T_DEFINED 1
1919
#endif
2020

21-
#include <stdio.h>
22-
#include <string.h>
2321
#ifdef __LINUX__
2422
#include <dlfcn.h>
2523
#endif
@@ -28,13 +26,10 @@
2826
#endif
2927
#include <ida.hpp>
3028
#include <idp.hpp>
31-
#include <ieee.h>
32-
#include <bytes.hpp>
33-
#include <diskio.hpp>
3429
#include <expr.hpp>
30+
#include <diskio.hpp>
3531
#include <loader.hpp>
3632
#include <kernwin.hpp>
37-
#include <netnode.hpp>
3833
#include "pywraps.hpp"
3934

4035
//-------------------------------------------------------------------------
@@ -83,6 +78,7 @@ static char g_idapython_dir[QMAXPATH];
8378
// Prototypes and forward declarations
8479

8580
// Alias to SWIG_Init
81+
//lint -esym(526,init_idaapi) not defined
8682
extern "C" void init_idaapi(void);
8783

8884
// Plugin run() callback
@@ -127,8 +123,8 @@ static bool g_alert_auto_scripts = true;
127123
static bool g_remove_cwd_sys_path = false;
128124
static bool g_use_local_python = false;
129125

130-
static void end_execution();
131-
static void begin_execution();
126+
static void end_execution(void);
127+
static void begin_execution(void);
132128

133129
//------------------------------------------------------------------------
134130
// This callback is called on various interpreter events
@@ -154,6 +150,10 @@ static int break_check(PyObject *obj, _frame *frame, int what, PyObject *arg)
154150
#ifdef ENABLE_PYTHON_PROFILING
155151
return tracefunc(obj, frame, what, arg);
156152
#else
153+
qnotused(obj);
154+
qnotused(frame);
155+
qnotused(what);
156+
qnotused(arg);
157157
return 0;
158158
#endif
159159
}
@@ -200,6 +200,7 @@ static void end_execution()
200200
}
201201

202202
//-------------------------------------------------------------------------
203+
//lint -esym(714,disable_script_timeout) Symbol not referenced
203204
void disable_script_timeout()
204205
{
205206
// Clear timeout
@@ -210,6 +211,7 @@ void disable_script_timeout()
210211
}
211212

212213
//-------------------------------------------------------------------------
214+
//lint -esym(714,set_script_timeout) Symbol not referenced
213215
int set_script_timeout(int timeout)
214216
{
215217
// Update the timeout
@@ -411,6 +413,20 @@ bool CheckScriptFiles()
411413
// Caller of this function should call handle_python_error() to clear the exception and print the error
412414
static int PyRunFile(const char *FileName)
413415
{
416+
#ifdef __NT__
417+
// if the current disk has no space (sic, the current directory, not the one
418+
// with the input file), PyRun_File() will die with a cryptic message that
419+
// C runtime library could not be loaded. So we check the disk space before
420+
// calling it.
421+
char curdir[QMAXPATH];
422+
if ( _getcwd(curdir, sizeof(curdir)) == NULL
423+
|| getdspace(curdir) == 0 )
424+
{
425+
warning("No free disk space on %s, python will not be available", curdir);
426+
return 0;
427+
}
428+
#endif
429+
414430
PyObject *PyFileObject = PyFile_FromString((char*)FileName, "r");
415431
PyObject *globals = GetMainGlobals();
416432
if ( globals == NULL || PyFileObject == NULL )
@@ -536,14 +552,6 @@ static bool RunScript(const char *script)
536552
return ok;
537553
}
538554

539-
//-------------------------------------------------------------------------
540-
bool idaapi IDAPython_Menu_Callback(void *ud)
541-
{
542-
// note: on 64-bit systems the pointer will be truncated to 32-bits!
543-
run((ssize_t)ud);
544-
return true;
545-
}
546-
547555
//-------------------------------------------------------------------------
548556
// This function parses a name into two different components (if it applies).
549557
// Example:
@@ -766,7 +774,6 @@ bool idaapi IDAPython_extlang_create_object(
766774
ok = pyw_convert_idc_args(args, nargs, pargs, NULL, errbuf, errbufsize);
767775
if ( !ok )
768776
break;
769-
ok = false;
770777

771778
// Call the constructor
772779
PYW_GIL_ENSURE;
@@ -861,7 +868,7 @@ bool idaapi IDAPython_extlang_get_attr(
861868
break;
862869

863870
result->set_string(clsname);
864-
cvt = CIP_OK;
871+
cvt = CIP_OK; //lint !e838
865872
break;
866873
}
867874

@@ -908,6 +915,7 @@ bool idaapi IDAPython_extlang_get_attr(
908915

909916
//-------------------------------------------------------------------------
910917
// Returns the attribute value of a given object from the global scope
918+
//lint -e{818}
911919
bool idaapi IDAPython_extlang_set_attr(
912920
idc_value_t *obj, // in: object name (may be NULL)
913921
const char *attr, // in: attribute name
@@ -969,6 +977,7 @@ bool idaapi IDAPython_extlang_set_attr(
969977

970978
//-------------------------------------------------------------------------
971979
// Calculator callback for Python external language evaluator
980+
//lint -e{818}
972981
bool idaapi IDAPython_extlang_calcexpr(
973982
ea_t /*current_ea*/,
974983
const char *expr,
@@ -1055,7 +1064,7 @@ bool idaapi IDAPython_extlang_call_method(
10551064
}
10561065

10571066
//-------------------------------------------------------------------------
1058-
extlang_t extlang_python =
1067+
const extlang_t extlang_python =
10591068
{
10601069
sizeof(extlang_t),
10611070
0,
@@ -1142,7 +1151,7 @@ bool idaapi IDAPYthon_cli_complete_line(
11421151
return false;
11431152

11441153
PYW_GIL_ENSURE;
1145-
PyObject *py_ret = PyObject_CallFunction(py_complete, "sisi", prefix, n, line, x);
1154+
PyObject *py_ret = PyObject_CallFunction(py_complete, "sisi", prefix, n, line, x); //lint !e1776
11461155
PYW_GIL_RELEASE;
11471156

11481157
Py_DECREF(py_complete);

0 commit comments

Comments
 (0)