Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pinksawtooth committed Jan 13, 2017
1 parent 55e4190 commit 4ca13e7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ida_plugin/nao.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
I referred to the following code
http://www.hexblog.com/?p=119
"""

#!/usr/bin/env python2.7
# coding: UTF-8

Expand Down Expand Up @@ -80,7 +85,7 @@ def colorize(self, lines):
self.add_line(s)


class AsmView(idaapi.simplecustviewer_t, AsmColorizer):
class Plug_UI(idaapi.simplecustviewer_t, AsmColorizer):
def Create(self):
ea = ScreenEA()
if not idaapi.simplecustviewer_t.Create(self, '%s - nao' % (idc.GetFunctionName(ScreenEA()))):
Expand All @@ -89,14 +94,14 @@ def Create(self):
self.instruction_list.extend(['ret'])
self.register_list = idautils.GetRegisterList()
self.register_list.extend(['eax', 'ebx', 'ecx', 'edx', 'edi', 'esi', 'ebp', 'esp'])

f = idaapi.get_func(ScreenEA())
self.fc = idaapi.FlowChart(f)
self.block_list = []
for block in self.fc:
self.block_list.append(format(block.startEA, 'x').upper())

self.reload_file(ea)
self.load(ea)

self.id_jmp = self.AddPopupMenu('Jump')

Expand All @@ -109,13 +114,13 @@ def jump(self):
if str_addr == search_addr:
self.Jump(i, 0, 0)

def reload_file(self, ea):
if not self.colorize_file(ea):
def load(self, ea):
if not self.deadcode_eliminate(ea):
self.Close()
return False
return True

def colorize_file(self, ea):
def deadcode_eliminate(self, ea):
instruction_list = []
address_list = list(FuncItems(ea))
lines = ''
Expand Down Expand Up @@ -192,18 +197,18 @@ def OnPopupMenu(self, menu_id):
return False

def create_view():
view = AsmView()
view = Plug_UI()
view.Create()
view.Show()
print 'eliminated!!'

def main():
ex_addmenu_item_ctx = idaapi.add_menu_item('Edit/', 'eliminate dead code', 'Shift-D', 0, create_view, ())
if ex_addmenu_item_ctx is None:
print('Failed to add menu!')
print('Failed to add nao!')

else:
print('Menu added successfully.')
print('nao added successfully.')

return True

Expand Down

0 comments on commit 4ca13e7

Please sign in to comment.