Skip to content

Commit

Permalink
update range selection for IDA disassembly views to facilitate revert…
Browse files Browse the repository at this point in the history
…ing individual instructions.

this aligns with the current / intended behavior of the patch preview UI.

related to #5
  • Loading branch information
gaasedelen committed Aug 17, 2024
1 parent c4bad44 commit fa9e0a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugins/patching/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
class PatchingCore(object):

PLUGIN_NAME = 'Patching'
PLUGIN_VERSION = '0.1.2'
PLUGIN_VERSION = '0.2.0-DEV'
PLUGIN_AUTHORS = 'Markus Gaasedelen'
PLUGIN_DATE = '2022'
PLUGIN_DATE = '2024'

def __init__(self, defer_load=False):

Expand Down
40 changes: 39 additions & 1 deletion plugins/patching/util/ida.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,45 @@ def read_range_selection(ctx):
# return the range of selected lines
return (True, start_ea, end_ea)

# normal IDA view
# special tweak for IDA disassembly views
elif ida_kernwin.get_widget_type(ctx.widget) == ida_kernwin.BWN_DISASM:

# extract the start/end cursor locations within the IDA disas view
p0 = ida_kernwin.twinpos_t()
p1 = ida_kernwin.twinpos_t()

#
# this is where we do a special override such that a user can select a
# few characters on a single instruction / line .. and we will return
# the 'range' of just that single instruction
#
# with a few characters selected / highlighted, IDA will return True
# to the read_selection() call below
#

if ida_kernwin.read_selection(ctx.widget, p0, p1):
start_ea = p0.at.toea()
end_ea = p1.at.toea()

#
# if the start and end address are the same with a successful
# selection read, that means the user's selection is on a single
# line / instruction
#
# we will calculate an appropriate 'end_ea' ourselves to capture
# the length of the entire instruction and return this as our own
# custom / mini range selection
#
# this facilitates the ability for users to reverst individual
# instructions within a patch by selecting a few characters of
# the instruction in question
#

if start_ea == end_ea:
end_ea = ida_bytes.get_item_end(end_ea)
return (True, start_ea, end_ea)

# any other IDA widget / viewer
return ida_kernwin.read_range_selection(ctx.widget)

def remove_ida_actions(popup):
Expand Down

0 comments on commit fa9e0a5

Please sign in to comment.