panraven

ce_csharp_decimal_novalue2bytes.lua

Dec 18th, 2020
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local cs_decimal_typeName = 'CSharp_Decimal_ASM'
  2.  
  3. cs_decimal_typeName = cs_decimal_typeName:gsub('%W','_')
  4.  
  5.  
  6. local script = string.format([=======[
  7. alloc(ConvertRoutine,$4000)
  8. alloc(ConvertBackRoutine,1024)
  9. alloc(TypeName,256)
  10. alloc(ByteSize,4)
  11. alloc(UsesFloat,1)
  12. alloc(CallMethod,1)
  13.  
  14. TypeName:
  15. db '%s',0
  16.  
  17. ByteSize:
  18. dd 10
  19.  
  20. UsesFloat:
  21. db 1 //Change to 1 if this custom type should be treated as a float
  22.  
  23. CallMethod:
  24. db 1 //Remove or change to 0 for legacy call mechanism
  25.  
  26. label(ds2to64)
  27. label(s_doublePowers10)
  28. label(NaN)
  29.  
  30. ConvertRoutine+3000:
  31. NaN:
  32. dd 0ffc00000,(float)0.5
  33. ds2to64:
  34. dq (double)1.8446744073709552e+019
  35. s_doublePowers10:
  36. dq (double)1e+00, (double)1e+01, (double)1e+02, (double)1e+03,
  37. dq (double)1e+04, (double)1e+05, (double)1e+06, (double)1e+07,
  38. dq (double)1e+08, (double)1e+09, (double)1e+10, (double)1e+11,
  39. dq (double)1e+12, (double)1e+13, (double)1e+14, (double)1e+15,
  40. dq (double)1e+16, (double)1e+17, (double)1e+18, (double)1e+19,
  41. dq (double)1e+20, (double)1e+21, (double)1e+22, (double)1e+23,
  42. dq (double)1e+24, (double)1e+25, (double)1e+26, (double)1e+27,
  43. dq (double)1e+28, (double)1e+29, (double)1e+30, (double)1e+31,
  44. dq (double)1e+32, (double)1e+33, (double)1e+34, (double)1e+35,
  45. dq (double)1e+36, (double)1e+37, (double)1e+38, (double)1e+39,
  46. dq (double)1e+40, (double)1e+41, (double)1e+42, (double)1e+43,
  47. dq (double)1e+44, (double)1e+45, (double)1e+46, (double)1e+47,
  48. dq (double)1e+48, (double)1e+49, (double)1e+50, (double)1e+51,
  49. dq (double)1e+52, (double)1e+53, (double)1e+54, (double)1e+55,
  50. dq (double)1e+56, (double)1e+57, (double)1e+58, (double)1e+59,
  51. dq (double)1e+60, (double)1e+61, (double)1e+62, (double)1e+63,
  52. dq (double)1e+64, (double)1e+65, (double)1e+66, (double)1e+67,
  53. dq (double)1e+68, (double)1e+69, (double)1e+70, (double)1e+71,
  54. dq (double)1e+72, (double)1e+73, (double)1e+74, (double)1e+75,
  55. dq (double)1e+76, (double)1e+77, (double)1e+78, (double)1e+79,
  56. dq (double)1e+80
  57.  
  58. label(skipDone)
  59. //The convert routine should hold a routine that converts the data to an integer (in eax)
  60. //function declared as: cdecl int ConvertRoutine(unsigned char *input, PTR_UINT address);
  61. //Note: Keep in mind that this routine can be called by multiple threads at the same time.
  62. ConvertRoutine:
  63. //jmp dllname.functionname
  64. [64-bit]
  65. //or manual:
  66. //parameters: (64-bit)
  67. //rcx=address of input
  68. //rdx=address
  69. //mov eax,[rcx] //eax now contains the bytes 'input' pointed to
  70. ////////////////////////////
  71. push   rsi
  72. push   rdi
  73. push   rdx
  74. push   rcx
  75. //  mov    edi,[rcx+04]
  76. //  jmp    skipDone
  77.   mov    rsi,rcx
  78.   mov    edi,[NaN]
  79.  
  80.   mov    edx,[rsi+0c]
  81.   test    edx,7fe0ffff
  82.   jne    skipDone
  83.   shr    edx,10
  84.   and    edx,ff
  85.   cmp    edx,1c
  86.   ja     skipDone
  87.   mov    ecx,edx
  88.  
  89.   movsd      xmm0,[ds2to64]
  90.   cvtsi2sd   xmm1,dword ptr[rsi+08]
  91.   mulsd      xmm0,xmm1
  92.   cvtsi2sd   xmm1,qword ptr[rsi]
  93.   addsd      xmm0,xmm1
  94.   movsd      xmm1,[rcx*8+s_doublePowers10]
  95.   divsd      xmm0,xmm1
  96.  
  97.   test       byte ptr[rsi+0f],80
  98.   je         short @f
  99.     xorpd    xmm1,xmm1
  100.     subsd    xmm1,xmm0
  101.     movsd    xmm0,xmm1
  102. @@:
  103.   cvtsd2ss   xmm0,xmm0
  104.   movd       edi,xmm0
  105.  
  106. skipDone:
  107.   mov    eax,edi
  108. pop    rcx
  109. pop    rdx
  110. pop    rdi
  111. pop    rsi
  112.  
  113. ////////////////////////////
  114. ret
  115. [/64-bit]
  116.  
  117. [32-bit]
  118. //jmp dllname.functionname
  119. //or manual:
  120. //parameters: (32-bit)
  121. push ebp
  122. mov ebp,esp
  123. //[ebp+8]=address of input
  124. //[ebp+c]=address
  125. //example:
  126. mov eax,[ebp+8] //place the address that contains the bytes into eax
  127. mov eax,[eax] //place the bytes into eax so it's handled as a normal 4 byte value
  128.  
  129. pop ebp
  130. ret
  131. [/32-bit]
  132.  
  133. //The convert back routine should hold a routine that converts the given integer back to a row of bytes (e.g when the user wats to write a new value)
  134. //function declared as: cdecl void ConvertBackRoutine(int i, PTR_UINT address, unsigned char *output);
  135. ConvertBackRoutine:
  136. //jmp dllname.functionname
  137. //or manual:
  138. [64-bit]
  139. //parameters: (64-bit)
  140. //ecx=input
  141. //rdx=address
  142. //r8=address of output
  143. //example:
  144.  
  145. ///  do no change
  146. ///mov [r8],ecx //place the integer at the 4 bytes pointed to by r8
  147.  
  148. ret
  149. [/64-bit]
  150.  
  151. [32-bit]
  152. //parameters: (32-bit)
  153. push ebp
  154. mov ebp,esp
  155. //[ebp+8]=input
  156. //[ebp+c]=address
  157. //[ebp+10]=address of output
  158. //example:
  159. push eax
  160. push ebx
  161. mov eax,[ebp+8] //load the value into eax
  162. mov ebx,[ebp+10] //load the output address into ebx
  163. mov [ebx],eax //write the value into the address
  164. pop ebx
  165. pop eax
  166.  
  167. pop ebp
  168. ret
  169. [/32-bit]
  170.  
  171. ]=======],cs_decimal_typeName)
RAW Paste Data