KiTpEmulateInstruction

INT64 __stdcall KiTpEmulateInstruction(UINT8 *a1, INT64 a2){
  int v2; 
  int InstructionBytes; 
  int v6; 
  CHAR v7; 
  CHAR v8; 
  CHAR v9; 
  INT64 v10; 
  INT64 *v11; 
  INT64 v12; 
  INT64 v13; 
  INT64 *RegisterAddressByIndex; 
  INT64 v15; 
  INT64 *v16; 
  int v17; 
  INT64 v18; 
  INT64 v19; 
  int v20; 
  _DWORD *v21; 
  UINT64 v23; 
  INT64 v24; 
  __int64 v25[3]; 
  __int64 v26; 
  CHAR v27; 
  __int64 a2a; 
  INT64 a4; 
  v2 = a1[21];
  v24 = 0i64;
  v25[0] = 0i64;
  v23 = 0i64;
  LOBYTE(a2a) = 0;
  v27 = 0;
  LOBYTE(v26) = 0;
  LODWORD(a4) = v2;
  InstructionBytes = KiTpFetchInstructionBytes((INT64)a1, &a2a, 1i64, &a4);
  if( InstructionBytes < 0 )
    goto LABEL_92;
  if( (a2a & 0xF0) == 80 )
  {
    v6 = KiTpEmulateRegisterPushPop((INT64)a1, a2, a2a);
    goto LABEL_89;
  }
  if( (a2a & 0xF0) == 0xB0 )
  {
    v6 = KiTpEmulateMovRegImm((INT64)a1, a2, a2a, &a4);
    goto LABEL_89;
  }
  if( (a2a & 0xC4) == 0 )
  {
    v6 = KiTpEmulateGroup0Instruction(a1, a2, a2a, &a4);
    goto LABEL_89;
  }
  if( (unsigned __int8)a2a > 0x8Au )
  {
    if( (unsigned __int8)a2a > 0xC6u )
    {
      if( (unsigned __int8)a2a != 199 )
        goto LABEL_77;
      if( !a2 )
        goto LABEL_87;
    }
    else
    {
      if( (unsigned __int8)a2a != 198 )
      {
        if( (unsigned __int8)a2a == 139 )
        {
LABEL_59:
          InstructionBytes = KiTpDecodeModRm(a1, a2, &a4);
          if( InstructionBytes < 0 )
            goto LABEL_92;
          if( !a2 )
            goto LABEL_47;
          KiTpDecodeModRmOperand((INT64)a1, a2, (UINT64)&v23, (CHAR)&v27, (CHAR)&v26);
          LOBYTE(v19) = v27;
          InstructionBytes = KiTpReadOperandValue((INT64)a1, a2, v23, v19, v26, (INT64)v25);
          if( InstructionBytes < 0 )
            goto LABEL_92;
          v18 = v25[0];
          goto LABEL_56;
        }
        if( (unsigned __int8)a2a == 141 )
        {
          InstructionBytes = KiTpDecodeModRm(a1, a2, &a4);
          if( InstructionBytes < 0 )
            goto LABEL_92;
          if( !a2 )
            goto LABEL_47;
          KiTpDecodeModRmOperand((INT64)a1, a2, (UINT64)&v23, (CHAR)&v27, (CHAR)&v26);
          if( (_BYTE)v26 )
          {
            v21 = *(_DWORD **)a2;
            InstructionBytes = -1073741795;
            v21[6] = 0;
            *v21 = -1073741795;
            goto LABEL_92;
          }
          v18 = v23;
LABEL_56:
          KiTpWriteRegisterValue((INT64)a1, a2, (a1[26] >> 3) & 7, (a1[25] & 4) != 0, v18);
          goto LABEL_90;
        }
        if( (unsigned __int8)a2a != 144 )
        {
          if( (unsigned __int8)a2a == 194 )
          {
            if( a2 )
            {
LABEL_74:
              KiTpAccessMemory();
              InstructionBytes = v20;
              if( v20 >= 0 )
              {
                *(_QWORD *)(*(_QWORD *)(a2 + 8) + 248i64) = v24;
                *(_QWORD *)(*(_QWORD *)(a2 + 8) + 152i64) += *((_QWORD *)a1 + 4) + 8i64;
                InstructionBytes = 0;
              }
              goto LABEL_92;
            }
            InstructionBytes = KiTpFetchInstructionBytes((INT64)a1, a1 + 32, 2i64, &a4);
            if( InstructionBytes < 0 )
              return(unsigned int)InstructionBytes;
          }
          else if( (unsigned __int8)a2a != 195 )
          {
            goto LABEL_77;
          }
          if( !a2 )
            goto LABEL_47;
          goto LABEL_74;
        }
        if( (a1[25] & 1) == 0 )
          goto LABEL_90;
LABEL_77:
        InstructionBytes = -1073741637;
        goto LABEL_92;
      }
      if( !a2 )
      {
        a1[1] = 8;
LABEL_87:
        KiTpSetImmediateOperandSize((INT64)a1, 16, 32, 32);
      }
    }
    v6 = KiTpEmulateGroup11Instruction((INT64)a1, a2, &a4);
    goto LABEL_89;
  }
  if( (unsigned __int8)a2a == 138 )
  {
    if( !a2 )
      a1[1] = 8;
    goto LABEL_59;
  }
  if( (unsigned __int8)a2a > 0x84u )
  {
    if( (unsigned __int8)a2a == 133 )
      goto LABEL_33;
    if( (unsigned __int8)a2a == 134 )
    {
      if( !a2 )
        a1[1] = 8;
    }
    else if( (unsigned __int8)a2a != 135 )
    {
      if( (unsigned __int8)a2a == 136 )
      {
        if( !a2 )
          a1[1] = 8;
      }
      else if( (unsigned __int8)a2a != 137 )
      {
        goto LABEL_77;
      }
      InstructionBytes = KiTpDecodeModRm(a1, a2, &a4);
      if( InstructionBytes < 0 )
        goto LABEL_92;
      if( a2 )
      {
        KiTpDecodeModRmOperand((INT64)a1, a2, (UINT64)&v23, (CHAR)&v27, (CHAR)&v26);
        RegisterAddressByIndex = (INT64 *)KiTpGetRegisterAddressByIndex(
                                            (INT64)a1,
                                            a2,
                                            (a1[26] >> 3) & 7,
                                            (a1[25] & 4) != 0,
                                            1);
        v25[0] = KiTpSignExtendOperandValue((INT64)a1, *RegisterAddressByIndex);
        a2a = v25[0];
        KiTpAccessMemory();
        goto LABEL_89;
      }
LABEL_47:
      InstructionBytes = 0;
LABEL_94:
      a1[24] = a4;
      return(unsigned int)InstructionBytes;
    }
    InstructionBytes = KiTpDecodeModRm(a1, a2, &a4);
    if( InstructionBytes < 0 )
      goto LABEL_92;
    if( !a2 )
      goto LABEL_47;
    KiTpDecodeModRmOperand((INT64)a1, a2, (UINT64)&v23, (CHAR)&v27, (CHAR)&v26);
    LOBYTE(v15) = v27;
    InstructionBytes = KiTpReadOperandValue((INT64)a1, a2, v23, v15, v26, (INT64)&v24);
    if( InstructionBytes >= 0 )
    {
      v16 = (INT64 *)KiTpGetRegisterAddressByIndex((INT64)a1, a2, (a1[26] >> 3) & 7, (a1[25] & 4) != 0, 1);
      v25[0] = KiTpSignExtendOperandValue((INT64)a1, *v16);
      v26 = v25[0];
      KiTpAccessMemory();
      InstructionBytes = v17;
      if( v17 >= 0 )
      {
        v18 = v24;
        goto LABEL_56;
      }
    }
LABEL_92:
    if( a2 )
      return(unsigned int)InstructionBytes;
    goto LABEL_93;
  }
  if( (unsigned __int8)a2a == 132 )
  {
    if( !a2 )
      a1[1] = 8;
LABEL_33:
    InstructionBytes = KiTpDecodeModRm(a1, a2, &a4);
    if( InstructionBytes < 0 )
      goto LABEL_92;
    if( a2 )
    {
      KiTpDecodeModRmOperand((INT64)a1, a2, (UINT64)&v23, (CHAR)&v27, (CHAR)&v26);
      LOBYTE(v10) = v27;
      InstructionBytes = KiTpReadOperandValue((INT64)a1, a2, v23, v10, v26, (INT64)&v24);
      if( InstructionBytes < 0 )
        goto LABEL_92;
      v11 = (INT64 *)KiTpGetRegisterAddressByIndex((INT64)a1, a2, (a1[26] >> 3) & 7, (a1[25] & 4) != 0, 1);
      v25[0] = KiTpSignExtendOperandValue((INT64)a1, *v11);
      v12 = v24 & v25[0];
      *(_DWORD *)(*(_QWORD *)(a2 + 8) + 68i64) &= 0xFFFFF7FE;
      KiTpSetFlagsZeroSignParity(v13, a2, v12);
      goto LABEL_90;
    }
    goto LABEL_47;
  }
  if( (unsigned __int8)a2a != 15 )
  {
    if( (unsigned __int8)a2a == 128 )
    {
      if( a2 )
        goto LABEL_23;
      a1[1] = 8;
    }
    else if( (unsigned __int8)a2a != 129 )
    {
      if( (unsigned __int8)a2a == 130 )
      {
        if( a2 )
          goto LABEL_23;
        a1[1] = 8;
      }
      else if( (unsigned __int8)a2a != 131 )
      {
        goto LABEL_77;
      }
      if( !a2 )
      {
        v7 = 8;
        v8 = 8;
        v9 = 8;
LABEL_22:
        KiTpSetImmediateOperandSize((INT64)a1, v9, v8, v7);
      }
LABEL_23:
      v6 = KiTpEmulateGroup1Instruction((INT64)a1, a2, &a4);
      goto LABEL_89;
    }
    if( a2 )
      goto LABEL_23;
    v7 = 32;
    v9 = 16;
    v8 = 32;
    goto LABEL_22;
  }
  InstructionBytes = KiTpFetchInstructionBytes((INT64)a1, &a2a, 1i64, &a4);
  if( InstructionBytes < 0 )
    goto LABEL_92;
  if( (unsigned __int8)(a2a + 74) > 1u )
    goto LABEL_77;
  v6 = KiTpEmulateMovzx(a1, a2, 8 * (((unsigned __int8)a2a & 1u) + 1), &a4);
LABEL_89:
  InstructionBytes = v6;
  if( v6 < 0 )
    goto LABEL_92;
LABEL_90:
  if( a2 )
  {
    *(_QWORD *)(*(_QWORD *)(a2 + 8) + 248i64) += a1[24];
    goto LABEL_92;
  }
LABEL_93:
  if( InstructionBytes >= 0 )
    goto LABEL_94;
  return(unsigned int)InstructionBytes;
}

Referenced by:

KiTpCompletion
KiTpHandleTrap
KiTpParseInstruction