Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 130 → Rev 131

/programs/other/archer/trunk/@RCHER.ASM
1,4 → 1,4
; @RCHER - DEflate unpacker v1.0
; @RCHER - Deflate unpacker v2.0 beta
;
; Written in pure assembler by Ivushkin Andrey aka Willow
;
8,15 → 8,17
;
; Compile with FASM
 
 
SYS equ meos
PARAM_PTR equ png_image
OUTBUF equ 4*1024*1024
png_imag = output+OUTBUF
PARAM_PTR = os_work;png_image
MEMINIT=next_code;output
DUMPFILE equ '/hd/1/out.txt'
 
SHOW_RBLOCK equ 0;1
SHOW_PNG_SEC equ 0;1
SHOW_METH equ 0;1
FILE_NUM equ 0
FILE_NUM equ 15;8
MEMORY equ 0x800000
 
BITS equ 16
28,7 → 30,6
SHOW_CHARS equ 0
BSIZE equ 512
INBUF equ BUFSIZE*BSIZE*2
OUTBUF equ 4*1024*1024
IGNORE_DIRS equ 0
 
MOVE_SLINE_LEV equ 8
40,6 → 41,9
IPC_MODE equ 100000b
RAW_MODE equ 1000000b
THREAD_YES equ 10000000b
LIST_MODE equ 100000000b
MEM_MODE equ 1000000000b
FIND_MODE equ 10000000000b
 
if SYS eq win
format PE console
57,8 → 61,8
dd 0x01
dd start
dd I_END
dd MEMORY
dd MEMORY-2048
dd MEMINIT
dd main_stack;MEMORY-2048
if PARAM_PTR eq param
dd 0
else
65,12 → 69,11
dd PARAM_PTR
end if
dd 0x0
include "lang.inc"
 
if PARAM_PTR eq param
param db 'RQ'
db '000037'
db '/hd/1/zip/png.zip',0
param db 'N'
db '000015'
db '/hd/1/zip/gz/fasm-1~1.tgz',0
end if
;match =meos,SYS
;{
77,14 → 80,17
include "macros.inc"
; purge mov
include "debug.inc"
include 'dump.inc'
;}
end if
 
language equ en
include 'lang.inc'
language equ lang
 
if SYS eq win
section '.text' code readable executable writeable
end if
 
include "arcmacro.inc"
include "parser.inc"
include "deflate.inc"
107,6 → 113,12
mcall 40,10000101b
; jmp again
CmdLine
cmdl:
test [Flags],LIST_MODE
jz red
 
; Dump [lpath],[lpath_len],os_work
; ud2
red:
call draw_window
mcall 12,2
134,12 → 146,15
mcall -1
.noquit:
mcall 17
mcall 64,1,MEMINIT
QueryFile
and [FileNum],0
mov [FileNum],FILE_NUM
test eax,eax
jnz still
end if
again:
; Dump Flags,4,os_work
mov [fat_],fat
Newline
xor eax,eax
; and [Flags],STAY_MODE
153,6 → 168,11
Msg 14
jmp quit
.sizeok2:
call KillViewer
xor eax,eax
mov ecx,(child_stack-fat)/4
mov edi,fat
rep stosd
mov [filesize],ebx
test [Flags],RAW_MODE
jz .norawm
213,13 → 233,37
jmp exit
.sizeok1:
if ~ SYS eq win
call KillViewer
end if
Msg 39
Msg 39 ; unpacking PNG
mov ecx,[unp_size]
add ecx,output
mov [png_],ecx
mov eax,[PNG_info.Width]
imul eax,[PNG_info.Height]
lea eax,[eax+eax*2]
add ecx,eax
; dps 'Mem='
; dpd ecx
mcall 64,1
test eax,eax
jz .ok
Msg 41
jmp exit
.ok:
mov edi,[outp]
call Deflate.blkbegin
jmp .defl_end
.sizeok:
mov ecx,[unp_size]
dpd ecx
add ecx,output
; mov [png_],ecx
mcall 64,1
test eax,eax
jz .ok2
Msg 41
jmp exit
.ok2:
call Deflate ; <===========
.defl_end:
test [bits],7
252,6 → 296,8
pop ecx esi
jmp .skipAdler
.skipCRC:
; dps 'Out='
; dpd ecx
call UAdler
Msg 10
mov eax,[Adler32]
283,6 → 329,9
else
test [Flags],PNG_MODE
jnz .nosave
test [Flags],LIST_MODE
jnz quit
 
