Python Plugin crazy

Storm Shadow

Administrator
Staff member
Developer
Ida Pro Expert
Elite Cracker
Any one know if its possible to add a Menu to top Menu.

As off now i can only add to like in the script to debuggers menu.

By the way this script is pretty easy to add as many functions as you like.

Just add ekstra extensions under
Code:
 idaapi.add_menu_item("Debugger/", "ZAdow: Connect Blocks!", "", 0, self.ZadowConnectBlocks, ())
Place in plugin folder and run via edit plugin.

Python:
import re
 
import idaapi
from idaapi import loader_t
from idaapi import *
from idautils import *
from idc import *
 
from PySide import QtGui
 
 
class ZadowFuncSelector(Choose2):
    ''' Choose '''
   
    def __init__(self, title, items, icon, parent, embedded = False):
        Choose2.__init__(self, title, [["Address", 12], ["Functions", 30]], embedded = embedded)
        self.items = items
        self.icon = icon
        self.parent = parent
        self.g_origin = None
        self.g_destination = None
 
       
    def GetItems(self):
        return self.items
 
   
    def SetItems(self, items):
        self.items = [] if items is None else items
 
       
    def OnClose(self):
        pass
 
   
    def OnGetLine(self, n):
        return self.items[n]
 
   
    def OnGetSize(self):
        return len(self.items)
 
   
    def OnSelectLine(self, n):
        # Callback for double-clicks
        pass
 
   
    def OnCommand(self, n, cmd_id):
        if cmd_id == self.cmd_origin:
            # mark as source
            self.g_origin = self.items[n][1]
            print "[info] Graph origin: %s" % self.g_origin
        elif cmd_id == self.cmd_dst:
            # mark as destination
            self.g_destination = self.items[n][1]
            print "[info] Graph destination: %s" % self.g_destination
        elif cmd_id == self.cmd_graph:
            # Graph it!
            print "[info] Creating Graph: %s -> %s" % (self.g_origin, self.g_destination)
            gc = self.parent.ia.connect_graph(self.g_origin, self.g_destination)
            if gc:
                gv = ConnectGraph(gc)
                gv.Show()             
        else:
            print "[info] Command not understood"
       
        return True
   
   
    def show(self):
        # It replaces the native Show() method
        t = self.Show()
        if t < 0:
            return False
        else:
            # Add some context menus :)
            self.cmd_origin = self.AddCommand("Set as origin")
            self.cmd_dst = self.AddCommand("Set as destination")
            self.cmd_graph = self.AddCommand("Graph it")
            return True
           
class Zadow(idaapi.plugin_t):
    flags = idaapi.PLUGIN_UNL
    comment = "This is a comment"
 
    help = "This is help"
    wanted_name = "Zadows cocktail"
    wanted_hotkey = "Alt-F8"
 
    def init(self):
        idaapi.msg("For fuck sake plugin is found. \n")
        return idaapi.PLUGIN_OK
 
    def run(self, arg):
        idaapi.msg("run() called with %d!\n" % arg)
 
    def term(self):
        idaapi.msg("")
   
    def AddMenuElements(self):
        '''Menus are better than no GUI at all *sigh*'''
       
        idaapi.add_menu_item("Debugger/", "Zadow: Connect Graph", "Ctrl+F8", 0, self.ZadowConnGraph, ())
        idaapi.add_menu_item("Debugger/", "ZAdow: Connect Blocks!", "", 0, self.ZadowConnectBlocks, ())   
##      idaapi.add_menu_item("/", "ZAdow: Run El spesiale!", "", 1, self._idaapi.load_binary_file, ()) '''
       
    def run(self, arg = 0):
        idaapi.msg("You did it Hombre. \n")
        idaapi.msg("Hombre you are runnig good.\n")
       
       
# Some menus are in order!
        self.AddMenuElements()
       
    def ZadowConnGraph(self):       
        # Love lambda functions :)
        moduleFunctions = [[hex(x), GetFunctionName(x)] for x in Functions()]
        ZadowFuncSelector("Select Functions to Connect", moduleFunctions, self.icon_id, parent = self).show()   
 
    def ZadowConnectBlocks(self):
        if self.src_basic_block and self.dst_basic_block:
            self.ia.function_bb_connect(self.src_basic_block, self.dst_basic_block)
            print "[Info] Drawing conn-+ect graph..."
        else:
            print "[Info] Check that you selected all parameters"
       
        return True   
       
 
 
       
       
 
def PLUGIN_ENTRY():
    return Zadow()
:cool:
 

Storm Shadow

Administrator
Staff member
Developer
Ida Pro Expert
Elite Cracker
i would recommend coding in IDLE, appently notepad++ fill whitespaces/blancspaces wrong, with error when you are runing the code.
 
Top