Skip to content

Commit

Permalink
Commit for 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lwerdna committed Aug 20, 2023
1 parent a071835 commit 4843ef9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
20 changes: 0 additions & 20 deletions keypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
font_mono = QFont('Courier New')
font_mono.setStyleHint(QFont.TypeWriter)


# ------------------------------------------------------------------------------
# utilities
# ------------------------------------------------------------------------------
Expand All @@ -132,7 +131,6 @@ def bv_to_arch(bview):

return bview.arch.name


# test if given address is valid binaryview address
def is_valid_addr(bview, addr):
# if the binaryview has sections, validity is whether the address is in a section
Expand All @@ -148,7 +146,6 @@ def is_valid_addr(bview, addr):
else:
return addr >= bview.start and addr < (bview.start + len(bview))


# given a valid address, return least address after the valid that is invalid
def get_invalid_addr(bview, addr):
if not is_valid_addr(bview, addr):
Expand All @@ -166,7 +163,6 @@ def get_invalid_addr(bview, addr):
else:
return bview.start + len(bv)


# disassemble using binaryninja
# returns (<instruction_string>, <instruction_length>)
def disassemble_binja_single(bview, addr):
Expand All @@ -185,7 +181,6 @@ def disassemble_binja_single(bview, addr):
strs = [' ' if s.isspace() else s for s in strs]
return (''.join(strs), length)


# disassemble using capstone
# returns (<instruction_string>, <instruction_length>)
# returns (None, None) if unable to disassemble
Expand All @@ -206,7 +201,6 @@ def disassemble_capstone_single(bview, addr):
# fixed bug , <instruction_length> is 'size',not 'length'
return (mnemonic + ' ' + op_str, size)


# disassemble data using capstone
# returns (<instruction_string>, <instruction_length>)
# returns (None, None) if unable to disassemble
Expand All @@ -221,27 +215,22 @@ def disassemble_capstone_single_data(bview, data, addr):
return (None, None)
return (mnemonic + ' ' + op_str, size)


# get length of instruction at addr
# returns None if unable to disassemble
def disassemble_length(bview, addr):
(instxt, length) = disassemble_binja_single(bview, addr)
return length


def error(msg):
show_message_box('KEYPATCH', msg, MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.ErrorIcon)


# b'\xaa\xbb\xcc\xdd' -> 'AA BB CC DD'
def bytes_to_str(data):
return ' '.join(['%02X' % x for x in data])


def strbytes_pretty(string):
return ' '.join(['%02X' % ord(x) for x in string])


def fixup(bview, assembly):
reserved = arch_to_reserved[bv_to_arch(bview)]

Expand Down Expand Up @@ -283,7 +272,6 @@ def fixup(bview, assembly):
# done
return assembly


# arch is keystone namespace
def get_nop(arch):
if arch in ['x16', 'x32', 'x64', 'x16att', 'x32att', 'x64att', 'x16nasm', 'x32nasm', 'x64nasm']:
Expand Down Expand Up @@ -313,7 +301,6 @@ def get_nop(arch):

raise Exception('no NOP for architecture: %s' % arch)


# ------------------------------------------------------------------------------
# GUI
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -479,7 +466,6 @@ def re_assemble(self):
except Exception as e:
self.error(str(e))

# Add a new function
# update the self.qle_data.text() and self.qle_fixedup.text() through self.edit_bytes.text()
def re_disassemble(self):
try:
Expand Down Expand Up @@ -537,7 +523,6 @@ def error(self, msg):
self.qle_data.setText(msg)
self.qle_data.home(True)


# ------------------------------------------------------------------------------
# fill range tool
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -671,7 +656,6 @@ def interval(self):
return errval
return (a, b, b - a)

# Add a new function
# get the left, right, and length(size) of the entered fill interval
# calculate right through left and length(size)
def interval_by_size_change(self):
Expand Down Expand Up @@ -771,7 +755,6 @@ def preview(self):

self.qle_preview.home(True)

# Add a new function
def preview_by_size_change(self):
(st, ed, fill_len) = self.interval_by_size_change()
if not fill_len: return None
Expand Down Expand Up @@ -816,7 +799,6 @@ def fill(self):
# print('writing 0x%X bytes to 0x%X' % (len(data), left))
self.bv.write(left, data)


# ------------------------------------------------------------------------------
# search tool
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -929,7 +911,6 @@ def results_clicked(self, item):
addr = int(m.group(1), 16)
self.bv.navigate(self.bv.view, addr)


# ------------------------------------------------------------------------------
# top level tab gui
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -961,7 +942,6 @@ def __init__(self, context, parent=None):
self.tab1.setFocus()
self.tab1.qle_assembly.setFocus()


# ------------------------------------------------------------------------------
# exported functions
# ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"capstone"
]
},
"version": "1.4",
"version": "1.5",
"minimumbinaryninjaversion": 2660
}

0 comments on commit 4843ef9

Please sign in to comment.