Python Hexrays Python Binding for IDA 6.1 & Hexrays 1.5

computerline

New member
Ida Pro Expert
I finaly compile hexrays-python successfull.

Download binary file :

Code:
https://mega.co.nz/#!sd8ARbSZ!gQeF3RqzgS_ynVR2KYxA0MIZxri1Ak5db45oiJ15gfw

Use :

Code:
# import the module in the interpreter context
import hexrays
# decompile function at 0x402010
c = hexrays.decompile(0x402010)
# print decompiled text
print str(c)
# access local variable names
print [str(v.name) for v in c.lvars]

Orginal Source :
Code:
https://github.com/EiNSTeiN-/hexrays-python
P/S : Edit link
 

Storm Shadow

Administrator
Staff member
Developer
Ida Pro Expert
Elite Cracker
got error
when putting the hexrays_python.plw in plugin folder ida stopp when loading file
Also import hexrays gives

Python>import hexrays
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\zadow\Downloads\ida\ida\python\hexrays.py", line 32, in <module>
_hexrays = swig_import_helper()
File "C:\Users´zadow\Downloads\ida\ida\python\hexrays.py", line 24, in swig_import_helper
import _hexrays
ImportError: No module named _hexrays

also i think my hexray version is version 1.1 ? only one i could track up
 

Storm Shadow

Administrator
Staff member
Developer
Ida Pro Expert
Elite Cracker
I found the 1 5 versjon:p
Still got the error thoug .where did you locate the Source for the python binding.
 

computerline

New member
Ida Pro Expert
So strangle :) I configre my system with python 27, Ida 6.1, hexrays 1.5, build using VS2010. Here my source, you can build yourself (replace your hexrays.hpp in sdk with my hexrays.hpp). Happy coding :)
Code:
http://rghost.net/52049751
 

computerline

New member
Ida Pro Expert
get some small errors when building,gonna see if its my vc setup thats screwed.
Have you seen the new build there is the wrapper also included. http://idapython.googlecode.com/svn/tags/build-1.5.6/

download with this great tool http://downloadsvn.codeplex.com/


As I known, idapython 1.5.2 is latest version that work with IDA 6.1, from 1.5.3 and above, alot of function was add to the sdk and idapython, so I can't fix that error. Unfortunate, hexrays-python was write for ida 6.3 and above, so It has some function that not work with sdk 6.1

You can show me some error, can I try to fix ?
 

computerline

New member
Ida Pro Expert
As very few example for this plugin I upload some example code :
vs01.py
Python:
""" It demonstrates how to decompile full function at current cursor position.
Author: ASUS
"""
import hexrays
import idaapi
 
def main():
  # Start hexrays plugin
  if not hexrays.init_hexrays_plugin():
	return False
 
  print "Hex-rays version %s has been detected" % hexrays.get_hexrays_version()
 
  # Get function at current screen address
  f = idaapi.get_func(idaapi.get_screen_ea());
  if f is None:
	print "Please position the cursor within a function"
	return True
 
  # Decompile whose function
  cfunc = hexrays.decompile(f);
  if cfunc is None:
	print "Failed to decompile!"
	return True
 
  # Print function as string
  print str(cfunc)
 
if main():
  # Terminate hexrays plugin
  hexrays.term_hexrays_plugin();

ex02.py

Python:
import hexrays
import idaapi
 
def main():
  if not hexrays.init_hexrays_plugin():
	return False
 
  print "Hex-rays version %s has been detected" % hexrays.get_hexrays_version()
 
  f = idaapi.get_func(idaapi.get_screen_ea());
  if f is None:
	print "Please position the cursor within a function"
	return True
  # Open pseudocode window
  vu = hexrays.open_pseudocode(idaapi.get_screen_ea(), 1);
  # Iterator thought each line of pseudocode
  for i in xrange(0, vu.sv.size()):
	# remove ida special tag
	line = idaapi.tag_remove(str(vu.sv[i]));
	# Display each line
	print "[%d] -> %s" % (i, line)
 
  return True
 