test [Flags],TAR_MODE
jnz .nomsg
Msg 37
289,9 → 338,11
.nomsg:
mov [outfile.out],ebx
mcall 58,outfile
; dps 'Before Quit1'
; ud2
test [Flags],TAR_MODE
jnz .nosave
call StartPad
jz exit.pad
; call StartPad
.nosave:
end if
test [Flags],PNG_MODE
300,7 → 351,7
mov edi,filters
mov ecx,6
rep stosd
mov edi,png_image
mov edi,[png_]
mov esi,output
;//
mov [outp],edi
320,7 → 371,7
call RunViewer
and [arc_base],0
and [Flags],STAY_MODE
; dps 'Before Quit2'
quit:
QueryFile
test eax,eax
332,7 → 383,10
test [Flags],TAR_MODE
jz .notar
Msg 37
test [Flags],LIST_MODE
jne quit
mcall 58,outfile
.pad:
call StartPad
.notar:
Msg 12
352,16 → 406,19
else
jz still
end if
mov ecx,dumpf_len
mov esi,dumpfile
mov edi,filename
rep movsb
call OpenFile
test ebx,ebx
jz again.sizebadq
; Dump output,255,os_work
; ud2
; mov ecx,dumpf_len
; mov esi,dumpfile
; mov edi,filename
; rep movsb
; call OpenFile
; test ebx,ebx
; jz again.sizebadq
call TarParse
mov ecx,[FileNum]
call TarFindN
; dpd [outfile.size]
cmp [outfile.size],0
jz again.sizebadq
mov ebx,esi
/programs/other/archer/trunk/arcmacro.inc
177,6 → 177,7
' ',\ ;38
<'®¤£®â®¢ª  ¨§®¡à ¦¥­¨ï...',13,10>,\ ;39
<'“ª ¦¨â¥ "R" ¤«ï ®¡à ¡®âª¨ áëàëå ¤ ­­ëå. Žâ¬¥­ .',13,10>,\ ;40
<'¥ 墠⠥⠯ ¬ïâ¨! Žâ¬¥­ .',13,10>,\ ; 41
' ',\ ;
' ',\ ;
' ',\ ;
185,7 → 186,6
' ',\ ;
' ',\ ;
' ',\ ;
' ',\ ;
' <- ­¥¨§¢¥áâ­ë© ¬¥â®¤ ᦠâ¨ï',\ ;50
' <- § è¨ä஢ ­',\ ;51
<'¥ ZIP  à娢',13,10> ; 52
232,6 → 232,7
' ',\ ;38
<'Preparing bitmap...',13,10>,\ ;39
<'Specify "R" to force raw data. Abort.',13,10>,\ ;40
<'Not enough memory! Abort.',13,10>,\ ;
' ',\ ;
' ',\ ;
' ',\ ;
240,7 → 241,6
' ',\ ;
' ',\ ;
' ',\ ;
' ',\ ;
' <- unknown compression method',\ ;50
' <- encrypted',\ ;51
<'Not a ZIP archive',13,10> ; 52
/programs/other/archer/trunk/data.inc
84,6 → 84,11
Dheader rb 12
Dpassword rb PASSW_LEN
 
png_ dd ?
fat_ dd ?
fat_fnum dd ?
lpath dd ?
lpath_len dd ?
png_bpp dd ?
sline_len dd ?
IDATcount dd ?
120,6 → 125,15
hclen db ?
max_len dw ?
 
fat:
rb 4096;512
child_stack:
rb 1024
main_stack:
area:
rb INBUF
os_work rb 4*1024
 
bl_count rb BITS
 
next_code rw BITS
143,16 → 157,10
Distance rw 32
Dist_c rw 32
 
 
area:
rb INBUF
 
os_work rb 4*1024
 
output:
rb OUTBUF
;rb OUTBUF
 
png_image:
;png_image:
if SYS eq win
rb OUTBUF
end if
/programs/other/archer/trunk/debug.inc
73,10 → 73,16
@@:
ret
 
_debug_crlf db 13, 10, 0
 
macro newline
{
dps <13,10>
pushf
pushad
mov edx, _debug_crlf
call debug_outstr
popad
popf
}
 
macro print message
/programs/other/archer/trunk/deflate.inc
128,7 → 128,7
end if
pusha
xor eax,eax
mov ecx,(area-bl_count) / 4
mov ecx,(output-bl_count) / 4
mov edi,bl_count
rep stosd
popa
/programs/other/archer/trunk/dump.inc
0,0 → 1,55
; Include file for dumping user apps' memory through new debug BOARD
 
; Max amount of bytes to be dumped
IPC_BUF equ 160
 
; Dump macro parameters:
; ptr - pointer to memory dumped
; len - dump length
; workarea - any work area for sysfunc 9
; run_new - if not empty, run BOARD unless it is running already
 
macro Dump ptr, len, workarea,run_new
{
local .exist,.lt
pusha
mov ebx,workarea
call Board_seek
if ~ run_new eq
test edx,edx
jne .exist
mcall 19,Board_seek.board_fn,0
mov edx,eax
mcall 5,20
end if
.exist:
mov esi,len
cmp esi,IPC_BUF
jbe .lt
mov esi,IPC_BUF
.lt:
mcall 60,2,edx,ptr
popa
}
 
if used Board_seek
Board_seek:
; ebx - prcinfo
xor edx,edx
mcall 9,,-1
mov ecx,eax
mov esi,dword[.board_fn]
.lp:
mcall 9
cmp dword[ebx+10],esi
; jne .no
; cmp dword[ebx+42],399
je .ok
.no:
loop .lp
ret
.ok:
mov edx,[ebx+30]
ret
.board_fn db 'BOARD '
end if
/programs/other/archer/trunk/macros.inc
143,9 → 143,6
 
 
 
 
 
 
; optimize the code for size
__regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
177,7 → 174,7
 
macro mov arg1,arg2
{
if (arg1 in __regs) & (arg2 eqtype 0)
if (arg1 in __regs) & ((arg2 eqtype 0) | (arg2 eqtype '0'))
if (arg2) = 0
xor arg1,arg1
else if (arg2) = 1
/programs/other/archer/trunk/parser.inc
22,12 → 22,86
rep movsb
mov dword[edi],0x00a0d
call DebugPrint
; mcall 10
; mcall 2
popa
call Add2Fat
ret
 
Add2Fat:
; edx - ptr, ecx - len
 
pusha
test [Flags],LIST_MODE
jz .ex
mov ebp,8
mov edi,edx
lea ebx,[edx+ecx]
mov ecx,[lpath_len]
cmp ecx,1
je .lbl
mov esi,[lpath]
repe cmpsb
jne .full
mov eax,[lpath_len]
sub dword[esp+24],eax;path_len-path
cmp edi,ebx
je .full
mov edx,edi
.lbl:
mov ecx,[esp+24]
mov al,'/'
repne scasb
mov eax,[fat_]
mov ecx,[esp+24]
jne .nofol
cmp edi,ebx
jne .full
lea ecx,[edi-1]
sub ecx,edx
or byte[eax+11],0x10
; sub edx,ecx
.nofol:
 
push [fat_fnum]
pop dword[eax+12]
mov edi,eax
mov esi,edx
.lp1:
 
mov bl,[esi]
lea edx,[eax+ebp]
inc esi
cmp bl,'.'
jne .nodot
lea edi,[eax+ebp]
mov ebp,11
jmp .ll
.nodot:
cmp edi,edx
jae .ll
mov [edi],bl
inc edi
.ll:
loop .lp1
mov ecx,11
dec eax
.lp2:
cmp byte[eax+ecx],0
jne .no0
mov byte[eax+ecx],' '
.no0:
loop .lp2
cmp eax,child_stack-1
jae .full
add [fat_],32
.full:
inc [fat_fnum]
.ex:
popa
ret
 
;path db '/';'fasm/examples/elfexe/'
;path_len:
 
; Parse routines:
; out: edx= 0 if all ok, 1 - central dir, 2-EOD
; 50 - encrypted
78,16 → 152,19
popa
end if
Newline
; Dump fat,160,os_work
ret
 
ZipFindN:
; ecx - file #
Msg 33
or [Flags],FIND_MODE
cmp ecx,[file_count]
jae .err
push ecx
call ResetFile
.nxt:
 
call ZipCrawl
cmp edx,51
je .ok2
111,6 → 188,7
add esi,eax
mov edx,5
.ex:
and [Flags],-1-FIND_MODE
push edx
Msg edx
pop edx
159,6 → 237,8
cmp byte[edx+ecx-1],'/'
je .skipdp
end if
test [Flags],FIND_MODE
jnz .skipdp
call PrintFilename
.skipdp:
movzx ecx,word[esi+28]
252,7 → 332,19
mov [PNG_info.Width],eax
mov eax,[PNG_info.Height]
bswap eax
mov ebx,eax
mov [PNG_info.Height],eax
call scanline_calc
; dps 'All='
cmp [PNG_info.Color_type],3
jne .nopal
shl eax,3
inc eax
.nopal:
inc eax
imul eax,ebx
mov [unp_size],eax
; dpd eax
add esi,25
cmp byte[esi-5],0
rep_err e,52,29
423,7 → 515,8
ret
 
TarParse:
call ResetFile
mov esi,output
; call ResetFile
.nxt:
call TarCrawl
; wait
436,8 → 529,9
inc [file_count]
.skipinc:
add eax,ecx
mov ebx,1
call FileSeek
; mov ebx,1
add esi,eax
; call FileSeek
jmp .nxt
 
TarFindN:
447,7 → 541,8
cmp ecx,[file_count]
jae .err
push ecx
call ResetFile
mov esi,output
; call ResetFile
.nxt:
call TarCrawl
if IGNORE_DIRS eq 1
461,8 → 556,9
dec dword[esp]
.seek:
add eax,ecx
mov ebx,1
call FileSeek
; mov ebx,1
add esi,eax
; call FileSeek
jmp .nxt
.err:
mov edx,4
559,13 → 655,8
.err:
ret
 
; Created: May 31, 2005
FiltCall:
dd PngFilter.nofilt,Filt_sub,Filt_up,Filt_av,Filt_paeth,PngFilter.nofilt
PngFilter:
; esi - filtered uncompressed image data
; edi - destination
mov cl,[PNG_info.Color_type]
scanline_calc:
movzx ecx,byte[PNG_info.Color_type]
mov eax,1
cmp cl,3
je .palette
594,6 → 685,15
jnz .noz2
inc eax
.noz2:
ret
 
; Created: May 31, 2005
FiltCall:
dd PngFilter.nofilt,Filt_sub,Filt_up,Filt_av,Filt_paeth,PngFilter.nofilt
PngFilter:
; esi - filtered uncompressed image data
; edi - destination
call scanline_calc
mov [sline_len],eax ; scanline length
push edi
and [Flags],not 1
/programs/other/archer/trunk/sys.inc
105,7 → 105,7
else
test [Flags],THREAD_YES
jnz .ex
mcall 51,1,thread,MEMORY
mcall 51,1,thread,child_stack;MEMORY
mov [child],eax
end if
.ex:
191,7 → 191,7
mov ecx,[PNG_info.Width]
shl ecx,16
add ecx,[PNG_info.Height]
mcall 7,png_image,,10 shl 16+25
mcall 7,[png_],,10 shl 16+25
mcall 12,2
.still:
mcall 10
208,6 → 208,7
jne .still
.close:
and [child],0
mcall 64,1,MEMINIT
mcall -1
 
KillViewer:
256,7 → 257,68
mov ecx,255
mov edi,filename
rep movsb
jmp again
; test [Flags],LIST_MODE
; jz again
xor eax,eax
mov edi,filename
mov ecx,255
repne scasb
cmp byte[edi-2],'/'
je .slash
mov byte[edi-1],'/'
inc edi
.slash:
; Dump filename,255,os_work
; ud2
mov ecx,edi
; dec ecx
mov edx,ecx
mov dword[Finfo],13
; mov dword[Finfo.count],1
mov edi,filename+5
sub ecx,edi
.lp:
mov al,'/'
repne scasb
; jne .ex
; dpd ecx
and byte[edi-1],0
mcall 58,Finfo
mov byte[edi-1],'/'
test ebx,32
jz .lp
test [Flags],LIST_MODE
jne .listm
and byte[edi-1],0
; Dump filename,255,os_work
jmp .agg
; ud2
.listm:
lea esi,[edi-1+ecx]
lea edi,[esi+1]
std
rep movsb
and byte[edi],0
cld
; dpd filename
 
inc edi
dpd edi
cmp edx,edi
jne .slash2
; cmp byte[edi],'/'
; je .slash2
mov byte[edi],'/'
inc edx
.slash2:
sub edx,edi
mov [lpath],edi
mov [lpath_len],edx
dpd edx
.agg:
mov dword[Finfo],0
; ud2
jmp again;cmdl
.yespar:
cmp al,'N'
jne .nonum
300,6 → 362,10
call get_6ASCII_num
jmp .fofs
.noofs2:
cmp al,'L'
jne .nolist
or [Flags],LIST_MODE
.nolist:
jmp .parse
 
get_6ASCII_num:
319,8 → 385,20
}
 
StartPad:
mcall 19,editorcmd,dumpfile
; mcall 19,editorcmd,dumpfile
pusha
mov esi,[outfile.size]
; dpd esi
mov [par_fsize],esi
mcall 19,editorcmd,editor_par
mov ecx,eax
mcall 5,20
mcall 60,2,,[outfile.out];output
mcall 64,1,MEMINIT
popa
ret
 
editorcmd db 'TINYPAD '
editor_par db '*'
par_fsize dd ?
end if