-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmuxzcat.lua
1971 lines (1755 loc) · 73.7 KB
/
muxzcat.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
XZ/LZMA decompressor ported from https://github.com/pts/muxzcat
Licensed under GNU GPL 2.0 or later
This should work under all Lua 5.1+
To use:
muxzcat.DecompressXzOrLzmaFile(input, output) will read an XZ/LZMA file from input (FILE* or path) and write the result to output (FILE* or path)
muxzcat.DecompressXzOrLzmaString(input) will decompress a loaded XZ/LZMA file and returns the result
muxzcat.GetError(num) will return a string representation for an error code
muxzcat.ErrorCodes is a table that reverses GetError()
Written by pts@fazekas.hu at Sat Feb 2 13:28:42 CET 2019
Ported to Lua by JackMacWindows
]]
local bitlib
if bit32 ~= nil then bitlib = bit32
elseif pcall(require, "bit32") then bitlib = require "bit32"
elseif pcall(require, "bit") then bitlib = require "bit"
elseif bit ~= nil then bitlib = bit
else
--[[---------------
LuaBit v0.4
-------------------
a bitwise operation lib for lua.
http:
How to use:
-------------------
bit.bnot(n) -- bitwise not (~n)
bit.band(m, n) -- bitwise and (m & n)
bit.bor(m, n) -- bitwise or (m | n)
bit.bxor(m, n) -- bitwise xor (m ^ n)
bit.brshift(n, bits) -- right shift (n >> bits)
bit.blshift(n, bits) -- left shift (n << bits)
bit.blogic_rshift(n, bits) -- logic right shift(zero fill >>>)
Please note that bit.brshift and bit.blshift only support number within
32 bits.
2 utility functions are provided too:
bit.tobits(n) -- convert n into a bit table(which is a 1/0 sequence)
-- high bits first
bit.tonumb(bit_tbl) -- convert a bit table into a number
-------------------
Under the MIT license.
copyright(c) 2006~2007 hanzhao (abrash_han@hotmail.com)
--]]---------------
------------------------
-- bit lib implementions
local function check_int(n)
-- checking not float
if(n - math.floor(n) > 0) then
error("trying to use bitwise operation on non-integer!")
end
end
local function to_bits(n)
check_int(n)
if(n < 0) then
-- negative
return to_bits(bitlib.bnot(math.abs(n)) + 1)
end
-- to bits table
local tbl = {}
local cnt = 1
while (n > 0) do
local last = math.mod(n,2)
if(last == 1) then
tbl[cnt] = 1
else
tbl[cnt] = 0
end
n = (n-last)/2
cnt = cnt + 1
end
return tbl
end
local function tbl_to_number(tbl)
local n = table.getn(tbl)
local rslt = 0
local power = 1
for i = 1, n do
rslt = rslt + tbl[i]*power
power = power*2
end
return rslt
end
local function expand(tbl_m, tbl_n)
local big = {}
local small = {}
if(table.getn(tbl_m) > table.getn(tbl_n)) then
big = tbl_m
small = tbl_n
else
big = tbl_n
small = tbl_m
end
-- expand small
for i = table.getn(small) + 1, table.getn(big) do
small[i] = 0
end
end
local function bit_or(m, n)
local tbl_m = to_bits(m)
local tbl_n = to_bits(n)
expand(tbl_m, tbl_n)
local tbl = {}
local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))
for i = 1, rslt do
if(tbl_m[i]== 0 and tbl_n[i] == 0) then
tbl[i] = 0
else
tbl[i] = 1
end
end
return tbl_to_number(tbl)
end
local function bit_and(m, n)
local tbl_m = to_bits(m)
local tbl_n = to_bits(n)
expand(tbl_m, tbl_n)
local tbl = {}
local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))
for i = 1, rslt do
if(tbl_m[i]== 0 or tbl_n[i] == 0) then
tbl[i] = 0
else
tbl[i] = 1
end
end
return tbl_to_number(tbl)
end
local function bit_not(n)
local tbl = to_bits(n)
local size = math.max(table.getn(tbl), 32)
for i = 1, size do
if(tbl[i] == 1) then
tbl[i] = 0
else
tbl[i] = 1
end
end
return tbl_to_number(tbl)
end
local function bit_xor(m, n)
local tbl_m = to_bits(m)
local tbl_n = to_bits(n)
expand(tbl_m, tbl_n)
local tbl = {}
local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))
for i = 1, rslt do
if(tbl_m[i] ~= tbl_n[i]) then
tbl[i] = 1
else
tbl[i] = 0
end
end
--table.foreach(tbl, --print)
return tbl_to_number(tbl)
end
local function bit_rshift(n, bits)
check_int(n)
local high_bit = 0
if(n < 0) then
-- negative
n = bit_not(math.abs(n)) + 1
high_bit = 2147483648 -- 0x80000000
end
for i=1, bits do
n = n/2
n = bit_or(math.floor(n), high_bit)
end
return math.floor(n)
end
-- logic rightshift assures zero filling shift
local function bit_logic_rshift(n, bits)
check_int(n)
if(n < 0) then
-- negative
n = bit_not(math.abs(n)) + 1
end
for i=1, bits do
n = n/2
end
return math.floor(n)
end
local function bit_lshift(n, bits)
check_int(n)
if(n < 0) then
-- negative
n = bit_not(math.abs(n)) + 1
end
for i=1, bits do
n = n*2
end
return bit_and(n, 4294967295) -- 0xFFFFFFFF
end
--------------------
-- bit lib interface
bitlib = {
-- bit operations
bnot = bit_not,
band = bit_and,
bor = bit_or,
bxor = bit_xor,
brshift = bit_rshift,
blshift = bit_lshift,
blogic_rshift = bit_logic_rshift,
}
end
if bitlib.blogic_rshift then
bitlib = {
arshift = bitlib.brshift,
band = bitlib.band,
bnot = bitlib.bnot,
bor = bitlib.bor,
btest = function(a, b) return bitlib.band(a, b) ~= 0 end,
bxor = bitlib.bxor,
lshift = bitlib.blshift,
rshift = bitlib.blogic_rshift
}
end
local band = {}
local bor = {}
local bxor = {}
local bnot = {}
local blshift = {}
local brshift = {}
setmetatable(band, {__sub = function(lhs)
local mt = {lhs, __sub = function(self, b) return bitlib.band(self[1], b) end}
return setmetatable(mt, mt)
end})
setmetatable(bor, {__sub = function(lhs)
local mt = {lhs, __sub = function(self, b) return bitlib.bor(self[1], b) end}
return setmetatable(mt, mt)
end})
setmetatable(bxor, {__sub = function(lhs)
local mt = {lhs, __sub = function(self, b) return bitlib.bxor(self[1], b) end}
return setmetatable(mt, mt)
end})
setmetatable(blshift, {__sub = function(lhs)
local mt = {lhs, __sub = function(self, b) return bitlib.lshift(self[1], b) end}
return setmetatable(mt, mt)
end})
setmetatable(brshift, {__sub = function(lhs)
local mt = {lhs, __sub = function(self, b) return bitlib.rshift(self[1], b) end}
return setmetatable(mt, mt)
end})
setmetatable(bnot, {__sub = function(_, rhs) return bitlib.bnot(rhs) end})
local str_input, str_output
local function writeTableSeq(tab, i, n, ...) if n ~= nil then tab[i] = n return writeTableSeq(tab, i+1, ...) end end
local function READ_FROM_STDIN_TO_ARY8(a, fromIdx, size)
local str
if str_input then
str, str_input = str_input:sub(1, size), str_input:sub(size+1)
for i = 1, #str, 256 do writeTableSeq(a, fromIdx + i - 1, str:byte(i, i + 256)) end
return #str
else
str = io.input():read(size)
for i = 1, #str, 256 do writeTableSeq(a, fromIdx + i - 1, str:byte(i, i + 256)) end
--assert(#a - fromIdx == #str - 1, (#a - fromIdx) .. ", " .. #str .. ", " .. size)
return #str
end
end
local function readTableSeq(tab, i, j) if i == j then return tab[i] elseif i > j then return nil else return tab[i], readTableSeq(tab, i+1, j) end end
local function WRITE_TO_STDOUT_FROM_ARY8(a, fromIdx, size)
if str_output then
for i = fromIdx, fromIdx + size - 1, 256 do str_output = str_output .. string.char(readTableSeq(a, i, math.min(fromIdx + size - 1, i + 255))) end
return size
else
for i = 1, size, 256 do io.output():write(string.char(readTableSeq(a, i+fromIdx-1, math.min(fromIdx + size - 1, i + fromIdx + 254)))) end
return size
end
end
local bufCur = 0;
local dicSize = 0;
local range = 0;
local code = 0;
local dicPos = 0;
local dicBufSize = 0;
local processedPos = 0;
local checkDicSize = 0;
local state = 0;
local rep0 = 1;
local rep1 = 1;
local rep2 = 1;
local rep3 = 1;
local remainLen = 0;
local tempBufSize = 0;
local readCur = 0;
local readEnd = 0;
local needFlush = 0;
local needInitLzma = 0;
local needInitDic = 0;
local needInitState = 0;
local needInitProp = 0;
local lc = 0;
local lp = 0;
local pb = 0;
local lcm8 = 0;
local _probs16 = {}
local probs16 = setmetatable({}, {__index = function(_, idx) return _probs16[idx] --[[-band- 0xFFFF]] end, __newindex = function(_, idx, val) _probs16[idx] = val -band- 0xFFFF end});
local _readBuf8 = {}
local readBuf8 = setmetatable({}, {__index = function(_, idx) return _readBuf8[idx] --[[-band- 0xFF]] end, __newindex = function(_, idx, val) _readBuf8[idx] = val -band- 0xFF end});
local _dic8 = {}
local dic8 = setmetatable({}, {__index = function(_, idx) return _dic8[idx] --[[-band- 0xFF]] end, __newindex = function(_, idx, val) _dic8[idx] = val -band- 0xFF end});
local function ResetGlobals()
bufCur = 0;
dicSize = 0;
range = 0;
code = 0;
dicPos = 0;
dicBufSize = 0;
processedPos = 0;
checkDicSize = 0;
state = 0;
rep0 = 1;
rep1 = 1;
rep2 = 1;
rep3 = 1;
remainLen = 0;
tempBufSize = 0;
readCur = 0;
readEnd = 0;
needFlush = 0;
needInitLzma = 0;
needInitDic = 0;
needInitState = 0;
needInitProp = 0;
lc = 0;
lp = 0;
pb = 0;
lcm8 = 0;
_probs16 = {}
_readBuf8 = {}
_dic8 = {}
end
local function LzmaDec_WriteRem(wrDicLimit)
if (((remainLen) ~= (0)) and ((remainLen) < (274))) then
local wrLen = remainLen;
if (((wrDicLimit - dicPos) < (wrLen))) then
wrLen = wrDicLimit - dicPos ;
end
if (((checkDicSize) == (0)) and ((dicSize - processedPos) <= (wrLen))) then
checkDicSize = dicSize;
end
processedPos = processedPos + wrLen;
remainLen = remainLen - wrLen;
while (((wrLen) ~= (0))) do
wrLen=wrLen-1;
dic8[dicPos] = dic8[(dicPos - rep0) + (((dicPos) < (rep0)) and dicBufSize or 0)] -band- 0xFF;
dicPos=dicPos+1;
end
end
end
local function LzmaDec_DecodeReal2(drDicLimit, drBufLimit)
local pbMask = ((1) -blshift- (pb)) - 1;
local lpMask = ((1) -blshift- (lp)) - 1;
local drI = 0;
local lastTime
if textutils then
os.queueEvent("nosleep")
lastTime = os.epoch("utc")
end
repeat
local drDicLimit2 = (((checkDicSize) == (0)) and ((dicSize - processedPos) < (drDicLimit - dicPos))) and (dicPos + (dicSize - processedPos)) or drDicLimit;
--print("drDicLimit2", drDicLimit2, "checkDicSize", checkDicSize, "dicSize", dicSize, "processedPos", processedPos, "drDicLimit", drDicLimit, "dicPos", dicPos)
remainLen = 0;
repeat
local drProbIdx = 0;
local drBound = 0;
local drTtt = 0;
local distance = 0;
local drPosState = processedPos -band- pbMask;
if textutils and os.epoch("utc") - lastTime > 3000 then
--write(".")
lastTime = os.epoch("utc")
os.queueEvent(os.pullEvent())
end
--print(rep0, rep1, rep2, rep3)
drProbIdx = 0 + (state -blshift- (4)) + drPosState ;
drTtt = probs16[drProbIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur = bufCur + 1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
local drSymbol = 0;
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
range = (drBound) ;
probs16[drProbIdx] = drTtt + ((bitlib.rshift((2048 - drTtt), (5))));
drProbIdx = 1846 ;
if (((checkDicSize) ~= (0)) or ((processedPos) ~= (0))) then
drProbIdx = drProbIdx + (768 * (((processedPos -band- lpMask) -blshift- lc) + (bitlib.rshift((dic8[(((dicPos) == (0)) and dicBufSize or dicPos) - 1]), (lcm8))))) ;
end
if (((state) < (7))) then
state = state - ((((state) < (4))) and state or 3);
drSymbol = 1 ;
repeat
drTtt = probs16[drProbIdx + drSymbol] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = ((bitlib.rshift((range), 11))) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx + drSymbol] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drSymbol = (drSymbol + drSymbol);
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx + drSymbol] = drTtt - (bitlib.rshift((drTtt), (5)));
drSymbol = (drSymbol + drSymbol) + 1;
end
until not (((drSymbol) < (0x100)))
else
local drMatchByte = dic8[(dicPos - rep0) + (((dicPos) < (rep0)) and dicBufSize or 0)];
local drMatchMask = 0x100;
state = state - (((state) < (10)) and 3 or 6);
drSymbol = 1 ;
repeat
local drBit;
local drProbLitIdx;
assert(drMatchMask == 0 or drMatchMask == 0x100);
drMatchByte = drMatchByte -blshift- 1 ;
drBit = (drMatchByte -band- drMatchMask) ;
drProbLitIdx = drProbIdx + drMatchMask + drBit + drSymbol ;
drTtt = probs16[drProbLitIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbLitIdx] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drSymbol = (drSymbol + drSymbol) ;
drMatchMask = drMatchMask -band- (bnot-drBit) ;
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbLitIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
drSymbol = (drSymbol + drSymbol) + 1 ;
drMatchMask = drMatchMask -band- drBit ;
end
until not (((drSymbol) < (0x100)));
end
dic8[dicPos] = drSymbol -band- 0xFF;
dicPos=dicPos+1;
processedPos=processedPos+1;
--print("continue2")
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
drProbIdx = 192 + state ;
drTtt = probs16[drProbIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
local shouldContinue = true
if (((code) < (drBound))) then
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
range = (drBound) ;
probs16[drProbIdx] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
state = state + 12;
drProbIdx = 818 ;
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
if (((checkDicSize) == (0)) and ((processedPos) == (0))) then
--print("A")
return 1;
end
drProbIdx = 204 + state ;
drTtt = probs16[drProbIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
range = (drBound) ;
probs16[drProbIdx] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drProbIdx = 240 + (state -blshift- (4)) + drPosState ;
drTtt = probs16[drProbIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
dic8[dicPos] = dic8[(dicPos - rep0) + (((dicPos) < (rep0)) and dicBufSize or 0)] -band- 0xFF;
dicPos=dicPos+1;
processedPos=processedPos+1;
state = ((state) < (7)) and 9 or 11;
--print("continue")
shouldContinue = false
end
if shouldContinue then
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
end
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
drProbIdx = 216 + state ;
drTtt = probs16[drProbIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
distance = rep1 ;
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
drProbIdx = 228 + state ;
drTtt = probs16[drProbIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
distance = rep2 ;
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
distance = rep3 ;
rep3 = rep2;
end
rep2 = rep1;
end
rep1 = rep0;
rep0 = distance;
end
if shouldContinue then
state = ((state) < (7)) and 8 or 11;
drProbIdx = 1332 ;
end
end
if shouldContinue then
--print(distance)
do
local drLimitSub;
local drOffset;
local drProbLenIdx = drProbIdx + 0;
drTtt = probs16[drProbLenIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
range = (drBound) ;
probs16[drProbLenIdx] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drProbLenIdx = drProbIdx + 2 + (drPosState -blshift- (3)) ;
drOffset = 0 ;
drLimitSub = (8) ;
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbLenIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
drProbLenIdx = drProbIdx + 1 ;
drTtt = probs16[drProbLenIdx] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
range = (drBound) ;
probs16[drProbLenIdx] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drProbLenIdx = drProbIdx + 130 + (drPosState -blshift- (3)) ;
drOffset = 8 ;
drLimitSub = 8 ;
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbLenIdx] = drTtt - (bitlib.rshift((drTtt), (5)));
drProbLenIdx = drProbIdx + 258 ;
drOffset = 8 + 8 ;
drLimitSub = 256 ;
end
end
do
remainLen = (1) ;
repeat
drTtt = probs16[(drProbLenIdx + remainLen)] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[(drProbLenIdx + remainLen)] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
remainLen = ((remainLen + remainLen));
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[(drProbLenIdx + remainLen)] = drTtt - (bitlib.rshift((drTtt), (5)));
remainLen = ((remainLen + remainLen) + 1);
end
until not (((remainLen) < (drLimitSub)));
remainLen = remainLen - (drLimitSub) ;
end
remainLen = remainLen + (drOffset) ;
end
if (((state) >= (12))) then
drProbIdx = 432 + ((((remainLen) < (4)) and remainLen or 4 - 1) -blshift- (6)) ;
do
distance = 1 ;
repeat
drTtt = probs16[(drProbIdx + distance)] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[(drProbIdx + distance)] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
distance = (distance + distance);
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[(drProbIdx + distance)] = drTtt - (bitlib.rshift((drTtt), (5)));
distance = (distance + distance) + 1;
end
until not (((distance) < ((64))));
distance = distance - (64) ;
end
assert((distance <= 0x7fffffff) and ((distance) < (64)));
if (((distance) >= (4))) then
local drPosSlot = distance;
local drDirectBitCount = (bitlib.rshift((distance), (1))) - 1;
distance = (2 -bor- (distance -band- 1)) ;
if (((drPosSlot) < (14))) then
distance = distance -blshift- drDirectBitCount ;
drProbIdx = 688 + distance - drPosSlot - 1 ;
do
local mask = 1;
drI = 1;
repeat
drTtt = probs16[drProbIdx + drI] ;
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx + drI] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drI = (drI + drI);
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx + drI] = drTtt - (bitlib.rshift((drTtt), (5)));
drI = (drI + drI) + 1 ;
distance = distance -bor- mask ;
end
mask = mask -blshift- 1 ;
drDirectBitCount = drDirectBitCount - 1
until not (((drDirectBitCount) ~= (0)));
end
else
drDirectBitCount = drDirectBitCount - 4 ;
repeat
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
range = ((bitlib.rshift((range), 1)));
if (((code - range) -band- 0x80000000 ~= 0)) then
distance = distance -blshift- 1;
else
code = code - (range);
distance = (distance -blshift- 1) + 1;
end
drDirectBitCount = drDirectBitCount-1;
until not (((drDirectBitCount) ~= (0)));
drProbIdx = 802 ;
distance = distance -blshift- 4 ;
do
drI = 1;
drTtt = probs16[drProbIdx + drI];
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx + drI] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drI = (drI + drI);
else
range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx + drI] = drTtt - (bitlib.rshift((drTtt), (5)));
drI = (drI + drI) + 1 ;
distance = distance -bor- 1 ;
end
drTtt = probs16[drProbIdx + drI];
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx + drI] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drI = (drI + drI);
else range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx + drI] = drTtt - (bitlib.rshift((drTtt), (5)));
drI = (drI + drI) + 1 ;
distance = distance -bor- 2 ;
end
drTtt = probs16[drProbIdx + drI];
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx + drI] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drI = (drI + drI);
else range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx + drI] = drTtt - (bitlib.rshift((drTtt), (5)));
drI = (drI + drI) + 1 ;
distance = distance -bor- 4 ;
end
drTtt = probs16[drProbIdx + drI];
assert((drTtt <= 0x7fffffff) and ((drTtt) <= (2048)));
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
drBound = (bitlib.rshift((range), 11)) * drTtt ;
if (((code) < (drBound))) then
range = (drBound) ;
probs16[drProbIdx + drI] = drTtt + (bitlib.rshift((2048 - drTtt), (5)));
drI = (drI + drI);
else range = range - (drBound) ;
code = code - (drBound) ;
probs16[drProbIdx + drI] = drTtt - (bitlib.rshift((drTtt), (5)));
drI = (drI + drI) + 1 ;
distance = distance -bor- 8 ;
end
end
if (((bnot-distance) == 0)) then
remainLen = remainLen + (274) ;
state = state - 12;
--print("break")
break;
end
end
end
assert((distance <= 0x7fffffff) and ((distance) <= (1610612736)));
rep3 = rep2;
rep2 = rep1;
rep1 = rep0;
rep0 = distance + 1;
if (((checkDicSize) == (0))) then
if (((distance) >= (processedPos))) then
--print("B")
return 1;
end
else
if (((distance) >= (checkDicSize))) then
--print("C")
return 1;
end
end
state = ((state) < (12 + 7)) and 7 or 7 + 3;
end
remainLen = remainLen + (2) ;
if (((drDicLimit2) == (dicPos))) then
--print("D")
return 1;
end
do
local drRem = drDicLimit2 - dicPos;
local curLen = (((drRem) < (remainLen)) and drRem or remainLen);
local pos = (dicPos - rep0) + (((dicPos) < (rep0)) and dicBufSize or 0);
processedPos = processedPos + curLen;
remainLen = remainLen - (curLen) ;
if (((pos + curLen) <= (dicBufSize))) then
assert(((dicPos) > (pos)));
assert(((curLen) > (0)));
repeat
dic8[dicPos] = dic8[pos] -band- 0xFF;
dicPos=dicPos+1
pos=pos+1
curLen=curLen-1
until not (((curLen) ~= (0)));
else
repeat
dic8[dicPos] = dic8[pos] -band- 0xFF;
dicPos=dicPos+1
pos=pos+1
if (((pos) == (dicBufSize))) then
pos = 0 ;
end
until not (((curLen) ~= (0)));
end
end
end
end
--print("drDicLimit2", drDicLimit2, "drBufLimit", drBufLimit, "dicPos", dicPos, "bufCur", bufCur)
until not (((dicPos) < (drDicLimit2)) and ((bufCur) < (drBufLimit)));
if (((range) < (16777216))) then
range = range -blshift- (8) ;
code = ((code -blshift- 8) -bor- (readBuf8[bufCur])) ;
bufCur=bufCur+1;
end
if (((processedPos) >= (dicSize))) then
checkDicSize = dicSize;
end
LzmaDec_WriteRem(drDicLimit);
until not (((dicPos) < (drDicLimit)) and ((bufCur) < (drBufLimit)) and ((remainLen) < (274)));
if (((remainLen) > (274))) then
remainLen = 274;
end
return 0;
end
local function LzmaDec_TryDummy(tdCur, tdBufLimit)
local tdRange = range;
local tdCode = code;
local tdState = state;
local tdRes;
local tdProbIdx;
local tdBound;
local tdTtt;
local tdPosState = (processedPos) -band- ((1 -blshift- pb) - 1);
tdProbIdx = 0 + (tdState -blshift- (4)) + tdPosState ;
tdTtt = probs16[tdProbIdx] ;
if (((tdRange) < (16777216))) then
if (((tdCur) >= (tdBufLimit))) then
return 0;
end
tdRange = tdRange -blshift- 8 ;
tdCode = (tdCode -blshift- 8) -bor- (readBuf8[tdCur]) ;
tdCur=tdCur+1;
end
tdBound = (bitlib.rshift((tdRange), 11)) * tdTtt ;
if (((tdCode) < (tdBound))) then
local tdSymbol = 1;
tdRange = tdBound ;
tdProbIdx = 1846 ;
if (((checkDicSize) ~= (0)) or ((processedPos) ~= (0))) then
tdProbIdx = tdProbIdx + (768 * ((((processedPos) -band- ((1 -blshift- (lp)) - 1)) -blshift- lc) + (bitlib.rshift((dic8[(((dicPos) == (0)) and dicBufSize or dicPos) - 1]), (lcm8))))) ;
end
if (((tdState) < (7))) then
repeat
tdTtt = probs16[tdProbIdx + tdSymbol] ;
if (((tdRange) < (16777216))) then
if (((tdCur) >= (tdBufLimit))) then
return 0;
end
tdRange = tdRange -blshift- 8 ;
tdCode = (tdCode -blshift- 8) -bor- (readBuf8[tdCur]) ;
tdCur=tdCur+1;
end
tdBound = (bitlib.rshift((tdRange), 11)) * tdTtt ;
if (((tdCode) < (tdBound))) then
tdRange = tdBound ;
tdSymbol = (tdSymbol + tdSymbol);
else tdRange = tdRange - tdBound ;
tdCode = tdCode - tdBound ;
tdSymbol = (tdSymbol + tdSymbol) + 1;
end
until not (((tdSymbol) < (0x100)));
else
local tdMatchByte = dic8[dicPos - rep0 + (((dicPos) < (rep0)) and dicBufSize or 0)];
local tdMatchMask = 0x100;
repeat
local tdBit;
local tdProbLitIdx;
assert(tdMatchMask == 0 or tdMatchMask == 0x100);
tdMatchByte = tdMatchByte -blshift- 1 ;
tdBit = (tdMatchByte -band- tdMatchMask) ;
tdProbLitIdx = tdProbIdx + tdMatchMask + tdBit + tdSymbol ;
tdTtt = probs16[tdProbLitIdx] ;
if (((tdRange) < (16777216))) then
if (((tdCur) >= (tdBufLimit))) then
return 0;
end
tdRange = tdRange -blshift- 8 ;
tdCode = (tdCode -blshift- 8) -bor- (readBuf8[tdCur]) ;
tdCur=tdCur+1;
end