Advertisement
Guest User

Untitled

a guest
Jul 21st, 2016
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.40 KB | None | 0 0
  1. using System.Threading;
  2.  
  3. namespace nManager.Wow.Helpers
  4. {
  5.     public class WDB5MemoryReader
  6.     {
  7.         private static int WowClientDB2__GetIndexAddressByIndex(int a1, int a2, ref short a3)
  8.         {
  9.             // this function read the Index list of the DB2 and return the address of the Index you wanted.
  10.             // I'm not exactly sure why it needs that tho but we can use it to verify (standalone) if an index exists.
  11.             int v3 = a1;
  12.             int v4 = a2;
  13.             int i = 0;
  14.             while (v3 != v4)
  15.             {
  16.                 if (i > 100000)
  17.                     break; // security anti freeze
  18.                 i++;
  19.                 int v5 = v3 + 4*((v4 - v3) >> 2)/2;
  20.                 if (Memory.WowMemory.Memory.ReadShort((uint) v5) >= a3)
  21.                     v4 = v3 + 4*((v4 - v3) >> 2)/2;
  22.                 else
  23.                     v3 = v5 + 4;
  24.             }
  25.             return v3;
  26.         }
  27.  
  28.         private static int WowClientDB2__GetIndexAddress2ByIndex(int a1, int a2, int a3)
  29.         {
  30.             // this function does a similar thing to the previous one, but I think for secondary indexes.
  31.             // I have not seen any db2 that would use it.
  32.             int v3 = a1;
  33.             int v4 = a2;
  34.             int i = 0;
  35.             while (v3 != v4)
  36.             {
  37.                 if (i > 100000)
  38.                     break; // security anti freeze
  39.                 i++;
  40.                 int v5 = (v3 + 8*((v4 - v3) >> 3)/2);
  41.                 if (Memory.WowMemory.Memory.ReadInt((uint) v5) >= a3)
  42.                     v4 = (v3 + 8*((v4 - v3) >> 3)/2);
  43.                 else
  44.                     v3 = (v5 + 8);
  45.             }
  46.             return v3;
  47.         }
  48.  
  49.         private static int WowClientDB2__GetRowPointerBySecondaryIndex(uint _this, int a2)
  50.         {
  51.             int v2; // esi@1
  52.             int v3; // eax@1
  53.             int result; // eax@3
  54.             if (_this <= 0)
  55.                 return 0;
  56.             v2 = (Memory.WowMemory.Memory.ReadInt(_this) + 8*(Memory.WowMemory.Memory.ReadInt(_this) + 1));
  57.             v3 = WowClientDB2__GetIndexAddress2ByIndex(Memory.WowMemory.Memory.ReadInt(_this), v2, a2);
  58.             if (v3 == v2 || Memory.WowMemory.Memory.ReadInt((uint) v3) != a2)
  59.                 result = 0;
  60.             else
  61.                 result = Memory.WowMemory.Memory.ReadInt((uint) (v3 + 4));
  62.             return result;
  63.  
  64.             /*
  65.                 int v2; // esi@1
  66.                 int v3; // eax@1
  67.                 int result; // eax@3
  68.  
  69.                 v2 = *(_DWORD *)this + 8 * *((_DWORD *)this + 1);
  70.                 v3 = sub_214B30(*(_DWORD *)this, *(_DWORD *)this + 8 * *((_DWORD *)this + 1), &a2);
  71.                 if ( v3 == v2 || *(_DWORD *)v3 != a2 )
  72.                 result = 0;
  73.                 else
  74.                 result = *(_DWORD *)(v3 + 4);
  75.                 return result;
  76.                 }
  77.             */
  78.         }
  79.  
  80.  
  81.         private static int WowClientDB2__GetRowPointerByIndex(uint _this, int a2)
  82.         {
  83.             int result;
  84.             uint v2 = _this;
  85.             int v5 = 0;
  86.             short v6 = 0;
  87.             bool goToEnd = false;
  88.             /*Memory.WowMemory.Memory.WriteUInt(Memory.WowMemory.Memory.ReadUInt(v2 + 56), Memory.WowMemory.Memory.ReadUInt(v2 + 56) + 1);
  89.             if (a2 == Memory.WowMemory.Memory.ReadUInt(v2 + 64))
  90.                 Memory.WowMemory.Memory.WriteUInt(Memory.WowMemory.Memory.ReadUInt(v2 + 60), Memory.WowMemory.Memory.ReadUInt(v2 + 60) + 1);
  91.             Memory.WowMemory.Memory.WriteInt(Memory.WowMemory.Memory.ReadUInt(v2 + 64), a2);*/
  92.  
  93.             if (a2 < Memory.WowMemory.Memory.ReadInt(v2 + 24) || a2 > Memory.WowMemory.Memory.ReadInt(v2 + 28))
  94.                 goToEnd = true;
  95.             else
  96.             {
  97.                 uint v3 = Memory.WowMemory.Memory.ReadUInt(v2 + 76);
  98.                 int v4 = a2 - Memory.WowMemory.Memory.ReadShort(v2 + 24);
  99.                 short v10 = (short) (a2 - Memory.WowMemory.Memory.ReadShort(v2 + 24));
  100.                 v5 = WowClientDB2__GetIndexAddressByIndex(Memory.WowMemory.Memory.ReadInt(v2 + 72), (int)(Memory.WowMemory.Memory.ReadInt(v2 + 72) + 4 * v3), ref v10);
  101.                 if (v5 == Memory.WowMemory.Memory.ReadInt(v2 + 72) + 4*Memory.WowMemory.Memory.ReadInt(v2 + 76) || Memory.WowMemory.Memory.ReadShort((uint) v5) != v4)
  102.                     goToEnd = true;
  103.             }
  104.             if (!goToEnd)
  105.             {
  106.                 v6 = Memory.WowMemory.Memory.ReadShort(((uint) (v5 + 2)));
  107.                 if (v6 == -2)
  108.                     return 0;
  109.             }
  110.             if (v6 == -1 || goToEnd)
  111.             {
  112.                 result = WowClientDB2__GetRowPointerBySecondaryIndex(Memory.WowMemory.Memory.ReadUInt(_this + 84), a2);
  113.             }
  114.             else
  115.             {
  116.                 short v8 = Memory.WowMemory.Memory.ReadShort(v2 + 32);
  117.                 if (v6 >= v8)
  118.                 {
  119.                     short v9 = (short) (v6 - v8);
  120.                     if ((ushort) v9 >= Memory.WowMemory.Memory.ReadInt(v2 + 44))
  121.                         return 0;
  122.                     result = (Memory.WowMemory.Memory.ReadInt(v2 + 8) + v9*Memory.WowMemory.Memory.ReadInt(v2 + 20));
  123.                 }
  124.                 else
  125.                 {
  126.                     result = (Memory.WowMemory.Memory.ReadInt(v2 + 4) + Memory.WowMemory.Memory.ReadInt(v2 + 16)*v6);
  127.                 }
  128.             }
  129.             return result;
  130.  
  131.             /*
  132.                 v2 = this;
  133.                 ++*(_DWORD *)(v2 + 56);
  134.                 if ( a2 == *(_DWORD *)(this + 64) )
  135.                     ++*(_DWORD *)(this + 60);
  136.                 *(_DWORD *)(this + 64) = a2;
  137.                
  138.                 if ( a2 < *(_DWORD *)(this + 24)
  139.                     || a2 > *(_DWORD *)(this + 28)
  140.                     || (v3 = *(_DWORD *)(this + 76),
  141.                         v4 = a2 - *(_WORD *)(v2 + 24),
  142.                         v10 = (unsigned __int16)(a2 - *(_WORD *)(v2 + 24)),
  143.                         v5 = sub_214AF6(*(_DWORD *)(v2 + 72), *(_DWORD *)(v2 + 72) + 4 * v3, &v10),
  144.                         v5 == *(_DWORD *)(v2 + 72) + 4 * *(_DWORD *)(v2 + 76))
  145.                     || *(_WORD *)v5 != v4 )
  146.                     goto LABEL_17;
  147.                 v6 = *(_WORD *)(v5 + 2);
  148.                 if ( (_WORD)v6 == -2 )
  149.                     return 0;
  150.                 if ( (_WORD)v6 == -1 )
  151.                 {
  152.                 LABEL_17:
  153.                     result = sub_216ECB(a2);
  154.                 }
  155.                 else
  156.                 {
  157.                     v8 = *(_WORD *)(v2 + 32);
  158.                     if ( (unsigned __int16)v6 >= v8 )
  159.                     {
  160.                     v9 = v6 - v8;
  161.                     if ( (unsigned int)v9 >= *(_DWORD *)(v2 + 44) )
  162.                         return 0;
  163.                     result = *(_DWORD *)(v2 + 8) + v9 * *(_DWORD *)(v2 + 20);
  164.                     }
  165.                     else
  166.                     {
  167.                     result = *(_DWORD *)(v2 + 4) + *(_DWORD *)(v2 + 16) * v6;
  168.                     }
  169.                 }
  170.                 return result;
  171.                 }
  172.             */
  173.         }
  174.  
  175.         private static bool WowClientDB2__CheckRowPointer(uint addressToDB2, int rowPtr)
  176.         {
  177.             return rowPtr > 0 && rowPtr != Memory.WowMemory.Memory.ReadByte(addressToDB2 + 0xDC);
  178.         }
  179.  
  180.         public static uint WowClientDB2__GetRowPointer(uint db2Offset, int reqId)
  181.         {
  182.             uint addressToDB2 = Memory.WowProcess.WowModule + db2Offset;
  183.  
  184.             if ((reqId >= 0 || Memory.WowMemory.Memory.ReadByte(Memory.WowMemory.Memory.ReadUInt(addressToDB2 + 0x98) + 0x58) == 1 && reqId != -1))
  185.             {
  186.                 if (reqId >= Memory.WowMemory.Memory.ReadUInt(addressToDB2 + 0xC8) && reqId <= Memory.WowMemory.Memory.ReadUInt(addressToDB2 + 0xC4))
  187.                 {
  188.                     int rowPtr = WowClientDB2__GetRowPointerByIndex(Memory.WowMemory.Memory.ReadUInt(addressToDB2 + 0xA8), reqId);
  189.                     if (rowPtr > 0)
  190.                     {
  191.                         if (WowClientDB2__CheckRowPointer(Memory.WowMemory.Memory.ReadUInt(addressToDB2), rowPtr))
  192.                             return (uint) rowPtr;
  193.                     }
  194.                 }
  195.             }
  196.             else
  197.             {
  198.                 // rare case where the first try at looking for ID fails
  199.                 // more things to dissect, but not yet interessting.
  200.             }
  201.             return 0;
  202.         }
  203.     }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement