Advertisement
Sconle254

a

Nov 20th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. int top = 32, base = 12;
  2. typedef DWORD _DWORD;
  3.  
  4. typedef int(__stdcall *rLuaS_newlstr)(int RL, const char *str, size_t l);
  5. rLuaS_newlstr r_luaS_newlstr = (rLuaS_newlstr)x(0x7740E0); // a
  6.  
  7. union r_Value
  8. {
  9. int b;
  10. double n;
  11. void* p;
  12. void* gc;
  13. };
  14.  
  15. struct r_TValue
  16. {
  17. r_Value value;
  18. int tt;
  19. };
  20.  
  21. r_TValue *rbxx_index2adr(INT rbx_L, INT idx) {
  22. // I'll partially copy IDA pseudocode LOL !!!!!
  23. int *result;
  24. int v3;
  25. const char rbx_luaO_nilobject[] = { 0, 0, 0, 0 };
  26.  
  27. if (idx <= 0)
  28. {
  29. if (idx <= -10000)
  30. {
  31. switch (idx)
  32. {
  33. case -10002:
  34. result = (int *)(rbx_L + 64);
  35. break;
  36. case -10001:
  37. result = (int *)(rbx_L + 80);
  38. *result = *(_DWORD *)(***(_DWORD ***)(rbx_L + 28) + base);
  39. result[2] = 7;
  40. break;
  41. case -10000:
  42. result = (int *)((*(_DWORD *)(rbx_L + 20) ^ (rbx_L + 20)) + 104);
  43. break;
  44. default:
  45. v3 = ***(_DWORD ***)(rbx_L + 28);
  46. if (-10002 - idx > *(unsigned __int8 *)(v3 + 7))
  47. result = (int *)&rbx_luaO_nilobject;
  48. else
  49. result = (int *)(v3 + 16 * (-10002 - idx) + 8);
  50. break;
  51. }
  52. }
  53. else
  54. {
  55. result = (int *)(*(_DWORD *)(rbx_L + top) + 16 * idx);
  56. }
  57. }
  58. else
  59. {
  60. result = (int *)&rbx_luaO_nilobject;
  61. if ((unsigned int)(16 * idx + *(_DWORD *)(rbx_L + base) - 16) < *(_DWORD *)(rbx_L + 32))
  62. result = (int *)(16 * idx + *(_DWORD *)(rbx_L + base) - 16);
  63. }
  64. return (r_TValue *)result;
  65. }
  66.  
  67. INT *rbx_index2adr(INT rbx_L, INT idx) {
  68. // I'll partially copy IDA pseudocode LOL !!!!!
  69. int *result;
  70. int v3;
  71. const char rbx_luaO_nilobject[] = { 0, 0, 0, 0 };
  72.  
  73. if (idx <= 0)
  74. {
  75. if (idx <= -10000)
  76. {
  77. switch (idx)
  78. {
  79. case -10002:
  80. result = (int *)(rbx_L + 64);
  81. break;
  82. case -10001:
  83. result = (int *)(rbx_L + 80);
  84. *result = *(_DWORD *)(***(_DWORD ***)(rbx_L + 28) + 12);
  85. result[2] = 7;
  86. break;
  87. case -10000:
  88. result = (int *)((*(_DWORD *)(rbx_L + 20) ^ (rbx_L + 20)) + 104);
  89. break;
  90. default:
  91. v3 = ***(_DWORD ***)(rbx_L + 28);
  92. if (-10002 - idx > *(unsigned __int8 *)(v3 + 7))
  93. result = (int *)&rbx_luaO_nilobject;
  94. else
  95. result = (int *)(v3 + 16 * (-10002 - idx) + 8);
  96. break;
  97. }
  98. }
  99. else
  100. {
  101. result = (int *)(*(_DWORD *)(rbx_L + top) + 16 * idx);
  102. }
  103. }
  104. else
  105. {
  106. result = (int *)&rbx_luaO_nilobject;
  107. if ((unsigned int)(16 * idx + *(_DWORD *)(rbx_L + base) - 16) < *(_DWORD *)(rbx_L + 32))
  108. result = (int *)(16 * idx + *(_DWORD *)(rbx_L + base) - 16);
  109. }
  110. return result;
  111. }
  112.  
  113. void r_lua_pushnil(DWORD a1) {
  114. *(_DWORD *)(*(_DWORD *)(a1 + top) + 8) = 0;
  115. *(_DWORD *)(a1 + top) += 16;
  116. }
  117.  
  118. void r_lua_pushboolean(DWORD a1, int a2) {
  119. _DWORD *v2;
  120. v2 = *(_DWORD **)(a1 + top);
  121. *v2 = a2 != 0;
  122. v2[2] = 3;
  123. *(_DWORD *)(a1 + top) += 16;
  124. }
  125.  
  126. void r_lua_pushstring(int rState, const char *s) {
  127. int v3 = *(DWORD *)(rState + top);
  128. *(DWORD *)v3 = r_luaS_newlstr(rState, s, strlen(s));
  129. *(DWORD *)(v3 + 8) = R_LUA_TSTRING;
  130. *(DWORD *)(rState + top) += 16;
  131. }
  132.  
  133. void r_lua_settop(int a1, int a2) {
  134. int i;
  135. if (a2 < 0)
  136. {
  137. *(_DWORD *)(a1 + top) += 16 * a2 + 16;
  138. }
  139. else
  140. {
  141. for (i = 16 * a2; *(_DWORD *)(a1 + top) < (unsigned int)(i + *(_DWORD *)(a1 + base)); *(_DWORD *)(a1 + top) += 16)
  142. *(_DWORD *)(*(_DWORD *)(a1 + top) + 8) = 0;
  143. *(_DWORD *)(a1 + top) = i + *(_DWORD *)(a1 + base);
  144. }
  145. }
  146.  
  147. void r_lua_pushvalue(DWORD a1, int a2)
  148. {
  149. r_TValue *p = rbxx_index2adr(a1, a2);
  150. int v3 = *(DWORD *)(a1 + top);
  151. *(DWORD *)v3 = *(DWORD *)p;
  152. *(DWORD *)(v3 + 4) = *(DWORD *)(p + 4);
  153. *(DWORD *)(v3 + 8) = p->tt;
  154. *(DWORD *)(a1 + top) += 16;
  155. }
  156.  
  157. inline int r_lua_toboolean(int rState, int idx) {
  158. return rbxx_index2adr(rState, idx)->value.b;
  159. }
  160.  
  161. inline int r_lua_type(int rState, int idx) {
  162. return rbxx_index2adr(rState, idx)->tt;
  163. }
  164.  
  165. int rxor = x(0x1A4CBD0); // updated
  166.  
  167. inline int r_lua_tonumber(int rState, int idx) {
  168. PVOID OldNumber = &rbxx_index2adr(rState, idx)->value.n;
  169. double NewNumber;
  170. __asm {
  171. mov edx, OldNumber
  172. mov eax, rxor
  173. movsd xmm1, qword ptr[edx]
  174. xorpd xmm1, [eax]
  175. movsd NewNumber, xmm1
  176. }
  177. return NewNumber;
  178. }
  179.  
  180. void r_lua_pushlightuserdata(DWORD a1, void* fn)
  181. {
  182. r_TValue* top = *(r_TValue**)(a1 + top);
  183. top->value.p = fn;
  184. top->tt = 1;
  185. *(DWORD*)(a1 + 32) += 16;
  186. }
  187.  
  188. INT r_lua_touserdata(INT rbx_L, signed int idx) {
  189. INT result;
  190.  
  191. INT* o = rbx_index2adr(rbx_L, idx);
  192. if (o[2] == 1)
  193. {
  194. result = *o;
  195. }
  196. else if (o[2] == 8)
  197. {
  198. result = *o + 24;
  199. }
  200. else
  201. {
  202. result = NULL;
  203. }
  204. return result;
  205. }
  206.  
  207. int r_lua_gettop(DWORD a1)
  208. {
  209. return (*(_DWORD *)(a1 + top) - *(_DWORD *)(a1 + base)) >> 4;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement