2010-03-22 15:19:43 +01:00
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# This is an example illustrating how to use customview in Python
|
|
|
|
# (c) Hex-Rays
|
|
|
|
#
|
|
|
|
import idaapi
|
|
|
|
import idc
|
2010-03-25 12:52:03 +01:00
|
|
|
from idaapi import simplecustviewer_t
|
|
|
|
#<pycode(py_custviewerex1)>
|
2010-03-22 15:19:43 +01:00
|
|
|
|
2015-02-08 03:59:53 +01:00
|
|
|
class say_something_handler_t(idaapi.action_handler_t):
|
|
|
|
def __init__(self, thing):
|
|
|
|
idaapi.action_handler_t.__init__(self)
|
|
|
|
self.thing = thing
|
|
|
|
|
|
|
|
def activate(self, ctx):
|
|
|
|
print self.thing
|
|
|
|
|
|
|
|
def update(self, ctx):
|
|
|
|
return idaapi.AST_ENABLE_ALWAYS
|
|
|
|
|
|
|
|
|
2010-03-22 15:19:43 +01:00
|
|
|
# -----------------------------------------------------------------------
|
2010-03-25 12:52:03 +01:00
|
|
|
class mycv_t(simplecustviewer_t):
|
2010-03-22 15:19:43 +01:00
|
|
|
def Create(self, sn=None):
|
|
|
|
# Form the title
|
|
|
|
title = "Simple custom view test"
|
|
|
|
if sn:
|
|
|
|
title += " %d" % sn
|
2010-03-25 12:52:03 +01:00
|
|
|
|
2010-06-28 14:36:40 +02:00
|
|
|
# Create the customviewer
|
2010-03-25 12:52:03 +01:00
|
|
|
if not simplecustviewer_t.Create(self, title):
|
2010-03-22 15:19:43 +01:00
|
|
|
return False
|
2010-03-25 12:52:03 +01:00
|
|
|
|
2010-03-22 15:19:43 +01:00
|
|
|
for i in xrange(0, 100):
|
|
|
|
self.AddLine("Line %d" % i)
|
2010-03-25 12:52:03 +01:00
|
|
|
|
2010-06-28 14:36:40 +02:00
|
|
|
# self.Jump(0)
|
|
|
|
|
2010-03-22 15:19:43 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
def OnClick(self, shift):
|
|
|
|
"""
|
|
|
|
User clicked in the view
|
|
|
|
@param shift: Shift flag
|
2010-10-07 11:47:04 +02:00
|
|
|
@return: Boolean. True if you handled the event
|
2010-03-22 15:19:43 +01:00
|
|
|
"""
|
|
|
|
print "OnClick, shift=%d" % shift
|
|
|
|
return True
|
|
|
|
|
|
|
|
def OnDblClick(self, shift):
|
|
|
|
"""
|
|
|
|
User dbl-clicked in the view
|
|
|
|
@param shift: Shift flag
|
2010-10-07 11:47:04 +02:00
|
|
|
@return: Boolean. True if you handled the event
|
2010-03-22 15:19:43 +01:00
|
|
|
"""
|
2010-03-25 12:52:03 +01:00
|
|
|
word = self.GetCurrentWord()
|
|
|
|
if not word: word = "<None>"
|
|
|
|
print "OnDblClick, shift=%d, current word=%s" % (shift, word)
|
2010-03-22 15:19:43 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
def OnCursorPosChanged(self):
|
|
|
|
"""
|
|
|
|
Cursor position changed.
|
2010-10-07 11:47:04 +02:00
|
|
|
@return: Nothing
|
2010-03-22 15:19:43 +01:00
|
|
|
"""
|
|
|
|
print "OnCurposChanged"
|
|
|
|
|
|
|
|
def OnClose(self):
|
|
|
|
"""
|
|
|
|
The view is closing. Use this event to cleanup.
|
2010-10-07 11:47:04 +02:00
|
|
|
@return: Nothing
|
2010-03-22 15:19:43 +01:00
|
|
|
"""
|
|
|
|
print "OnClose " + self.title
|
|
|
|
|
|
|
|
def OnKeydown(self, vkey, shift):
|
|
|
|
"""
|
|
|
|
User pressed a key
|
|
|
|
@param vkey: Virtual key code
|
|
|
|
@param shift: Shift flag
|
2010-10-07 11:47:04 +02:00
|
|
|
@return: Boolean. True if you handled the event
|
2010-03-22 15:19:43 +01:00
|
|
|
"""
|
|
|
|
print "OnKeydown, vk=%d shift=%d" % (vkey, shift)
|
|
|
|
# ESCAPE?
|
|
|
|
if vkey == 27:
|
|
|
|
self.Close()
|
2010-06-28 14:36:40 +02:00
|
|
|
# VK_DELETE
|
2010-03-22 15:19:43 +01:00
|
|
|
elif vkey == 46:
|
|
|
|
n = self.GetLineNo()
|
2010-03-25 12:52:03 +01:00
|
|
|
if n is not None:
|
|
|
|
self.DelLine(n)
|
|
|
|
self.Refresh()
|
|
|
|
print "Deleted line %d" % n
|
2010-03-22 15:19:43 +01:00
|
|
|
# Goto?
|
|
|
|
elif vkey == ord('G'):
|
2010-03-25 12:52:03 +01:00
|
|
|
n = self.GetLineNo()
|
|
|
|
if n is not None:
|
|
|
|
v = idc.AskLong(self.GetLineNo(), "Where to go?")
|
|
|
|
if v:
|
|
|
|
self.Jump(v, 0, 5)
|
2010-03-22 15:19:43 +01:00
|
|
|
elif vkey == ord('R'):
|
|
|
|
print "refreshing...."
|
|
|
|
self.Refresh()
|
|
|
|
elif vkey == ord('C'):
|
|
|
|
print "refreshing current line..."
|
|
|
|
self.RefreshCurrent()
|
|
|
|
elif vkey == ord('A'):
|
|
|
|
s = idc.AskStr("NewLine%d" % self.Count(), "Append new line")
|
|
|
|
self.AddLine(s)
|
|
|
|
self.Refresh()
|
|
|
|
elif vkey == ord('X'):
|
|
|
|
print "Clearing all lines"
|
|
|
|
self.ClearLines()
|
|
|
|
self.Refresh()
|
|
|
|
elif vkey == ord('I'):
|
|
|
|
n = self.GetLineNo()
|
|
|
|
s = idc.AskStr("InsertedLine%d" % n, "Insert new line")
|
|
|
|
self.InsertLine(n, s)
|
|
|
|
self.Refresh()
|
|
|
|
elif vkey == ord('E'):
|
|
|
|
l = self.GetCurrentLine(notags=1)
|
|
|
|
if not l:
|
|
|
|
return False
|
|
|
|
n = self.GetLineNo()
|
|
|
|
print "curline=<%s>" % l
|
|
|
|
l = l + idaapi.COLSTR("*", idaapi.SCOLOR_VOIDOP)
|
|
|
|
self.EditLine(n, l)
|
|
|
|
self.RefreshCurrent()
|
|
|
|
print "Edited line %d" % n
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def OnHint(self, lineno):
|
|
|
|
"""
|
|
|
|
Hint requested for the given line number.
|
|
|
|
@param lineno: The line number (zero based)
|
|
|
|
@return:
|
2010-06-28 14:36:40 +02:00
|
|
|
- tuple(number of important lines, hint string)
|
2010-03-22 15:19:43 +01:00
|
|
|
- None: if no hint available
|
|
|
|
"""
|
2010-06-28 14:36:40 +02:00
|
|
|
return (1, "OnHint, line=%d" % lineno)
|
2010-03-22 15:19:43 +01:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
try:
|
|
|
|
# created already?
|
|
|
|
mycv
|
|
|
|
print "Already created, will close it..."
|
|
|
|
mycv.Close()
|
|
|
|
del mycv
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def show_win():
|
|
|
|
x = mycv_t()
|
|
|
|
if not x.Create():
|
|
|
|
print "Failed to create!"
|
|
|
|
return None
|
|
|
|
x.Show()
|
2015-02-08 03:59:53 +01:00
|
|
|
tcc = x.GetTCustomControl()
|
|
|
|
|
|
|
|
# Register actions
|
|
|
|
for thing in ["Hello", "World"]:
|
|
|
|
actname = "custview:say_%s" % thing
|
|
|
|
idaapi.register_action(
|
|
|
|
idaapi.action_desc_t(actname, "Say %s" % thing, say_something_handler_t(thing)))
|
|
|
|
idaapi.attach_action_to_popup(tcc, None, actname)
|
2010-03-22 15:19:43 +01:00
|
|
|
return x
|
2015-02-08 03:59:53 +01:00
|
|
|
|
2010-03-22 15:19:43 +01:00
|
|
|
mycv = show_win()
|
|
|
|
if not mycv:
|
|
|
|
del mycv
|
|
|
|
|
|
|
|
def make_many(n):
|
2010-03-25 12:52:03 +01:00
|
|
|
L = []
|
2010-03-22 15:19:43 +01:00
|
|
|
for i in xrange(1, n+1):
|
2010-03-25 12:52:03 +01:00
|
|
|
v = mycv_t()
|
|
|
|
if not v.Create(i):
|
2010-03-22 15:19:43 +01:00
|
|
|
break
|
2010-03-25 12:52:03 +01:00
|
|
|
v.Show()
|
|
|
|
L.append(v)
|
|
|
|
return L
|
2010-03-22 15:19:43 +01:00
|
|
|
|
2010-03-25 12:52:03 +01:00
|
|
|
#</pycode(py_custviewerex1)>
|