Rizin
unix-like reverse engineering framework and cli tools
capstone.CsInsn Class Reference
Inheritance diagram for capstone.CsInsn:

Public Member Functions

def __init__ (self, cs, all_info)
 
def __repr__ (self)
 
def id (self)
 
def address (self)
 
def size (self)
 
def bytes (self)
 
def mnemonic (self)
 
def op_str (self)
 
def regs_read (self)
 
def regs_write (self)
 
def groups (self)
 
def __getattr__ (self, name)
 
def errno (self)
 
def reg_name (self, reg_id, default=None)
 
def insn_name (self, default=None)
 
def group_name (self, group_id, default=None)
 
def group (self, group_id)
 
def reg_read (self, reg_id)
 
def reg_write (self, reg_id)
 
def op_count (self, op_type)
 
def op_find (self, op_type, position)
 
def regs_access (self)
 

Public Attributes

 operands
 

Private Member Functions

def __gen_detail (self)
 

Private Attributes

 _raw
 
 _cs
 

Detailed Description

Definition at line 530 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

def capstone.CsInsn.__init__ (   self,
  cs,
  all_info 
)

Definition at line 531 of file __init__.py.

531  def __init__(self, cs, all_info):
532  self._raw = copy_ctypes(all_info)
533  self._cs = cs
534  if self._cs._detail and self._raw.id != 0:
535  # save detail
536  self._raw.detail = ctypes.pointer(all_info.detail._type_())
537  ctypes.memmove(ctypes.byref(self._raw.detail[0]), ctypes.byref(all_info.detail[0]), ctypes.sizeof(type(all_info.detail[0])))
538 
int type
Definition: mipsasm.c:17
def copy_ctypes(src)
Definition: __init__.py:320

Member Function Documentation

◆ __gen_detail()

def capstone.CsInsn.__gen_detail (   self)
private

Definition at line 625 of file __init__.py.

625  def __gen_detail(self):
626  if self._raw.id == 0:
627  # do nothing in skipdata mode
628  return
629 
630  arch = self._cs.arch
631  if arch == CS_ARCH_ARM:
632  (self.usermode, self.vector_size, self.vector_data, self.cps_mode, self.cps_flag, self.cc, self.update_flags, \
633  self.writeback, self.mem_barrier, self.operands) = arm.get_arch_info(self._raw.detail.contents.arch.arm)
634  elif arch == CS_ARCH_ARM64:
635  (self.cc, self.update_flags, self.writeback, self.operands) = \
636  arm64.get_arch_info(self._raw.detail.contents.arch.arm64)
637  elif arch == CS_ARCH_X86:
638  (self.prefix, self.opcode, self.rex, self.addr_size, \
639  self.modrm, self.sib, self.disp, \
640  self.sib_index, self.sib_scale, self.sib_base, self.xop_cc, self.sse_cc, \
641  self.avx_cc, self.avx_sae, self.avx_rm, self.eflags, \
642  self.modrm_offset, self.disp_offset, self.disp_size, self.imm_offset, self.imm_size, \
643  self.operands) = x86.get_arch_info(self._raw.detail.contents.arch.x86)
644  elif arch == CS_ARCH_M68K:
645  (self.operands, self.op_size) = m68k.get_arch_info(self._raw.detail.contents.arch.m68k)
646  elif arch == CS_ARCH_MIPS:
647  self.operands = mips.get_arch_info(self._raw.detail.contents.arch.mips)
648  elif arch == CS_ARCH_PPC:
649  (self.bc, self.bh, self.update_cr0, self.operands) = \
650  ppc.get_arch_info(self._raw.detail.contents.arch.ppc)
651  elif arch == CS_ARCH_SPARC:
652  (self.cc, self.hint, self.operands) = sparc.get_arch_info(self._raw.detail.contents.arch.sparc)
653  elif arch == CS_ARCH_SYSZ:
654  (self.cc, self.operands) = systemz.get_arch_info(self._raw.detail.contents.arch.sysz)
655  elif arch == CS_ARCH_XCORE:
656  (self.operands) = xcore.get_arch_info(self._raw.detail.contents.arch.xcore)
657  elif arch == CS_ARCH_TMS320C64X:
658  (self.condition, self.funit, self.parallel, self.operands) = tms320c64x.get_arch_info(self._raw.detail.contents.arch.tms320c64x)
659  elif arch == CS_ARCH_M680X:
660  (self.flags, self.operands) = m680x.get_arch_info(self._raw.detail.contents.arch.m680x)
661  elif arch == CS_ARCH_EVM:
662  (self.pop, self.push, self.fee) = evm.get_arch_info(self._raw.detail.contents.arch.evm)
663 
664 

