xzlwbl / idapython

Automatically exported from code.google.com/p/idapython
Other
0 stars 0 forks source link

op_t::n field is exposed as str; should be int #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
0. Click an x86 instruction.
1. idaapi.decode_insn(idaapi.get_screen_ea())
2. op = idaapi.get_instruction_operand(idaapi.cvar.cmd, 0)
3. print op.n, type(op.n)

What is the expected output? What do you see instead?
Expected: 0 <type 'int'>
Actual: <type 'str'>

SWIG seems to be confused by the use of type char for the n field. I have a 
wrapper class that fixes the problem:
class Operand(object):
  '''An operand.
  Thin wrapper to work around an IDAPython bug: SWIG thinks the "n" field 
of
  op_t is a string because it has type char.
  '''
  def __init__(self, op):
    self.op = op
    self.n = ord(op.n)

  def to_ida(self):
    return self.op

  def __getattr__(self, attribute):
    return getattr(self.op, attribute)

  def __cmp__(self, op):
    return cmp(self.op, op.op)

What version of the product are you using? On what operating system?
IDAPython 1.1.92 shipped with 32-bit IDA 5.5.0.925 on Windows 7.

Please provide any additional information below.

Original issue reported on code.google.com by evilspor...@gmail.com on 13 Jul 2009 at 5:22

GoogleCodeExporter commented 9 years ago
Fixed. All char members of op_t and insn_t are now converted as integers.

http://code.google.com/p/idapython/source/detail?r=210
http://code.google.com/p/idapython/source/detail?r=209

Original comment by gergely.erdelyi on 21 Jul 2009 at 6:47