Backport fixes; add bookmarks sample

This commit is contained in:
Arnaud Diederen
2023-05-23 12:21:29 +02:00
parent b281924149
commit dcca75f50e
11 changed files with 332 additions and 49 deletions
+40
View File
@@ -0,0 +1,40 @@
"""
summary: list bookmarks associated to a listing
description:
This sample shows how to programmatically access the list of
bookmarks placed in a listing widget (e.g., "IDA View-A",
"Pseudocode-", …) using the low-level `ida_moves.bookmarks_t`
type.
keywords: bookmarks
"""
import ida_kernwin
import ida_moves
class list_bookmarks_ah_t(ida_kernwin.action_handler_t):
def activate(self, ctx):
v = ida_kernwin.get_current_viewer()
if v:
print("### Bookmarks for %s" % ida_kernwin.get_widget_title(v))
ud = ida_kernwin.get_viewer_user_data(v)
for loc, desc in ida_moves.bookmarks_t(v):
print("\t'%s': %s" % (loc.place()._print(ud), desc))
def update(self, ctx):
return ida_kernwin.AST_ENABLE_FOR_WIDGET \
if ida_kernwin.get_current_viewer() \
else ida_kernwin.AST_DISABLE_FOR_WIDGET
ACTION_NAME = "example:list_bookmarks"
ACTION_LABEL = "List bookmarks"
ACTION_SHORTCUT = "Ctrl+!"
ACTION_HELP = "Press %s to list bookmarks" % ACTION_SHORTCUT
if ida_kernwin.register_action(ida_kernwin.action_desc_t(
ACTION_NAME,
ACTION_LABEL,
list_bookmarks_ah_t(),
ACTION_SHORTCUT)):
print("Registered action \"%s\". %s" % (ACTION_LABEL, ACTION_HELP))
+48
View File
@@ -1,6 +1,7 @@
<!--
Used keywords:
actions
bookmarks
chooser
coloring
colors
@@ -815,6 +816,52 @@ information (e.g., '.text:08047718'), but it is possible to
</li>
</ul>
</div>
</div>
<div class="example-entry collapsed-entry" name="list_bookmarks">
<div>
<span class="exp-col expander">&#x25B9;</span>
<span class="exp-col collapser" style="display:none">&#x25BF;</span>
<a href="core/list_bookmarks.py">list_bookmarks</a>: <i>List bookmarks associated to a listing</i>
</div>
<div class="details" id="DIV_list_bookmarks">
<pre>
This sample shows how to programmatically access the list of
bookmarks placed in a listing widget (e.g., "IDA View-A",
"Pseudocode-", …) using the low-level `ida_moves.bookmarks_t`
type.
</pre>
<ul>
<li>Category: core</li>
<li>Summary: List bookmarks associated to a listing</li>
<li>View on <a href="https://github.com/idapython/src/blob/master/examples/core/list_bookmarks.py">GitHub</a></li>
<li>Keywords:
bookmarks
</li>
<li>Shortcut:
Ctrl+!
</li>
<li>APIs used
<ul>
<li>ida_kernwin.AST_DISABLE_FOR_WIDGET</li>
<li>ida_kernwin.AST_ENABLE_FOR_WIDGET</li>
<li>ida_kernwin.action_desc_t</li>
<li>ida_kernwin.action_handler_t</li>
<li>ida_kernwin.get_current_viewer</li>
<li>ida_kernwin.get_viewer_user_data</li>
<li>ida_kernwin.get_widget_title</li>
<li>ida_kernwin.register_action</li>
<li>ida_moves.bookmarks_t</li>
</ul>
</li>
</ul>
</div>
</div>
@@ -1631,6 +1678,7 @@ symbols that the process being debugged, provides.
<li>APIs used
<ul>
<li>ida_dbg.DSTATE_SUSP</li>
<li>ida_dbg.get_process_state</li>
<li>ida_dbg.is_debugger_on</li>
<li>ida_ida.inf_get_max_ea</li>
+40
View File
@@ -650,6 +650,45 @@ plugin
* ida_lines.SCOLOR_INV
* ida_lines.user_defined_prefix_t
</blockquote>
</details>
#### list_bookmarks
<details>
<summary>List bookmarks associated to a listing</summary>
<blockquote>
#### Source code
<a href="https://github.com/idapython/src/blob/master/examples/core/list_bookmarks.py">core/list_bookmarks.py</a>
#### Category
core
#### Description
This sample shows how to programmatically access the list of
bookmarks placed in a listing widget (e.g., "IDA View-A",
"Pseudocode-", …) using the low-level `ida_moves.bookmarks_t`
type.
#### Shortcut
Ctrl+!
#### Keywords
bookmarks
#### Uses
* ida_kernwin.AST_DISABLE_FOR_WIDGET
* ida_kernwin.AST_ENABLE_FOR_WIDGET
* ida_kernwin.action_desc_t
* ida_kernwin.action_handler_t
* ida_kernwin.get_current_viewer
* ida_kernwin.get_viewer_user_data
* ida_kernwin.get_widget_title
* ida_kernwin.register_action
* ida_moves.bookmarks_t
</blockquote>
</details>
@@ -1334,6 +1373,7 @@ Queries the debugger (possibly remotely) for the list of
symbols that the process being debugged, provides.
#### Uses
* ida_dbg.DSTATE_SUSP
* ida_dbg.get_process_state
* ida_dbg.is_debugger_on
* ida_ida.inf_get_max_ea
Binary file not shown.
+34 -12
View File
@@ -45076,6 +45076,13 @@ class plugin_t(pyidc_opaque_object_t)
| pyidc_opaque_object_t
| builtins.object
|
| Methods defined here:
|
| run(self, arg)
|
| term(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from pyidc_opaque_object_t:
|
| __dict__
@@ -71217,8 +71224,19 @@ class bookmarks_t(builtins.object)
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
| __getitem__(self, idx)
|
| __init__(self, w)
| Build an object suitable for iterating bookmarks
| associated with the specified widget.
|
| Note: all ea_t-based widgets (e.g., "IDA View-*",
| "Pseudocode-*", "Hex View-*", ...) share a common storage,
| so bookmarks can be re-used interchangeably between them
|
| __iter__(self)
|
| __len__(self)
|
| __repr__ = _swig_repr(self)
|
@@ -71238,12 +71256,11 @@ class bookmarks_t(builtins.object)
| @param e: lochist_entry_t const &
| @param ud: void *
|
| get(*args) -> 'bool'
| get(out_entry, out_desc, index, ud) -> bool
| get(*args) -> 'PyObject *'
| get(out, _index, ud) -> PyObject *
|
| @param out_entry: lochist_entry_t *
| @param out_desc: qstring *
| @param index: uint32 *
| @param out: lochist_entry_t *
| @param _index: uint32
| @param ud: void *
|
| get_desc(*args) -> 'qstring *'
@@ -71305,12 +71322,11 @@ bookmarks_t_find_index(*args) -> 'uint32'
Help on function bookmarks_t_get in module ida_moves:
bookmarks_t_get(*args) -> 'bool'
bookmarks_t_get(out_entry, out_desc, index, ud) -> bool
bookmarks_t_get(*args) -> 'PyObject *'
bookmarks_t_get(out, _index, ud) -> PyObject *
@param out_entry: lochist_entry_t *
@param out_desc: qstring *
@param index: uint32 *
@param out: lochist_entry_t *
@param _index: uint32
@param ud: void *
Help on function bookmarks_t_get_desc in module ida_moves:
@@ -96775,6 +96791,12 @@ get_processes(*args) -> 'ssize_t'
@param proclist: (C++: procinfo_vec_t *) array with information about each running process
@return: number of processes or -1 on error
Help on function get_processor_name in module idc:
get_processor_name()
Get name of the current processor
@return: processor name
Help on function get_qword in module ida_bytes:
get_qword(*args) -> 'uint64'
+34 -12
View File
@@ -44896,6 +44896,13 @@ class plugin_t(pyidc_opaque_object_t)
| pyidc_opaque_object_t
| builtins.object
|
| Methods defined here:
|
| run(self, arg)
|
| term(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from pyidc_opaque_object_t:
|
| __dict__
@@ -70295,8 +70302,19 @@ class bookmarks_t(builtins.object)
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
| __getitem__(self, idx)
|
| __init__(self, w)
| Build an object suitable for iterating bookmarks
| associated with the specified widget.
|
| Note: all ea_t-based widgets (e.g., "IDA View-*",
| "Pseudocode-*", "Hex View-*", ...) share a common storage,
| so bookmarks can be re-used interchangeably between them
|
| __iter__(self)
|
| __len__(self)
|
| __repr__ = _swig_repr(self)
|
@@ -70316,12 +70334,11 @@ class bookmarks_t(builtins.object)
| @param e: lochist_entry_t const &
| @param ud: void *
|
| get(*args) -> 'bool'
| get(out_entry, out_desc, index, ud) -> bool
| get(*args) -> 'PyObject *'
| get(out, _index, ud) -> PyObject *
|
| @param out_entry: lochist_entry_t *
| @param out_desc: qstring *
| @param index: uint32 *
| @param out: lochist_entry_t *
| @param _index: uint32
| @param ud: void *
|
| get_desc(*args) -> 'qstring *'
@@ -70383,12 +70400,11 @@ bookmarks_t_find_index(*args) -> 'uint32'
Help on function bookmarks_t_get in module ida_moves:
bookmarks_t_get(*args) -> 'bool'
bookmarks_t_get(out_entry, out_desc, index, ud) -> bool
bookmarks_t_get(*args) -> 'PyObject *'
bookmarks_t_get(out, _index, ud) -> PyObject *
@param out_entry: lochist_entry_t *
@param out_desc: qstring *
@param index: uint32 *
@param out: lochist_entry_t *
@param _index: uint32
@param ud: void *
Help on function bookmarks_t_get_desc in module ida_moves:
@@ -95853,6 +95869,12 @@ get_processes(*args) -> 'ssize_t'
@param proclist: (C++: procinfo_vec_t *) array with information about each running process
@return: number of processes or -1 on error
Help on function get_processor_name in module idc:
get_processor_name()
Get name of the current processor
@return: processor name
Help on function get_qword in module ida_bytes:
get_qword(*args) -> 'uint64'
+1 -1
View File
@@ -404,7 +404,7 @@ def struct_unpack(buffer, signed = False, offs = 0):
# ------------------------------------------------------------
try:
"".decode("UTF-8").encode("mbcs")
b"".decode("UTF-8").encode("mbcs")
has_mbcs = True
except:
has_mbcs = False
+3
View File
@@ -0,0 +1,3 @@
#<pycode(py_moves)>
import ida_kernwin
#</pycode(py_moves)>
+34 -12
View File
@@ -45051,6 +45051,13 @@ class plugin_t(pyidc_opaque_object_t)
| pyidc_opaque_object_t
| builtins.object
|
| Methods defined here:
|
| run(self, arg)
|
| term(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from pyidc_opaque_object_t:
|
| __dict__
@@ -67359,8 +67366,19 @@ class bookmarks_t(builtins.object)
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
| __getitem__(self, idx)
|
| __init__(self, w)
| Build an object suitable for iterating bookmarks
| associated with the specified widget.
|
| Note: all ea_t-based widgets (e.g., "IDA View-*",
| "Pseudocode-*", "Hex View-*", ...) share a common storage,
| so bookmarks can be re-used interchangeably between them
|
| __iter__(self)
|
| __len__(self)
|
| __repr__ = _swig_repr(self)
|
@@ -67380,12 +67398,11 @@ class bookmarks_t(builtins.object)
| @param e: lochist_entry_t const &
| @param ud: void *
|
| get(*args) -> 'bool'
| get(out_entry, out_desc, index, ud) -> bool
| get(*args) -> 'PyObject *'
| get(out, _index, ud) -> PyObject *
|
| @param out_entry: lochist_entry_t *
| @param out_desc: qstring *
| @param index: uint32 *
| @param out: lochist_entry_t *
| @param _index: uint32
| @param ud: void *
|
| get_desc(*args) -> 'qstring *'
@@ -67447,12 +67464,11 @@ bookmarks_t_find_index(*args) -> 'uint32'
Help on function bookmarks_t_get in module ida_moves:
bookmarks_t_get(*args) -> 'bool'
bookmarks_t_get(out_entry, out_desc, index, ud) -> bool
bookmarks_t_get(*args) -> 'PyObject *'
bookmarks_t_get(out, _index, ud) -> PyObject *
@param out_entry: lochist_entry_t *
@param out_desc: qstring *
@param index: uint32 *
@param out: lochist_entry_t *
@param _index: uint32
@param ud: void *
Help on function bookmarks_t_get_desc in module ida_moves:
@@ -92917,6 +92933,12 @@ get_processes(*args) -> 'ssize_t'
@param proclist: (C++: procinfo_vec_t *) array with information about each running process
@return: number of processes or -1 on error
Help on function get_processor_name in module idc:
get_processor_name()
Get name of the current processor
@return: processor name
Help on function get_qword in module ida_bytes:
get_qword(*args) -> 'uint64'
+34 -12
View File
@@ -44871,6 +44871,13 @@ class plugin_t(pyidc_opaque_object_t)
| pyidc_opaque_object_t
| builtins.object
|
| Methods defined here:
|
| run(self, arg)
|
| term(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from pyidc_opaque_object_t:
|
| __dict__
@@ -66437,8 +66444,19 @@ class bookmarks_t(builtins.object)
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
| __getitem__(self, idx)
|
| __init__(self, w)
| Build an object suitable for iterating bookmarks
| associated with the specified widget.
|
| Note: all ea_t-based widgets (e.g., "IDA View-*",
| "Pseudocode-*", "Hex View-*", ...) share a common storage,
| so bookmarks can be re-used interchangeably between them
|
| __iter__(self)
|
| __len__(self)
|
| __repr__ = _swig_repr(self)
|
@@ -66458,12 +66476,11 @@ class bookmarks_t(builtins.object)
| @param e: lochist_entry_t const &
| @param ud: void *
|
| get(*args) -> 'bool'
| get(out_entry, out_desc, index, ud) -> bool
| get(*args) -> 'PyObject *'
| get(out, _index, ud) -> PyObject *
|
| @param out_entry: lochist_entry_t *
| @param out_desc: qstring *
| @param index: uint32 *
| @param out: lochist_entry_t *
| @param _index: uint32
| @param ud: void *
|
| get_desc(*args) -> 'qstring *'
@@ -66525,12 +66542,11 @@ bookmarks_t_find_index(*args) -> 'uint32'
Help on function bookmarks_t_get in module ida_moves:
bookmarks_t_get(*args) -> 'bool'
bookmarks_t_get(out_entry, out_desc, index, ud) -> bool
bookmarks_t_get(*args) -> 'PyObject *'
bookmarks_t_get(out, _index, ud) -> PyObject *
@param out_entry: lochist_entry_t *
@param out_desc: qstring *
@param index: uint32 *
@param out: lochist_entry_t *
@param _index: uint32
@param ud: void *
Help on function bookmarks_t_get_desc in module ida_moves:
@@ -91995,6 +92011,12 @@ get_processes(*args) -> 'ssize_t'
@param proclist: (C++: procinfo_vec_t *) array with information about each running process
@return: number of processes or -1 on error
Help on function get_processor_name in module idc:
get_processor_name()
Get name of the current processor
@return: processor name
Help on function get_qword in module ida_bytes:
get_qword(*args) -> 'uint64'
+64
View File
@@ -17,6 +17,8 @@
%ignore graph_location_info_t::deserialize(memory_deserializer_t &);
%ignore renderer_info_pos_t::serialize(bytevec_t *) const;
%ignore renderer_info_pos_t::deserialize(memory_deserializer_t &);
%ignore bookmarks_t_get;
%ignore bookmarks_t::get(lochist_entry_t *, qstring *, uint32 *, void *);
%template(segm_move_info_vec_t) qvector<segm_move_info_t>;
@@ -27,4 +29,66 @@
//</inline(py_moves)>
%}
%pythoncode %{
#<pycode(py_moves)>
#</pycode(py_moves)>
%}
// bookmarks_t::get
%extend bookmarks_t {
static PyObject *get(lochist_entry_t *out, uint32 _index, void *ud)
{
uint32 index = _index;
qstring desc;
return bookmarks_t::get(out, &desc, &index, ud)
? Py_BuildValue("(sI)", desc.c_str(), index)
: Py_BuildValue("(OO)", Py_None, Py_None);
}
%pythoncode {
def __init__(self, w):
"""
Build an object suitable for iterating bookmarks
associated with the specified widget.
Note: all ea_t-based widgets (e.g., "IDA View-*",
"Pseudocode-*", "Hex View-*", ...) share a common storage,
so bookmarks can be re-used interchangeably between them
"""
self.widget = w
self.userdata = ida_kernwin.get_viewer_user_data(self.widget)
self.template = lochist_entry_t()
if ida_kernwin.get_custom_viewer_location(self.template, self.widget):
p = self.template.place()
if p is not None:
p_id = ida_kernwin.get_place_class_id(p.name())
if p_id > -1 and ida_kernwin.is_place_class_ea_capable(p_id):
idap_id = ida_kernwin.get_place_class_id("idaplace_t")
if idap_id > -1:
idap = ida_kernwin.get_place_class_template(idap_id)
if idap is not None:
self.template.set_place(idap)
def __iter__(self):
p = self.template.place()
if p is not None:
for idx in range(bookmarks_t.size(self.template, self.userdata)):
yield self[idx]
def __len__(self):
return bookmarks_t.size(self.template, self.userdata)
def __getitem__(self, idx):
p = self.template.place()
if p is not None:
if isinstance(idx, int) and idx >= 0 and idx < len(self):
loc = lochist_entry_t()
loc.set_place(p)
desc, _ = bookmarks_t.get(loc, idx, self.userdata)
return loc, desc
else:
raise IndexError()
}
}
%include "moves.hpp"