Skip to content
This repository was archived by the owner on Nov 19, 2018. It is now read-only.

Commit 608538d

Browse files
author
elias.bachaalany
committed
- IDA Pro 6.1 support
- Added AskUsingForm() with embedded forms support (check ex_askusingform.py example and formchooser.py in the SDK) - Added idautils.DecodePreviousInstruction() / DecodePrecedingInstruction() - Added idc.BeginTypeUpdating() / EndTypeUpdating() for fast batch type update operations - Added more IDP callbacks - Added UI_Hooks with a few notification events - Added idaapi.process_ui_action() / idc.ProcessUiAction() - Added netnode.index() to get netnode number - Better handling of ea_t values with bitwise negation - Execute statement hotkey (Ctrl-F3), script timeout, and other options are now configurable with Python.cfg - bugfix: idaapi.msg() / error() and warning() so they don't accept vararg - bugfix: processor_t.id constants were incorrect - bugfix: get_debug_names() was broken with IDA64 - Various bugfixes
1 parent a753d07 commit 608538d

47 files changed

Lines changed: 9239 additions & 4769 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGES.txt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
11
Please see http://code.google.com/p/idapython/source/list for a detailed list of changes.
22

3+
4+
Changes from version 1.4.3 to 1.5.0
5+
------------------------------------
6+
- IDA Pro 6.1 support
7+
- Added AskUsingForm() with embedded forms support (check ex_askusingform.py example and formchooser.py in the SDK)
8+
- Added idautils.DecodePreviousInstruction() / DecodePrecedingInstruction()
9+
- Added idc.BeginTypeUpdating() / EndTypeUpdating() for fast batch type update operations
10+
- Added more IDP callbacks
11+
- Added UI_Hooks with a few notification events
12+
- Added idaapi.process_ui_action() / idc.ProcessUiAction()
13+
- Added netnode.index() to get netnode number
14+
- Better handling of ea_t values with bitwise negation
15+
- Execute statement hotkey (Ctrl-F3), script timeout, and other options are now configurable with Python.cfg
16+
- bugfix: idaapi.msg() / error() and warning() so they don't accept vararg
17+
- bugfix: processor_t.id constants were incorrect
18+
- bugfix: get_debug_names() was broken with IDA64
19+
- Various bugfixes
20+
321
Changes from version 1.4.2 to 1.4.3
422
------------------------------------
5-
- IDA 6.0 support
23+
- IDA Pro 6.0 support
624
- Python CLI now prints expression evaluation result (no need to use print())
725
- Changed Alt-8 to Ctrl-F3 (because it conflicts with window switching key Alt+n)
826
- Added get_highlighted_identifier()
927
- Added PluginForm class to allow UI development with either PyQt4 or PySide
1028
- Added idautils.Entries() to enum entrypoints
1129

30+
1231
Changes from version 1.4.1 to 1.4.2
1332
------------------------------------
1433
- Added command completion
1534
- Added necessary changes so it compiles with Python 2.7
1635
- Wrapped set_user_defined_prefix()
1736

37+
1838
Changes from version 1.4.0 to 1.4.1
1939
------------------------------------
2040
- Added cli_t
2141
- Added idaapi.ph to access current process fields
2242
- Changed the copyright string to IDAPython Team
2343
- Some platform dependant classes are present but useable only where applicable
2444

45+
2546
Changes from version 1.3.0 to 1.4.0
2647
------------------------------------
2748
- IDA Pro 5.7 support
@@ -35,17 +56,16 @@ Changes from version 1.3.0 to 1.4.0
3556
- Documented all manually wrapped functions (check 'pywraps' module in the docs)
3657
- Lots of cleanups and fixes
3758

59+
3860
Changes from version 1.2.0 to 1.3.0
3961
------------------------------------
40-
4162
- IDA Pro 5.6 support
4263
- Added Appcall mechanism
4364
- Added procregs to idautils.py (r254)
4465
- Lots of cleanups and fixes
4566

4667
Changes from version 1.1.0 to 1.2.0
4768
------------------------------------
48-
4969
- 64-bit support (largely untested)
5070
- IDA Pro 5.5 support
5171
- Long running (or inifinitely looping) scripts can now be stopped
@@ -58,7 +78,6 @@ Changes from version 1.1.0 to 1.2.0
5878

