Added IDA Pro 6.1 SP1 changes (thanks to Arnaud from Hex-Rays)

This commit is contained in:
elias.bachaalany@gmail.com 2014-02-04 02:31:52 +00:00
parent 78c79f85b9
commit 866e631dc7
12 changed files with 94 additions and 31 deletions

View File

@ -1022,9 +1022,8 @@ bool idaapi IDAPython_extlang_calcexpr(
begin_execution(); begin_execution();
result = newref_t(PyRun_String(expr, Py_eval_input, globals, globals)); result = newref_t(PyRun_String(expr, Py_eval_input, globals, globals));
end_execution(); end_execution();
}
if ( ok && result != NULL )
ok = return_python_result(rv, result, errbuf, errbufsize); ok = return_python_result(rv, result, errbuf, errbufsize);
}
return ok; return ok;
} }

View File

@ -330,7 +330,7 @@ def Structs():
def StructMembers(sid): def StructMembers(sid):
""" """
Get a list of structure members information. Get a list of structure members information (or stack vars if given a frame).
@param sid: ID of the structure. @param sid: ID of the structure.
@ -338,14 +338,17 @@ def StructMembers(sid):
@note: If 'sid' does not refer to a valid structure, @note: If 'sid' does not refer to a valid structure,
an exception will be raised. an exception will be raised.
@note: This will not return 'holes' in structures/stack frames;
it only returns defined structure members.
""" """
off = idc.GetFirstMember(sid) m = idc.GetFirstMember(sid)
if off == idaapi.BADNODE: if m == -1:
raise Exception("No structure with ID: 0x%x" % sid) raise Exception("No structure with ID: 0x%x" % sid)
members = idc.GetMemberQty(sid) while (m != idaapi.BADADDR):
for idx in range(0, members): name = idc.GetMemberName(sid, m)
yield (off, idc.GetMemberName(sid, off), idc.GetMemberSize(sid, off)) if name:
off = idc.GetStrucNextOff(sid, off) yield (m, name, idc.GetMemberSize(sid, m))
m = idc.GetStrucNextOff(sid, m)
def DecodePrecedingInstruction(ea): def DecodePrecedingInstruction(ea):

View File

@ -4943,7 +4943,7 @@ def GetStrucName(sid):
@param sid: structure type ID @param sid: structure type ID
@return: -1 if bad structure type ID is passed @return: None if bad structure type ID is passed
otherwise returns structure type name. otherwise returns structure type name.
""" """
return idaapi.get_struc_name(sid) return idaapi.get_struc_name(sid)
@ -5023,8 +5023,8 @@ def GetStrucPrevOff(sid, offset):
@param sid: structure type ID @param sid: structure type ID
@param offset: current offset @param offset: current offset
@return: -1 if bad structure type ID is passed @return: -1 if bad structure type ID is passed,
or no (more) offsets in the structure idaapi.BADADDR if no (more) offsets in the structure,
otherwise returns previous offset in a structure. otherwise returns previous offset in a structure.
@note: IDA allows 'holes' between members of a @note: IDA allows 'holes' between members of a
@ -5052,8 +5052,8 @@ def GetStrucNextOff(sid, offset):
@param sid: structure type ID @param sid: structure type ID
@param offset: current offset @param offset: current offset
@return: -1 if bad structure type ID is passed @return: -1 if bad structure type ID is passed,
or no (more) offsets in the structure idaapi.BADADDR if no (more) offsets in the structure,
otherwise returns next offset in a structure. otherwise returns next offset in a structure.
@note: IDA allows 'holes' between members of a @note: IDA allows 'holes' between members of a
@ -5077,8 +5077,8 @@ def GetFirstMember(sid):
@param sid: structure type ID @param sid: structure type ID
@return: -1 if bad structure type ID is passed @return: -1 if bad structure type ID is passed,
or structure has no members idaapi.BADADDR if structure has no members,
otherwise returns offset of the first member. otherwise returns offset of the first member.
@note: IDA allows 'holes' between members of a @note: IDA allows 'holes' between members of a
@ -5102,8 +5102,8 @@ def GetLastMember(sid):
@param sid: structure type ID @param sid: structure type ID
@return: -1 if bad structure type ID is passed @return: -1 if bad structure type ID is passed,
or structure has no members idaapi.BADADDR if structure has no members,
otherwise returns offset of the last member. otherwise returns offset of the last member.
@note: IDA allows 'holes' between members of a @note: IDA allows 'holes' between members of a
@ -5212,7 +5212,7 @@ def GetMemberSize(sid, member_offset):
at offset 2, then 2,3,4,5 denote at offset 2, then 2,3,4,5 denote
the same structure member. the same structure member.
@return: -1 if bad structure type ID is passed @return: None if bad structure type ID is passed,
or no such member in the structure or no such member in the structure
otherwise returns size of the specified otherwise returns size of the specified
member in bytes. member in bytes.

