SM4_enCode SM4_deCode

int __cdecl SM4_enCode(int a1, int a2, int a3)
{
  int v3; // edi@1
  int v4; // eax@1
  int v5; // eax@1
  int *v6; // edi@1
  int v7; // eax@1
  int v8; // ecx@1
  int *v9; // ST14_4@1
  signed __int32 v10; // edi@1
  int v11; // edx@1
  void *v12; // edi@2
  size_t v13; // edi@4
  size_t v14; // ST0C_4@4
  int v15; // edi@4
  int result; // eax@4
  int v17; // [sp+0h] [bp-5Ch]@4
  signed __int32 v18; // [sp+Ch] [bp-50h]@1
  unsigned __int8 *v19; // [sp+10h] [bp-4Ch]@1
  int *v20; // [sp+14h] [bp-48h]@1
  const void *v21; // [sp+18h] [bp-44h]@2
  int *v22; // [sp+1Ch] [bp-40h]@1
  int v23; // [sp+20h] [bp-3Ch]@4
  char v24; // [sp+27h] [bp-35h]@4
  int v25; // [sp+48h] [bp-14h]@1

  v3 = a1;
  v22 = (int *)&_stack_chk_guard;
  v25 = _stack_chk_guard;
  v18 = (*(int (__cdecl **)(int, const char *))(*(_DWORD *)a1 + 24))(a1, "java/lang/String");
  v19 = (unsigned __int8 *)(*(int (__cdecl **)(int, const char *))(*(_DWORD *)v3 + 668))(v3, "UTF-8");
  v4 = (*(int (__cdecl **)(int, signed __int32, const char *, const char *))(*(_DWORD *)v3 + 132))(
         v3,
         v18,
         "getBytes",
         "(Ljava/lang/String;)[B");
  v5 = _JNIEnv::CallObjectMethod(a1, a3, v4, (char)v19);
  v6 = (int *)v5;
  v7 = (*(int (__cdecl **)(int, int))(*(_DWORD *)a1 + 684))(a1, v5);
  v8 = *(_DWORD *)a1;
  v20 = v6;
  v9 = v6;
  v10 = v7;
  v11 = (*(int (__cdecl **)(int, int *, _DWORD))(v8 + 736))(a1, v9, 0);
  v18 = v10;
  if ( v10 <= 0 )
  {
    v19 = 0;
  }
  else
  {
    v21 = (const void *)v11;
    v12 = malloc(v18 + 1);
    memcpy(v12, v21, v18);
    v11 = (int)v21;
    v19 = (unsigned __int8 *)v12;
    *((_BYTE *)v12 + v18) = 0;
  }
  (*(void (__cdecl **)(int, int *, int))(*(_DWORD *)a1 + 768))(a1, v20, v11);
  memcpy(&v24, "lIIh8mmplDg4kQMd148F2eMQLPCQ7Y9y", 0x21u);
  v20 = &v17;
  v13 = 16 * (((v18 + ((unsigned int)(v18 >> 31) >> 28)) >> 4) - (((v18 & 0xFu) < 1) - 1));
  v18 = (signed __int32)&v17 - v13;
  sm4_crypt_cbc((unsigned __int8 *)&v24, 1, v13, v19, (unsigned __int8 *)&v17 - v13, &v23);
  v14 = v13;
  v15 = (*(int (__cdecl **)(int, size_t))(*(_DWORD *)a1 + 704))(a1, v13);
  (*(void (__cdecl **)(int, int, _DWORD, size_t, signed __int32))(*(_DWORD *)a1 + 832))(a1, v15, 0, v14, v18);
  result = *v22;
  if ( *v22 == v25 )
    result = v15;
  return result;
}