5979
Changes from version 0.9.0 to 1.0.0
6080
-----------------------------------
61-
6281
- Upgraded IDA Pro base version to 5.1
6382
- Dropped Python 2.4 support
6483
- Mac OS X support
@@ -76,7 +95,6 @@ Changes from version 0.9.0 to 1.0.0
7695

7796
Changes from version 0.8.0 to 0.9.0
7897
-----------------------------------
79-
8098
- Upgraded base version to IDA Pro 5.0
8199
- Works with IDA Pro 5.1
82100
- Python 2.4 and 2.5 supported
@@ -92,7 +110,6 @@ Changes from version 0.8.0 to 0.9.0
92110

93111
Changes from version 0.7.0 to 0.8.0
94112
-----------------------------------
95-
96113
- Added support for IDA Pro 4.9
97114
- Dropped support for IDA Pro 4.7
98115
- NOTE: Windows version is linked against Python 2.4.

README.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ Mailing list for the project is hosted by Google Groups at
3838
INSTALLATION FROM BINARIES
3939
--------------------------
4040

41-
1. Install Python 2.5 or 2.6 from http://www.python.org/
42-
2. Copy the python and python64 directories to the IDA install directory
43-
3. Copy the plugins to the %IDADIR%\plugins\
44-
41+
1. Install 2.6 or 2.7 from http://www.python.org/
42+
2. Copy "python" directory to %IDADIR%
43+
3. Copy "plugins" directory to the %IDADIR%\plugins\
44+
4. Copy "python.cfg" to %IDADIR%\cfg
4545

4646
USAGE
4747
-----
@@ -88,3 +88,4 @@ or
8888

8989
The user init file is read and executed at the end of the init process.
9090

91+
Please note that IDAPython can be configured with "python.cfg" file.

