mirror of
https://github.com/idapython/src
synced 2026-06-08 14:47:00 +00:00
Modernize Python 2 code to get ready for Python 3
This commit is contained in:
@@ -4,6 +4,7 @@ Original code by Bryce Boe: http://www.bryceboe.com/2010/09/01/submitting-binari
|
||||
Modified by Elias Bachaalany <elias at hex-rays.com>
|
||||
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import hashlib, httplib, mimetypes, os, pprint, simplejson, sys, urlparse
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
# -----------------------------------------------------------------------
|
||||
# This is an example illustrating how to use customview in Python
|
||||
# The sample will allow you to open an assembly file and display it in color
|
||||
@@ -192,9 +193,9 @@ class asmview_t(ida_kernwin.simplecustviewer_t, asm_colorizer_t):
|
||||
self.ClearLines()
|
||||
self.Refresh()
|
||||
elif vkey == ord('S'):
|
||||
print "Selection (x1, y1, x2, y2) = ", self.GetSelection()
|
||||
print("Selection (x1, y1, x2, y2) = ", self.GetSelection())
|
||||
elif vkey == ord('I'):
|
||||
print "Position (line, x, y) = ", self.GetPos(mouse = 0)
|
||||
print("Position (line, x, y) = ", self.GetPos(mouse = 0))
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -107,7 +107,7 @@ def CallStackWalk(nn):
|
||||
sp = idautils.cpu.Esp - word_size
|
||||
while sp < stack_seg.end_ea:
|
||||
sp += word_size
|
||||
ptr = idautils.GetDataList(sp, 1, word_size).next()
|
||||
ptr = next(idautils.GetDataList(sp, 1, word_size))
|
||||
seg = ida_segment.getseg(ptr)
|
||||
# only accept executable segments
|
||||
if (not seg) or ((seg.perm & ida_segment.SEGPERM_EXEC) == 0):
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
# -----------------------------------------------------------------------
|
||||
# Debugger command prompt with CustomViewers
|
||||
# (c) Hex-Rays
|
||||
@@ -96,7 +97,7 @@ class dbgcmd_t(ida_kernwin.simplecustviewer_t):
|
||||
def show_win():
|
||||
x = dbgcmd_t()
|
||||
if not x.Create():
|
||||
print "Failed to create debugger command line!"
|
||||
print("Failed to create debugger command line!")
|
||||
return None
|
||||
x.Show()
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ Copyright (c) 1990-2018 Hex-Rays
|
||||
ALL RIGHTS RESERVED.
|
||||
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
|
||||
@@ -54,7 +55,7 @@ def GetDriverDispatch():
|
||||
|
||||
# force reloading of module symbols
|
||||
if not CmdReloadForce():
|
||||
print "Could not communicate with WinDbg, make sure the debugger is running!"
|
||||
print("Could not communicate with WinDbg, make sure the debugger is running!")
|
||||
return None
|
||||
|
||||
# get driver list
|
||||
@@ -75,7 +76,7 @@ def GetDriverDispatch():
|
||||
tbl_out = CmdDrvObj(drvname)
|
||||
|
||||
if not tbl_out:
|
||||
print "Failed to get driver object for", drvname
|
||||
print("Failed to get driver object for", drvname)
|
||||
continue
|
||||
|
||||
# for each line
|
||||
@@ -116,4 +117,4 @@ if r:
|
||||
c = DispatchChoose("Dispatch table browser", r)
|
||||
c.Show(True)
|
||||
else:
|
||||
print "Failed to retrieve dispatchers list!"
|
||||
print("Failed to retrieve dispatchers list!")
|
||||
|
||||
@@ -6,6 +6,7 @@ Copyright (c) 1990-2009 Hex-Rays
|
||||
ALL RIGHTS RESERVED.
|
||||
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
|
||||
@@ -51,4 +52,4 @@ def main():
|
||||
|
||||
ok, r = main()
|
||||
if not ok:
|
||||
print r
|
||||
print(r)
|
||||
|
||||
@@ -16,6 +16,7 @@ The general syntax is:
|
||||
Copyright (c) 1990-2018 Hex-Rays
|
||||
ALL RIGHTS RESERVED.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
import re
|
||||
|
||||
import ida_idaapi
|
||||
@@ -73,7 +74,7 @@ def FindInstructions(instr, asm_where=None):
|
||||
bin_str = ' '.join(["%02X" % ord(x) for x in buf])
|
||||
|
||||
# find all binary strings
|
||||
print "Searching for: [%s]" % bin_str
|
||||
print("Searching for: [%s]" % bin_str)
|
||||
ea = ida_ida.cvar.inf.min_ea
|
||||
ret = []
|
||||
while True:
|
||||
@@ -154,7 +155,7 @@ def find(s=None, x=False, asm_where=None):
|
||||
c = SearchResultChoose(title, results)
|
||||
c.Show(True)
|
||||
else:
|
||||
print ret
|
||||
print(ret)
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
print "Please use find('asm_stmt1;xx yy;...', x=Bool,asm_where=ea) to search for instructions or opcodes. Specify x=true to filter out non-executable segments"
|
||||
print("Please use find('asm_stmt1;xx yy;...', x=Bool,asm_where=ea) to search for instructions or opcodes. Specify x=true to filter out non-executable segments")
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
# -----------------------------------------------------------------------
|
||||
# This is an example illustrating how to enumerate all addresses
|
||||
# that refer to all imported functions in a given module
|
||||
@@ -47,7 +48,7 @@ def find_import_ref(dllname):
|
||||
continue
|
||||
|
||||
# save results
|
||||
if not R.has_key(i):
|
||||
if i not in R:
|
||||
R[i] = []
|
||||
|
||||
R[i].append(ea)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
# -----------------------------------------------------------------------
|
||||
# This is an example illustrating how to:
|
||||
# - enumerate imports
|
||||
@@ -100,7 +101,7 @@ class ImpExpForm_t(PluginForm):
|
||||
"""
|
||||
global ImpExpForm
|
||||
del ImpExpForm
|
||||
print "Closed"
|
||||
print("Closed")
|
||||
|
||||
|
||||
def Show(self):
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import ida_kernwin
|
||||
import ida_segment
|
||||
|
||||
+8
-7
@@ -7,6 +7,7 @@ It will be easy to see what thread uses what handler and what handlers are commo
|
||||
Copyright (c) 1990-2018 Hex-Rays
|
||||
ALL RIGHTS RESERVED.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import ida_kernwin
|
||||
import ida_graph
|
||||
@@ -88,7 +89,7 @@ class SEHGraph(ida_graph.GraphViewer):
|
||||
|
||||
# Get the node id given the handler address
|
||||
# We use an addr -> id dictionary so that similar addresses get similar node id
|
||||
if not addr_id.has_key(handler):
|
||||
if handler not in addr_id:
|
||||
id = self.AddNode( (False, handler, s) )
|
||||
addr_id[handler] = id # add this ID
|
||||
else:
|
||||
@@ -113,12 +114,12 @@ class SEHGraph(ida_graph.GraphViewer):
|
||||
self.Show()
|
||||
s = "SEH chain for " + hex(value)
|
||||
t = "-" * len(s)
|
||||
print t
|
||||
print s
|
||||
print t
|
||||
print(t)
|
||||
print(s)
|
||||
print(t)
|
||||
for handler in self.result[value]:
|
||||
print "%x: %s" % (handler, self.names[handler])
|
||||
print t
|
||||
print("%x: %s" % (handler, self.names[handler]))
|
||||
print(t)
|
||||
else:
|
||||
ida_kernwin.jumpto(value)
|
||||
return True
|
||||
@@ -127,7 +128,7 @@ class SEHGraph(ida_graph.GraphViewer):
|
||||
# -----------------------------------------------------------------------
|
||||
def main():
|
||||
if not ida_idd.dbg_can_query():
|
||||
print "The debugger must be active and suspended before using this script!"
|
||||
print("The debugger must be active and suspended before using this script!")
|
||||
return
|
||||
|
||||
# Save current thread id
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ Copyright (c) 1990-2009 Hex-Rays
|
||||
ALL RIGHTS RESERVED.
|
||||
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
|
||||
@@ -81,4 +82,4 @@ def main():
|
||||
return (True, "Success!")
|
||||
r = main()
|
||||
if not r[0]:
|
||||
print r[1]
|
||||
print(r[1])
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
# -----------------------------------------------------------------------
|
||||
# VirusTotal IDA Plugin
|
||||
# By Elias Bachaalany <elias at hex-rays.com>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import os
|
||||
|
||||
@@ -8,7 +9,7 @@ def __sys(cmd, fmt=None, echo=True):
|
||||
r = []
|
||||
for cmd in [x for x in (cmd % fmt).split("\n") if len(x)]:
|
||||
if echo:
|
||||
print ">>>", cmd
|
||||
print(">>>", cmd)
|
||||
r.append((os.system(cmd), cmd))
|
||||
return r
|
||||
|
||||
@@ -48,12 +49,12 @@ void func%(n)d()
|
||||
"""
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print "usage: gen nb_calls pause_frequency"
|
||||
print("usage: gen nb_calls pause_frequency")
|
||||
sys.exit(0)
|
||||
|
||||
n = int(sys.argv[1])
|
||||
if n < 1:
|
||||
print "at least one call should be passed!"
|
||||
print("at least one call should be passed!")
|
||||
sys.exit(1)
|
||||
|
||||
m = int(sys.argv[2])
|
||||
|
||||
@@ -6,6 +6,7 @@ and returns the results in a new web browser page.
|
||||
|
||||
This script depends on the feedparser package: http://code.google.com/p/feedparser/
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
import ida_kernwin
|
||||
@@ -57,11 +58,11 @@ class msdnapihelp_plugin_t(ida_idaapi.plugin_t):
|
||||
v = ida_kernwin.get_current_viewer()
|
||||
ident, ok = ida_kernwin.get_highlight(v)
|
||||
if not ok:
|
||||
print "No identifier was highlighted"
|
||||
print("No identifier was highlighted")
|
||||
return
|
||||
|
||||
ident = self.sanitize_name(ident)
|
||||
print "Looking up '%s' in MSDN online" % ident
|
||||
print("Looking up '%s' in MSDN online" % ident)
|
||||
d = feedparser.parse(get_url(ident))
|
||||
if len(d['entries']) > 0:
|
||||
url = d['entries'][0].link
|
||||
@@ -71,7 +72,7 @@ class msdnapihelp_plugin_t(ida_idaapi.plugin_t):
|
||||
import webbrowser
|
||||
webbrowser.open_new_tab(url)
|
||||
else:
|
||||
print "API documentation not found for: %s" % ident
|
||||
print("API documentation not found for: %s" % ident)
|
||||
|
||||
|
||||
def term(self):
|
||||
|
||||
Reference in New Issue
Block a user