int __cdecl SM4_deCode(int *a1, int a2, int a3)
{
  unsigned int v3; // edx@1
  char *v4; // edi@1
  int v5; // eax@3
  int v6; // eax@3
  int v7; // eax@3
  signed __int32 v8; // edi@3
  int v9; // eax@3
  int v10; // ecx@3
  int v11; // eax@3
  int result; // eax@3
  bool v13; // cf@3
  int v14; // [sp+0h] [bp-5Ch]@1
  signed __int32 v15; // [sp+Ch] [bp-50h]@1
  int v16; // [sp+10h] [bp-4Ch]@3
  const void *v17; // [sp+14h] [bp-48h]@1
  unsigned __int8 *v18; // [sp+18h] [bp-44h]@1
  unsigned int *v19; // [sp+1Ch] [bp-40h]@1
  int v20; // [sp+20h] [bp-3Ch]@3
  char v21; // [sp+27h] [bp-35h]@1
  int *v22; // [sp+30h] [bp-2Ch]@3
  int v23; // [sp+34h] [bp-28h]@3
  int v24; // [sp+38h] [bp-24h]@3
  signed __int32 v25; // [sp+3Ch] [bp-20h]@3
  int v26; // [sp+40h] [bp-1Ch]@3
  const char *v27; // [sp+44h] [bp-18h]@3
  unsigned int v28; // [sp+48h] [bp-14h]@1
  int v29; // [sp+4Ch] [bp-10h]@3

  v19 = (unsigned int *)&_stack_chk_guard;
  v28 = _stack_chk_guard;
  v17 = (const void *)(*(int (__cdecl **)(int *, int, _DWORD))(*a1 + 736))(a1, a3, 0);
  v15 = (*(int (__cdecl **)(int *, int))(*a1 + 684))(a1, a3);
  v3 = (v15 + 15) & 0xFFFFFFF0;
  v18 = (unsigned __int8 *)&v14 - v3;
  v4 = (char *)&v14 - v3;
  memcpy(&v21, "lIIh8mmplDg4kQMd148F2eMQLPCQ7Y9y", 0x21u);
  if ( v15 > 0 )
    memcpy(v4, v17, v15);
  sm4_crypt_cbc((unsigned __int8 *)&v21, 0, v15, (unsigned __int8 *)v4, v18, &v20);
  v5 = *a1;
  v26 = (int)a1;
  v6 = (*(int (__cdecl **)(int *, const char *))(v5 + 24))(a1, "java/lang/String");
  v17 = (const void *)v6;
  v16 = *a1;
  v27 = (const char *)v6;
  v16 = (*(int (__cdecl **)(int *, int, const char *, const char *))(v16 + 132))(
          a1,
          v6,
          "",
          "([BLjava/lang/String;)V");
  v7 = *a1;
  v8 = v15;
  v27 = (const char *)v15;
  v9 = (*(int (__cdecl **)(int *, signed __int32, unsigned int, int))(v7 + 704))(a1, v15, v28, v29);
  v10 = *a1;
  v26 = (int)v18;
  v25 = v8;
  v24 = 0;
  v23 = v9;
  LOBYTE(v8) = v9;
  v22 = a1;
  (*(void (__cdecl **)(int *, int, _DWORD, signed __int32, unsigned __int8 *, const char *))(v10 + 832))(
    a1,
    v9,
    0,
    v25,
    v18,
    v27);
  v11 = *a1;
  v27 = "UTF-8";
  v26 = (int)a1;
  v26 = (*(int (__cdecl **)(int *))(v11 + 668))(a1);
  result = _JNIEnv::NewObject(a1, v17, v16, v8);
  v13 = *v19 < v28;
  return result;
}
int __cdecl sm4_crypt_cbc(unsigned __int8 *a1, int a2, size_t size, unsigned __int8 *src, unsigned __int8 *a5, int *a6)
{
  return sm4_crypt_cbc(a1, a2, size, src, a5, a6);
}