if main():
  hexrays.term_hexrays_plugin();

vs03.py
Need PySide to code work
Python:
""" Xref plugin for Hexrays Decompiler
 
Author: EiNSTeiN_ <einstein@g3nius.org>
 
Show decompiler-style Xref when the X key is pressed in the Decompiler window.
 
- It supports any global name: functions, strings, integers, etc.
- It supports structure member.
 
"""
 
import idautils
import idaapi
import idc
 
import hexrays
import traceback
 
try:
	from PyQt4 import QtCore, QtGui
	print 'Using PyQt'
except:
	print 'PyQt not available'
 
	try:
		from PySide import QtGui, QtCore
		print 'Using PySide'
	except:
		print 'PySide not available'
 
XREF_EA = 0
XREF_STRUC_MEMBER = 1
 
class XrefsForm(idaapi.PluginForm):
 
	def __init__(self, target):
 
		idaapi.PluginForm.__init__(self)
 
		self.target = target
 
		if type(self.target) == hexrays.cfunc_t:
	 
			self.__type = XREF_EA
			self.__ea = self.target.entry_ea
			self.__name = 'Xrefs of %x' % (self.__ea, )
	 
		elif type(self.target) == hexrays.cexpr_t and self.target.opname == 'obj':
	 
			self.__type = XREF_EA
			self.__ea = self.target.obj_ea
			self.__name = 'Xrefs of %x' % (self.__ea, )
 
		elif type(self.target) == hexrays.cexpr_t and self.target.opname in ('memptr', 'memref'):
	 
			self.__type = XREF_STRUC_MEMBER
			name = self.get_struc_name()
			self.__name = 'Xrefs of %s' % (name, )
 
		else:
			raise ValueError('cannot show xrefs for this kind of target')
 
		return
 
	def get_struc_name(self):
 
		x = self.target.operands['x']
		m = self.target.operands['m']
 
		xtype = typestring(x.type.u_str())
		xtype.remove_ptr_or_array()
		typename = str(xtype)
 
		sid = idc.GetStrucIdByName(typename)
		member = idc.GetMemberName(sid, m)
 
		return '%s::%s' % (typename, member)
 
	def OnCreate(self, form):
 
		# Get parent widget
		try:
			self.parent = self.FormToPySideWidget(form)
		except:
			self.parent = self.FormToPyQtWidget(form)
 
		self.populate_form()
 
		return
 
	def Show(self):
		idaapi.PluginForm.Show(self, self.__name)
		return
 
	def populate_form(self):
		# Create layout
		layout = QtGui.QVBoxLayout()
 
		layout.addWidget(QtGui.QLabel(self.__name))
		self.table = QtGui.QTableWidget()
		layout.addWidget(self.table)
 
		self.table.setColumnCount(3)
		self.table.setHorizontalHeaderItem(0, QtGui.QTableWidgetItem("Address"))
		self.table.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem("Function"))
		self.table.setHorizontalHeaderItem(2, QtGui.QTableWidgetItem("Line"))
 
		self.table.setColumnWidth(0, 80)
		self.table.setColumnWidth(1, 150)
		self.table.setColumnWidth(2, 450)
 
		self.table.cellDoubleClicked.connect(self.double_clicked)
 
		#~ self.table.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
		self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows )
		self.parent.setLayout(layout)
 
		self.populate_table()
 
		return
 
	def double_clicked(self, row, column):
 
		ea = self.functions[row]
		hexrays.open_pseudocode(ea, True)
 
		return
 
	def get_decompiled_line(self, cfunc, ea):
 
		#if ea not in cfunc.eamap:
		#	print 'strange, %x is not in %x eamap' % (ea, cfunc.entry_ea)
		#	return
 
		#insnvec = cfunc.eamap[ea]
		insnvec = hexrays.open_pseudocode(ea, 0)
		lines = []
		for stmt in insnvec.sv:
	 
			#qs = qstring()
			#qp = qstring_printer_t(cfunc.__deref__(), qs, False)
	 
			#stmt._print(0, qp)
			#s = str(qs).split('\n')[0]
		 
			#s = idaapi.tag_remove(stmt)
			lines.append(idaapi.tag_remove(str(stmt)))
 
		return '\n'.join(lines)
 
	def get_items_for_ea(self, ea):
 
		frm = [x.frm for x in idautils.XrefsTo(self.__ea)]
 
		items = []
		for ea in frm:
			try:
				cfunc = hexrays.decompile(ea)
				cfunc.refcnt += 1
		 
				self.functions.append(cfunc.entry_ea)
				self.items.append((ea, idc.GetFunctionName(cfunc.entry_ea), self.get_decompiled_line(cfunc, ea)))
		 
			except Exception as e:
				print 'could not decompile: %s' % (str(e), )
 
		return
 
	def get_items_for_type(self):
 
		x = self.target.operands['x']
		m = self.target.operands['m']
 
		xtype = typestring(x.type.u_str())
		xtype.remove_ptr_or_array()
		typename = str(xtype)
 
		addresses = []
		for ea in idautils.Functions():
	 
			try:
				cfunc = hexrays.decompile(ea)
				cfunc.refcnt += 1
			except:
				print 'Decompilation of %x failed' % (ea, )
				continue
	 
			str(cfunc)
	 
			for citem in cfunc.treeitems:
				citem = citem.to_specific_type
				if not (type(citem) == hexrays.cexpr_t and citem.opname in ('memptr', 'memref')):
					continue
		 
				_x = citem.operands['x']
				_m = citem.operands['m']
				_xtype = typestring(_x.type.u_str())
				_xtype.remove_ptr_or_array()
				_typename = str(_xtype)
		 
				#~ print 'in', hex(cfunc.entry_ea), _typename, _m
		 
				if not (_typename == typename and _m == m):
					continue
		 
				parent = citem
				while parent:
					if type(parent.to_specific_type) == hexrays.cinsn_t:
						break
					parent = cfunc.body.find_parent_of(parent)
		 
				if not parent:
					print 'cannot find parent statement (?!)'
					continue
		 
				if parent.ea in addresses:
					continue
		 
				if parent.ea == idaapi.BADADDR:
					print 'parent.ea is BADADDR'
					continue
		 
				addresses.append(parent.ea)
		 
				self.functions.append(cfunc.entry_ea)
				self.items.append((parent.ea, idc.GetFunctionName(cfunc.entry_ea), self.get_decompiled_line(cfunc, int(parent.ea))))
	 
 
		return []
 
	def populate_table(self):
 
		self.functions = []
		self.items = []
 
		if self.__type == XREF_EA:
			self.get_items_for_ea(self.__ea)
		else:
			self.get_items_for_type()
 
		self.table.setRowCount(len(self.items))
 
		i = 0
		for item in self.items:
			address, func, line = item
			item = QtGui.QTableWidgetItem('0x%x' % (address, ))
			item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable)
			self.table.setItem(i, 0, item)
			item = QtGui.QTableWidgetItem(func)
			item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable)
			self.table.setItem(i, 1, item)
			item = QtGui.QTableWidgetItem(line)
			item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable)
			self.table.setItem(i, 2, item)
	 
			i += 1
 
		self.table.resizeRowsToContents()
 
		return
 
	def OnClose(self, form):
		pass
 