References capstone.CsInsn._cs, capstone.CsInsn._raw, rz_il_vm_t.addr_size, capstone.X86.UnionOpInfo.addr_size, cs_x86.addr_size, capstone.X86.UnionOpInfo.avx_cc, cs_x86.avx_cc, capstone.X86.UnionOpInfo.avx_rm, cs_x86.avx_rm, capstone.X86.UnionOpInfo.avx_sae, cs_x86.avx_sae, rz_analysis_function_t.cc, rz_callable_at.cc, ppc_alias.cc, capstone.Arm.UnionOpInfo.cc, capstone.Arm.OpInfo.cc, capstone.Arm64.UnionOpInfo.cc, capstone.Arm64.OpInfo.cc, capstone.Sparc.UnionOpInfo.cc, capstone.Sparc.OpInfo.cc, capstone.Systemz.UnionOpInfo.cc, capstone.Systemz.OpInfo.cc, cs_arm.cc, cs_arm64.cc, cs_sparc.cc, cs_sysz.cc, capstone.Arm.UnionOpInfo.cps_flag, cs_arm.cps_flag, capstone.Arm.UnionOpInfo.cps_mode, cs_arm.cps_mode, rz_analysis_op_t.disp, capstone.Arm.MemType.disp, capstone.Arm64.MemType.disp, capstone.Mips.MemType.disp, capstone.Ppc.MemType.disp, capstone.Sparc.MemType.disp, capstone.Systemz.MemType.disp, capstone.X86.MemType.disp, capstone.X86.UnionOpInfo.disp, capstone.X86.OpInfo.disp, capstone.Xcore.MemType.disp, arm_op_mem.disp, arm64_op_mem.disp, m68k_op_mem.disp, m68k_op_br_disp.disp, mips_op_mem.disp, ppc_op_mem.disp, sparc_op_mem.disp, sysz_op_mem.disp, tms320c64x_op_mem.disp, x86_op_mem.disp, cs_x86.disp, xcore_op_mem.disp, cs_x86_encoding.disp_offset, m68k_op_br_disp.disp_size, cs_x86_encoding.disp_size, x86_thread_state32.eflags, user_regs_struct_x86_64.eflags, user_regs_struct_x86_32.eflags, match.eflags, capstone.X86.UnionOpInfo.eflags, capstone.X86.OpInfo.eflags, cs_x86.eflags, cs_x86_encoding.imm_offset, cs_x86_encoding.imm_size, MCInst.imm_size, capstone.Arm.UnionOpInfo.mem_barrier, cs_arm.mem_barrier, capstone.X86.UnionOpInfo.modrm, capstone.X86.OpInfo.modrm, cs_x86.modrm, cs_x86_encoding.modrm_offset, cs_m68k.op_size, arc_fields_t.opcode, _pic_midrange_op_analysis_info.opcode, aarch64_opcode.opcode, aarch64_inst.opcode, Opcode_t.opcode, avr_decoder_t.opcode, op_code.opcode, op_basic.opcode, op_nbasic.opcode, HexInsn.opcode, powerpc_opcode.opcode, tricore_opcode.opcode, pcp_opcode.opcode, xtensa_lookup_entry_struct.opcode, _jasm.opcode, bytecode_t.opcode, lh5801_insn_desc.opcode, lh5801_insn.opcode, msp430_cmd.opcode, _nios2_opcode_hash.opcode, insn_extra_t.opcode, insn_t.opcode, ps_opcode_t.opcode, propeller_cmd.opcode, rsp_instruction_priv.opcode, rsp_instruction.opcode, sh_op_raw_t.opcode, sh_opcode_t.opcode, sparc_opcode_hash.opcode, tms320_dasm_t.opcode, decoded_insn.opcode, lookup_t.opcode, rz_analysis_addr_hint_record_t.opcode, rz_analysis_hint_t.opcode, RzBinDwarfLineOp.opcode, InternalInstruction.opcode, capstone.X86.UnionOpInfo.opcode, capstone.X86.OpInfo.opcode, cs_x86.opcode, powerpc_macro.operands, xtensa_iclass_internal_struct.operands, xtensa_isa_internal_struct.operands, cs_mips.operands, msp430_cmd.operands, InternalInstruction.operands, cs_sparc.operands, ppcps_t.operands, cs_sysz.operands, powerpc_opcode.operands, InstructionSpecifier.operands, capstone.CsInsn.operands, cs_arm.operands, amd29k_instr_s.operands, ps_opcode_t.operands, cs_arm64.operands, cs_ppc.operands, cs_tms320c64x.operands, cs_x86.operands, cs_xcore.operands, aarch64_opcode.operands, aarch64_inst.operands, cr16_cmd.operands, ebc_command.operands, h8300_cmd.operands, insn_type_descr_t.operands, cs_m680x.operands, cs_m68k.operands, Opcode_t.operands, propeller_cmd.operands, rsp_instruction.operands, v810_cmd.operands, v850_cmd.operands, CILOpcodeReader.prefix, bfd_elf_special_section.prefix, propeller_cmd.prefix, rz_analysis_op_t.prefix, rz_bin_t.prefix, capstone.X86.UnionOpInfo.prefix, capstone.X86.OpInfo.prefix, tar_header.prefix, cs_x86.prefix, capstone.X86.UnionOpInfo.rex, capstone.X86.OpInfo.rex, cs_x86.rex, InternalInstruction.sib, capstone.X86.UnionOpInfo.sib, capstone.X86.OpInfo.sib, cs_x86.sib, capstone.X86.UnionOpInfo.sib_base, cs_x86.sib_base, capstone.X86.UnionOpInfo.sib_index, cs_x86.sib_index, capstone.X86.UnionOpInfo.sib_scale, cs_x86.sib_scale, capstone.X86.UnionOpInfo.sse_cc, cs_x86.sse_cc, capstone.Arm.UnionOpInfo.update_flags, cs_arm.update_flags, cs_arm64.update_flags, capstone.Arm.UnionOpInfo.usermode, capstone.Arm.OpInfo.usermode, cs_arm.usermode, capstone.Arm.UnionOpInfo.vector_data, cs_arm.vector_data, capstone.Arm.UnionOpInfo.vector_size, cs_arm.vector_size, aarch64_opnd_info.writeback, aarch64_opnd_info::.writeback, Opcode_t.writeback, capstone.Arm.UnionOpInfo.writeback, capstone.Arm.OpInfo.writeback, capstone.Arm64.OpInfo.writeback, cs_arm.writeback, cs_arm64.writeback, MCInst.writeback, capstone.X86.UnionOpInfo.xop_cc, and cs_x86.xop_cc.