Scripts/AsmViewer.py

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# -----------------------------------------------------------------------
2+
# This is an example illustrating how to use customview in Python
3+
# The sample will allow you to open an assembly file and display it in color
4+
# (c) Hex-Rays
5+
#
6+
import idaapi
7+
import idautils
8+
import idc
9+
import os
10+
11+
# ----------------------------------------------------------------------
12+
class asm_colorizer_t(object):
13+
def is_id(self, ch):
14+
return ch == '_' or ch.isalpha() or '0' <= ch <= '9'
15+
16+
def get_identifier(self, line, x, e):
17+
i = x
18+
is_digit = line[i].isdigit()
19+
while i < e:
20+
ch = line[i]
21+
if not self.is_id(ch):
22+
if ch != '.' or not is_digit:
23+
break
24+
i += 1
25+
return (i, line[x:i])
26+
27+
def get_quoted_string(self, line, x, e):
28+
quote = line[x]
29+
i = x + 1
30+
while i < e:
31+
ch = line[i]
32+
if ch == '\\' and line[i+1] == quote:
33+
i += 1
34+
elif ch == quote:
35+
i += 1 # also take the quote
36+
break
37+
i += 1
38+
return (i, line[x:i])
39+
40+
def colorize(self, lines):
41+
for line in lines:
42+
line = line.rstrip()
43+
if not line:
44+
self.add_line()
45+
continue
46+
x = 0
47+
e = len(line)
48+
s = ""
49+
while x < e:
50+
ch = line[x]
51+
# String?
52+
if ch == '"' or ch == "'":
53+
x, w = self.get_quoted_string(line, x, e)
54+
s += self.as_string(w)
55+
# Tab?
56+
elif ch == '\t':
57+
s += ' ' * 4
58+
x += 1
59+
# Comment?
60+
elif ch == ';':
61+
s += self.as_comment(line[x:])
62+
# Done with this line
63+
break
64+
elif ch == '.' and x + 1 < e:
65+
x, w = self.get_identifier(line, x + 1, e)
66+
s += self.as_directive(ch + w)
67+
# Identifiers?
68+
elif self.is_id(ch):
69+
x, w = self.get_identifier(line, x, e)
70+
# Number?
71+
if ch.isdigit():
72+
s += self.as_num(w)
73+
# Other identifier
74+
else:
75+
s += self.as_id(w)
76+
# Output as is
77+
else:
78+
s += ch
79+
x += 1
80+
self.add_line(s)
81+
82+
# -----------------------------------------------------------------------
83+
class asmview_t(idaapi.simplecustviewer_t, asm_colorizer_t):
84+
def Create(self, fn):
85+
# Create the customview
86+
if not idaapi.simplecustviewer_t.Create(self, "Viewing file - %s" % os.path.basename(fn)):
87+
return False
88+
89+
self.instruction_list = idautils.GetInstructionList()
90+
self.instruction_list.extend(["ret"])
91+
self.register_list = idautils.GetRegisterList()
92+
self.register_list.extend(["eax", "ebx", "ecx", "edx", "edi", "esi", "ebp", "esp"])
93+
94+
self.fn = fn
95+
if not self.reload_file():
96+
return False
97+
98+
self.id_refresh = self.AddPopupMenu("Refresh")
99+
self.id_close = self.AddPopupMenu("Close")
100+
101+
return True
102+
103+
def reload_file(self):
104+
if not self.colorize_file(self.fn):
105+
self.Close()
106+
return False
107+
return True
108+
109+
def colorize_file(self, fn):
110+
try:
111+
f = open(fn, "r")
112+
lines = f.readlines()
113+
f.close()
114+
self.ClearLines()
115+
self.colorize(lines)
116+
return True
117+
except:
118+
return False
119+
120+
def add_line(self, s=None):
121+
if not s:
122+
s = ""
123+
self.AddLine(s)
124+
125+
def as_comment(self, s):
126+
return idaapi.COLSTR(s, idaapi.SCOLOR_RPTCMT)
127+
128+
def as_id(self, s):
129+
t = s.lower()
130+
if t in self.register_list:
131+
return idaapi.COLSTR(s, idaapi.SCOLOR_REG)
132+
elif t in self.instruction_list:
133+
return idaapi.COLSTR(s, idaapi.SCOLOR_INSN)
134+
else:
135+
return s
136+
137+
def as_string(self, s):
138+
return idaapi.COLSTR(s, idaapi.SCOLOR_STRING)
139+
140+
def as_num(self, s):
141+
return idaapi.COLSTR(s, idaapi.SCOLOR_NUMBER)
142+
143+
def as_directive(self, s):
144+
return idaapi.COLSTR(s, idaapi.SCOLOR_KEYWORD)
145+
146+
def OnPopupMenu(self, menu_id):
147+
"""
148+
A context (or popup) menu item was executed.
149+
@param menu_id: ID previously registered with AddPopupMenu()
150+
@return: Boolean
151+
"""
152+
if self.id_refresh == menu_id:
153+
return self.reload_file()
154+
elif self.id_close == menu_id:
155+
self.Close()
156+
return True
157+
return False
158+
159+
def OnKeydown(self, vkey, shift):
160+
"""
161+
User pressed a key
162+
@param vkey: Virtual key code
163+
@param shift: Shift flag
164+
@return Boolean. True if you handled the event
165+
"""
166+
# ESCAPE
167+
if vkey == 27:
168+
self.Close()
169+
elif vkey == ord('H'):
170+
lineno = self.GetLineNo()
171+
if lineno is not None:
172+
line, fg, bg = self.GetLine(lineno)
173+
if line and line[0] != idaapi.SCOLOR_INV:
174+
s = idaapi.SCOLOR_INV + line + idaapi.SCOLOR_INV
175+
self.EditLine(lineno, s, fg, bg)
176+
self.Refresh()
177+
elif vkey == ord('C'):
178+
self.ClearLines()
179+
self.Refresh()
180+
elif vkey == ord('S'):
181+
print "Selection (x1, y1, x2, y2) = ", self.GetSelection()
182+
elif vkey == ord('I'):
183+
print "Position (line, x, y) = ", self.GetPos(mouse = 0)
184+
else:
185+
return False
186+
return True
187+
188+
# -----------------------------------------------------------------------
189+
class asmviewplg(idaapi.plugin_t):
190+
flags = idaapi.PLUGIN_KEEP
191+
comment = "ASM viewer"
192+
help = "This is help"
193+
wanted_name = "ASM file viewer"
194+
wanted_hotkey = "Alt-F8"
195+
def __init__(self):
196+
self.view = None
197+
198+
def init(self):
199+
return idaapi.PLUGIN_KEEP
200+
def run(self, arg):
201+
if self.view:
202+
self.Close()
203+
fn = idc.AskFile(0, "*.asm", "Select ASM file to view")
204+
if not fn:
205+
return
206+
self.view = asmview_t()
207+
if not self.view.Create(fn):
208+
return
209+
self.view.Show()
210+
211+
def term(self):
212+
if self.view:
213+
self.view.Close()
214+
215+
def PLUGIN_ENTRY():
216+
return asmviewplg()

0 commit comments

Comments
 (0)