class hexrays_callback_info(object):
 
	def __init__(self):
		self.vu = None
		return
 
	def show_xrefs(self, vu):
 
		vu.get_current_item(hexrays.USE_KEYBOARD)
		item = vu.item
 
		sel = None
		if item.citype == hexrays.VDI_EXPR and item.it.to_specific_type.opname in ('obj', 'memref', 'memptr'):
			# if an expression is selected. verify that it's either a cot_obj, cot_memref or cot_memptr
			sel = item.it.to_specific_type
	 
		elif item.citype == hexrays.VDI_FUNC:
			# if the function itself is selected, show xrefs to it.
			sel = item.f
		else:
			return False
 
		form = XrefsForm(sel)
		form.Show()
		return True
 
	def menu_callback(self):
		self.show_xrefs(self.vu)
		return 0
 
	def event_callback(self, event, *args):
 
		try:
			if event == hexrays.hxe_keyboard:
				vu, keycode, shift = args
		 
				if idaapi.lookup_key_code(keycode, shift, True) == idaapi.get_key_code("X") and shift == 0:
					if self.show_xrefs(vu):
						return 1
		 
			elif event == hexrays.hxe_right_click:
				self.vu = args[0]
				hexrays.add_custom_viewer_popup_item(self.vu.ct, "Xrefs", "X", self.menu_callback)
	 
		except:
			traceback.print_exc()
 
		return 0
 