Referenced by capstone.CsInsn.__getattr__().

◆ __getattr__()

def capstone.CsInsn.__getattr__ (   self,
  name 
)

Definition at line 665 of file __init__.py.

665  def __getattr__(self, name):
666  if not self._cs._detail:
667  raise CsError(CS_ERR_DETAIL)
668 
669  attr = object.__getattribute__
670  if not attr(self, '_cs')._detail:
671  raise AttributeError(name)
672  _dict = attr(self, '__dict__')
673  if 'operands' not in _dict:
674  self.__gen_detail()
675  if name not in _dict:
676  if self._raw.id == 0:
677  raise CsError(CS_ERR_SKIPDATA)
678  raise AttributeError(name)
679  return _dict[name]
680 

References capstone.CsInsn.__gen_detail(), capstone.CsInsn._cs, and capstone.CsInsn._raw.

◆ __repr__()

def capstone.CsInsn.__repr__ (   self)

Definition at line 539 of file __init__.py.

539  def __repr__(self):
540  return '<CsInsn 0x%x [%s]: %s %s>' % (self.address, self.bytes.hex(), self.mnemonic, self.op_str)
541 
static const char hex[16]
Definition: print.c:21

References dwarf_var_location_t.address, ExtAuxRegister.address, property_table_entry_t.address, reloc_cache_entry.address, rz_xnu_kernelcache_parsed_pointer_t.address, cache_map_t.address, cache_img_t.address, cache_mapping_slide.address, _RzParsedPointer.address, rz_analysis_type_alloca_t.address, rz_analysis_esil_t.address, rz_bin_source_line_sample_t.address, RzBinDwarfState.address, dwarf_attr_kind.address, RzBinDwarfSMRegisters.address, rz_il_vm_event_mem_read_t.address, rz_il_vm_event_mem_write_t.address, _PPA.address, diff_function_t.address, capstone.M680x.OpRelative.address, capstone.M680x.OpExtended.address, capstone.CsInsn.address(), m680x_op_rel.address, m680x_op_ext.address, MCInst.address, uv_interface_address_s.address, _HeapBlockBasicInfo.address, rz_test_asm_test_t.bytes, rz_test_asm_test_output_t.bytes, mcore_t.bytes, go_string_recover_t.bytes, rz_asm_code_t.bytes, rz_bp_arch_t.bytes, rz_reg_arena_t.bytes, capstone.CsInsn.bytes(), Length.bytes, hex, amd29k_instr_s.mnemonic, amd29k_instruction_s.mnemonic, Opcode_t.mnemonic, avr_opcode_t.mnemonic, _pic_baseline_op.mnemonic, _pic_midrange_op.mnemonic, rsp_instruction_priv.mnemonic, rsp_instruction.mnemonic, sh_op_raw_t.mnemonic, sh_opcode_t.mnemonic, lookup_t.mnemonic, rz_analysis_op_t.mnemonic, RzPseudoGrammar.mnemonic, capstone.CsInsn.mnemonic(), customized_mnem.mnemonic, cs_opt_mnem.mnemonic, and capstone.CsInsn.op_str().

