def __init__(self, *args, **kwargs): """Supported forms: * AESKEYGENASSIST(xmm, xmm/m128, imm8) [AES] """ origin = kwargs.get("origin") prototype = kwargs.get("prototype") if origin is None and prototype is None and peachpy.x86_64.options.get_debug_level( ) > 0: origin = inspect.stack() super(AESKEYGENASSIST, self).__init__("AESKEYGENASSIST", origin=origin, prototype=prototype) self.operands = tuple(map(check_operand, args)) if len(self.operands) != 3: raise SyntaxError( "Instruction \"AESKEYGENASSIST\" requires 3 operands") self.go_name = "AESKEYGENASSIST" self.in_regs = (False, True, False) self.out_regs = (True, False, False) self.out_operands = (True, False, False) self.avx_mode = False self.isa_extensions = frozenset([peachpy.x86_64.isa.aes]) if is_xmm(self.operands[0]) and is_xmm(self.operands[1]) and is_imm( self.operands[2]): if not is_imm8(self.operands[2]): raise ValueError("Argument #2 can not be encoded as imm8") self.encodings.append((0x20, lambda op, rex=False: bytearray( [0x66]) + optional_rex(op[0].hcode, op[1], rex) + bytearray([ 0x0F, 0x3A, 0xDF, 0xC0 | op[0].lcode << 3 | op[1].lcode, op[2] & 0xFF ]))) elif is_xmm(self.operands[0]) and is_m128(self.operands[1]) and is_imm( self.operands[2]): if not is_imm8(self.operands[2]): raise ValueError("Argument #2 can not be encoded as imm8") self.encodings.append( (0x30, lambda op, rex=False, sib=False, min_disp=0: bytearray( [0x66]) + optional_rex(op[0].hcode, op[1].address, rex) + bytearray([0x0F, 0x3A, 0xDF]) + modrm_sib_disp( op[0].lcode, op[1].address, sib, min_disp) + bytearray( [op[2] & 0xFF]))) else: raise SyntaxError( "Invalid operand types: AESKEYGENASSIST " + ", ".join(map(format_operand_type, self.operands))) if peachpy.stream.active_stream is not None: peachpy.stream.active_stream.add_instruction(self)
def __init__(self, *args, **kwargs): """Supported forms: * SHA256RNDS2(xmm, xmm/m128, xmm0) [SHA] """ origin = kwargs.get("origin") prototype = kwargs.get("prototype") if origin is None and prototype is None and peachpy.x86_64.options.get_debug_level( ) > 0: origin = inspect.stack() super(SHA256RNDS2, self).__init__("SHA256RNDS2", origin=origin, prototype=prototype) self.operands = tuple(map(check_operand, args)) if len(self.operands) != 3: raise SyntaxError( "Instruction \"SHA256RNDS2\" requires 3 operands") self.in_regs = (True, True, True) self.out_regs = (True, False, False) self.out_operands = (True, False, False) self.avx_mode = False self.isa_extensions = frozenset([peachpy.x86_64.isa.sha]) if is_xmm(self.operands[0]) and is_xmm(self.operands[1]) and is_xmm0( self.operands[2]): self.encodings.append((0x20, lambda op, rex=False: optional_rex( op[0].hcode, op[1], rex) + bytearray( [0x0F, 0x38, 0xCB, 0xC0 | op[0].lcode << 3 | op[1].lcode]) )) elif is_xmm(self.operands[0]) and is_m128( self.operands[1]) and is_xmm0(self.operands[2]): self.encodings.append( (0x30, lambda op, rex=False, sib=False, min_disp=0: optional_rex(op[0].hcode, op[1].address, rex) + bytearray( [0x0F, 0x38, 0xCB]) + modrm_sib_disp( op[0].lcode, op[1].address, sib, min_disp))) else: raise SyntaxError( "Invalid operand types: SHA256RNDS2 " + ", ".join(map(format_operand_type, self.operands))) if peachpy.stream.active_stream is not None: peachpy.stream.active_stream.add_instruction(self)
def __init__(self, *args, **kwargs): """Supported forms: * RDRAND(r16) [RDRAND] * RDRAND(r32) [RDRAND] * RDRAND(r64) [RDRAND] """ origin = kwargs.get("origin") prototype = kwargs.get("prototype") if origin is None and prototype is None and peachpy.x86_64.options.get_debug_level( ) > 0: origin = inspect.stack() super(RDRAND, self).__init__("RDRAND", origin=origin, prototype=prototype) self.operands = tuple(map(check_operand, args)) if len(self.operands) != 1: raise SyntaxError("Instruction \"RDRAND\" requires 1 operands") self.in_regs = (False, ) self.out_regs = (True, ) self.out_operands = (True, ) self.isa_extensions = frozenset([peachpy.x86_64.isa.rdrand]) if is_r16(self.operands[0]): self.encodings.append( (0x20, lambda op, rex=False: bytearray([0x66]) + optional_rex( 0, op[0], rex) + bytearray( [0x0F, 0xC7, 0xF0 | op[0].lcode]))) elif is_r32(self.operands[0]): self.encodings.append((0x20, lambda op, rex=False: optional_rex( 0, op[0], rex) + bytearray([0x0F, 0xC7, 0xF0 | op[0].lcode]))) elif is_r64(self.operands[0]): self.encodings.append((0x00, lambda op: bytearray( [0x48 | op[0].hcode, 0x0F, 0xC7, 0xF0 | op[0].lcode]))) else: raise SyntaxError( "Invalid operand types: RDRAND " + ", ".join(map(format_operand_type, self.operands))) if peachpy.stream.active_stream is not None: peachpy.stream.active_stream.add_instruction(self)