i = hexrays_callback_info()
hexrays.install_hexrays_callback(i.event_callback)
vs04.py
Callback Function
Python:
""" It demonstrates how to iterate a cblock_t object.
 
Author: EiNSTeiN_ <einstein@g3nius.org>
 
This example show how to use callback in hexrays
"""
import idautils
import idaapi
import idc
import hexrays
import traceback
 
class hexrays_callback_info(object):
 
	def __init__(self):
		return
 
	def event_callback(self, event, *args):
 
		try:
			print 'Callback event trick'
			if event == hexrays.hxe_refresh_pseudocode:
				for vu in args:
					for i in range(vu.sv.size()):
						print "[%d] %s" % (i, idaapi.tag_remove(str(vu.sv[i])));
		except:
			traceback.print_exc()
 
		return 0
 
if hexrays.init_hexrays_plugin():
	print 'Plugin Init'
	i = hexrays_callback_info()
	hexrays.install_hexrays_callback(i.event_callback)
else:
	print 'cblock visitor: hexrays is not available.'
vs05.py
Python:
""" It demonstrates how to iterate a cblock_t object.
 
Author: EiNSTeiN_ <einstein@g3nius.org>
 
This is a rewrite in Python of the vds7 example that comes with hexrays sdk.
"""
 
import idautils
import idaapi
import idc
import hexrays
 
import traceback
 
class cblock_visitor_t(hexrays.ctree_visitor_t):
 
	def __init__(self):
		hexrays.ctree_visitor_t.__init__(self, hexrays.CV_FAST)
		print 'object init'
		return
 
	def visit_insn(self, ins):
		print 'visit_insn(self, ins)'
		try:
			if ins.op == hexrays.cit_block:
				print 'cit_block'
				self.dump_block(ins.ea, ins.cblock)
		except:
			traceback.print_exc()
 
		return 0
 
	def dump_block(self, ea, b):
		# iterate over all block instructions
		print "dumping block %x" % (ea, )
		for ins in b:
			print "  %x: insn %s" % (ins.ea, ins.opname)
 
		return
 
class hexrays_callback_info(object):
 
	def __init__(self):
		return
 
	def event_callback(self, event, *args):
 
		try:
			if event == hexrays.hxe_maturity:
				cfunc, maturity = args
				print 'event ocur'
				if maturity == hexrays.CMAT_BUILT:
					print 'CMAT_BUILD'
					cbv = cblock_visitor_t()
					#help(cfunc.body)
					cbv.visit_insn(cfunc.body)
   
		except:
			traceback.print_exc()
 
		return 0
 
if hexrays.init_hexrays_plugin():
	i = hexrays_callback_info()
	hexrays.install_hexrays_callback(i.event_callback)
else:
	print 'cblock visitor: hexrays is not available.'
pyprint.py
Code:
""" Python printer for Hexrays Decompiler
 
Author: EiNSTeiN_ <einstein@g3nius.org>
 
 
Prints out the AST (Syntax Tree) with a Python syntax instead of the normal C syntax.
 
* Pre/post increments or decrements are translated into "i += 1".
* For loops are translated in an equivalent while loop.
* Some names are translated, like strlen or printf, more should be added.
* Structures are printed out as classes.
 
Usage:
>>> pyprint(here()) # print current function
>>> pyprint(0x402010) # print function at specified address
"""
 
import idautils
import hexrays
 
