lua-obfuscator 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/index.d.ts +14 -0
  2. package/dist/index.js +58 -0
  3. package/dist/prometheus/LICENSE +661 -0
  4. package/dist/prometheus/benchmark.lua +34 -0
  5. package/dist/prometheus/build.bat +10 -0
  6. package/dist/prometheus/cli.lua +12 -0
  7. package/dist/prometheus/doc/README.md +11 -0
  8. package/dist/prometheus/doc/SUMMARY.md +27 -0
  9. package/dist/prometheus/doc/advanced/using-prometheus-in-your-lua-application.md +31 -0
  10. package/dist/prometheus/doc/getting-started/command-line-options.md +13 -0
  11. package/dist/prometheus/doc/getting-started/installation.md +11 -0
  12. package/dist/prometheus/doc/getting-started/obfuscating-your-first-script.md +50 -0
  13. package/dist/prometheus/doc/getting-started/presets.md +10 -0
  14. package/dist/prometheus/doc/getting-started/the-config-object.md +58 -0
  15. package/dist/prometheus/doc/getting-started/writing-a-custom-config-file.md +56 -0
  16. package/dist/prometheus/doc/steps/anti-tamper.md +11 -0
  17. package/dist/prometheus/doc/steps/constantarray.md +71 -0
  18. package/dist/prometheus/doc/steps/encryptstrings.md +86 -0
  19. package/dist/prometheus/doc/steps/proxifylocals.md +47 -0
  20. package/dist/prometheus/doc/steps/splitstrings.md +40 -0
  21. package/dist/prometheus/doc/steps/vmify.md +9 -0
  22. package/dist/prometheus/doc/steps/wrapinfunction.md +29 -0
  23. package/dist/prometheus/prometheus-main.lua +1 -0
  24. package/dist/prometheus/readme.md +57 -0
  25. package/dist/prometheus/readme.txt +5 -0
  26. package/dist/prometheus/src/cli.lua +154 -0
  27. package/dist/prometheus/src/colors.lua +61 -0
  28. package/dist/prometheus/src/config.lua +35 -0
  29. package/dist/prometheus/src/highlightlua.lua +61 -0
  30. package/dist/prometheus/src/logger.lua +62 -0
  31. package/dist/prometheus/src/presets.lua +174 -0
  32. package/dist/prometheus/src/prometheus/ast.lua +792 -0
  33. package/dist/prometheus/src/prometheus/bit.lua +521 -0
  34. package/dist/prometheus/src/prometheus/compiler/compiler.lua +2365 -0
  35. package/dist/prometheus/src/prometheus/enums.lua +106 -0
  36. package/dist/prometheus/src/prometheus/namegenerators/Il.lua +41 -0
  37. package/dist/prometheus/src/prometheus/namegenerators/confuse.lua +169 -0
  38. package/dist/prometheus/src/prometheus/namegenerators/mangled.lua +26 -0
  39. package/dist/prometheus/src/prometheus/namegenerators/mangled_shuffled.lua +35 -0
  40. package/dist/prometheus/src/prometheus/namegenerators/number.lua +11 -0
  41. package/dist/prometheus/src/prometheus/namegenerators.lua +7 -0
  42. package/dist/prometheus/src/prometheus/parser.lua +969 -0
  43. package/dist/prometheus/src/prometheus/pipeline.lua +250 -0
  44. package/dist/prometheus/src/prometheus/randomLiterals.lua +41 -0
  45. package/dist/prometheus/src/prometheus/randomStrings.lua +24 -0
  46. package/dist/prometheus/src/prometheus/scope.lua +332 -0
  47. package/dist/prometheus/src/prometheus/step.lua +79 -0
  48. package/dist/prometheus/src/prometheus/steps/AddVararg.lua +33 -0
  49. package/dist/prometheus/src/prometheus/steps/AntiTamper.lua +194 -0
  50. package/dist/prometheus/src/prometheus/steps/ConstantArray.lua +521 -0
  51. package/dist/prometheus/src/prometheus/steps/EncryptStrings.lua +239 -0
  52. package/dist/prometheus/src/prometheus/steps/NumbersToExpressions.lua +82 -0
  53. package/dist/prometheus/src/prometheus/steps/ProxifyLocals.lua +313 -0
  54. package/dist/prometheus/src/prometheus/steps/SplitStrings.lua +338 -0
  55. package/dist/prometheus/src/prometheus/steps/Vmify.lua +30 -0
  56. package/dist/prometheus/src/prometheus/steps/Watermark.lua +61 -0
  57. package/dist/prometheus/src/prometheus/steps/WatermarkCheck.lua +50 -0
  58. package/dist/prometheus/src/prometheus/steps/WrapInFunction.lua +45 -0
  59. package/dist/prometheus/src/prometheus/steps.lua +12 -0
  60. package/dist/prometheus/src/prometheus/tokenizer.lua +546 -0
  61. package/dist/prometheus/src/prometheus/unparser.lua +866 -0
  62. package/dist/prometheus/src/prometheus/util.lua +297 -0
  63. package/dist/prometheus/src/prometheus/visitast.lua +245 -0
  64. package/dist/prometheus/src/prometheus.lua +71 -0
  65. package/dist/prometheus/tests/closures.lua +12 -0
  66. package/dist/prometheus/tests/fibonacci.lua +10 -0
  67. package/dist/prometheus/tests/loops.lua +8 -0
  68. package/dist/prometheus/tests/primes.lua +18 -0
  69. package/dist/prometheus/tests.lua +149 -0
  70. package/package.json +25 -0
  71. package/src/index.ts +76 -0
  72. package/src/prometheus/.editorconfig +4 -0
  73. package/src/prometheus/.gitattributes +2 -0
  74. package/src/prometheus/.gitbook.yaml +1 -0
  75. package/src/prometheus/.github/ISSUE_TEMPLATE/bug_report.md +25 -0
  76. package/src/prometheus/.github/workflows/Build.yml +49 -0
  77. package/src/prometheus/.github/workflows/Test.yml +19 -0
  78. package/src/prometheus/LICENSE +661 -0
  79. package/src/prometheus/benchmark.lua +34 -0
  80. package/src/prometheus/build.bat +10 -0
  81. package/src/prometheus/cli.lua +12 -0
  82. package/src/prometheus/doc/README.md +11 -0
  83. package/src/prometheus/doc/SUMMARY.md +27 -0
  84. package/src/prometheus/doc/advanced/using-prometheus-in-your-lua-application.md +31 -0
  85. package/src/prometheus/doc/getting-started/command-line-options.md +13 -0
  86. package/src/prometheus/doc/getting-started/installation.md +11 -0
  87. package/src/prometheus/doc/getting-started/obfuscating-your-first-script.md +50 -0
  88. package/src/prometheus/doc/getting-started/presets.md +10 -0
  89. package/src/prometheus/doc/getting-started/the-config-object.md +58 -0
  90. package/src/prometheus/doc/getting-started/writing-a-custom-config-file.md +56 -0
  91. package/src/prometheus/doc/steps/anti-tamper.md +11 -0
  92. package/src/prometheus/doc/steps/constantarray.md +71 -0
  93. package/src/prometheus/doc/steps/encryptstrings.md +86 -0
  94. package/src/prometheus/doc/steps/proxifylocals.md +47 -0
  95. package/src/prometheus/doc/steps/splitstrings.md +40 -0
  96. package/src/prometheus/doc/steps/vmify.md +9 -0
  97. package/src/prometheus/doc/steps/wrapinfunction.md +29 -0
  98. package/src/prometheus/prometheus-main.lua +1 -0
  99. package/src/prometheus/readme.md +57 -0
  100. package/src/prometheus/readme.txt +5 -0
  101. package/src/prometheus/src/cli.lua +154 -0
  102. package/src/prometheus/src/colors.lua +61 -0
  103. package/src/prometheus/src/highlightlua.lua +61 -0
  104. package/src/prometheus/src/logger.lua +62 -0
  105. package/src/prometheus/src/presets.lua +174 -0
  106. package/src/prometheus/src/prometheus/ast.lua +792 -0
  107. package/src/prometheus/src/prometheus/bit.lua +521 -0
  108. package/src/prometheus/src/prometheus/compiler/compiler.lua +2365 -0
  109. package/src/prometheus/src/prometheus/enums.lua +106 -0
  110. package/src/prometheus/src/prometheus/namegenerators/Il.lua +41 -0
  111. package/src/prometheus/src/prometheus/namegenerators/confuse.lua +169 -0
  112. package/src/prometheus/src/prometheus/namegenerators/mangled.lua +26 -0
  113. package/src/prometheus/src/prometheus/namegenerators/mangled_shuffled.lua +35 -0
  114. package/src/prometheus/src/prometheus/namegenerators/number.lua +11 -0
  115. package/src/prometheus/src/prometheus/namegenerators.lua +7 -0
  116. package/src/prometheus/src/prometheus/parser.lua +969 -0
  117. package/src/prometheus/src/prometheus/pipeline.lua +250 -0
  118. package/src/prometheus/src/prometheus/randomLiterals.lua +41 -0
  119. package/src/prometheus/src/prometheus/randomStrings.lua +24 -0
  120. package/src/prometheus/src/prometheus/scope.lua +332 -0
  121. package/src/prometheus/src/prometheus/step.lua +79 -0
  122. package/src/prometheus/src/prometheus/steps/AddVararg.lua +33 -0
  123. package/src/prometheus/src/prometheus/steps/AntiTamper.lua +194 -0
  124. package/src/prometheus/src/prometheus/steps/ConstantArray.lua +521 -0
  125. package/src/prometheus/src/prometheus/steps/EncryptStrings.lua +239 -0
  126. package/src/prometheus/src/prometheus/steps/NumbersToExpressions.lua +82 -0
  127. package/src/prometheus/src/prometheus/steps/ProxifyLocals.lua +313 -0
  128. package/src/prometheus/src/prometheus/steps/SplitStrings.lua +338 -0
  129. package/src/prometheus/src/prometheus/steps/Vmify.lua +30 -0
  130. package/src/prometheus/src/prometheus/steps/Watermark.lua +61 -0
  131. package/src/prometheus/src/prometheus/steps/WatermarkCheck.lua +50 -0
  132. package/src/prometheus/src/prometheus/steps/WrapInFunction.lua +45 -0
  133. package/src/prometheus/src/prometheus/steps.lua +12 -0
  134. package/src/prometheus/src/prometheus/tokenizer.lua +546 -0
  135. package/src/prometheus/src/prometheus/unparser.lua +866 -0
  136. package/src/prometheus/src/prometheus/util.lua +297 -0
  137. package/src/prometheus/src/prometheus/visitast.lua +245 -0
  138. package/src/prometheus/src/prometheus.lua +71 -0
  139. package/src/prometheus/tests/closures.lua +12 -0
  140. package/src/prometheus/tests/fibonacci.lua +10 -0
  141. package/src/prometheus/tests/loops.lua +8 -0
  142. package/src/prometheus/tests/primes.lua +18 -0
  143. package/src/prometheus/tests.lua +149 -0
  144. package/tsconfig.json +13 -0
