Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

Convert IDA pseudo code to C# (This post closed)

Featured Replies

  • Author
  • Localization

179971c, posted Thu Feb 09, 2023 3:08 am (75369)


Need help to convert this function (DecryptMemory) to C# code, any code simplify or improve readability are also welcome.

Code:
System_Byte_array *__stdcall ResourceManager__DecryptMemory(ResourceManager_o *this, System_String_o *strPath, System_Byte_array *enryptedMemory, const MethodInfo *method)
{
  System_Byte_array *v4; // rbp
  System_String_o *v5; // r14
  __int64 v6; // r13
  int v7; // ebx
  __int64 v8; // r8
  __int64 v9; // r9
  __int64 v10; // rsi
  int v11; // edi
  __int64 v12; // r8
  __int64 v13; // r9
  __int64 v14; // r8
  __int64 v15; // r9
  System_Array_o *v16; // rax
  int v17; // ebx
  int v18; // er15
  int32_t v19; // er14
  int v20; // edx
  uint64_t v21; // r12
  int v22; // edi
  int v23; // eax
  __int64 v24; // rcx
  __int64 v25; // rdx
  System_String_o *v26; // rdi
  System_String_o *v27; // rdi
  System_Text_Encoding_o *v28; // rax
  __int64 v30; // rax
  __int64 v31; // rax
  __int64 v32; // rax
  __int64 v33; // rax
  __int64 v34; // rax
  System_Byte_array *dst; // [rsp 30h] [rbp-48h]
  System_String_o *v36; // [rsp 88h] [rbp 10h]
  System_Byte_array *src; // [rsp 90h] [rbp 18h]

  v36 = strPath;
  v4 = enryptedMemory;
  v5 = strPath;
  if ( !byte_18383084A )
  {
    sub_1802908E0(58372i64, strPath, enryptedMemory, method);
    byte_18383084A = 1;
  }
  if ( !v4 )
    goto LABEL_34;
  if ( SLODWORD(v4->max_length) < 8 )
    return 0i64;
  v6 = sub_1802906B0(ulong___TypeInfo, 4i64, enryptedMemory, method);
  System_Runtime_CompilerServices_RuntimeHelpers__InitializeArray_6459807856(
    (System_Array_o *)v6,
    Field__PrivateImplementationDetails__BF43CDF8D96CA09E1591D08469EDFB9E391A8259,
    0i64);
  v7 = v4->max_length;
  v10 = sub_1802906B0(byte___TypeInfo, (unsigned int)(v7 - 8), v8, v9);
  v11 = (v7 - 8) / 16;
  dst = (System_Byte_array *)sub_1802906B0(byte___TypeInfo, 16i64, v12, v13);
  v16 = (System_Array_o *)sub_1802906B0(byte___TypeInfo, 16i64, v14, v15);
  v17 = 0;
  src = (System_Byte_array *)v16;
  v18 = 0;
  if ( v11 > 0 )
  {
    v19 = 0;
    do
    {
      System_Array__Copy_6457446880((System_Array_o *)v4, v19 8, v16, 0, 16, 0i64);
      if ( !v6 )
        goto LABEL_34;
      v20 = v18 % *(_DWORD *)(v6 24);
      if ( (unsigned int)v20 >= *(_DWORD *)(v6 24) )
      {
        v30 = ((__int64 (*)(void))sub_180290860)();
        sub_180290A30(v30, 0i64);
      }
      v21 = *(_QWORD *)(v6 8i64 * v20 32);
      if ( (Utility_TypeInfo->_2.bitflags2 & 2) != 0 && !Utility_TypeInfo->_2.cctor_finished )
        il2cpp_runtime_class_init();
      Utility__shuffle16(dst, src, v21, 0i64);
      System_Array__Copy_6457446880((System_Array_o *)dst, 0, (System_Array_o *)v10, v19, 16, 0i64);
      v16 = (System_Array_o *)src;
      v18;
      v19 = 16;
    }
    while ( v18 < v11 );
    v5 = v36;
  }
  v22 = 16 * v11;
  if ( !v10 )
    goto LABEL_34;
  while ( 1 )
  {
    v23 = *(_DWORD *)(v10 24);
    if ( v22 >= v23 )
      break;
    v24 = v22;
    v25 = v22 8i64;
    if ( (unsigned int)v25 >= LODWORD(v4->max_length) )
    {
      v32 = sub_180290860(v22, v25, enryptedMemory, method);
      sub_180290A30(v32, 0i64);
    }
    if ( v22 >= (unsigned int)v23 )
    {
      v31 = sub_180290860(v22, v25, enryptedMemory, method);
      sub_180290A30(v31, 0i64);
    }
    v22;
    *(_BYTE *)(v24 v10 32) = v4->m_Items[v25];
  }
  if ( (System_IO_Path_TypeInfo->_2.bitflags2 & 2) != 0 && !System_IO_Path_TypeInfo->_2.cctor_finished )
    il2cpp_runtime_class_init();
  v26 = System_IO_Path__GetFileNameWithoutExtension(v5, 0i64);
  if ( (Utility_TypeInfo->_2.bitflags2 & 2) != 0 && !Utility_TypeInfo->_2.cctor_finished )
    il2cpp_runtime_class_init();
  v27 = Utility__sha1Hashed(v26, 0i64);
  v28 = System_Text_Encoding__get_ASCII(0i64);
  if ( !v28 )
LABEL_34:
    sub_180290A60(this, strPath, enryptedMemory, method);
  for ( enryptedMemory = (System_Byte_array *)((__int64 (__fastcall *)(System_Text_Encoding_o *, System_String_o *, const MethodInfo *))v28->klass->vtable._18_GetBytes.methodPtr)(
                                                v28,
                                                v27,
                                                v28->klass->vtable._18_GetBytes.method);
        ;
        *(_BYTE *)(v17 v10 32) ^= enryptedMemory->m_Items[(int)strPath] )
  {
    this = (ResourceManager_o *)*(unsigned int *)(v10 24);
    if ( v17 >= (int)this )
      break;
    method = (const MethodInfo *)v17;
    if ( v17 >= (unsigned int)this )
    {
      v34 = sub_180290860(this, strPath, enryptedMemory, v17);
      sub_180290A30(v34, 0i64);
    }
    if ( !enryptedMemory )
      goto LABEL_34;
    strPath = (System_String_o *)(unsigned int)(v17 >> 31);
    LODWORD(strPath) = v17 % SLODWORD(enryptedMemory->max_length);
    if ( (unsigned int)strPath >= LODWORD(enryptedMemory->max_length) )
    {
      v33 = sub_180290860(this, strPath, enryptedMemory, v17);
      sub_180290A30(v33, 0i64);
    }
  }
  return (System_Byte_array *)v10;
}


Code:
internal static readonly .__StaticArrayInitTypeSize=32 BF43CDF8D96CA09E1591D08469EDFB9E391A8259 /*Metadata offset 0x5752D2*/;
3D 06 F4 2B C5 7A 9E 18 D1 64 F2 8B 05 EA 97 3C
C3 F7 D5 91 04 A2 6B E8 A4 2F 1E D0 73 8B 9C 56


Code:
__int64 __fastcall sub_1802906B0(__int64 a1, unsigned int a2)
{
  return il2cpp_array_new_specific_0(a1, a2);
}
  • Author
  • Localization

179971c, posted Mon Feb 13, 2023 9:57 pm (75418)


Since no one answered and I have solved it myself, this post is closed.
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.