translate_name = {
	'.strlen': 'len',
	'.printf': 'print',
	'.puts': 'print',
}
 
class printer(object):
 
	def __init__(self, cfunc, print_structures=True):
   
		self.cfunc = cfunc
   
		#~ self.structs = dict([(s[2], dict([(m[0], m[1]) for m in idautils.StructMembers(s[1])])) for s in idautils.Structs()])
   
		self.used_structs = []
   
		return
 
	def __str__(self):
   
		fct = s = '# Function: 0x%x\n' % (self.cfunc.entry_ea, )
		fct += self.do(self.cfunc)
   
		members = self.do_structs()
   
		return '%s\n\n%s' % (members, fct)
 
	def do_struct(self, name):
		s = ''
   
		sid = idc.GetStrucIdByName(name)
   
		s += 'class %s():\n' % (name, )
		s += '  def __init__(self):\n'
		for offset, name, size in idautils.StructMembers(sid):
	   
			flags = idc.GetMemberFlag(sid, offset)
			if flags & idaapi.FF_STRU == idaapi.FF_STRU:
				msid = idc.GetMemberStrId(sid, offset)
				value = idc.GetStrucName(msid)
				if value not in self.used_structs:
					self.used_structs.append(value)
			else:
				value = '0'
			s += '	self.%s = %s\n' % (name, value)
		s += '	return'
   
		return s
 
	def do_structs(self):
   
		s = ''
   
		for name in self.used_structs:
			s += self.do_struct(name)
   
		return s
 
	def do(self, obj):
   
		_indent = lambda s: '  ' + '\n  '.join(s.split('\n'))
   
		if type(obj) in (hexrays.cfuncptr_t, hexrays.cfunc_t):
			body = self.do(obj.body)[1:]
	   
			prototype = 'def %s(%s):' % (self.make_name(self.cfunc.entry_ea), \
					', '.join([str(a.name) for a in self.cfunc.arguments]))
	   
			vars = '\n'
			for lvar in obj.lvars:
				if lvar.is_arg_var:
					continue
				if not lvar.used:
					continue
				if lvar._type.is_struct:
					#~ value = '%s()' % str(lvar._type)
					vars += '  %s = %s()\n' % (lvar.name, str(lvar._type))
				else:
					vars += '  # %s %s\n' % (str(lvar._type), lvar.name, )
	   
			s = prototype + vars + body
		elif type(obj) == hexrays.cinsn_t:
	   
			if obj.op == hexrays.cit_continue:
				return 'continue'
			elif obj.op == hexrays.cit_break:
				return 'break'
	   
			s = self.do(obj.details)
	   
		elif type(obj) == hexrays.cblock_t:
	   
			lines = []
			for stmt in obj:
				lines.append(_indent(self.do(stmt)))
	   
			s = ':\n%s' % ('\n'.join(lines), )
	   
		elif type(obj) == hexrays.cif_t:
	   
			cond = self.do(obj.expr)
			ithen = self.do(obj.ithen)
			if obj.ielse:
				ielse = self.do(obj.ielse)
			else:
				ielse = None
	   
			s = 'if (%s)%s' % (cond, ithen, )
			if ielse:
				s += '\nelse%s' % (ielse, )
	   
		elif type(obj) == hexrays.cfor_t:
	   
			init = self.do(obj.init)
			body = self.do(obj.body)
			step = self.do(obj.step)
	   
			if obj.expr.op == hexrays.cot_empty:
				cond = 'True'
			else:
				cond = self.do(obj.expr)
	   
			s = '%s\nwhile (%s)%s\n%s' % (init, cond, body, _indent(step))
	   
		elif type(obj) == hexrays.cwhile_t:
	   
			cond = self.do(obj.expr)
			body = self.do(obj.body)
	   
			s = 'while (%s)%s' % (cond, body, )
	   
		elif type(obj) == hexrays.cdo_t:
	   
			cond = self.do(obj.expr)
			body = self.do(obj.body)
	   
			s = 'while True%s\n  if not (%s):\n	break' % (body, cond)
   
		elif type(obj) == hexrays.creturn_t:
	   
			s = 'return %s' % (self.do(obj.expr), )
   
		#~ elif type(obj) == hexrays.cswitch_t:
	   
		#~ elif type(obj) == hexrays.cgoto_t:
	   
		#~ elif type(obj) == hexrays.casm_t:
	   
		elif type(obj) in (hexrays.cexpr_t, hexrays.carg_t):
	   
			format = {
				hexrays.cot_comma:	'{x}, {y}',
				hexrays.cot_asg:	  '{x} = {y}',
				hexrays.cot_asgbor:  '{x} |= {y}',
				hexrays.cot_asgxor:  '{x} ^= {y}',
				hexrays.cot_asgband:  '{x} &= {y}',
				hexrays.cot_asgadd:  '{x} += {y}',
				hexrays.cot_asgsub:  '{x} -= {y}',
				hexrays.cot_asgmul:  '{x} *= {y}',
				hexrays.cot_asgsshr:  '{x} >>= {y}',
				hexrays.cot_asgushr:  '{x} >>= {y}',
				hexrays.cot_asgshl:  '{x} <<= {y}',
				hexrays.cot_asgsdiv:  '{x} /= {y}',
				hexrays.cot_asgudiv:  '{x} /= {y}',
				hexrays.cot_asgsmod:  '{x} %= {y}',
				hexrays.cot_asgumod:  '{x} %= {y}',
				hexrays.cot_tern:	'{x} ? {y} : {z}',
				hexrays.cot_lor:	  '{x} || {y}',
				hexrays.cot_land:	'{x} && {y}',
				hexrays.cot_bor:	  '{x} | {y}',
				hexrays.cot_xor:	  '{x} ^ {y}',
				hexrays.cot_band:	'{x} & {y}',
				hexrays.cot_eq:	  '{x} == {y}',
				hexrays.cot_ne:	  '{x} != {y}',
				hexrays.cot_sge:	  '{x} >= {y}',
				hexrays.cot_uge:	  '{x} >= {y}',
				hexrays.cot_sle:	  '{x} <= {y}',
				hexrays.cot_ule:	  '{x} <= {y}',
				hexrays.cot_sgt:	  '{x} >  {y}',
				hexrays.cot_ugt:	  '{x} >  {y}',
				hexrays.cot_slt:	  '{x} <  {y}',
				hexrays.cot_ult:	  '{x} <  {y}',
				hexrays.cot_sshr:	'{x} >> {y}',
				hexrays.cot_ushr:	'{x} >> {y}',
				hexrays.cot_shl:	  '{x} << {y}',
				hexrays.cot_add:	  '{x} + {y}',
				hexrays.cot_sub:	  '{x} - {y}',
				hexrays.cot_mul:	  '{x} * {y}',
				hexrays.cot_sdiv:	'{x} / {y}',
				hexrays.cot_udiv:	'{x} / {y}',
				hexrays.cot_smod:	'{x} % {y}',
				hexrays.cot_umod:	'{x} % {y}',
				hexrays.cot_fadd:	'{x} + {y}',
				hexrays.cot_fsub:	'{x} - {y}',
				hexrays.cot_fmul:	'{x} * {y}',
				hexrays.cot_fdiv:	'{x} / {y}',
				hexrays.cot_fneg:	'-{x}',
				hexrays.cot_neg:	  '-{x}',
				hexrays.cot_lnot:	'!{x}',
				hexrays.cot_bnot:	'~{x}',
				hexrays.cot_ptr:	  '*{x}',
				hexrays.cot_ref:	  '&{x}',
				hexrays.cot_postinc:  '{x} += 1',
				hexrays.cot_postdec:  '{x} -= 1',
				hexrays.cot_preinc:  '{x} += 1',
				hexrays.cot_predec:  '{x} -= 1',
				hexrays.cot_call:	'{x}({a})',
				hexrays.cot_idx:	  '{x}[{y}]',
				hexrays.cot_num:	  '{n}',
				hexrays.cot_fnum:	'{fpc}',
				hexrays.cot_str:	  '{string}',
				hexrays.cot_var:	  '{v}',
				hexrays.cot_sizeof:  'sizeof({x})',
				hexrays.cot_helper:  '{helper}',
				hexrays.cot_cast:	'{x}',
			}
	   
			#~ hexrays.cot_memref:  '{x}.{m}',
			#~ hexrays.cot_memptr:  '{x}->{m}',
			#~ hexrays.cot_obj:	  '{obj_ea}',
	   
			if obj.op in format:
		   
				operands = obj.operands
				for name in operands:
			   
					if type(operands[name]) == hexrays.cnumber_t:
				   
						operands[name] = operands[name].value(obj.type)
				   
					else:
						operands[name] = self.do(operands[name])
				s = format[obj.op].format(**operands)
		   
			elif obj.op == hexrays.cot_obj:
		   
				s = self.make_name(obj.obj_ea)
		   
			elif obj.op in (hexrays.cot_memptr, hexrays.cot_memref):
		   
				x = obj.operands['x']
				m = obj.operands['m']
		   
				xtype = typestring(x.type.u_str())
				xtype.remove_ptr_or_array()
				typename = str(xtype)
		   
				sid = idc.GetStrucIdByName(str(xtype))
				if not sid:
					print 'error getting structure %s' % (repr(typename), )
					member = 'field_%x' % (m, )
				else:
					member = idc.GetMemberName(sid, m)
					if not member:
						member = 'field_%x' % (m, )
					else:
						if typename not in self.used_structs:
							self.used_structs.append(typename)
		   
				name = self.do(x)
		   
				s = '{x}.{m}'.format(x=name, m=member)
		   
			elif obj.op == hexrays.cot_empty:
				s = ''
			else:
				s = '<%s>' % (repr(obj.opname), )
   
		elif type(obj) == hexrays.var_ref_t:
	   
			s = self.cfunc.lvars[obj.idx].name
   
		elif type(obj) == hexrays.typestring:
	   
			s = str(obj)
   
		elif type(obj) == hexrays.carglist_t:
	   
			s = ', '.join([self.do(v) for v in obj])
   
		else:
	   
			print 'I do not know how to print object type %s' % (obj.__class__.__name__, )
			return ''
   
		return s
 
	def make_name(self, ea):
   
   
		if idaapi.get_func(ea) is None:
	   
			try:
				s = idc.GetString(ea)
				if s:
					return repr(s)
			except:
				pass
   
		names = dict(idautils.Names())
   
		name = names.get(ea)
		if name:
			if name in translate_name:
				name = translate_name[name]
		else:
			name = 'loc_%x' % (ea, )
   
		return name
 
