Ameisen

Untitled

Jun 22nd, 2022
1,194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. int Foo0(int index) {
  2.     return Impl.ProductsArray[index];
  3. }
  4.  
  5. int Foo0a(int index) {
  6.     ref int rawArray = ref MemoryMarshal.GetArrayDataReference(Impl.ProductsArray);
  7.     return Unsafe.AddByteOffset(ref rawArray, (IntPtr)(index * sizeof(int)));
  8. }
  9.  
  10. int Foo1(int index) {
  11.     return Impl.ProductsPtr[index];
  12. }
  13.  
  14. static class Impl {
  15.     internal static readonly int[] ProductsArray = new int[] { 0x090000,0x000900,0x040102,0x010402 };
  16.     internal static ReadOnlySpan<byte> ProductsSpan => new byte[] { 0x00,0x00,0x09,0x00, 0x00,0x09,0x00,0x00, 0x02,0x01,0x04,0x00, 0x02,0x04,0x01,0x00 };
  17.     internal static readonly unsafe int* ProductsPtr = (int*)Unsafe.AsPointer(ref Unsafe.AsRef(ProductsSpan.GetPinnableReference()));
  18. }
  19.  
  20. ---
  21.  
  22. <Main>g__Foo0|4_0 (Int32)
  23. L0000   push    rsi
  24. L0001   sub rsp, 0x20
  25. L0005   mov esi, ecx
  26. L0007   mov rcx, 0x7ffa20a8cde0
  27. L0011   mov edx, 1
  28. L0016   call    0x00007ffa7fb391e0
  29. L001b   mov rax, [rax]
  30. L001e   cmp esi, [rax+8]
  31. L0021   jae short L0030
  32. L0023   movsxd  rdx, esi
  33. L0026   mov eax, [rax+rdx*4+0x10]
  34. L002a   add rsp, 0x20
  35. L002e   pop rsi
  36. L002f   ret
  37. L0030   call    0x00007ffa7fb3abc0
  38. L0035   int3   
  39.  
  40. <Main>g__Foo0a|4_1 (Int32)
  41. L0000   push    rsi
  42. L0001   sub rsp, 0x20
  43. L0005   mov esi, ecx
  44. L0007   mov rcx, 0x7ffa20a8cde0
  45. L0011   mov edx, 1
  46. L0016   call    0x00007ffa7fb391e0
  47. L001b   mov rax, [rax]
  48. L001e   cmp [rax], eax
  49. L0020   add rax, 0x10
  50. L0024   shl esi, 2
  51. L0027   movsxd  rdx, esi
  52. L002a   mov eax, [rax+rdx]
  53. L002d   add rsp, 0x20
  54. L0031   pop rsi
  55. L0032   ret
  56.  
  57. <Main>g__Foo1|4_2 (Int32)
  58. L0000   push    rsi
  59. L0001   sub rsp, 0x20
  60. L0005   mov esi, ecx
  61. L0007   mov rcx, 0x7ffa20a8cde0
  62. L0011   mov edx, 1
  63. L0016   call    0x00007ffa7fb393b0
  64. L001b   mov rax, [rax+8]
  65. L001f   movsxd  rdx, esi
  66. L0022   mov eax, [rax+rdx*4]
  67. L0025   add rsp, 0x20
  68. L0029   pop rsi
  69. L002a   ret
Advertisement
Add Comment
Please, Sign In to add comment