View File

@ -72,6 +72,15 @@ _orig_stdout = sys.stdout;
_orig_stderr = sys.stderr; _orig_stderr = sys.stderr;
sys.stdout = sys.stderr = IDAPythonStdOut() sys.stdout = sys.stderr = IDAPythonStdOut()
# -----------------------------------------------------------------------
# Initialize the help, with our own stdin wrapper, that'll query the user
# -----------------------------------------------------------------------
import pydoc
class IDAPythonHelpPrompter:
def readline(self):
return idaapi.askstr(0, '', 'Help topic?')
help = pydoc.Helper(input = IDAPythonHelpPrompter(), output = sys.stdout)
# Assign a default sys.argv # Assign a default sys.argv
sys.argv = [""] sys.argv = [""]

View File

@ -111,12 +111,8 @@ public:
// Declare a variable to acquire/release the GIL // Declare a variable to acquire/release the GIL
#define PYW_GIL_GET gil_lock_t lock; #define PYW_GIL_GET gil_lock_t lock;
#ifdef _DEBUG
#define GIL_CHKCONDFAIL (PyGILState_GetThisThreadState() != _PyThreadState_Current)
#else
#define GIL_CHKCONDFAIL (((debug & IDA_DEBUG_PLUGIN) == IDA_DEBUG_PLUGIN) \ #define GIL_CHKCONDFAIL (((debug & IDA_DEBUG_PLUGIN) == IDA_DEBUG_PLUGIN) \
&& PyGILState_GetThisThreadState() != _PyThreadState_Current) && PyGILState_GetThisThreadState() != _PyThreadState_Current)
#endif
#define PYW_GIL_CHECK_LOCKED_SCOPE() \ #define PYW_GIL_CHECK_LOCKED_SCOPE() \
do \ do \

View File

@ -167,7 +167,7 @@ static error_t idaapi idc_py_invoke0(
idc_value_t *argv, idc_value_t *argv,
idc_value_t *res) idc_value_t *res)
{ {
PYW_GIL_CHECK_LOCKED_SCOPE(); PYW_GIL_GET;
PyObject *pyfunc = (PyObject *) argv[0].pvoid; PyObject *pyfunc = (PyObject *) argv[0].pvoid;
newref_t py_result(PyObject_CallFunctionObjArgs(pyfunc, NULL)); newref_t py_result(PyObject_CallFunctionObjArgs(pyfunc, NULL));

View File

@ -20,7 +20,7 @@ import bisect
import __builtin__ import __builtin__
import imp import imp
def require(modulename): def require(modulename, package=None):
""" """
Load, or reload a module. Load, or reload a module.
@ -41,7 +41,7 @@ def require(modulename):
else: else:
import importlib import importlib
import inspect import inspect
m = importlib.import_module(modulename) m = importlib.import_module(modulename, package)
frame_obj, filename, line_number, function_name, lines, index = inspect.stack()[1] frame_obj, filename, line_number, function_name, lines, index = inspect.stack()[1]
importer_module = inspect.getmodule(frame_obj) importer_module = inspect.getmodule(frame_obj)
if importer_module is None: # No importer module; called from command line if importer_module is None: # No importer module; called from command line

View File

@ -4,6 +4,11 @@
// For get_enum_id() // For get_enum_id()
%apply unsigned char *OUTPUT { uchar *serial }; %apply unsigned char *OUTPUT { uchar *serial };
// get_[first|last]_serial_enum_member() won't take serials as input; it'll be present as output
%apply unsigned char *OUTPUT { uchar *out_serial };
// get_[next|prev]_serial_enum_member() take serials as input, and have the result present as output
%apply unsigned char *INOUT { uchar *in_out_serial };
// Unexported and kernel-only declarations // Unexported and kernel-only declarations
%ignore FlagsEnable; %ignore FlagsEnable;
%ignore FlagsDisable; %ignore FlagsDisable;

View File

@ -1347,7 +1347,7 @@ static error_t idaapi idc_py_invoke0(
idc_value_t *argv, idc_value_t *argv,
idc_value_t *res) idc_value_t *res)
{ {
PYW_GIL_CHECK_LOCKED_SCOPE(); PYW_GIL_GET;
PyObject *pyfunc = (PyObject *) argv[0].pvoid; PyObject *pyfunc = (PyObject *) argv[0].pvoid;
newref_t py_result(PyObject_CallFunctionObjArgs(pyfunc, NULL)); newref_t py_result(PyObject_CallFunctionObjArgs(pyfunc, NULL));
@ -2115,7 +2115,7 @@ import bisect
import __builtin__ import __builtin__
import imp import imp
def require(modulename): def require(modulename, package=None):
""" """
Load, or reload a module. Load, or reload a module.
@ -2136,7 +2136,7 @@ def require(modulename):
else: else:
import importlib import importlib
import inspect import inspect
m = importlib.import_module(modulename) m = importlib.import_module(modulename, package)
frame_obj, filename, line_number, function_name, lines, index = inspect.stack()[1] frame_obj, filename, line_number, function_name, lines, index = inspect.stack()[1]
importer_module = inspect.getmodule(frame_obj) importer_module = inspect.getmodule(frame_obj)
if importer_module is None: # No importer module; called from command line if importer_module is None: # No importer module; called from command line

View File

@ -37,7 +37,6 @@
%ignore close_comment; %ignore close_comment;
%ignore copy_extra_cmts; %ignore copy_extra_cmts;
%ignore gen_extra_cmts; %ignore gen_extra_cmts;
%ignore get_first_free_extra_cmtidx;
%ignore Dumper; %ignore Dumper;
%ignore init_lines; %ignore init_lines;
%ignore save_lines; %ignore save_lines;

View File

@ -12,6 +12,18 @@
%ignore unregister_custom_refinfo; %ignore unregister_custom_refinfo;
%ignore get_custom_refinfos; %ignore get_custom_refinfos;
%template (ids_array) wrapped_array<tid_t,32>;
%extend strpath_t {
wrapped_array<tid_t,32> __getIds() {
return wrapped_array<tid_t,32>($self->ids);
}
%pythoncode {
ids = property(__getIds)
}
}
%include "nalt.hpp" %include "nalt.hpp"
%{ %{

View File

@ -154,6 +154,7 @@
} }
$1 = ea_t($1_temp); $1 = ea_t($1_temp);
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Convert qstring // Convert qstring
%typemap(in) qstring* %typemap(in) qstring*
@ -166,14 +167,17 @@
$1 = new qstring(buf, length); $1 = new qstring(buf, length);
} }
} }
%typemap(freearg) qstring* %typemap(freearg) qstring*
{ {
delete $1; delete $1;
} }
%typemap(out) qstring* %typemap(out) qstring*
{ {
$result = PyString_FromStringAndSize($1->c_str(), $1->length()); $result = PyString_FromStringAndSize($1->c_str(), $1->length());
} }
#ifdef __EA64__ #ifdef __EA64__
%apply longlong *INOUT { sval_t *value }; %apply longlong *INOUT { sval_t *value };
%apply ulonglong *INOUT { ea_t *addr }; %apply ulonglong *INOUT { ea_t *addr };
@ -183,3 +187,39 @@
%apply unsigned int *INOUT { ea_t *addr }; %apply unsigned int *INOUT { ea_t *addr };
%apply unsigned int *INOUT { sel_t *sel }; %apply unsigned int *INOUT { sel_t *sel };
#endif #endif
//-------------------------------------------------------------------------
// The following is to be used to expose an array of items
// to IDAPython. This will not make a copy (on purpose!).
//-------------------------------------------------------------------------
//
// (Very) heavily inspired by:
// http://stackoverflow.com/questions/7713318/nested-structure-array-access-in-python-using-swig?rq=1
//
%immutable;
%inline %{
template <typename Type, size_t N>
struct wrapped_array {
Type (&data)[N];
wrapped_array(Type (&data)[N]) : data(data) { }
};
%}
%mutable;
%extend wrapped_array {
inline size_t __len__() const { return N; }
inline const Type& __getitem__(size_t i) const throw(std::out_of_range) {
if (i >= N || i < 0)
throw std::out_of_range("out of bounds access");
return $self->data[i];
}
inline void __setitem__(size_t i, const Type& v) throw(std::out_of_range) {
if (i >= N || i < 0)
throw std::out_of_range("out of bounds access");
$self->data[i] = v;
}
}