Kpack - Using of F68, Box_Lib, Proc_Lib and OpenDialog.

git-svn-id: svn://kolibrios.org@1686 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Marat Zakiyanov (Mario79) 2010-11-03 13:24:14 +00:00
parent c47985823d
commit 31b1595dc8
5 changed files with 1079 additions and 901 deletions

View File

@ -8,7 +8,7 @@ aCompress db 'COMPRESS',0
aDecompress db 'DECOMPRESS',0
definoutname db 0
defpath db '/RD/1/'
curedit dd 0
;curedit dd 0
info_str db 'KPack - Kolibri Packer, version 0.13',10
db 'Uses LZMA v4.32 compression library',10,10
@ -56,4 +56,132 @@ 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
;---------------------------------------------------------------------
align 4
ProcLib_import:
OpenDialog_Init dd aOpenDialog_Init
OpenDialog_Start dd aOpenDialog_Start
;OpenDialog__Version dd aOpenDialog_Version
dd 0
dd 0
aOpenDialog_Init db 'OpenDialog_init',0
aOpenDialog_Start db 'OpenDialog_start',0
;aOpenDialog_Version db 'Version_OpenDialog',0
;---------------------------------------------------------------------
align 4
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
option_box_draw dd aOption_box_draw
option_box_mouse dd aOption_box_mouse
version_op dd aVersion_op
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
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
aOption_box_draw db 'option_box_draw',0
aOption_box_mouse db 'option_box_mouse',0
aVersion_op db 'version_op',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
err_message_found_lib1 db 'box_lib.obj - Not found!',0
err_message_found_lib2 db 'proc_lib.obj - Not found!',0
err_message_import1 db 'box_lib.obj - Wrong import!',0
err_message_import2 db 'proc_lib.obj - Wrong import!',0
system_dir_Boxlib db '/sys/lib/box_lib.obj',0
system_dir_ProcLib db '/sys/lib/proc_lib.obj',0
;---------------------------------------------------------------------
align 4
l_libs_start:
; load_library boxlib_name,cur_dir_path,buf_cmd_lin,system_path,\
; err_message_found_lib,head_f_l,myimport,err_message_import,head_f_i
library01 l_libs system_dir_Boxlib+9, cur_dir_path, library_path, system_dir_Boxlib, \
err_message_found_lib1, head_f_l, Box_lib_import, err_message_import1, head_f_i
library02 l_libs system_dir_ProcLib+9, cur_dir_path, library_path, system_dir_ProcLib, \
err_message_found_lib2, head_f_l, ProcLib_import, err_message_import2, head_f_i
load_lib_end:
;---------------------------------------------------------------------
align 4
OpenDialog_data:
.type dd 0
.procinfo dd procinfo ;+4
.com_area_name dd communication_area_name ;+8
.com_area dd 0 ;+12
.opendir_pach dd temp_dir_pach ;+16
.dir_default_pach dd communication_area_default_pach ;+20
.start_path dd open_dialog_path ;+24
.draw_window dd draw_window ;+28
.status dd 0 ;+32
.openfile_pach dd fname_buf ;+36
.filename_area dd filename_area ;+40
.filter_area dd Filter
.x:
.x_size dw 420 ;+48 ; Window X size
.x_start dw 10 ;+50 ; Window X position
.y:
.y_size dw 320 ;+52 ; Window y size
.y_start dw 10 ;+54 ; Window Y position
communication_area_name:
db 'FFFFFFFF_open_dialog',0
open_dialog_path:
db '/sys/File Managers/opendial',0
communication_area_default_pach:
db '/rd/1',0
path4 db '/rd/1/temp',0
Filter:
dd Filter.end - Filter.1
.1:
;db 'BIN',0
;db 'DAT',0
.end:
db 0
start_temp_file_name: db 'temp.bin',0
;---------------------------------------------------------------------
align 4
edit1 edit_box 160, 62, 1+22, 0xffffff, 0xff, 0x80ff, 0, 0x8000, 256, inname, mouse_dd, 0, 11,11
edit2 edit_box 160, 62, 17+22, 0xffffff, 0xff, 0x80ff, 0, 0x8000,256, outname, mouse_dd, 0, 7,7
edit3 edit_box 160, 62, 33+22, 0xffffff, 0xff, 0x80ff, 0, 0x8000,256, path, mouse_dd, 0, 6,6
editboxes_end:
mouse_dd dd 0
;---------------------------------------------------------------------

View File