def here():
	return idaapi.get_screen_ea()
 
def pyprint(ea):
 
	c = hexrays.decompile(ea)
	c.refcnt += 1
 
	p = printer(c)
	s = str(p)
 
	return s
 
Last edited by a moderator:

Storm Shadow

Administrator
Staff member
Developer
Ida Pro Expert
Elite Cracker
not sure why but when loading lets say a arm file ida hangs up, when removing your plugin the arm files loads fine again.(hexrays_python.plw)
 

computerline

New member
Ida Pro Expert
I think we need to check for this plugin is only run on x86 or x64, it does not support for work with hexrays for arm

Code:
//-------------------------------------------------------------------------
// Plugin init routine
int idaapi init(void)
{
if((strncmp(inf.procName, "metapc", 6) == 0) && (inf.filetype == f_PE))
{
if ( HexraysPython_Init() )
   return PLUGIN_KEEP;
}
	return PLUGIN_SKIP;
}
 
//-------------------------------------------------------------------------
// Plugin term routine
void idaapi term(void)
{
if (g_initialized)
{
HexraysPython_Term();
}
}

Code:
https://mega.co.nz/#!JVFQ2LCK!0t9mNJRWsCpnjtHEgU28woeafouFohR_Mh8mS60QR8Y

P/S: I reviewed source and apply some bug fix
 
Last edited by a moderator:
Top