forked from KolibriOS/kolibrios
Kpack v 0.20
Added code for packing the kernel.mnt git-svn-id: svn://kolibrios.org@1713 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
843504d669
commit
f19e882566
32
programs/other/kpack/trunk/calltrick2.inc
Normal file
32
programs/other/kpack/trunk/calltrick2.inc
Normal file
@ -0,0 +1,32 @@
|
||||
pop esi
|
||||
push esi
|
||||
loader_patch4:
|
||||
mov ecx, 0 ; will be patched: number of calltrick entries
|
||||
ctrloop:
|
||||
lodsb
|
||||
@@:
|
||||
cmp al, 0xF
|
||||
jnz .f
|
||||
lodsb
|
||||
cmp al, 80h
|
||||
jb @b
|
||||
cmp al, 90h
|
||||
jb @f
|
||||
.f:
|
||||
sub al, 0E8h
|
||||
cmp al, 1
|
||||
ja ctrloop
|
||||
@@:
|
||||
cmp byte [esi], 0 ; will be patched: code in calltrick entries
|
||||
loader_patch5:
|
||||
jnz ctrloop
|
||||
lodsd
|
||||
; "bswap eax" is not supported on i386
|
||||
; mov al,0/bswap eax = 4 bytes, following instructions = 9 bytes
|
||||
shr ax, 8
|
||||
ror eax, 16
|
||||
xchg al, ah
|
||||
sub eax, esi
|
||||
add eax, [esp]
|
||||
mov [esi-4], eax
|
||||
loop ctrloop
|
@ -10,7 +10,7 @@ definoutname db 0
|
||||
defpath db '/RD/1/'
|
||||
;curedit dd 0
|
||||
|
||||
info_str db 'KPack - Kolibri Packer, version 0.15',10
|
||||
info_str db 'KPack - Kolibri Packer, version 0.20',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
|
||||
@ -26,6 +26,10 @@ usage_str db 'Written by diamond in 2006, 2007, 2009 specially for KolibriOS',10
|
||||
db ' or enter input and output file name,',10
|
||||
db ' enter path and press needed button',10
|
||||
usage_len = $ - usage_str
|
||||
already_str db 'Already packed kernel.mnt file',10
|
||||
already_len = $ - already_str
|
||||
notkernel_str db 'This is not kernel.mnt file',10
|
||||
notkernel_len = $ - notkernel_str
|
||||
errload_str db 'Cannot load input file',10
|
||||
errload_len = $ - errload_str
|
||||
outfileerr_str db 'Cannot save output file',10
|
||||
@ -75,21 +79,25 @@ Box_lib_import:
|
||||
edit_box_draw dd aEdit_box_draw
|
||||
edit_box_key dd aEdit_box_key
|
||||
edit_box_mouse dd aEdit_box_mouse
|
||||
version_ed dd aVersion_ed
|
||||
;version_ed dd aVersion_ed
|
||||
|
||||
option_box_draw dd aOption_box_draw
|
||||
option_box_mouse dd aOption_box_mouse
|
||||
version_op dd aVersion_op
|
||||
check_box_draw dd aCheck_box_draw
|
||||
check_box_mouse dd aCheck_box_mouse
|
||||
;version_ch dd aVersion_ch
|
||||
|
||||
scrollbar_ver_draw dd aScrollbar_ver_draw
|
||||
scrollbar_ver_mouse dd aScrollbar_ver_mouse
|
||||
scrollbar_hor_draw dd aScrollbar_hor_draw
|
||||
scrollbar_hor_mouse dd aScrollbar_hor_mouse
|
||||
version_scrollbar dd aVersion_scrollbar
|
||||
;option_box_draw dd aOption_box_draw
|
||||
;option_box_mouse dd aOption_box_mouse
|
||||
;version_op dd aVersion_op
|
||||
|
||||
menu_bar_draw dd aMenu_bar_draw
|
||||
menu_bar_mouse dd aMenu_bar_mouse
|
||||
version_menu_bar dd aVersion_menu_bar
|
||||
;scrollbar_ver_draw dd aScrollbar_ver_draw
|
||||
;scrollbar_ver_mouse dd aScrollbar_ver_mouse
|
||||
;scrollbar_hor_draw dd aScrollbar_hor_draw
|
||||
;scrollbar_hor_mouse dd aScrollbar_hor_mouse
|
||||
;version_scrollbar dd aVersion_scrollbar
|
||||
|
||||
;menu_bar_draw dd aMenu_bar_draw
|
||||
;menu_bar_mouse dd aMenu_bar_mouse
|
||||
;version_menu_bar dd aVersion_menu_bar
|
||||
|
||||
dd 0
|
||||
dd 0
|
||||
@ -97,21 +105,25 @@ version_menu_bar dd aVersion_menu_bar
|
||||
aEdit_box_draw db 'edit_box',0
|
||||
aEdit_box_key db 'edit_box_key',0
|
||||
aEdit_box_mouse db 'edit_box_mouse',0
|
||||
aVersion_ed db 'version_ed',0
|
||||
;aVersion_ed db 'version_ed',0
|
||||
|
||||
aOption_box_draw db 'option_box_draw',0
|
||||
aOption_box_mouse db 'option_box_mouse',0
|
||||
aVersion_op db 'version_op',0
|
||||
aCheck_box_draw db 'check_box_draw',0
|
||||
aCheck_box_mouse db 'check_box_mouse',0
|
||||
;aVersion_ch db 'version_ch',0
|
||||
|
||||
aScrollbar_ver_draw db 'scrollbar_v_draw',0
|
||||
aScrollbar_ver_mouse db 'scrollbar_v_mouse',0
|
||||
aScrollbar_hor_draw db 'scrollbar_h_draw',0
|
||||
aScrollbar_hor_mouse db 'scrollbar_h_mouse',0
|
||||
aVersion_scrollbar db 'version_scrollbar',0
|
||||
;aOption_box_draw db 'option_box_draw',0
|
||||
;aOption_box_mouse db 'option_box_mouse',0
|
||||
;aVersion_op db 'version_op',0
|
||||
|
||||
aMenu_bar_draw db 'menu_bar_draw',0
|
||||
aMenu_bar_mouse db 'menu_bar_mouse',0
|
||||
aVersion_menu_bar db 'version_menu_bar',0
|
||||
;aScrollbar_ver_draw db 'scrollbar_v_draw',0
|
||||
;aScrollbar_ver_mouse db 'scrollbar_v_mouse',0
|
||||
;aScrollbar_hor_draw db 'scrollbar_h_draw',0
|
||||
;aScrollbar_hor_mouse db 'scrollbar_h_mouse',0
|
||||
;aVersion_scrollbar db 'version_scrollbar',0
|
||||
|
||||
;aMenu_bar_draw db 'menu_bar_draw',0
|
||||
;aMenu_bar_mouse db 'menu_bar_mouse',0
|
||||
;aVersion_menu_bar db 'version_menu_bar',0
|
||||
;---------------------------------------------------------------------
|
||||
head_f_i:
|
||||
head_f_l db 'System error',0
|
||||
@ -189,3 +201,30 @@ editboxes_end:
|
||||
|
||||
mouse_dd dd 0
|
||||
;---------------------------------------------------------------------
|
||||
|
||||
check1 check_box 353,40,4,10,0x80AABBCC,0,0,check_text,6
|
||||
|
||||
check_text db 'Kernel',0
|
||||
;*********************************************************************
|
||||
; Kerpack data
|
||||
;*********************************************************************
|
||||
align 4
|
||||
fn70_read:
|
||||
dd 0
|
||||
dd 0
|
||||
dd 0
|
||||
insize3 dd 200*1024
|
||||
infile3 dd infile
|
||||
db 0
|
||||
dd fullname
|
||||
|
||||
align 4
|
||||
fn70_write:
|
||||
dd 2
|
||||
dd 0
|
||||
dd 0
|
||||
outsize3 dd ?
|
||||
outfile3 dd outfile
|
||||
db 0
|
||||
dd fullname
|
||||
;*********************************************************************
|
@ -42,8 +42,7 @@ fn70start rd 1
|
||||
fn70size rd 1
|
||||
fn70zero rd 1
|
||||
fn70dest rd 1
|
||||
fullname rb 256
|
||||
|
||||
fullname rb 4096 ;256
|
||||
;---------------------------------------------------------------------
|
||||
align 4
|
||||
file_attr rd 8
|
||||
@ -199,7 +198,7 @@ _numPrevBits: rd 1
|
||||
_numPosBits: rd 1
|
||||
_posMask: rd 1
|
||||
_posStateBits: rd 1
|
||||
range: rd 1
|
||||
_range: rd 1
|
||||
_cacheSize: rd 1
|
||||
_cyclicBufferSize: rd 1
|
||||
;-----------------------------------------------------
|
||||
@ -224,3 +223,14 @@ pack_length: rd 1
|
||||
;---------------------------------------------------------------------
|
||||
; Compress data area end
|
||||
;---------------------------------------------------------------------
|
||||
|
||||
;*********************************************************************
|
||||
; Kerpack data
|
||||
;*********************************************************************
|
||||
align 4
|
||||
inptr dd ?
|
||||
indelta dd ?
|
||||
insize1 dd ?
|
||||
;ct1 rb 256
|
||||
;ctn dd ?
|
||||
;cti db ?
|
284
programs/other/kpack/trunk/kerpack.inc
Normal file
284
programs/other/kpack/trunk/kerpack.inc
Normal file
@ -0,0 +1,284 @@
|
||||
; do not touch "purge mov"!!!
|
||||
purge mov ; for the correct patch of loader
|
||||
; do not touch "purge mov"!!!
|
||||
;*********************************************************************
|
||||
;die_with_err:
|
||||
; pop esi
|
||||
;@@:
|
||||
; lodsb
|
||||
; test al,al
|
||||
; jz @f
|
||||
|
||||
; mov cl,al
|
||||
; mcall 63,1
|
||||
; jmp @b
|
||||
;*********************************************************************
|
||||
;@@:
|
||||
; mcall 63,,13
|
||||
; mcall ,,10
|
||||
; mcall -1
|
||||
;*********************************************************************
|
||||
kerpack:
|
||||
call clear_mess_and_displogo
|
||||
|
||||
mov ecx,200*1024*3+6A8000h
|
||||
mcall 68,12
|
||||
mov [infile],eax
|
||||
mov [infile3],eax
|
||||
add eax,200*1024
|
||||
mov [inbuftmp],eax
|
||||
add eax,200*1024
|
||||
mov [outfile],eax
|
||||
add eax,200*1024
|
||||
mov [workmem],eax
|
||||
|
||||
|
||||
mov esi,inname
|
||||
call get_full_name
|
||||
|
||||
mov [insize3],200*1024 ; max size of input file
|
||||
|
||||
mcall 70,fn70_read
|
||||
cmp eax,6
|
||||
jz read_ok
|
||||
;--------------------------------------
|
||||
read_err:
|
||||
; call die_with_err
|
||||
; db 'KerPack: cannot load kernel.mnt',0
|
||||
mov esi,errload_str
|
||||
push errload_len
|
||||
pop ecx
|
||||
call write_string
|
||||
jmp read_ok.exit
|
||||
;*********************************************************************
|
||||
read_ok:
|
||||
mov [insize3],ebx
|
||||
|
||||
mov edi,[infile]
|
||||
add edi,[insize3]
|
||||
cmp dword [edi-8],dword 'KERN'
|
||||
jnz .lzma_set_dict_size
|
||||
|
||||
cmp dword [edi-4],dword 'PACK'
|
||||
jnz .lzma_set_dict_size
|
||||
;--------------------------------------
|
||||
mov esi,already_str
|
||||
push already_len
|
||||
pop ecx
|
||||
call write_string
|
||||
jmp read_ok.exit
|
||||
;*********************************************************************
|
||||
.not_kernel:
|
||||
mov esi,notkernel_str
|
||||
push notkernel_len
|
||||
pop ecx
|
||||
call write_string
|
||||
jmp read_ok.exit
|
||||
;*********************************************************************
|
||||
.lzma_set_dict_size:
|
||||
push 18
|
||||
call lzma_set_dict_size
|
||||
; find jump to 32-bit code
|
||||
; mov edi,infile - 1
|
||||
mov edi,[infile]
|
||||
mov eax,edi
|
||||
add eax,[insize3]
|
||||
dec edi
|
||||
;--------------------------------------
|
||||
@@:
|
||||
cmp eax,edi
|
||||
je .not_kernel
|
||||
|
||||
inc edi
|
||||
cmp dword [edi],0xE88EE08E ; mov fs,ax/mov gs,ax
|
||||
jnz @b
|
||||
|
||||
cmp dword [edi+4],0x00BCD08E ; mov ss,ax/mov esp,00xxxxxx
|
||||
jnz @b
|
||||
|
||||
add edi,11
|
||||
mov [inptr],edi
|
||||
sub edi,[infile] ; infile
|
||||
mov [indelta],edi
|
||||
lea eax,[ebx+0x10000]
|
||||
mov dword [loader_patch3+2],eax
|
||||
sub ebx,edi
|
||||
mov [insize1],ebx
|
||||
call preprocess_calltrick3
|
||||
|
||||
mov al,[cti]
|
||||
mov [loader_patch5-1],al
|
||||
mov eax,[ctn]
|
||||
mov [loader_patch4+1],eax
|
||||
mov eax,[inptr]
|
||||
; add eax, outfile - infile + loader_size - 5
|
||||
add eax,[outfile]
|
||||
sub eax,[infile]
|
||||
add eax,loader_size - 5
|
||||
|
||||
push eax
|
||||
call tell_compress_mess
|
||||
pop eax
|
||||
|
||||
push [workmem] ;workmem
|
||||
push [insize1]
|
||||
push eax
|
||||
push [inptr]
|
||||
call lzma_compress
|
||||
|
||||
add eax, loader_size-5
|
||||
mov [loader_patch1+6],eax
|
||||
add eax,[indelta]
|
||||
mov [outsize3],eax
|
||||
mov eax,[indelta]
|
||||
; mov ecx,dword [eax + outfile + loader_size - 4]
|
||||
mov ecx,eax
|
||||
add ecx,[outfile]
|
||||
mov ecx,[ecx + loader_size - 4]
|
||||
|
||||
bswap ecx
|
||||
mov [loader_patch2+4],ecx
|
||||
add eax, 0x10000
|
||||
mov [loader_patch1+1],eax
|
||||
mov esi,[infile] ;infile
|
||||
mov edi,[outfile] ;outfile
|
||||
mov ecx,[indelta]
|
||||
rep movsb
|
||||
|
||||
mov esi,loader_start
|
||||
mov ecx,loader_size
|
||||
rep movsb
|
||||
|
||||
mov eax,[outfile]
|
||||
add eax,[outsize3]
|
||||
mov [eax],dword 'KERN'
|
||||
mov [eax+4],dword 'PACK'
|
||||
add dword [outsize3],8
|
||||
|
||||
mov eax,[outsize3]
|
||||
mov ecx,100
|
||||
mul ecx
|
||||
div [insize3]
|
||||
aam
|
||||
xchg al,ah
|
||||
add ax,'00'
|
||||
mov [ratio],ax
|
||||
mov esi,done_str
|
||||
push done_len
|
||||
pop ecx
|
||||
call write_string
|
||||
|
||||
mov eax,[outfile]
|
||||
mov [outfile3],eax
|
||||
|
||||
mov esi,outname
|
||||
call get_full_name
|
||||
|
||||
mcall 70,fn70_write
|
||||
test eax,eax
|
||||
jz .exit ;@f
|
||||
; call die_with_err
|
||||
; db 'KerPack: cannot save kernel.mnt',0
|
||||
|
||||
mov esi,outfileerr_str
|
||||
push outfileerr_len
|
||||
pop ecx
|
||||
call write_string
|
||||
;*********************************************************************
|
||||
.exit:
|
||||
; call die_with_err
|
||||
; db 'KerPack: all is OK',0
|
||||
call return_memory
|
||||
ret
|
||||
;*********************************************************************
|
||||
preprocess_calltrick3:
|
||||
; input preprocessing
|
||||
mov edi,ct1
|
||||
xor eax,eax
|
||||
push edi
|
||||
mov ecx,256/4
|
||||
rep stosd
|
||||
|
||||
pop edi
|
||||
mov ecx,ebx
|
||||
mov esi,[inptr]
|
||||
mov ebx,[inbuftmp] ;inbuftmp
|
||||
xchg eax,edx
|
||||
;--------------------------------------
|
||||
input_pre3:
|
||||
lodsb
|
||||
;--------------------------------------
|
||||
@@:
|
||||
cmp al,0Fh
|
||||
jnz ip3
|
||||
|
||||
dec ecx
|
||||
jz input_pre_done3
|
||||
|
||||
lodsb
|
||||
cmp al,80h
|
||||
jb @b
|
||||
|
||||
cmp al,90h
|
||||
jb @f
|
||||
;--------------------------------------
|
||||
ip3:
|
||||
sub al,0E8h
|
||||
cmp al,1
|
||||
ja input_pre_cont3
|
||||
;--------------------------------------
|
||||
@@:
|
||||
cmp ecx,5
|
||||
jb input_pre_done3
|
||||
|
||||
lodsd
|
||||
add eax,esi
|
||||
sub eax,[inptr]
|
||||
cmp eax,[insize1]
|
||||
jae xxx3
|
||||
|
||||
cmp eax,1000000h
|
||||
jae xxx3
|
||||
|
||||
sub ecx,4
|
||||
xchg al,ah
|
||||
rol eax,16
|
||||
xchg al,ah
|
||||
mov [esi-4],eax
|
||||
inc edx
|
||||
mov [ebx],esi
|
||||
add ebx,4
|
||||
jmp input_pre_cont3
|
||||
;*********************************************************************
|
||||
xxx3:
|
||||
sub esi,4
|
||||
movzx eax,byte [esi]
|
||||
mov byte [eax+edi],1
|
||||
;--------------------------------------
|
||||
input_pre_cont3:
|
||||
loop input_pre3
|
||||
;--------------------------------------
|
||||
input_pre_done3:
|
||||
mov [ctn],edx
|
||||
xor eax,eax
|
||||
mov ecx,256
|
||||
repnz scasb
|
||||
jnz pack_calltrick_done
|
||||
|
||||
not cl
|
||||
mov [cti],cl
|
||||
;--------------------------------------
|
||||
@@:
|
||||
cmp ebx,[inbuftmp] ;inbuftmp
|
||||
jz pack_calltrick_done
|
||||
|
||||
sub ebx,4
|
||||
mov eax,[ebx]
|
||||
mov [eax-4],cl
|
||||
jmp @b
|
||||
;*********************************************************************
|
||||
pack_calltrick_done:
|
||||
ret
|
||||
;*********************************************************************
|
||||
include 'loader_lzma.inc'
|
||||
;*********************************************************************
|
@ -1,5 +1,10 @@
|
||||
; kpack = Kolibri Packer
|
||||
;---------------------------------------------------------------------
|
||||
; version: 0.20
|
||||
; last update: 07/12/2010
|
||||
; changed by: Marat Zakiyanov aka Mario79, aka Mario
|
||||
; changes: Added code for packing the kernel.mnt
|
||||
;---------------------------------------------------------------------
|
||||
; version: 0.15
|
||||
; last update: 06/11/2010
|
||||
; changed by: Marat Zakiyanov aka Mario79, aka Mario
|
||||
@ -142,8 +147,29 @@ still:
|
||||
push dword edit3
|
||||
call [edit_box_mouse]
|
||||
|
||||
push dword check1
|
||||
call [check_box_mouse]
|
||||
|
||||
jmp still
|
||||
;*********************************************************************
|
||||
tell_compress_mess:
|
||||
push compressing_len
|
||||
pop ecx
|
||||
mov esi,compressing_str
|
||||
call write_string
|
||||
ret
|
||||
;*********************************************************************
|
||||
clear_mess_and_displogo:
|
||||
call refresh_editbox_data
|
||||
; clear messages
|
||||
call clear_messages
|
||||
; display logo
|
||||
mov esi,info_str
|
||||
push info_len
|
||||
pop ecx
|
||||
call write_string
|
||||
ret
|
||||
;*********************************************************************
|
||||
clear_messages:
|
||||
xor eax,eax
|
||||
mov ecx,80*20/4+1
|
||||
@ -169,9 +195,17 @@ button:
|
||||
dec eax
|
||||
jnz nopack
|
||||
|
||||
mov eax,[check1+32]
|
||||
test eax,10b
|
||||
jnz @f
|
||||
|
||||
call pack
|
||||
jmp still
|
||||
;---------------------------------------------------------------------
|
||||
@@:
|
||||
call kerpack
|
||||
jmp still
|
||||
;---------------------------------------------------------------------
|
||||
nopack:
|
||||
dec eax
|
||||
jnz nounpack
|
||||
@ -416,10 +450,15 @@ draw_window:
|
||||
draw_editbox:
|
||||
push dword edit1
|
||||
call [edit_box_draw]
|
||||
|
||||
push dword edit2
|
||||
call [edit_box_draw]
|
||||
|
||||
push dword edit3
|
||||
call [edit_box_draw]
|
||||
|
||||
push dword check1
|
||||
call [check_box_draw]
|
||||
ret
|
||||
;*********************************************************************
|
||||
set_editbox_position:
|
||||
@ -508,6 +547,9 @@ include 'lzma_set_dict_size.inc'
|
||||
;lzma_decompress:
|
||||
include 'lzma_decompress.inc'
|
||||
;---------------------------------------------------------------------
|
||||
;kerpack code:
|
||||
include 'kerpack.inc'
|
||||
;---------------------------------------------------------------------
|
||||
;initialized variables and constants
|
||||
include 'const_var.inc'
|
||||
;---------------------------------------------------------------------
|
||||
|
460
programs/other/kpack/trunk/loader_lzma.inc
Normal file
460
programs/other/kpack/trunk/loader_lzma.inc
Normal file
@ -0,0 +1,460 @@
|
||||
loader_start:
|
||||
; start address; this code will be injected after the init code
|
||||
; (some commands below "B32" in the kernel)
|
||||
mov edi, 0x280000
|
||||
lea ebx, [edi+loader_size1+16]
|
||||
lea edx, [ebx+4]
|
||||
loader_patch1:
|
||||
mov esi, 0 ; will be patched: start address to copy
|
||||
mov ecx, 0 ; will be patched: size of data to copy
|
||||
push esi
|
||||
rep movsb
|
||||
jmp edx
|
||||
loader_size1 = $ - loader_start
|
||||
|
||||
loader_patch2:
|
||||
dd 0x280000 + loader_size
|
||||
dd 0 ; will be patched: start value for code
|
||||
; (LZMA-specific)
|
||||
dd -1
|
||||
dd _RangeDecoderBitDecode_edx - loader_start + 0x280000
|
||||
dd _RangeDecoderBitDecode - loader_start + 0x280000
|
||||
|
||||
RangeDecoderBitDecode equ dword [ebx]
|
||||
RangeDecoderBitDecode_edx equ dword [ebx-4]
|
||||
code_ equ ebx-12
|
||||
range equ ebx-8
|
||||
|
||||
rep1 equ ebx-28
|
||||
rep2 equ ebx-24
|
||||
rep3 equ ebx-20
|
||||
inptr_ldr equ ebx-16
|
||||
|
||||
pb equ 2 ; pos state bits
|
||||
lp equ 0 ; literal pos state bits
|
||||
lc equ 3 ; literal context bits
|
||||
posStateMask equ ((1 shl pb)-1)
|
||||
literalPosMask equ ((1 shl lp)-1)
|
||||
|
||||
kNumPosBitsMax = 4
|
||||
kNumPosStatesMax = (1 shl kNumPosBitsMax)
|
||||
|
||||
kLenNumLowBits = 3
|
||||
kLenNumLowSymbols = (1 shl kLenNumLowBits)
|
||||
kLenNumMidBits = 3
|
||||
kLenNumMidSymbols = (1 shl kLenNumMidBits)
|
||||
kLenNumHighBits = 8
|
||||
kLenNumHighSymbols = (1 shl kLenNumHighBits)
|
||||
|
||||
LenChoice = 0
|
||||
LenChoice2 = 1
|
||||
LenLow = 2
|
||||
LenMid = (LenLow + (kNumPosStatesMax shl kLenNumLowBits))
|
||||
LenHigh = (LenMid + (kNumPosStatesMax shl kLenNumMidBits))
|
||||
kNumLenProbs = (LenHigh + kLenNumHighSymbols)
|
||||
|
||||
kNumStates = 12
|
||||
kNumLitStates = 7
|
||||
kStartPosModelIndex = 4
|
||||
kEndPosModelIndex = 14
|
||||
kNumFullDistances = (1 shl (kEndPosModelIndex/2))
|
||||
kNumPosSlotBits = 6
|
||||
kNumLenToPosStates = 4
|
||||
kNumAlignBits = 4
|
||||
kAlignTableSize = (1 shl kNumAlignBits)
|
||||
kMatchMinLen = 2
|
||||
|
||||
IsMatch = 0
|
||||
IsRep = 0xC0 ; (IsMatch + (kNumStates shl kNumPosBitsMax))
|
||||
IsRepG0 = 0xCC ; (IsRep + kNumStates)
|
||||
IsRepG1 = 0xD8 ; (IsRepG0 + kNumStates)
|
||||
IsRepG2 = 0xE4 ; (IsRepG1 + kNumStates)
|
||||
IsRep0Long = 0xF0 ; (IsRepG2 + kNumStates)
|
||||
PosSlot = 0x1B0 ; (IsRep0Long + (kNumStates shl kNumPosBitsMax))
|
||||
SpecPos = 0x2B0 ; (PosSlot + (kNumLenToPosStates shl kNumPosSlotBits))
|
||||
Align_ = 0x322 ; (SpecPos + kNumFullDistances - kEndPosModelIndex)
|
||||
Lencoder = 0x332 ; (Align_ + kAlignTableSize)
|
||||
RepLencoder = 0x534 ; (Lencoder + kNumLenProbs)
|
||||
Literal = 0x736 ; (RepLencoder + kNumLenProbs)
|
||||
|
||||
LZMA_BASE_SIZE = 1846 ; must be ==Literal
|
||||
LZMA_LIT_SIZE = 768
|
||||
|
||||
kNumTopBits = 24
|
||||
kTopValue = (1 shl kNumTopBits)
|
||||
|
||||
kNumBitModelTotalBits = 11
|
||||
kBitModelTotal = (1 shl kNumBitModelTotalBits)
|
||||
kNumMoveBits = 5
|
||||
|
||||
uninit_base = 2C0000h
|
||||
|
||||
p = uninit_base
|
||||
|
||||
unpacker:
|
||||
xor ebp, ebp
|
||||
xor eax, eax
|
||||
dec eax
|
||||
lea edi, [rep1]
|
||||
stosd
|
||||
stosd
|
||||
stosd
|
||||
|
||||
xchg eax, esi
|
||||
; mov ecx, Literal + (LZMA_LIT_SIZE shl (lc+lp))
|
||||
mov ch, (Literal + (LZMA_LIT_SIZE shl (lc+lp)) + 0xFF) shr 8
|
||||
mov eax, kBitModelTotal/2
|
||||
mov edi, p
|
||||
rep stosd
|
||||
|
||||
pop edi
|
||||
push edi
|
||||
loader_patch3:
|
||||
.main_loop:
|
||||
cmp edi, dword 0 ; will be patched: end of data to unpack
|
||||
jae .main_loop_done
|
||||
|
||||
if posStateMask
|
||||
mov edx, edi
|
||||
and edx, posStateMask
|
||||
else
|
||||
xor edx, edx
|
||||
end if
|
||||
push eax ; al = previous byte
|
||||
lea eax, [ebp + ((p+IsMatch*4) shr (kNumPosBitsMax+2))]
|
||||
shl eax, kNumPosBitsMax+2
|
||||
if posStateMask
|
||||
call RangeDecoderBitDecode_edx
|
||||
else
|
||||
call RangeDecoderBitDecode
|
||||
end if
|
||||
pop eax
|
||||
jc .1
|
||||
|
||||
movzx eax, al
|
||||
if literalPosMask
|
||||
mov ah, dl
|
||||
and ah, literalPosMask
|
||||
end if
|
||||
if ((LZMA_LIT_SIZE*4) and ((1 shl (8-lc)) - 1)) <> 0
|
||||
shr eax, 8-lc
|
||||
imul eax, LZMA_LIT_SIZE*4
|
||||
else
|
||||
and al, not ((1 shl (8-lc)) - 1)
|
||||
imul eax, (LZMA_LIT_SIZE*4) shr (8-lc)
|
||||
end if
|
||||
add eax, p+Literal*4
|
||||
mov dl, 1
|
||||
cmp ebp, kNumLitStates
|
||||
jb .literal
|
||||
|
||||
mov cl, [edi + esi]
|
||||
;--------------------------------------
|
||||
.lx0:
|
||||
add cl, cl
|
||||
adc dh, 1
|
||||
call RangeDecoderBitDecode_edx
|
||||
|
||||
adc dl, dl
|
||||
jc .lx1
|
||||
|
||||
xor dh, dl
|
||||
test dh, 1
|
||||
mov dh, 0
|
||||
jnz .lx0
|
||||
;--------------------------------------
|
||||
.literal:
|
||||
@@:
|
||||
call RangeDecoderBitDecode_edx
|
||||
adc dl, dl
|
||||
jnc @b
|
||||
;--------------------------------------
|
||||
.lx1:
|
||||
mov eax, ebp
|
||||
cmp al, 4
|
||||
jb @f
|
||||
|
||||
cmp al, 10
|
||||
mov al, 3
|
||||
jb @f
|
||||
|
||||
mov al, 6
|
||||
@@:
|
||||
sub ebp, eax
|
||||
xchg eax, edx
|
||||
;--------------------------------------
|
||||
.stosb_main_loop:
|
||||
stosb
|
||||
jmp .main_loop
|
||||
;*********************************************************************
|
||||
.1:
|
||||
lea eax, [p + IsRep*4 + ebp*4]
|
||||
call RangeDecoderBitDecode
|
||||
jnc .10
|
||||
|
||||
add eax, (IsRepG0 - IsRep)*4 ;lea eax, [p + IsRepG0*4 + ebp*4]
|
||||
call RangeDecoderBitDecode
|
||||
jc .111
|
||||
|
||||
mov eax, ebp
|
||||
shl eax, kNumPosBitsMax+2
|
||||
add eax, p + IsRep0Long*4
|
||||
call RangeDecoderBitDecode_edx
|
||||
jc .1101
|
||||
|
||||
cmp ebp, 7
|
||||
sbb ebp, ebp
|
||||
lea ebp, [ebp+ebp+11]
|
||||
mov al, [edi + esi]
|
||||
jmp .stosb_main_loop
|
||||
;*********************************************************************
|
||||
.111:
|
||||
add eax, (IsRepG1 - IsRepG0) * 4 ;lea eax, [p + IsRepG1*4 + ebp*4]
|
||||
call RangeDecoderBitDecode
|
||||
xchg esi, [rep1]
|
||||
jnc @f
|
||||
|
||||
add eax, (IsRepG2 - IsRepG1) * 4 ;lea eax, [p + IsRepG2*4 + ebp*4]
|
||||
call RangeDecoderBitDecode
|
||||
xchg esi, [rep2]
|
||||
jnc @f
|
||||
|
||||
xchg esi, [rep3]
|
||||
;--------------------------------------
|
||||
@@:
|
||||
.1101:
|
||||
mov eax, p + RepLencoder*4
|
||||
call LzmaLenDecode1
|
||||
|
||||
push 8
|
||||
jmp .rmu
|
||||
;*********************************************************************
|
||||
.10:
|
||||
xchg esi, [rep1]
|
||||
xchg esi, [rep2]
|
||||
mov [rep3], esi
|
||||
mov eax, p + Lencoder*4
|
||||
call LzmaLenDecode1
|
||||
|
||||
push kNumLenToPosStates-1
|
||||
pop edx
|
||||
cmp edx, ecx
|
||||
jb @f
|
||||
|
||||
mov edx, ecx
|
||||
;--------------------------------------
|
||||
@@:
|
||||
push ecx
|
||||
push kNumPosSlotBits
|
||||
pop ecx
|
||||
mov eax, p+PosSlot*4
|
||||
shl edx, cl
|
||||
call RangeDecoderBitTreeDecode1
|
||||
|
||||
mov esi, ecx
|
||||
cmp ecx, kStartPosModelIndex
|
||||
jb .l6
|
||||
|
||||
mov edx, ecx
|
||||
xor eax, eax
|
||||
shr ecx, 1
|
||||
adc al, 2
|
||||
dec ecx
|
||||
shl eax, cl
|
||||
mov esi, eax
|
||||
sub eax, edx
|
||||
lea eax, [p + (SpecPos - 1)*4 + eax*4]
|
||||
cmp edx, kEndPosModelIndex
|
||||
jb .l59
|
||||
; call RangeDecoderDecodeDirectBits
|
||||
;RangeDecoderDecodeDirectBits:
|
||||
xor eax, eax
|
||||
;--------------------------------------
|
||||
.l:
|
||||
shr dword [range], 1
|
||||
add eax, eax
|
||||
mov edx, [code_]
|
||||
sub edx, [range]
|
||||
jb @f
|
||||
|
||||
mov [code_], edx
|
||||
add al, 1 shl kNumAlignBits
|
||||
;--------------------------------------
|
||||
@@:
|
||||
call update_decoder
|
||||
dec ecx
|
||||
cmp ecx, kNumAlignBits
|
||||
jnz .l
|
||||
; ret
|
||||
add esi, eax
|
||||
mov eax, p+Align_*4
|
||||
;--------------------------------------
|
||||
.l59:
|
||||
; call RangeDecoderReverseBitTreeDecode_addesi
|
||||
;_RangeDecoderReverseBitTreeDecode_addesi:
|
||||
; in: eax->probs,ecx=numLevels
|
||||
; out: esi+=length; destroys edx
|
||||
push edi
|
||||
xor edx, edx
|
||||
inc edx
|
||||
mov edi, edx
|
||||
;--------------------------------------
|
||||
@@:
|
||||
call RangeDecoderBitDecode_edx
|
||||
jnc .591
|
||||
|
||||
add esi, edi
|
||||
stc
|
||||
;--------------------------------------
|
||||
.591:
|
||||
adc edx, edx
|
||||
add edi, edi
|
||||
loop @b
|
||||
|
||||
pop edi
|
||||
; ret
|
||||
;--------------------------------------
|
||||
.l6:
|
||||
pop ecx
|
||||
not esi
|
||||
push 7
|
||||
;--------------------------------------
|
||||
.rmu:
|
||||
cmp ebp, 7
|
||||
pop ebp
|
||||
jb @f
|
||||
add ebp, 3
|
||||
;--------------------------------------
|
||||
@@:
|
||||
.repmovsb:
|
||||
inc ecx
|
||||
push esi
|
||||
add esi, edi
|
||||
rep movsb
|
||||
|
||||
lodsb
|
||||
pop esi
|
||||
jmp .stosb_main_loop
|
||||
;*********************************************************************
|
||||
.main_loop_done:
|
||||
include 'calltrick2.inc'
|
||||
ret
|
||||
;*********************************************************************
|
||||
_RangeDecoderBitDecode:
|
||||
; in: eax->prob
|
||||
; out: CF=bit
|
||||
push edx
|
||||
mov edx, [range]
|
||||
shr edx, kNumBitModelTotalBits
|
||||
imul edx, [eax]
|
||||
cmp [code_], edx
|
||||
jae .ae
|
||||
|
||||
mov [range], edx
|
||||
mov edx, kBitModelTotal
|
||||
sub edx, [eax]
|
||||
shr edx, kNumMoveBits
|
||||
add [eax], edx
|
||||
;--------------------------------------
|
||||
.n:
|
||||
pushfd
|
||||
call update_decoder
|
||||
|
||||
popfd
|
||||
pop edx
|
||||
ret
|
||||
;*********************************************************************
|
||||
.ae:
|
||||
sub [range], edx
|
||||
sub [code_], edx
|
||||
mov edx, [eax]
|
||||
shr edx, kNumMoveBits
|
||||
sub [eax], edx
|
||||
stc
|
||||
jmp .n
|
||||
;*********************************************************************
|
||||
update_decoder:
|
||||
cmp byte [range+3], 0 ;cmp dword [range], kTopValue
|
||||
jnz @f ;jae @f
|
||||
|
||||
shl dword [range], 8
|
||||
shl dword [code_], 8
|
||||
push eax
|
||||
mov eax, [inptr_ldr]
|
||||
mov al, [eax]
|
||||
inc dword [inptr_ldr]
|
||||
mov byte [code_], al
|
||||
pop eax
|
||||
@@:
|
||||
ret
|
||||
;*********************************************************************
|
||||
_RangeDecoderBitDecode_edx:
|
||||
push eax
|
||||
lea eax, [eax+edx*4]
|
||||
call RangeDecoderBitDecode
|
||||
|
||||
pop eax
|
||||
ret
|
||||
;*********************************************************************
|
||||
LzmaLenDecode1:
|
||||
; in: eax->prob, edx=posState
|
||||
; out: ecx=len
|
||||
|
||||
; LenChoice==0
|
||||
; add eax, LenChoice*4
|
||||
if kLenNumMidBits <> kLenNumLowBits
|
||||
error in optimization
|
||||
end if
|
||||
mov cl, kLenNumMidBits
|
||||
call RangeDecoderBitDecode
|
||||
jnc .0
|
||||
|
||||
add eax, (LenChoice2-LenChoice)*4
|
||||
call RangeDecoderBitDecode
|
||||
jc @f
|
||||
if (kLenNumMidBits <> 3) | (LenMid-LenChoice2 > 0x7F + kLenNumMidBits)
|
||||
shl edx, cl
|
||||
add edx, LenMid-LenChoice2
|
||||
else
|
||||
lea edx, [ecx + edx*8 - kLenNumMidBits + LenMid-LenChoice2]
|
||||
end if
|
||||
push kLenNumLowSymbols
|
||||
jmp RangeDecoderBitTreeDecode1.1
|
||||
;*********************************************************************
|
||||
@@:
|
||||
mov edx, LenHigh-LenChoice2
|
||||
mov cl, kLenNumHighBits
|
||||
push kLenNumLowSymbols + kLenNumMidSymbols
|
||||
jmp RangeDecoderBitTreeDecode1.1
|
||||
;*********************************************************************
|
||||
.0:
|
||||
shl edx, cl
|
||||
if LenLow = 2
|
||||
inc edx
|
||||
inc edx
|
||||
else
|
||||
add edx, LenLow
|
||||
end if
|
||||
;--------------------------------------
|
||||
RangeDecoderBitTreeDecode1:
|
||||
; in: eax+edx*4->probs,ecx=numLevels
|
||||
; out: ecx=length; destroys edx
|
||||
push 0
|
||||
.1:
|
||||
lea eax, [eax+edx*4]
|
||||
xor edx, edx
|
||||
inc edx
|
||||
push ecx
|
||||
@@:
|
||||
call RangeDecoderBitDecode_edx
|
||||
|
||||
adc edx, edx
|
||||
loop @b
|
||||
|
||||
pop ecx
|
||||
btc edx, ecx
|
||||
pop ecx
|
||||
add ecx, edx
|
||||
ret
|
||||
loader_size = $ - loader_start
|
||||
;*********************************************************************
|
@ -181,7 +181,7 @@ CEncoder_Init:
|
||||
;RangeEncoder_Init
|
||||
and dword [low],0
|
||||
and dword [low+4],0
|
||||
or dword [range],0xFFFFFFFF
|
||||
or dword [_range],0xFFFFFFFF
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
@ -1884,22 +1884,22 @@ RangeEncoder_EncodeDirectBits:
|
||||
;----------------------------------------------------------
|
||||
.labl_00:
|
||||
mov eax,[esp+8]
|
||||
shr dword [range],1
|
||||
shr dword [_range],1
|
||||
dec esi
|
||||
mov ecx,esi
|
||||
shr eax,cl
|
||||
test al,1
|
||||
je .labl_01
|
||||
|
||||
mov eax,[range]
|
||||
mov eax,[_range]
|
||||
add [low],eax
|
||||
adc dword [low+4],0
|
||||
;----------------------------------------------------------
|
||||
.labl_01:
|
||||
cmp dword [range],0x1000000
|
||||
cmp dword [_range],0x1000000
|
||||
jnb .labl_02
|
||||
|
||||
shl dword [range],8
|
||||
shl dword [_range],8
|
||||
call RangeEncoder_ShiftLow
|
||||
;----------------------------------------------------------
|
||||
.labl_02:
|
||||
@ -3179,14 +3179,14 @@ RangeEncoder_ShiftLow:
|
||||
|
||||
;* Call: ***************************************************************
|
||||
CMyBitEncoder_Encode:
|
||||
mov ecx,[range]
|
||||
mov ecx,[_range]
|
||||
mov eax,[edx]
|
||||
shr ecx,0xB
|
||||
imul ecx,eax
|
||||
cmp dword [esp+4],0
|
||||
jne .labl_00
|
||||
|
||||
mov [range],ecx
|
||||
mov [_range],ecx
|
||||
mov ecx,2048
|
||||
sub ecx,eax
|
||||
shr ecx,5
|
||||
@ -3197,17 +3197,17 @@ CMyBitEncoder_Encode:
|
||||
.labl_00:
|
||||
add [low],ecx
|
||||
adc dword [low+4],0
|
||||
sub [range],ecx
|
||||
sub [_range],ecx
|
||||
mov ecx,eax
|
||||
shr ecx,5
|
||||
sub eax,ecx
|
||||
mov [edx],eax
|
||||
;----------------------------------------------------------
|
||||
.labl_01:
|
||||
cmp dword [range],0x1000000
|
||||
cmp dword [_range],0x1000000
|
||||
jnb .labl_02
|
||||
|
||||
shl dword [range],8
|
||||
shl dword [_range],8
|
||||
call RangeEncoder_ShiftLow
|
||||
;----------------------------------------------------------
|
||||
.labl_02:
|
||||
|
@ -1,24 +1,6 @@
|
||||
;*********************************************************************
|
||||
pack:
|
||||
call refresh_editbox_data
|
||||
; clear messages
|
||||
call clear_messages
|
||||
; display logo
|
||||
mov esi,info_str
|
||||
push info_len
|
||||
pop ecx
|
||||
call write_string
|
||||
; load input file
|
||||
mov esi,inname
|
||||
call get_full_name
|
||||
mov ebx,fn70block
|
||||
mov [ebx],dword 5
|
||||
and [ebx+4],dword 0
|
||||
and [ebx+8],dword 0
|
||||
and [ebx+12],dword 0
|
||||
mov [ebx+16],dword file_attr
|
||||
mcall 70
|
||||
test eax,eax
|
||||
call displogo_and_readfile
|
||||
jz inopened
|
||||
;---------------------------------------------------------------------
|
||||
infileerr:
|
||||
@ -154,10 +136,8 @@ lzma_setds:
|
||||
call lzma_set_dict_size
|
||||
;--------------------------------------
|
||||
no_lzma_setds:
|
||||
push compressing_len
|
||||
pop ecx
|
||||
mov esi,compressing_str
|
||||
call write_string
|
||||
call tell_compress_mess
|
||||
|
||||
mov esi,[outfile1]
|
||||
mov edi,[outfile2]
|
||||
movsd
|
||||
|
@ -1,25 +1,6 @@
|
||||
;*********************************************************************
|
||||
unpack:
|
||||
call refresh_editbox_data
|
||||
; clear messages
|
||||
call clear_messages
|
||||
; display logo
|
||||
mov esi,info_str
|
||||
push info_len
|
||||
pop ecx
|
||||
call write_string
|
||||
|
||||
; load input file
|
||||
mov esi,inname
|
||||
call get_full_name
|
||||
mov ebx,fn70block
|
||||
mov [ebx],dword 5
|
||||
and [ebx+4],dword 0
|
||||
and [ebx+8],dword 0
|
||||
and [ebx+12],dword 0
|
||||
mov [ebx+16],dword file_attr
|
||||
mcall 70
|
||||
test eax,eax
|
||||
call displogo_and_readfile
|
||||
jnz infileerr
|
||||
|
||||
mov ecx,[insize]
|
||||
@ -181,3 +162,18 @@ return_memory:
|
||||
@@:
|
||||
ret
|
||||
;*********************************************************************
|
||||
displogo_and_readfile:
|
||||
call clear_mess_and_displogo
|
||||
; load input file
|
||||
mov esi,inname
|
||||
call get_full_name
|
||||
mov ebx,fn70block
|
||||
mov [ebx],dword 5
|
||||
and [ebx+4],dword 0
|
||||
and [ebx+8],dword 0
|
||||
and [ebx+12],dword 0
|
||||
mov [ebx+16],dword file_attr
|
||||
mcall 70
|
||||
test eax,eax
|
||||
ret
|
||||
;*********************************************************************
|
Loading…
Reference in New Issue
Block a user