@ -1,5 +1,4 @@
;---------------------------------------------------------------------
;rb 0xD3C ;unknown space area
params:
rb 256
;---------------------------------------------------------------------
@ -7,12 +6,11 @@ color_table rd 10
skinheight rd 1
innamelen rd 1
inname rb 48
inname rb 256 ;48
outnamelen rd 1
outname rb 48
outname rb 256 ;48
pathlen rd 1
path rb 48
curedit_y rd 1
path rb 256 ;48
message_mem rb 80*20
message_cur_pos rd 1
@ -45,7 +43,7 @@ fn70start rd 1
fn70size rd 1
fn70zero rd 1
fn70dest rd 1
fullname rb 100
fullname rb 256
;---------------------------------------------------------------------
align 4
@ -57,6 +55,24 @@ align 4
rb 4096
stacktop:
;---------------------------------------------------------------------
cur_dir_path:
rb 4096
;---------------------------------------------------------------------
library_path:
rb 4096
;---------------------------------------------------------------------
temp_dir_pach:
rb 4096
;---------------------------------------------------------------------
fname_buf:
rb 4096
;---------------------------------------------------------------------
filename_area:
rb 256
;---------------------------------------------------------------------
procinfo:
rb 1024
;---------------------------------------------------------------------
; Deconpress area
align 4
unpack.p rb 0x1F36*4

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,512 @@
;*********************************************************************
pack:
; call clear_edit_points
; and [curedit],0
; 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
jz inopened
;---------------------------------------------------------------------
infileerr:
call return_memory
mov esi,errload_str
push errload_len
pop ecx
jmp write_string
;---------------------------------------------------------------------
inopened:
mov ebx,[insize]
test ebx,ebx
jz infileerr
; maximum memory requests: 2*insize + 2*(maxoutsize+400h) + worksize
; mov esi,[memf]
xor esi,esi
; mov [infile],esi
add esi,ebx
mov [inbuftmp],esi
add esi,ebx
mov [outfile],esi
mov [outfile1],esi
mov [outfilebest],esi
mov ecx,ebx
shr ecx,3
add ecx,ebx
add ecx,400h
add esi,ecx
mov [outfile2],esi
add esi,ecx
mov [workmem],esi
add ecx,ebx
add ecx,ecx
; add ecx,[memf]
; LZMA requires 0x448000 + dictsize*9.5 bytes for workmem,
and [lzma_dictsize],0
push ecx
mov eax,ebx
dec eax
bsr ecx,eax
inc ecx
cmp ecx,28
jb @f
mov cl,28
;--------------------------------------
@@:
mov edx,ecx
xor eax,eax
inc eax
shl eax,cl
imul eax,19
shr eax,1
add eax,448000h
pop ecx
add ecx,eax
; mcall 64,1
; test eax,eax
; jz mem_ok
mcall 68,12
mov [infile],eax
add [inbuftmp],eax
add [outfile],eax
add [outfile1],eax
add [outfilebest],eax
add [outfile2],eax
add [workmem],eax
;--------------------------------------
; try to use smaller dictionary
;meml0:
; cmp edx,4
; jbe memf1
;
; dec edx
; xor eax,eax
; inc eax
; mov ecx,edx
; shl eax,cl
; imul eax,19
; shr eax,1
; add eax,509000h
; pop ecx
; push ecx
; add ecx,eax
; mcall 64
; test eax,eax
; jnz meml0
;--------------------------------------
; ok, say warning and continue
; mov [lzma_dictsize],edx
; mov esi,lzma_memsmall_str
; push lzma_memsmall_len
; pop ecx
; call write_string
; jmp mem_ok
;---------------------------------------------------------------------
;memf1:
; mov esi,nomem_str
; push nomem_len
; pop ecx
; jmp write_string
;---------------------------------------------------------------------
mem_ok:
mov eax,[insize]
mov ebx,fn70block
mov [ebx],byte 0
mov [ebx+12],eax
mov esi,[infile]
mov [ebx+16],esi
mcall 70
test eax,eax
jnz infileerr
mov eax,[outfile]
mov [eax],dword 'KPCK' ;'KCPK'
mov ecx,[insize]
mov [eax+4],dword ecx
mov edi,eax
; set LZMA dictionary size
mov eax,[lzma_dictsize]
test eax,eax
js no_lzma_setds
jnz lzma_setds
mov ecx,[insize]
dec ecx
bsr eax,ecx
inc eax
cmp eax,28
jb lzma_setds
mov eax,28
;--------------------------------------
lzma_setds:
push eax
call lzma_set_dict_size
;--------------------------------------
no_lzma_setds:
push compressing_len
pop ecx
mov esi,compressing_str
call write_string
mov esi,[outfile1]
mov edi,[outfile2]
movsd
movsd
movsd
call pack_lzma
mov [outsize],eax
mov eax,[outfile]
mov [outfilebest],eax
mov [method],use_lzma
;--------------------------------------
@@:
call preprocess_calltrick
test eax,eax
jz noct1
call set_outfile
call pack_lzma
add eax,5
cmp eax,[outsize]
jae @f
mov [outsize],eax
mov eax,[outfile]
mov [outfilebest],eax
mov [method],use_lzma or use_calltrick1
;--------------------------------------
@@:
noct1:
call set_outfile
push [ctn]
mov al,[cti]
push eax
call preprocess_calltrick2
test eax,eax
jz noct2
call set_outfile
call pack_lzma
add eax,5
cmp eax,[outsize]
jae @f
mov [outsize],eax
mov eax,[outfile]
mov [outfilebest],eax
mov [method],use_lzma or use_calltrick2
pop ecx
pop ecx
push [ctn]
mov al,[cti]
push eax
;--------------------------------------
@@:
noct2:
pop eax
mov [cti],al
pop [ctn]
add [outsize],12
mov eax,[outsize]
cmp eax,[insize]
jb packed_ok
mov esi,too_big_str
push too_big_len
pop ecx
jmp write_string
;---------------------------------------------------------------------
packed_ok:
; set header
movzx eax,[method]
mov edi,[outfilebest]
mov [edi+8],eax
test al,use_calltrick1 or use_calltrick2
jz @f
mov ecx,[outsize]
add ecx,edi
mov eax,[ctn]
mov [ecx-5],eax
mov al,[cti]
mov [ecx-1],al
;--------------------------------------
@@:
mov eax,[outsize]
mov ecx,100
mul ecx
div [insize]
aam
xchg al,ah
add ax,'00'
mov [ratio],ax
mov esi,done_str
push done_len
pop ecx
call write_string
;--------------------------------------
; save output file
saveout:
mov esi,outname
call get_full_name
mov ebx,fn70block
mov [ebx],byte 2
mov eax,[outfilebest]
mov ecx,[outsize]
mov [ebx+12],ecx
mov [ebx+16],eax
mcall 70
test eax,eax
jz @f
;--------------------------------------
outerr:
mov esi,outfileerr_str
push outfileerr_len
pop ecx
jmp write_string
;---------------------------------------------------------------------
@@:
xor eax,eax
mov ebx,fn70block
mov [ebx],byte 6
mov [ebx+4],eax
mov [ebx+8],eax
mov [ebx+12],eax
mov [ebx+16],dword file_attr
mcall 70
call return_memory
ret
;---------------------------------------------------------------------
set_outfile:
mov eax,[outfilebest]
xor eax,[outfile1]
xor eax,[outfile2]
mov [outfile],eax
ret
;---------------------------------------------------------------------
pack_calltrick_fail:
xor eax,eax
mov [ctn],0
ret
;---------------------------------------------------------------------
preprocess_calltrick:
; input preprocessing
xor eax,eax
mov edi,ct1
mov ecx,256/4
push edi
rep stosd
pop edi
mov ecx,[insize]
mov esi,[infile]
xchg eax,edx
mov ebx,[inbuftmp]
;--------------------------------------
input_pre:
lodsb
sub al,0E8h
cmp al,1
ja input_pre_cont
cmp ecx,5
jb input_pre_done
lodsd
add eax,esi
sub eax,[infile]
cmp eax,[insize]
jae xxx
cmp eax,1000000h
jae xxx
sub ecx,4
; bswap is not supported on i386
xchg al,ah
ror eax,16
xchg al,ah
mov [esi-4],eax
inc edx
mov [ebx],esi
add ebx,4
jmp input_pre_cont
;---------------------------------------------------------------------
xxx:
sub esi,4
movzx eax,byte [esi]
mov [eax+edi],byte 1
;--------------------------------------
input_pre_cont:
loop input_pre
;--------------------------------------
input_pre_done:
mov [ctn],edx
xor eax,eax
mov ecx,256
repnz scasb
jnz pack_calltrick_fail
not cl
mov [cti],cl
@@:
cmp ebx,[inbuftmp]
jz @f
sub ebx,4
mov eax,[ebx]
mov [eax-4],cl
jmp @b
;---------------------------------------------------------------------
@@:
mov al,1
ret
;---------------------------------------------------------------------
pack_lzma:
mov eax,[outfile]
add eax,11
push [workmem] ;workmem
push [insize] ;length
push eax ;destination
push [infile] ;source
call lzma_compress
mov ecx,[outfile]
mov edx,[ecx+12]
xchg dl,dh
ror edx,16
xchg dl,dh
mov [ecx+12],edx
dec eax
ret
;---------------------------------------------------------------------
preprocess_calltrick2:
; restore input
mov esi,[infile]
mov ecx,[ctn]
jecxz pc2l2
;--------------------------------------
pc2l1:
lodsb
sub al,0E8h
cmp al,1
ja pc2l1
mov al,[cti]
cmp [esi],al
jnz pc2l1
lodsd
shr ax,8
ror eax,16
xchg al,ah
sub eax,esi
add eax,[infile]
mov [esi-4],eax
loop pc2l1
;--------------------------------------
pc2l2:
; input preprocessing
mov edi,ct1
xor eax,eax
push edi
mov ecx,256/4
rep stosd
pop edi
mov ecx,[insize]
mov esi,[infile]
mov ebx,[inbuftmp]
xchg eax,edx
;--------------------------------------
input_pre2:
lodsb
;--------------------------------------
@@:
cmp al,0Fh
jnz ip1
dec ecx
jz input_pre_done2
lodsb
cmp al,80h
jb @b
cmp al,90h
jb @f
;--------------------------------------
ip1:
sub al,0E8h
cmp al,1
ja input_pre_cont2
;--------------------------------------
@@:
cmp ecx,5
jb input_pre_done2
lodsd
add eax,esi
sub eax,[infile]
cmp eax,[insize]
jae xxx2
cmp eax,1000000h
jae xxx2
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_cont2
;---------------------------------------------------------------------
xxx2: sub esi,4
movzx eax,byte [esi]
mov [eax+edi],byte 1
;--------------------------------------
input_pre_cont2:
loop input_pre2
;--------------------------------------
input_pre_done2:
mov [ctn],edx
xor eax,eax
mov ecx,256
repnz scasb
jnz pack_calltrick_fail
not cl
mov [cti],cl
;--------------------------------------
@@:
cmp ebx,[inbuftmp]
jz @f
sub ebx,4
mov eax,[ebx]
mov [eax-4],cl
jmp @b
;---------------------------------------------------------------------
@@:
mov al,1
ret
;*********************************************************************