int __cdecl sm4_crypt_cbc(unsigned __int8 *a1, int a2, size_t size, unsigned __int8 *src, unsigned __int8 *a5, int *a6)
{
  int *v6; // edi@1
  size_t v7; // esi@3
  char *v8; // eax@3
  bool v9; // cf@3
  size_t v10; // esi@3
  __m128 *v11; // eax@5
  __m128 *v12; // esi@8
  size_t v13; // ecx@10
  size_t v14; // eax@13
  __m128 *v15; // esi@13
  unsigned __int8 *v16; // ecx@13
  unsigned __int8 *v17; // ST1C_4@14
  size_t v18; // edi@14
  unsigned __int8 *v19; // ecx@16
  int v20; // eax@16
  size_t v21; // ecx@17
  size_t v22; // edi@19
  int v23; // eax@19
  __m128 *v24; // esi@19
  int v25; // edx@19
  int v26; // ST1C_4@20
  _BYTE *v27; // ecx@23
  int v28; // eax@23
  unsigned __int8 *v31; // [sp+4h] [bp-B8h]@5
  size_t v32; // [sp+8h] [bp-B4h]@5
  __m128 *v33; // [sp+18h] [bp-A4h]@3
  size_t v34; // [sp+1Ch] [bp-A0h]@19
  size_t v35; // [sp+20h] [bp-9Ch]@19
  int v36; // [sp+28h] [bp-94h]@12
  int v37; // [sp+A8h] [bp-14h]@1

  v6 = a6;
  v37 = _stack_chk_guard;
  if ( size )
  {
    if ( size & 0xF )
    {
      v7 = ((size + ((unsigned int)((signed int)size >> 31) >> 28)) & 0xFFFFFFF0) + 16;
      v8 = (char *)malloc(v7);
      v33 = (__m128 *)v8;
      v9 = v7 < size;
      v10 = v7 - size;
      if ( v9 || v10 == 0 )
        v10 = 0;
      v6 = a6;
      memset(&v8[size], 0, v10);
      v32 = size;
      v31 = src;
      v11 = v33;
    }
    else
    {
      v11 = (__m128 *)malloc(size);
      v32 = size;
      v31 = src;
    }
    v12 = v11;
    memcpy(v11, v31, v32);
    if ( a2 )
    {
      if ( a2 == 1 )
      {
        v13 = size;
        if ( size & 0xF )
          v13 = ((size + ((unsigned int)((signed int)size >> 31) >> 28)) & 0xFFFFFFF0) + 16;
        *v6 = v13;
        sm4_setkey_enc((unsigned __int32 *)&v36, a1);
        *v12 = _mm_xor_ps(*v12, (__m128)xmmword_2140);
        sub_10C0(a5);
        if ( (signed int)size >= 17 )
        {
          v14 = size + 16;
          v15 = v12 + 1;
          v16 = a5 + 16;
          do
          {
            v17 = v16;
            *v15 = _mm_xor_ps(*v15, *((__m128 *)v16 - 1));
            v18 = v14;
            sub_10C0(v16);
            v14 = v18 - 16;
            ++v15;
            v16 = v17 + 16;
          }
          while ( (signed int)(v18 - 16) > 32 );
        }
      }
    }
    else
    {
      sm4_setkey_dec((unsigned __int32 *)&v36, a1);
      sub_10C0(a5);
      v19 = a5;
      *(__m128 *)a5 = _mm_xor_ps(*(__m128 *)a5, (__m128)xmmword_2140);
      v20 = 0;
      if ( (signed int)size >= 17 )
      {
        v21 = -33;
        if ( (signed int)~size > -34 )
          v21 = ~size;
        v22 = ((v21 + size + 16) >> 4) + 1;
        v34 = (v21 + size + 32) & 0xFFFFFFF0;
        v23 = (int)&v12[1];
        v24 = (__m128 *)(a5 + 16);
        v35 = ((v21 + size + 16) >> 4) + 1;
        v25 = v23;
        do
        {
          v26 = v25;
          sub_10C0(v24);
          *v24 = _mm_xor_ps(*v24, *(__m128 *)(v26 - 16));
          v25 = v26 + 16;
          ++v24;
          --v22;
        }
        while ( v22 );
        v19 = &a5[v34];
        v20 = 16 * v35;
        v6 = a6;
      }
      *v6 = v20;
      if ( *v19 )
      {
        v27 = v19 + 1;
        v28 = v20 + 1;
        do
          *v6 = v28++;
        while ( *v27++ != 0 );
      }
    }
  }
  else
  {
    *a6 = 0;
  }
  return _stack_chk_guard;
}