◆ address()

def capstone.CsInsn.address (   self)

Definition at line 549 of file __init__.py.

549  def address(self):
550  return self._raw.address
551 

References capstone.CsInsn._raw.

Referenced by capstone.CsInsn.__repr__().

◆ bytes()

def capstone.CsInsn.bytes (   self)

Definition at line 559 of file __init__.py.

559  def bytes(self):
560  return bytearray(self._raw.bytes)[:self._raw.size]
561 
static ut8 bytes[32]
Definition: asm_arc.c:23

References capstone.CsInsn._raw.

Referenced by capstone.CsInsn.__repr__().

◆ errno()

def capstone.CsInsn.errno (   self)

Definition at line 682 of file __init__.py.

682  def errno(self):
683  return _cs.cs_errno(self._cs.csh)
684 

References capstone.CsInsn._cs.

Referenced by capstone.CsError.__str__().

◆ group()

def capstone.CsInsn.group (   self,
  group_id 
)

Definition at line 714 of file __init__.py.

714  def group(self, group_id):
715  if self._raw.id == 0:
716  raise CsError(CS_ERR_SKIPDATA)
717 
718  if self._cs._diet:
719  # Diet engine cannot provide group information
720  raise CsError(CS_ERR_DIET)
721 
722  return group_id in self.groups
723 

