jump_next_comment

summary: implement a “jump to next comment” action within IDA’s listing

description:

We want our action not only to find the next line containing a comment, but to also place the cursor at the right horizontal position.

To find that position, we will have to inspect the text that IDA generates, looking for the start of a comment. However, we won’t be looking for a comment “prefix” (e.g., “; “), as that would be too fragile.

Instead, we will look for special “tags” that IDA injects into textual lines, and that bear semantic information.

Those tags are primarily used for rendering (i.e., switching colors), but can also be very handy for spotting tokens of interest (registers, addresses, comments, prefixes, instruction mnemonics, …)

keywords: idaview, actions

see_also: save_and_restore_listing_pos

level: intermediate

Attributes

ACTION_NAME

ACTION_LABEL

ACTION_SHORTCUT

ACTION_HELP

Classes

jump_next_comment_ah_t

Functions

find_comment_visual_position_in_tagged_line(line)

We'll look for tags for all types of comments, and if

jump_next_comment(v)

Starting at the current line, keep generating lines until

Module Contents

jump_next_comment.find_comment_visual_position_in_tagged_line(line)

We’ll look for tags for all types of comments, and if found return the visual position of the tag in the line (using ‘ida_lines.tag_strlen’)

jump_next_comment.jump_next_comment(v)

Starting at the current line, keep generating lines until a comment is found. When this happens, position the viewer at the right coordinates.

class jump_next_comment.jump_next_comment_ah_t

Bases: ida_kernwin.action_handler_t

activate(ctx)

Activate an action. This function implements the core behavior of an action. It is called when the action is triggered, from a menu, from a popup menu, from the toolbar, or programmatically.

Returns:

non-zero: all IDA windows will be refreshed

update(ctx)

Update an action. This is called when the context of the UI changed, and we need to let the action update some of its properties if needed (label, icon, …) In addition, this lets IDA know whether the action is enabled, and when it should be queried for availability again. Note: This callback is not meant to change anything in the application’s state, except by calling one (or many) of the “update_action_*()” functions on this very action.

jump_next_comment.ACTION_NAME = 'jump_next_comment:jump'
jump_next_comment.ACTION_LABEL = 'Jump to the next comment'
jump_next_comment.ACTION_SHORTCUT = 'Ctrl+Alt+C'
jump_next_comment.ACTION_HELP = 'Press Ctrl+Alt+C to jump to the next comment'