@@ -0,0 +1,521 @@
1
+ -- This Module was NOT written by Levno_710
2
+ -- Credit: https://github.com/davidm/lua-bit-numberlua
3
+
4
+ --[[
5
+ LUA MODULE
6
+ bit.numberlua - Bitwise operations implemented in pure Lua as numbers,
7
+ with Lua 5.2 'bit32' and (LuaJIT) LuaBitOp 'bit' compatibility interfaces.
8
+ SYNOPSIS
9
+ local bit = require 'bit.numberlua'
10
+ print(bit.band(0xff00ff00, 0x00ff00ff)) --> 0xffffffff
11
+
12
+ -- Interface providing strong Lua 5.2 'bit32' compatibility
13
+ local bit32 = require 'bit.numberlua'.bit32
14
+ assert(bit32.band(-1) == 0xffffffff)
15
+
16
+ -- Interface providing strong (LuaJIT) LuaBitOp 'bit' compatibility
17
+ local bit = require 'bit.numberlua'.bit
18
+ assert(bit.tobit(0xffffffff) == -1)
19
+
20
+ DESCRIPTION
21
+
22
+ This library implements bitwise operations entirely in Lua.
23
+ This module is typically intended if for some reasons you don't want
24
+ to or cannot install a popular C based bit library like BitOp 'bit' [1]
25
+ (which comes pre-installed with LuaJIT) or 'bit32' (which comes
26
+ pre-installed with Lua 5.2) but want a similar interface.
27
+
28
+ This modules represents bit arrays as non-negative Lua numbers. [1]
29
+ It can represent 32-bit bit arrays when Lua is compiled
30
+ with lua_Number as double-precision IEEE 754 floating point.
31
+ The module is nearly the most efficient it can be but may be a few times
32
+ slower than the C based bit libraries and is orders or magnitude
33
+ slower than LuaJIT bit operations, which compile to native code. Therefore,
34
+ this library is inferior in performane to the other modules.
35
+ The `xor` function in this module is based partly on Roberto Ierusalimschy's
36
+ post in http://lua-users.org/lists/lua-l/2002-09/msg00134.html .
37
+
38
+ The included BIT.bit32 and BIT.bit sublibraries aims to provide 100%
39
+ compatibility with the Lua 5.2 "bit32" and (LuaJIT) LuaBitOp "bit" library.
40
+ This compatbility is at the cost of some efficiency since inputted
41
+ numbers are normalized and more general forms (e.g. multi-argument
42
+ bitwise operators) are supported.
43
+
44
+ STATUS
45
+ WARNING: Not all corner cases have been tested and documented.
46
+ Some attempt was made to make these similar to the Lua 5.2 [2]
47
+ and LuaJit BitOp [3] libraries, but this is not fully tested and there
48
+ are currently some differences. Addressing these differences may
49
+ be improved in the future but it is not yet fully determined how to
50
+ resolve these differences.
51
+
52
+ The BIT.bit32 library passes the Lua 5.2 test suite (bitwise.lua)
53
+ http://www.lua.org/tests/5.2/ . The BIT.bit library passes the LuaBitOp
54
+ test suite (bittest.lua). However, these have not been tested on
55
+ platforms with Lua compiled with 32-bit integer numbers.
56
+ API
57
+ BIT.tobit(x) --> z
58
+
59
+ Similar to function in BitOp.
60
+
61
+ BIT.tohex(x, n)
62
+
63
+ Similar to function in BitOp.
64
+
65
+ BIT.band(x, y) --> z
66
+
67
+ Similar to function in Lua 5.2 and BitOp but requires two arguments.
68
+
69
+ BIT.bor(x, y) --> z
70
+
71
+ Similar to function in Lua 5.2 and BitOp but requires two arguments.
72
+ BIT.bxor(x, y) --> z
73
+
74
+ Similar to function in Lua 5.2 and BitOp but requires two arguments.
75
+
76
+ BIT.bnot(x) --> z
77
+
78
+ Similar to function in Lua 5.2 and BitOp.
79
+ BIT.lshift(x, disp) --> z
80
+
81
+ Similar to function in Lua 5.2 (warning: BitOp uses unsigned lower 5 bits of shift),
82
+
83
+ BIT.rshift(x, disp) --> z
84
+
85
+ Similar to function in Lua 5.2 (warning: BitOp uses unsigned lower 5 bits of shift),
86
+ BIT.extract(x, field [, width]) --> z
87
+
88
+ Similar to function in Lua 5.2.
89
+
90
+ BIT.replace(x, v, field, width) --> z
91
+
92
+ Similar to function in Lua 5.2.
93
+
94
+ BIT.bswap(x) --> z
95
+
96
+ Similar to function in Lua 5.2.
97
+ BIT.rrotate(x, disp) --> z
98
+ BIT.ror(x, disp) --> z
99
+
100
+ Similar to function in Lua 5.2 and BitOp.
101
+ BIT.lrotate(x, disp) --> z
102
+ BIT.rol(x, disp) --> z
103
+ Similar to function in Lua 5.2 and BitOp.
104
+
105
+ BIT.arshift
106
+
107
+ Similar to function in Lua 5.2 and BitOp.
108
+
109
+ BIT.btest
110
+
111
+ Similar to function in Lua 5.2 with requires two arguments.
112
+ BIT.bit32
113
+
114
+ This table contains functions that aim to provide 100% compatibility
115
+ with the Lua 5.2 "bit32" library.
116
+
117
+ bit32.arshift (x, disp) --> z
118
+ bit32.band (...) --> z
119
+ bit32.bnot (x) --> z
120
+ bit32.bor (...) --> z
121
+ bit32.btest (...) --> true | false
122
+ bit32.bxor (...) --> z
123
+ bit32.extract (x, field [, width]) --> z
124
+ bit32.replace (x, v, field [, width]) --> z
125
+ bit32.lrotate (x, disp) --> z
126
+ bit32.lshift (x, disp) --> z
127
+ bit32.rrotate (x, disp) --> z
128
+ bit32.rshift (x, disp) --> z
129
+ BIT.bit
130
+
131
+ This table contains functions that aim to provide 100% compatibility
132
+ with the LuaBitOp "bit" library (from LuaJIT).
133
+
134
+ bit.tobit(x) --> y
135
+ bit.tohex(x [,n]) --> y
136
+ bit.bnot(x) --> y
137
+ bit.bor(x1 [,x2...]) --> y
138
+ bit.band(x1 [,x2...]) --> y
139
+ bit.bxor(x1 [,x2...]) --> y
140
+ bit.lshift(x, n) --> y
141
+ bit.rshift(x, n) --> y
142
+ bit.arshift(x, n) --> y
143
+ bit.rol(x, n) --> y
144
+ bit.ror(x, n) --> y
145
+ bit.bswap(x) --> y
146
+
147
+ DEPENDENCIES
148
+ None (other than Lua 5.1 or 5.2).
149
+
150
+ DOWNLOAD/INSTALLATION
151
+ If using LuaRocks:
152
+ luarocks install lua-bit-numberlua
153
+ Otherwise, download <https://github.com/davidm/lua-bit-numberlua/zipball/master>.
154
+ Alternately, if using git:
155
+ git clone git://github.com/davidm/lua-bit-numberlua.git
156
+ cd lua-bit-numberlua
157
+ Optionally unpack:
158
+ ./util.mk
159
+ or unpack and install in LuaRocks:
160
+ ./util.mk install
161
+ REFERENCES
162
+ [1] http://lua-users.org/wiki/FloatingPoint
163
+ [2] http://www.lua.org/manual/5.2/
164
+ [3] http://bitop.luajit.org/
165
+
166
+ LICENSE
167
+ (c) 2008-2011 David Manura. Licensed under the same terms as Lua (MIT).
168
+ Permission is hereby granted, free of charge, to any person obtaining a copy
169
+ of this software and associated documentation files (the "Software"), to deal
170
+ in the Software without restriction, including without limitation the rights
171
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
172
+ copies of the Software, and to permit persons to whom the Software is
173
+ furnished to do so, subject to the following conditions:
174
+ The above copyright notice and this permission notice shall be included in
175
+ all copies or substantial portions of the Software.
176
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
177
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
179
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
180
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
181
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
182
+ THE SOFTWARE.
183
+ (end license)
184
+ --]]
185
+
186
+ local M = {_TYPE='module', _NAME='bit.numberlua', _VERSION='0.3.1.20120131'}
187
+
188
+ local floor = math.floor
189
+
190
+ local MOD = 2^32
191
+ local MODM = MOD-1
192
+
193
+ local function memoize(f)
194
+ local mt = {}
195
+ local t = setmetatable({}, mt)
196
+ function mt:__index(k)
197
+ local v = f(k); t[k] = v
198
+ return v
199
+ end
200
+ return t
201
+ end
202
+
203
+ local function make_bitop_uncached(t, m)
204
+ local function bitop(a, b)
205
+ local res,p = 0,1
206
+ while a ~= 0 and b ~= 0 do
207
+ local am, bm = a%m, b%m
208
+ res = res + t[am][bm]*p
209
+ a = (a - am) / m
210
+ b = (b - bm) / m
211
+ p = p*m
212
+ end
213
+ res = res + (a+b)*p
214
+ return res
215
+ end
216
+ return bitop
217
+ end
218
+
219
+ local function make_bitop(t)
220
+ local op1 = make_bitop_uncached(t,2^1)
221
+ local op2 = memoize(function(a)
222
+ return memoize(function(b)
223
+ return op1(a, b)
224
+ end)
225
+ end)
226
+ return make_bitop_uncached(op2, 2^(t.n or 1))
227
+ end
228
+
229
+ -- ok? probably not if running on a 32-bit int Lua number type platform
230
+ function M.tobit(x)
231
+ return x % 2^32
232
+ end
233
+
234
+ M.bxor = make_bitop {[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0}, n=4}
235
+ local bxor = M.bxor
236
+
237
+ function M.bnot(a) return MODM - a end
238
+ local bnot = M.bnot
239
+
240
+ function M.band(a,b) return ((a+b) - bxor(a,b))/2 end
241
+ local band = M.band
242
+
243
+ function M.bor(a,b) return MODM - band(MODM - a, MODM - b) end
244
+ local bor = M.bor
245
+
246
+ local lshift, rshift -- forward declare
247
+
248
+ function M.rshift(a,disp) -- Lua5.2 insipred
249
+ if disp < 0 then return lshift(a,-disp) end
250
+ return floor(a % 2^32 / 2^disp)
251
+ end
252
+ rshift = M.rshift
253
+
254
+ function M.lshift(a,disp) -- Lua5.2 inspired
255
+ if disp < 0 then return rshift(a,-disp) end
256
+ return (a * 2^disp) % 2^32
257
+ end
258
+ lshift = M.lshift
259
+
260
+ function M.tohex(x, n) -- BitOp style
261
+ n = n or 8
262
+ local up
263
+ if n <= 0 then
264
+ if n == 0 then return '' end
265
+ up = true
266
+ n = - n
267
+ end
268
+ x = band(x, 16^n-1)
269
+ return ('%0'..n..(up and 'X' or 'x')):format(x)
270
+ end
271
+ local tohex = M.tohex
272
+
273
+ function M.extract(n, field, width) -- Lua5.2 inspired
274
+ width = width or 1
275
+ return band(rshift(n, field), 2^width-1)
276
+ end
277
+ local extract = M.extract
278
+
279
+ function M.replace(n, v, field, width) -- Lua5.2 inspired
280
+ width = width or 1
281
+ local mask1 = 2^width-1
282
+ v = band(v, mask1) -- required by spec?
283
+ local mask = bnot(lshift(mask1, field))
284
+ return band(n, mask) + lshift(v, field)
285
+ end
286
+ local replace = M.replace
287
+
288
+ function M.bswap(x) -- BitOp style
289
+ local a = band(x, 0xff); x = rshift(x, 8)
290
+ local b = band(x, 0xff); x = rshift(x, 8)
291
+ local c = band(x, 0xff); x = rshift(x, 8)
292
+ local d = band(x, 0xff)
293
+ return lshift(lshift(lshift(a, 8) + b, 8) + c, 8) + d
294
+ end
295
+ local bswap = M.bswap
296
+
297
+ function M.rrotate(x, disp) -- Lua5.2 inspired
298
+ disp = disp % 32
299
+ local low = band(x, 2^disp-1)
300
+ return rshift(x, disp) + lshift(low, 32-disp)
301
+ end
302
+ local rrotate = M.rrotate
303
+
304
+ function M.lrotate(x, disp) -- Lua5.2 inspired
305
+ return rrotate(x, -disp)
306
+ end
307
+ local lrotate = M.lrotate
308
+
309
+ M.rol = M.lrotate -- LuaOp inspired
310
+ M.ror = M.rrotate -- LuaOp insipred
311
+
312
+
313
+ function M.arshift(x, disp) -- Lua5.2 inspired
314
+ local z = rshift(x, disp)
315
+ if x >= 0x80000000 then z = z + lshift(2^disp-1, 32-disp) end
316
+ return z
317
+ end
318
+ local arshift = M.arshift
319
+
320
+ function M.btest(x, y) -- Lua5.2 inspired
321
+ return band(x, y) ~= 0
322
+ end
323
+
324
+ --
325
+ -- Start Lua 5.2 "bit32" compat section.
326
+ --
327
+
328
+ M.bit32 = {} -- Lua 5.2 'bit32' compatibility
329
+
330
+
331
+ local function bit32_bnot(x)
332
+ return (-1 - x) % MOD
333
+ end
334
+ M.bit32.bnot = bit32_bnot
335
+
336
+ local function bit32_bxor(a, b, c, ...)
337
+ local z
338
+ if b then
339
+ a = a % MOD
340
+ b = b % MOD
341
+ z = bxor(a, b)
342
+ if c then
343
+ z = bit32_bxor(z, c, ...)
344
+ end
345
+ return z
346
+ elseif a then
347
+ return a % MOD
348
+ else
349
+ return 0
350
+ end
351
+ end
352
+ M.bit32.bxor = bit32_bxor
353
+
354
+ local function bit32_band(a, b, c, ...)
355
+ local z
356
+ if b then
357
+ a = a % MOD
358
+ b = b % MOD
359
+ z = ((a+b) - bxor(a,b)) / 2
360
+ if c then
361
+ z = bit32_band(z, c, ...)
362
+ end
363
+ return z
364
+ elseif a then
365
+ return a % MOD
366
+ else
367
+ return MODM
368
+ end
369
+ end
370
+ M.bit32.band = bit32_band
371
+
372
+ local function bit32_bor(a, b, c, ...)
373
+ local z
374
+ if b then
375
+ a = a % MOD
376
+ b = b % MOD
377
+ z = MODM - band(MODM - a, MODM - b)
378
+ if c then
379
+ z = bit32_bor(z, c, ...)
380
+ end
381
+ return z
382
+ elseif a then
383
+ return a % MOD
384
+ else
385
+ return 0
386
+ end
387
+ end
388
+ M.bit32.bor = bit32_bor
389
+
390
+ function M.bit32.btest(...)
391
+ return bit32_band(...) ~= 0
392
+ end
393
+
394
+ function M.bit32.lrotate(x, disp)
395
+ return lrotate(x % MOD, disp)
396
+ end
397
+
398
+ function M.bit32.rrotate(x, disp)
399
+ return rrotate(x % MOD, disp)
400
+ end
401
+
402
+ function M.bit32.lshift(x,disp)
403
+ if disp > 31 or disp < -31 then return 0 end
404
+ return lshift(x % MOD, disp)
405
+ end
406
+
407
+ function M.bit32.rshift(x,disp)
408
+ if disp > 31 or disp < -31 then return 0 end
409
+ return rshift(x % MOD, disp)
410
+ end
411
+
412
+ function M.bit32.arshift(x,disp)
413
+ x = x % MOD
414
+ if disp >= 0 then
415
+ if disp > 31 then
416
+ return (x >= 0x80000000) and MODM or 0
417
+ else
418
+ local z = rshift(x, disp)
419
+ if x >= 0x80000000 then z = z + lshift(2^disp-1, 32-disp) end
420
+ return z
421
+ end
422
+ else
423
+ return lshift(x, -disp)
424
+ end
425
+ end
426
+
427
+ function M.bit32.extract(x, field, ...)
428
+ local width = ... or 1
429
+ if field < 0 or field > 31 or width < 0 or field+width > 32 then error 'out of range' end
430
+ x = x % MOD
431
+ return extract(x, field, ...)
432
+ end
433
+
434
+ function M.bit32.replace(x, v, field, ...)
435
+ local width = ... or 1
436
+ if field < 0 or field > 31 or width < 0 or field+width > 32 then error 'out of range' end
437
+ x = x % MOD
438
+ v = v % MOD
439
+ return replace(x, v, field, ...)
440
+ end
441
+
442
+
443
+ --
444
+ -- Start LuaBitOp "bit" compat section.
445
+ --
446
+
447
+ M.bit = {} -- LuaBitOp "bit" compatibility
448
+
449
+ function M.bit.tobit(x)
450
+ x = x % MOD
451
+ if x >= 0x80000000 then x = x - MOD end
452
+ return x
453
+ end
454
+ local bit_tobit = M.bit.tobit
455
+
456
+ function M.bit.tohex(x, ...)
457
+ return tohex(x % MOD, ...)
458
+ end
459
+
460
+ function M.bit.bnot(x)
461
+ return bit_tobit(bnot(x % MOD))
462
+ end
463
+
464
+ local function bit_bor(a, b, c, ...)
465
+ if c then
466
+ return bit_bor(bit_bor(a, b), c, ...)
467
+ elseif b then
468
+ return bit_tobit(bor(a % MOD, b % MOD))
469
+ else
470
+ return bit_tobit(a)
471
+ end
472
+ end
473
+ M.bit.bor = bit_bor
474
+
475
+ local function bit_band(a, b, c, ...)
476
+ if c then
477
+ return bit_band(bit_band(a, b), c, ...)
478
+ elseif b then
479
+ return bit_tobit(band(a % MOD, b % MOD))
480
+ else
481
+ return bit_tobit(a)
482
+ end
483
+ end
484
+ M.bit.band = bit_band
485
+
486
+ local function bit_bxor(a, b, c, ...)
487
+ if c then
488
+ return bit_bxor(bit_bxor(a, b), c, ...)
489
+ elseif b then
490
+ return bit_tobit(bxor(a % MOD, b % MOD))
491
+ else
492
+ return bit_tobit(a)
493
+ end
494
+ end
495
+ M.bit.bxor = bit_bxor
496
+
497
+ function M.bit.lshift(x, n)
498
+ return bit_tobit(lshift(x % MOD, n % 32))
499
+ end
500
+
501
+ function M.bit.rshift(x, n)
502
+ return bit_tobit(rshift(x % MOD, n % 32))
503
+ end
504
+
505
+ function M.bit.arshift(x, n)
506
+ return bit_tobit(arshift(x % MOD, n % 32))
507
+ end
508
+
509
+ function M.bit.rol(x, n)
510
+ return bit_tobit(lrotate(x % MOD, n % 32))
511
+ end
512
+
513
+ function M.bit.ror(x, n)
514
+ return bit_tobit(rrotate(x % MOD, n % 32))
515
+ end
516
+
517
+ function M.bit.bswap(x)
518
+ return bit_tobit(bswap(x % MOD))
519
+ end
520
+
521
+ return M