References capstone.CsInsn._cs, capstone.CsInsn._raw, capstone.CsInsn.groups(), m68k_info.groups, insn_map.groups, and index_stream.groups.

◆ group_name()

def capstone.CsInsn.group_name (   self,
  group_id,
  default = None 
)

Definition at line 705 of file __init__.py.

705  def group_name(self, group_id, default=None):
706  if self._cs._diet:
707  # Diet engine cannot provide group name
708  raise CsError(CS_ERR_DIET)
709 
710  return _ascii_name_or_default(_cs.cs_group_name(self._cs.csh, group_id), default)
711 
712 
def _ascii_name_or_default(name, default)
Definition: __init__.py:525

References capstone._ascii_name_or_default(), and capstone.CsInsn._cs.

◆ groups()

def capstone.CsInsn.groups (   self)

Definition at line 612 of file __init__.py.

612  def groups(self):
613  if self._raw.id == 0:
614  raise CsError(CS_ERR_SKIPDATA)
615 
616  if self._cs._diet:
617  # Diet engine cannot provide @groups
618  raise CsError(CS_ERR_DIET)
619 
620  if self._cs._detail:
621  return self._raw.detail.contents.groups[:self._raw.detail.contents.groups_count]
622 
623  raise CsError(CS_ERR_DETAIL)
624 

References capstone.CsInsn._cs, and capstone.CsInsn._raw.

Referenced by capstone.CsInsn.group().

◆ id()

def capstone.CsInsn.id (   self)

Definition at line 544 of file __init__.py.

544  def id(self):
545  return self._raw.id
546 
int id
Definition: op.c:540

References capstone.CsInsn._raw.

Referenced by capstone.CsInsn.insn_name().

◆ insn_name()

◆ mnemonic()

def capstone.CsInsn.mnemonic (   self)

Definition at line 564 of file __init__.py.

564  def mnemonic(self):
565  if self._cs._diet:
566  # Diet engine cannot provide @mnemonic.
567  raise CsError(CS_ERR_DIET)
568 
569  return self._raw.mnemonic.decode('ascii')
570 
mnemonic
Definition: z80asm.h:48

References capstone.CsInsn._cs, and capstone.CsInsn._raw.

Referenced by capstone.CsInsn.__repr__().

◆ op_count()

◆ op_find()

◆ op_str()

def capstone.CsInsn.op_str (   self)

Definition at line 573 of file __init__.py.

573  def op_str(self):
574  if self._cs._diet:
575  # Diet engine cannot provide @op_str.
576  raise CsError(CS_ERR_DIET)
577 
578  return self._raw.op_str.decode('ascii')
579 

References capstone.CsInsn._cs, and capstone.CsInsn._raw.

Referenced by capstone.CsInsn.__repr__().

◆ reg_name()

def capstone.CsInsn.reg_name (   self,
  reg_id,
  default = None 
)

Definition at line 686 of file __init__.py.

686  def reg_name(self, reg_id, default=None):
687  if self._cs._diet:
688  # Diet engine cannot provide register name
689  raise CsError(CS_ERR_DIET)
690 
691  return _ascii_name_or_default(_cs.cs_reg_name(self._cs.csh, reg_id), default)
692 

References capstone._ascii_name_or_default(), and capstone.CsInsn._cs.

◆ reg_read()

def capstone.CsInsn.reg_read (   self,
  reg_id 
)

Definition at line 725 of file __init__.py.

725  def reg_read(self, reg_id):
726  if self._raw.id == 0:
727  raise CsError(CS_ERR_SKIPDATA)
728 
729  if self._cs._diet:
730  # Diet engine cannot provide regs_read information
731  raise CsError(CS_ERR_DIET)
732 
733  return reg_id in self.regs_read
734 

References capstone.CsInsn._cs, capstone.CsInsn._raw, capstone.CsInsn.regs_read(), and m68k_info.regs_read.

◆ reg_write()

def capstone.CsInsn.reg_write (   self,
  reg_id 
)

Definition at line 736 of file __init__.py.

736  def reg_write(self, reg_id):
737  if self._raw.id == 0:
738  raise CsError(CS_ERR_SKIPDATA)
739 
740  if self._cs._diet:
741  # Diet engine cannot provide regs_write information
742  raise CsError(CS_ERR_DIET)
743 
744  return reg_id in self.regs_write
745 

References capstone.CsInsn._cs, capstone.CsInsn._raw, capstone.CsInsn.regs_write(), and m68k_info.regs_write.

◆ regs_access()

def capstone.CsInsn.regs_access (   self)

Definition at line 771 of file __init__.py.

771  def regs_access(self):
772  if self._raw.id == 0:
773  raise CsError(CS_ERR_SKIPDATA)
774 
775  regs_read = (ctypes.c_uint16 * 64)()
776  regs_read_count = ctypes.c_uint8()
777  regs_write = (ctypes.c_uint16 * 64)()
778  regs_write_count = ctypes.c_uint8()
779 
780  status = _cs.cs_regs_access(self._cs.csh, self._raw, ctypes.byref(regs_read), ctypes.byref(regs_read_count), ctypes.byref(regs_write), ctypes.byref(regs_write_count))
781  if status != CS_ERR_OK:
782  raise CsError(status)
783 
784  if regs_read_count.value > 0:
785  regs_read = regs_read[:regs_read_count.value]
786  else:
787  regs_read = ()
788 
789  if regs_write_count.value > 0:
790  regs_write = regs_write[:regs_write_count.value]
791  else:
792  regs_write = ()
793 
794  return (regs_read, regs_write)
795 
796 
797 

References capstone.CsInsn._cs, and capstone.CsInsn._raw.

◆ regs_read()

def capstone.CsInsn.regs_read (   self)

Definition at line 582 of file __init__.py.

582  def regs_read(self):
583  if self._raw.id == 0:
584  raise CsError(CS_ERR_SKIPDATA)
585 
586  if self._cs._diet:
587  # Diet engine cannot provide @regs_read.
588  raise CsError(CS_ERR_DIET)
589 
590  if self._cs._detail:
591  return self._raw.detail.contents.regs_read[:self._raw.detail.contents.regs_read_count]
592 
593  raise CsError(CS_ERR_DETAIL)
594 

References capstone.CsInsn._cs, and capstone.CsInsn._raw.

Referenced by capstone.CsInsn.reg_read().

◆ regs_write()

def capstone.CsInsn.regs_write (   self)

Definition at line 597 of file __init__.py.

597  def regs_write(self):
598  if self._raw.id == 0:
599  raise CsError(CS_ERR_SKIPDATA)
600 
601  if self._cs._diet:
602  # Diet engine cannot provide @regs_write
603  raise CsError(CS_ERR_DIET)
604 
605  if self._cs._detail:
606  return self._raw.detail.contents.regs_write[:self._raw.detail.contents.regs_write_count]
607 
608  raise CsError(CS_ERR_DETAIL)
609 

References capstone.CsInsn._cs, and capstone.CsInsn._raw.

Referenced by capstone.CsInsn.reg_write().

◆ size()

def capstone.CsInsn.size (   self)

Definition at line 554 of file __init__.py.

554  def size(self):
555  return self._raw.size
556 
voidpf void uLong size
Definition: ioapi.h:138

References capstone.CsInsn._raw.

Member Data Documentation

◆ _cs

◆ _raw

◆ operands

capstone.CsInsn.operands

The documentation for this class was generated from the following file: