Kpack - fully roaming LZMA code is now

git-svn-id: svn://kolibrios.org@1681 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Marat Zakiyanov (Mario79) 2010-10-31 11:06:54 +00:00
parent d6f81b2980
commit 6f90a83af7
6 changed files with 1828 additions and 1419 deletions

View File

@ -0,0 +1,59 @@
;---------------------------------------------------------------------
aQuestion db '?'
caption_str db 'KPack',0
buttons1names db ' InFile:'
db 'OutFile:'
db ' Path:'
aCompress db 'COMPRESS',0
aDecompress db 'DECOMPRESS',0
definoutname db 0
defpath db '/RD/1/'
curedit dd 0
info_str db 'KPack - Kolibri Packer, version 0.13',10
db 'Uses LZMA v4.32 compression library',10,10
info_len = $ - info_str
usage_str db 'Written by diamond in 2006, 2007, 2009 specially for KolibriOS',10
db 'LZMA is copyright (c) 1999-2005 by Igor Pavlov',10
db 10
db 'Command-line usage:',10
db ' kpack infile [outfile]',10
db 'If no output file is specified,',10
db ' packed data will be written back to input file',10
db 10
db 'Window usage:',10
db " enter input file name, output file name and press needed button",10
usage_len = $ - usage_str
errload_str db 'Cannot load input file',10
errload_len = $ - errload_str
outfileerr_str db 'Cannot save output file',10
outfileerr_len = $ - outfileerr_str
nomem_str db 'No memory',10
nomem_len = $ - nomem_str
too_big_str db 'failed, output is greater than input.',10
too_big_len = $ - too_big_str
compressing_str db 'Compressing ... '
compressing_len = $ - compressing_str
lzma_memsmall_str db 'Warning: not enough memory for default LZMA settings,',10
db ' will use less dictionary size',10
lzma_memsmall_len = $ - lzma_memsmall_str
notpacked_str db 'Input file is not packed with KPack!',10
notpacked_len = $ - notpacked_str
unpacked_ok db 'Unpacked successful',10
unpacked_len = $ - unpacked_ok
done_str db 'OK! Compression ratio: '
ratio dw '00'
db '%',10
done_len = $ - done_str
;---------------------------------------------------------------------
align 4
LiteralNextStates:
db 0,0,0,0,1,2,3,4,5,6,4,5
MatchNextStates:
db 7,7,7,7,7,7,7,10,10,10,10,10
RepNextStates:
db 8,8,8,8,8,8,8,11,11,11,11,11
ShortRepNextStates:
db 9,9,9,9,9,9,9,11,11,11,11,11
;---------------------------------------------------------------------

View File

@ -0,0 +1,204 @@
;---------------------------------------------------------------------
;rb 0xD3C ;unknown space area
params:
rb 256
;---------------------------------------------------------------------
color_table rd 10
skinheight rd 1
innamelen rd 1
inname rb 48
outnamelen rd 1
outname rb 48
pathlen rd 1
path rb 48
curedit_y rd 1
message_mem rb 80*20
message_cur_pos rd 1
outsize rd 1
infile rd 1
outfile rd 1
outfile1 rd 1
outfile2 rd 1
outfilebest rd 1
inbuftmp rd 1
workmem rd 1
lzma_dictsize rd 1
ct1 rb 256
ctn rd 1
cti rb 1
use_lzma = 1
use_no_calltrick = 0
use_calltrick1 = 40h
use_calltrick2 = 80h
method rb 1
;---------------------------------------------------------------------
align 4
fn70block:
fn70op rd 1
fn70start rd 1
fn70size rd 1
fn70zero rd 1
fn70dest rd 1
fullname rb 100
;---------------------------------------------------------------------
align 4
file_attr rd 8
insize rd 1 ; last qword in file_attr
rd 1
;---------------------------------------------------------------------
align 4
rb 4096
stacktop:
;---------------------------------------------------------------------
; Deconpress area
align 4
unpack.p rb 0x1F36*4
unpack.code_:
rd 1
unpack.range:
rd 1
unpack.rep0 rd 1
unpack.rep1 rd 1
unpack.rep2 rd 1
unpack.rep3 rd 1
unpack.previousByte rb 1
;---------------------------------------------------------------------
; Compress area
align 4
_lenEncoder:
rd 8451
;-----------------------------------------------------
_prices:
rd 4384
rd 17
;-----------------------------------------------------
_finished: rb 1
_writeEndMark: rb 1
_longestMatchWasFound: rb 1
_previousByte: rb 1
_longestMatchLength: rd 1
;-----------------------------------------------------
g_FastPos:
rb 1024
;-----------------------------------------------------
_posSlotPrices:
rd 256
;-----------------------------------------------------
_isRep0Long:
rd 192
;-----------------------------------------------------
distances:
rd 274
;-----------------------------------------------------
_optimumCurrentIndex: rd 1
_additionalOffset: rd 1
;-----------------------------------------------------
_isRepG1:
rd 12
;-----------------------------------------------------
_isMatch:
rd 192
;-----------------------------------------------------
_alignPriceCount: rd 1
_numLiteralContextBits: rd 1
;-----------------------------------------------------
_literalEncoder:
rd 114
;-----------------------------------------------------
nowPos64:
rd 2
;-----------------------------------------------------
_distancesPrices:
rd 512
;-----------------------------------------------------
_repDistances:
rd 4
;-----------------------------------------------------
_posSlotEncoder:
rd 1028
;-----------------------------------------------------
lastPosSlotFillingPos:
rd 2
;-----------------------------------------------------
_numFastBytes: rd 1
_posStateMask: rd 1
;-----------------------------------------------------
_isRepG0:
rd 12
;-----------------------------------------------------
_repMatchLenEncoder:
rd 8451
rd 4384
rd 17
;-----------------------------------------------------
_isRepG2:
rd 12
;-----------------------------------------------------
_dictionarySize: rd 1
_numLiteralPosStateBits: rd 1
_distTableSize: rd 1
_optimumEndIndex: rd 1
;-----------------------------------------------------
;static CState state
state.State: rb 1
state.Prev1IsChar: rb 1
state.Prev2: rb 2
state.PosPrev2: rd 1
state.BackPrev2: rd 1
state.Price: rd 1
state.PosPrev: rd 1
state.BackPrev: rd 1
state.Backs:
rd 4
;----------------------------------------------------
rd 40950
;-----------------------------------------------------
_alignPrices:
rd 16
;-----------------------------------------------------
_isRep:
rd 12
;-----------------------------------------------------
_posAlignEncoder:
rd 256
;-----------------------------------------------------
i_01: rd 1
;-----------------------------------------------------
_state: rb 1
_cache: rb 1
_state.Prev2: rb 2
_posEncoders: rd 1
_numPrevBits: rd 1
_numPosBits: rd 1
_posMask: rd 1
_posStateBits: rd 1
range: rd 1
_cacheSize: rd 1
_cyclicBufferSize: rd 1
;-----------------------------------------------------
low:
rd 2
;-----------------------------------------------------
Models:
rd 512
;-----------------------------------------------------
_matchMaxLen: rd 1
pack_pos: rd 1
_cutValue: rd 1
_hash: rd 1
;-----------------------------------------------------
crc_table:
rd 256
;-----------------------------------------------------
_buffer: rd 1
_pos: rd 1
_streamPos: rd 1
pack_length: rd 1
;---------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,9 @@ lzma_decompress:
push edi push edi
push ebx push ebx
push ebp push ebp
mov esi,[esp+0x14] mov esi,[esp+20]
xor ebp,ebp xor ebp,ebp
mov edi,0xD6B8 mov edi,unpack.code_
inc esi inc esi
lodsd lodsd
bswap eax bswap eax
@ -20,43 +20,47 @@ lzma_decompress:
xchg esi,eax xchg esi,eax
stosd stosd
mov ecx,0x1F36 mov ecx,0x1F36
mov eax,0x400 mov eax,1024
mov edi,0x59E0 mov edi,unpack.p
rep stosd rep stosd
mov edi,[esp+0x18] mov edi,[esp+24]
mov ebx, edi mov ebx, edi
add ebx,[esp+0x1C] add ebx,[esp+28]
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_00: .main_loop:
cmp edi,ebx cmp edi,ebx
jnb .labl_19 jnb .main_loop_done
mov edx,edi mov edx,edi
and edx,3 and edx,3
push eax push eax
mov eax,ebp mov eax,ebp
shl eax,6 shl eax,6
lea eax,[eax+edx*4+0x59E0] lea eax,[eax+edx*4+unpack.p]
call cm_pr_20 call RangeDecoderBitDecode
pop eax pop eax
jb .labl_06 jb .labl_06
movzx eax,al movzx eax,al
shr eax,5 shr eax,5
imul eax,eax,0xC00 imul eax,eax,3072
add eax,0x76B8 add eax,unpack.p+0x1CD8
mov cl,1 mov cl,1
cmp ebp,7 cmp ebp,7
jb .labl_02 jb .labl_02
mov dl,[edi+esi] mov dl,[edi+esi]
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_01: .labl_01:
add dl,dl add dl,dl
setb ch setb ch
push eax push eax
lea eax,[eax+ecx*4+0x400] lea eax,[eax+ecx*4+1024]
call cm_pr_20 call RangeDecoderBitDecode
pop eax pop eax
adc cl,cl adc cl,cl
jb .labl_03 jb .labl_03
xor ch,cl xor ch,cl
test ch,1 test ch,1
mov ch,0 mov ch,0
@ -65,7 +69,7 @@ lzma_decompress:
.labl_02: .labl_02:
push eax push eax
lea eax,[eax+ecx*4] lea eax,[eax+ecx*4]
call cm_pr_20 call RangeDecoderBitDecode
pop eax pop eax
adc cl,cl adc cl,cl
jnb .labl_02 jnb .labl_02
@ -74,64 +78,72 @@ lzma_decompress:
mov eax,ebp mov eax,ebp
cmp al,4 cmp al,4
jb .labl_04 jb .labl_04
cmp al,0xA
cmp al,10
mov al,3 mov al,3
jb .labl_04 jb .labl_04
mov al,6 mov al,6
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_04: .labl_04:
sub ebp,eax sub ebp,eax
xchg ecx,eax xchg ecx,eax
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_05: .main_loop_1:
stosb stosb
jmp .labl_00 jmp .main_loop
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_06: .labl_06:
lea eax,[0x5CE0+ebp*4] lea eax,[unpack.p+768+ebp*4]
call cm_pr_20 call RangeDecoderBitDecode
jnb .labl_09 jnb .labl_09
add eax,0x30 ;'0'
call cm_pr_20 add eax,48
call RangeDecoderBitDecode
jb .labl_07 jb .labl_07
mov eax, ebp mov eax, ebp
shl eax,6 shl eax,6
lea eax,[eax+edx*4+0x5DA0] lea eax,[eax+edx*4+unpack.p+0x3C0]
call cm_pr_20 call RangeDecoderBitDecode
jb .labl_08 jb .labl_08
cmp ebp,7 cmp ebp,7
sbb ebp,ebp sbb ebp,ebp
lea ebp,[ebp+ebp+0xB] lea ebp,[ebp+ebp+11]
mov al,[edi+esi] mov al,[edi+esi]
jmp .labl_05 jmp .main_loop_1
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_07: .labl_07:
add eax,0x30 ;'0' add eax,48
call cm_pr_20 call RangeDecoderBitDecode
xchg esi,[0xD6C0] xchg esi,[unpack.rep0]
jnb .labl_08 jnb .labl_08
add eax,0x30 ;'0'
call cm_pr_20 add eax,48
xchg esi,[0xD6C4] call RangeDecoderBitDecode
xchg esi,[unpack.rep1]
jnb .labl_08 jnb .labl_08
xchg esi,[0xD6C8]
xchg esi,[unpack.rep2]
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_08: .labl_08:
mov eax,0x6EB0 mov eax,unpack.p+0x14D0
call cm_pr_22 call LzmaLenDecode
push 8 push 8
jmp .labl_17 jmp .labl_17
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_09: .labl_09:
xchg esi,[0xD6C0] xchg esi,[unpack.rep0]
xchg esi,[0xD6C4] xchg esi,[unpack.rep1]
mov [0xD6C8],esi mov [unpack.rep2],esi
mov eax,0x66A8 mov eax,unpack.p+0xCC8
call cm_pr_22 call LzmaLenDecode
push 3 push 3
pop eax pop eax
cmp eax,ecx cmp eax,ecx
jb .labl_10 jb .labl_10
mov eax,ecx mov eax,ecx
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_10: .labl_10:
@ -140,11 +152,12 @@ lzma_decompress:
pop ecx pop ecx
shl eax,cl shl eax,cl
shl eax,2 shl eax,2
add eax,0x60A0 add eax,unpack.p+0x6C0
call cm_pr_23 call RangeDecoderBitTreeDecode
mov esi,ecx mov esi,ecx
cmp ecx,4 cmp ecx,4
jb .labl_16 jb .labl_16
push ecx push ecx
xor eax,eax xor eax,eax
inc eax inc eax
@ -154,11 +167,12 @@ lzma_decompress:
shl eax,cl shl eax,cl
mov esi, eax mov esi, eax
pop edx pop edx
cmp edx,0xE cmp edx,14
jnb .labl_11 jnb .labl_11
sub eax,edx sub eax,edx
shl eax,2 shl eax,2
add eax,0x649C add eax,unpack.p+0xABC
jmp .labl_14 jmp .labl_14
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_11: .labl_11:
@ -166,21 +180,22 @@ lzma_decompress:
xor eax,eax xor eax,eax
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_12: .labl_12:
shr dword [0xD6BC],1 shr dword [unpack.range],1
add eax, eax add eax, eax
mov edx,[0xD6B8] mov edx,[unpack.code_]
sub edx,[0xD6BC] sub edx,[unpack.range]
jb .labl_13 jb .labl_13
mov [0xD6B8],edx
mov [unpack.code_],edx
inc eax inc eax
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_13: .labl_13:
call cm_pr_21 call RangeDecoderBitDecode_1
loop .labl_12 loop .labl_12
mov cl,4 mov cl,4
shl eax,cl shl eax,cl
add esi,eax add esi,eax
mov eax,0x6668 mov eax,unpack.p+0xC88
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_14: .labl_14:
push edi push edi
@ -192,7 +207,7 @@ lzma_decompress:
.labl_15: .labl_15:
push eax push eax
lea eax,[eax+edx*4] lea eax,[eax+edx*4]
call cm_pr_20 call RangeDecoderBitDecode
lahf lahf
adc edx,edx adc edx,edx
sahf sahf
@ -213,6 +228,7 @@ lzma_decompress:
cmp ebp,7 cmp ebp,7
pop ebp pop ebp
jb .labl_18 jb .labl_18
inc ebp inc ebp
inc ebp inc ebp
inc ebp inc ebp
@ -224,107 +240,117 @@ lzma_decompress:
rep movsb rep movsb
lodsb lodsb
pop esi pop esi
jmp .labl_05 jmp .main_loop_1
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_19: .main_loop_done:
pop ebp pop ebp
pop ebx pop ebx
pop edi pop edi
pop esi pop esi
ret 0xC ret 12
;***************************************************************************** ;*****************************************************************************
;* Call: *************************************************************** ;* Call: ***************************************************************
cm_pr_20: RangeDecoderBitDecode:
; in: eax->prob
; out: CF=bit; destroys eax
push edx push edx
mov edx,[0xD6BC] mov edx,[unpack.range]
shr edx,0xB shr edx,11
imul edx,[eax] imul edx,[eax]
cmp [0xD6B8],edx cmp [unpack.code_],edx
jnb .labl_01 jnb .2
mov [0xD6BC],edx
mov edx,0x800 mov [unpack.range],edx
mov edx,2048
sub edx,[eax] sub edx,[eax]
shr edx,5 shr edx,5
add [eax],edx add [eax],edx
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_00: .1:
pushfd pushfd
call cm_pr_21 call RangeDecoderBitDecode_1
popfd popfd
pop edx pop edx
ret ret
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_01: .2:
sub [0xD6BC],edx sub [unpack.range],edx
sub [0xD6B8],edx sub [unpack.code_],edx
mov edx,[eax] mov edx,[eax]
shr edx,5 shr edx,5
sub [eax],edx sub [eax],edx
stc stc
jmp .labl_00 jmp .1
;*********************************************************************** ;***********************************************************************
;* Call: *************************************************************** ;* Call: ***************************************************************
cm_pr_21: RangeDecoderBitDecode_1:
cmp [0xD6BF],byte 0 cmp byte [unpack.range+3],0
jne .labl_00 jne @f
shl dword [0xD6BC],8
shl dword [0xD6B8],8 shl dword [unpack.range],8
shl dword [unpack.code_],8
push eax push eax
mov eax,[0xD6CC] mov eax,[unpack.rep3]
mov al,[eax] mov al,[eax]
inc dword [0xD6CC] inc dword [unpack.rep3]
mov [0xD6B8],al mov [unpack.code_],al
pop eax pop eax
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_00: @@:
ret ret
;*********************************************************************** ;***********************************************************************
;* Call: *************************************************************** ;* Call: ***************************************************************
cm_pr_22: LzmaLenDecode:
call cm_pr_20 ; in: eax->prob, edx=posState
jnb .labl_01 ; out: ecx=len
call RangeDecoderBitDecode
jnb .2
add eax,4 add eax,4
call cm_pr_20 call RangeDecoderBitDecode
jb .labl_00 jb .1
mov cl,3 mov cl,3
shl edx,cl shl edx,cl
lea eax,[eax+edx*4+0x204] lea eax,[eax+edx*4+516]
call cm_pr_23 call RangeDecoderBitTreeDecode
add ecx,8 add ecx,8
ret ret
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_00: .1:
add eax,0x404 add eax,1028
mov cl,8 mov cl,8
call cm_pr_23 call RangeDecoderBitTreeDecode
add ecx,0x10 add ecx,16
ret ret
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_01: .2:
mov cl,3 mov cl,3
shl edx,cl shl edx,cl
lea eax,[eax+edx*4+8] lea eax,[eax+edx*4+8]
;*********************************************************************** ;***********************************************************************
;* Call: *************************************************************** ;* Call: ***************************************************************
cm_pr_23: RangeDecoderBitTreeDecode:
; in: eax->probs,ecx=numLevels
; out: ecx=length; destroys edx
push edi push edi
xor edx,edx xor edx,edx
inc edx inc edx
mov edi,edx mov edi,edx
xchg edi, eax xchg edi, eax
;-------------------------------------------------------------------- ;--------------------------------------------------------------------
.labl_00: @@:
push eax push eax
lea eax,[edi+edx*4] lea eax,[edi+edx*4]
call cm_pr_20 call RangeDecoderBitDecode
pop eax pop eax
adc dl,dl adc dl,dl
add al,al add al,al
loop .labl_00 loop @b
sub dl,al sub dl,al
pop edi pop edi
mov ecx,edx mov ecx,edx

View File

@ -1,11 +1,12 @@
;* Call: *************************************************************** ;* Call: ***************************************************************
; lzma_set_dict_size(unsigned logdictsize)
lzma_set_dict_size: lzma_set_dict_size:
mov ecx,[esp+4] mov ecx,[esp+4]
xor eax,eax xor eax,eax
inc eax inc eax
shl eax,cl shl eax,cl
mov [0x29568],eax mov [_dictionarySize],eax
lea eax,[ecx+ecx] lea eax,[ecx+ecx]
mov [0x29570],eax mov [_distTableSize],eax
ret 4 ret 4
;***************************************************************************** ;*****************************************************************************