unsigned __int32 __cdecl sm4_setkey_enc(int a1, int a2)
{
  unsigned __int32 v2; // esi@1
  unsigned __int32 v3; // edi@1
  unsigned __int32 v4; // edx@1
  int v5; // ebx@1
  _DWORD *v6; // ecx@1
  _DWORD *v7; // ST1C_4@2
  unsigned __int32 v8; // ST18_4@2
  unsigned __int32 v9; // ST14_4@2
  unsigned int v10; // eax@2
  int v11; // edx@2
  int v12; // ecx@2
  int v13; // eax@2
  unsigned __int32 result; // eax@2
  unsigned __int32 v15; // [sp+4h] [bp-24h]@1

  v15 = _byteswap_ulong(*(_DWORD *)a2) ^ 0x5356A350;
  v2 = _byteswap_ulong(*(_DWORD *)(a2 + 4)) ^ 0xA13AFAC7;
  v3 = _byteswap_ulong(*(_DWORD *)(a2 + 8)) ^ 0x7D9971D9;
  v4 = _byteswap_ulong(*(_DWORD *)(a2 + 12)) ^ 0x2BCD07DC;
  v5 = 0;
  v6 = &unk_249C;
  do
  {
    v7 = v6;
    v8 = v2;
    v9 = v4;
    v10 = *v6 ^ v3 ^ v4 ^ v2;
    v11 = ((unsigned __int8)byte_251C[v10 >> 24] << 24) | ((unsigned __int8)byte_251C[(unsigned __int8)(v10 >> 16)] << 16);
    v2 = v3;
    v12 = v11 | ((unsigned __int8)byte_251C[BYTE1(v10)] << 8);
    v3 = v9;
    v13 = v12 | (unsigned __int8)byte_251C[(unsigned __int8)v10];
    v4 = v13 ^ (__PAIR__((unsigned int)v13, v12) >> 9) ^ v15 ^ (__PAIR__((unsigned int)v13, v11) >> 19);
    *(_DWORD *)(a1 + 4 * v5++) = v4;
    v6 = v7 + 1;
    result = v8;
    v15 = v8;
  }
  while ( v5 != 32 );
  return result;
}