View File

@ -0,0 +1,199 @@
;*********************************************************************
unpack:
; call clear_edit_points
; and [curedit],0
; 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
jnz infileerr
mov ecx,[insize]
test ecx,ecx
jz infileerr
; mov ecx,[memf]
; mov [infile],ecx
; add ecx,eax
; mov [outfile],ecx
; mov [outfilebest],ecx
; mcall 64,1
; test eax,eax
; jnz memf1
mcall 68,12
mov [infile],eax
mov ebx,fn70block
mov [ebx],byte 0
mov [ebx+16],eax
mov eax,[insize]
mov [ebx+12],eax
mcall 70
test eax,eax
jnz infileerr
mov eax,[infile]
cmp [eax],dword 'KPCK'
jz @f
;--------------------------------------
unpack_err:
call return_memory
mov esi,notpacked_str
push notpacked_len
pop ecx
jmp write_string
;---------------------------------------------------------------------
@@:
; mov ecx,[outfile]
; add ecx,dword [eax+4]
; mcall 64,1
; test eax,eax
; jnz memf1
mov ecx,[eax+4]
add ecx,[insize]
mcall 68,20,,[infile]
mov [infile],eax
add eax,[insize]
mov [outfile],eax
mov [outfilebest],eax
mov esi,[infile]
mov eax,[esi+8]
push eax
and al,0C0h
cmp al,0C0h
pop eax
jz unpack_err
and al,not 0C0h
dec eax
jnz unpack_err
mov eax,[esi+4]
mov [outsize],eax
push eax
push [outfile]
add esi,11
push esi
mov eax,[esi+1]
xchg al,ah
ror eax,16
xchg al,ah
mov [esi+1],eax
call lzma_decompress
mov esi,[infile]
test [esi+8],byte 80h
jnz uctr1
test [esi+8],byte 40h
jz udone
add esi,[insize]
sub esi,5
lodsd
mov ecx,eax
jecxz udone
mov dl,[esi]
mov esi,[outfile]
;--------------------------------------
uc1:
lodsb
sub al,0E8h
cmp al,1
ja uc1
cmp [esi],dl
jnz uc1
lodsd
shr ax,8
ror eax,16
xchg al,ah
sub eax,esi
add eax,[outfile]
mov [esi-4],eax
loop uc1
jmp udone
;---------------------------------------------------------------------
uctr1:
add esi,[insize]
sub esi,5
lodsd
mov ecx,eax
jecxz udone
mov dl,[esi]
mov esi,[outfile]
;--------------------------------------
uc2:
lodsb
;--------------------------------------
@@:
cmp al,15
jnz uf
lodsb
cmp al,80h
jb @b
cmp al,90h
jb @f
;--------------------------------------
uf:
sub al,0E8h
cmp al,1
ja uc2
;--------------------------------------
@@:
cmp [esi],dl
jnz uc2
lodsd
shr ax,8
ror eax,16
xchg al,ah
sub eax,esi
add eax,[outfile]
mov [esi-4],eax
loop uc2
;--------------------------------------
udone:
mov esi,unpacked_ok
push unpacked_len
pop ecx
call write_string
jmp saveout
;*********************************************************************
return_memory:
mov ecx,[infile]
test ecx,ecx
jz @f
mcall 68,13,
xor eax,eax
mov [infile],eax
@@:
ret
;*********************************************************************