int __cdecl sm4_setkey_dec(int a1, int a2)
{
  unsigned __int32 v2; // edx@1
  unsigned __int32 v3; // edi@1
  unsigned __int32 v4; // esi@1
  int v5; // ebx@1
  _DWORD *v6; // eax@1
  unsigned __int32 v7; // ST18_4@2
  unsigned __int32 v8; // ST14_4@2
  unsigned __int32 v9; // ST10_4@2
  unsigned int v10; // ecx@2
  int v11; // esi@2
  int v12; // edx@2
  int v13; // ecx@2
  int v14; // esi@2
  int v15; // esi@3
  int v16; // ecx@3
  int v17; // edx@3
  int v18; // eax@3
  int v19; // eax@3
  int v20; // eax@3
  int v21; // eax@3
  int v22; // eax@3
  int v23; // eax@3
  int v24; // eax@3
  int v25; // eax@3
  int v26; // eax@3
  int v27; // eax@3
  int v28; // eax@3
  int v29; // eax@3
  int v30; // eax@3
  int result; // eax@3
  unsigned __int32 v32; // [sp+4h] [bp-24h]@1

  v32 = _byteswap_ulong(*(_DWORD *)a2) ^ 0x5356A350;
  v2 = _byteswap_ulong(*(_DWORD *)(a2 + 4)) ^ 0xA13AFAC7;
  v3 = _byteswap_ulong(*(_DWORD *)(a2 + 8)) ^ 0x7D9971D9;
  v4 = _byteswap_ulong(*(_DWORD *)(a2 + 12)) ^ 0x2BCD07DC;
  v5 = 0;
  v6 = &unk_249C;
  do
  {
    v7 = v2;
    v8 = v3;
    v9 = v4;
    v10 = *v6 ^ v3 ^ v4 ^ v2;
    v11 = ((unsigned __int8)byte_251C[v10 >> 24] << 24) | ((unsigned __int8)byte_251C[(unsigned __int8)(v10 >> 16)] << 16);
    v3 = v9;
    v12 = v11 | ((unsigned __int8)byte_251C[BYTE1(v10)] << 8);
    v13 = v12 | (unsigned __int8)byte_251C[(unsigned __int8)v10];
    v14 = (__PAIR__((unsigned int)v13, v12) >> 9) ^ v32 ^ (__PAIR__((unsigned int)v13, v11) >> 19);
    v2 = v8;
    v4 = v13 ^ v14;
    *(_DWORD *)(a1 + 4 * v5++) = v4;
    ++v6;
    v32 = v7;
  }
  while ( v5 != 32 );
  v15 = a1;
  v16 = *(_DWORD *)a1;
  v17 = *(_DWORD *)(a1 + 4);
  *(_DWORD *)a1 = *(_DWORD *)(a1 + 124);
  *(_DWORD *)(a1 + 124) = v16;
  *(_DWORD *)(v15 + 4) = *(_DWORD *)(v15 + 120);
  *(_DWORD *)(a1 + 120) = v17;
  v18 = *(_DWORD *)(a1 + 8);
  *(_DWORD *)(v15 + 8) = *(_DWORD *)(v15 + 116);
  *(_DWORD *)(a1 + 116) = v18;
  v19 = *(_DWORD *)(a1 + 12);
  *(_DWORD *)(v15 + 12) = *(_DWORD *)(v15 + 112);
  *(_DWORD *)(a1 + 112) = v19;
  v20 = *(_DWORD *)(a1 + 16);
  *(_DWORD *)(v15 + 16) = *(_DWORD *)(v15 + 108);
  *(_DWORD *)(a1 + 108) = v20;
  v21 = *(_DWORD *)(a1 + 20);
  *(_DWORD *)(v15 + 20) = *(_DWORD *)(v15 + 104);
  *(_DWORD *)(a1 + 104) = v21;
  v22 = *(_DWORD *)(a1 + 24);
  *(_DWORD *)(v15 + 24) = *(_DWORD *)(v15 + 100);
  *(_DWORD *)(a1 + 100) = v22;
  v23 = *(_DWORD *)(a1 + 28);
  *(_DWORD *)(v15 + 28) = *(_DWORD *)(v15 + 96);
  *(_DWORD *)(a1 + 96) = v23;
  v24 = *(_DWORD *)(a1 + 32);
  *(_DWORD *)(v15 + 32) = *(_DWORD *)(v15 + 92);
  *(_DWORD *)(a1 + 92) = v24;
  v25 = *(_DWORD *)(a1 + 36);
  *(_DWORD *)(v15 + 36) = *(_DWORD *)(v15 + 88);
  *(_DWORD *)(a1 + 88) = v25;
  v26 = *(_DWORD *)(a1 + 40);
  *(_DWORD *)(v15 + 40) = *(_DWORD *)(v15 + 84);
  *(_DWORD *)(a1 + 84) = v26;
  v27 = *(_DWORD *)(a1 + 44);
  *(_DWORD *)(v15 + 44) = *(_DWORD *)(v15 + 80);
  *(_DWORD *)(a1 + 80) = v27;
  v28 = *(_DWORD *)(a1 + 48);
  *(_DWORD *)(v15 + 48) = *(_DWORD *)(v15 + 76);
  *(_DWORD *)(a1 + 76) = v28;
  v29 = *(_DWORD *)(a1 + 52);
  *(_DWORD *)(v15 + 52) = *(_DWORD *)(v15 + 72);
  *(_DWORD *)(a1 + 72) = v29;
  v30 = *(_DWORD *)(a1 + 56);
  *(_DWORD *)(v15 + 56) = *(_DWORD *)(v15 + 68);
  *(_DWORD *)(a1 + 68) = v30;
  result = *(_DWORD *)(a1 + 60);
  *(_DWORD *)(a1 + 60) = *(_DWORD *)(a1 + 64);
  *(_DWORD *)(a1 + 64) = result;
  return result;
}


你可能感兴趣的:(加密)