flat assembler
Message board for the users of flat assembler.
Index
> DOS > tiny .ZIP viewers (122 and 254 bytes) Goto page 1, 2 Next |
Is this useless? | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
Total Votes : 22 |
Author |
|
rugxulo 03 Nov 2006, 10:05
Okay, well, if anyone payed close attention, I mentioned writing a .ZIP viewer for DOS (EDIT: see attachment in post below). Actually, it works okay but could probably be vastly improved if I put more effort into it and then eventually rewrote it. But, for fun, I decided to do this instead:
P.S. Thanks to vid, Grenhald, relsoft, http://www.256b.com, etc. for inspiration! P.P.S. I'm not attaching a file but putting it in a code block instead so that non-members of the forum can see/get it too! 122-byte .ZIP viewer
If you want a decent cmdline archive viewer (not written by me, heh) w/ .ASM source, get ARCLDS (reads ACE, ARC, ARJ, CAB, DWC, HA, HAP, HPK, HYP, LIM, LHA/LZH, PAK, RAR, SQZ, YAC, ZIP, ZOO) 0.94.3 beta (2006-08-06). Else, Win32 peeps, get IZarc or WinUHA for all your basic archiving needs (except PAQ8?, of course)! (new!) IZarc now supports BZip2 compression in .ZIPs, AES encryption in .ZIPs, and can handle archives > 4GB (i.e., it's more compatible with WinZip 9). Code: ; C.ASM -- 122-byte .ZIP viewer! ; reads local headers ; only outputs filenames to STDOUT ; ; public domain, free for any use, no credit necessary ; assemble w/ FASM 1.67.14 ; ; Thank you, Lord Jesus, for your kindness and mercy, etc. ; ; rugxulo AT bellsouth DOT net ; Monday, November 6, 2006 11:37am CR=13 LF=10 STDOUT=1 org 100h Komenco: mov ax,3D00h mov si,80h cmp byte [si+1],CR jz Fino xor bh,bh mov bl,[si] mov byte [si+bx+1],bh lea dx,[si+2] int 21h jc Fino xchg bx,ax Ekzamenu: mov cx,local_header_size mov dx,local_header call read_file mov di,filesize_compressed cmp word [di-18],'PK' jnz Fino ; cmp word [di-16],0201h ; jz Fino cmp word [di-16],0403h jnz Fino push word [di+2] push word [di] mov cx,[di+8] push cx add cx,[di+10] mov dx,buffer call read_file pop cx mov ah,40h push bx mov bx,STDOUT int 21h pop bx mov ah,2 mov dl,CR int 21h mov dl,LF int 21h pop dx pop cx test dx,dx jnz Bonege jcxz Ekzamenu Bonege: mov ax,4201h int 21h jnc Ekzamenu Fino: mov ax,4C00h int 21h ; read_file read_file: mov ah,3Fh int 21h jc Fino cmp ax,cx jnz Fino read_file_ret: ret local_header: id rb 4 version rb 2 bitfield rb 2 compression rb 2 filetime rb 2 filedate rb 2 crc rb 4 filesize_compressed rb 4 filesize_uncompressed rb 4 filename_length rb 2 extra_field_length rb 2 local_header_size = $-local_header buffer: ; EOF Last edited by rugxulo on 16 Nov 2006, 02:03; edited 4 times in total |
|||
03 Nov 2006, 10:05 |
|
vid 03 Nov 2006, 10:23
still lot of place for improving there
|
|||
03 Nov 2006, 10:23 |
|
rugxulo 03 Nov 2006, 11:00
<EDIT>
Well, I guess I may as well post my (unfinished, unpolished, needing-a-rewrite, very-slightly-buggy) semi-full-featured .ZIP viewer for DOS here. It ain't able to use FASM (yet), so please don't whine. Here's a text screen dump/screenshot: Code: [ WinXP ] Sun 11/05/2006>av AV19TEMP.ZIP /i! /m! /p /l! AV19TEMP.ZIP av19.asm 16,049 (74,475) Oct,28,2006 09:24:06a [Defl-X] avlazy.bat 866 (2,461) Jan,03,2006 09:49:28a [Defl-X] av19.com 4,585 (4,585) Oct,28,2006 09:31:06a [Stored] izappnfo.txt 38,981 (166,297) May,28,2004 06:20:00p [Defl-X] all4one.bat 85 (147) Oct,29,2004 09:25:38p [Defl-N] one4all.bat 66 (66) Oct,27,2004 08:03:16p [Stored] av186.asm 13,183 (65,416) Jul,07,2005 10:44:20p [Defl-X] debugit.bat 998 (1,869) Oct,07,2005 11:51:16p [Defl-X] zip630.txt 34,010 (136,852) Oct,07,2006 06:52:54p [Defl-X] jmp2ret.bat 713 (1,685) Aug,16,2006 12:46:36p [Defl-X] 10 items: 0 dirs + 10 files 109,536 bytes (453,853 unzipped) Created by ZIP 2.3 : DOS, OS/2, WinNT FAT [ WinXP ] Sun 11/05/2006>scrndump And here's the help screen: Code: AV 0.19 (October 28, 2006) rugxulo AT bellsouth DOT net Usage: av /z:cXi c:\dir\ /E myfile.zip /c ! print archive Comment after view /d ! print Dirs only, not files /e print numbers in kb (kb = 1024) /f ! print only Files, not dirs /h Help screen (/? also works) /i ! list numitems & size totals Info /k ! print archive Komment only /l ! do not List name of opened file /m ! print compr. Method nums (! sub-) /n print CRLF after every fname /o no colors /p ! no Pause if screen is full /q ! Quiet mode (summary info only) /r ! clear or Reset to CO80 then list /s(.asm) ! Search for fnames w/ ".asm" /u no commas /x ! toggle printing numbers in heX /y !+ wait after view or until kbhit /z: multiple options (/z:icp!) TODO:
P.S. It ain't no great piece of software, but enjoy (if possible ... or have a good laugh, heh). </EDIT>
Last edited by rugxulo on 16 Nov 2006, 01:41; edited 2 times in total |
|||||||||||
03 Nov 2006, 11:00 |
|
rugxulo 05 Nov 2006, 23:56
Bugfixed!
Code: ; C02.ASM -- 254-byte .ZIP viewer! ; (successor to the 122-byte "filenames-only" .ZIP viewer) ; ; public domain, free for any use, no credit necessary ; assemble w/ FASM 1.67.14 (http://www.flatassembler.net) ; ; God listens, God loves, God forgives, God helps ... thanks, God! ; ; rugxulo AT bellsouth DOT net ; ; Wednesday, November 15, 2006 6:58pm ; ; ; +===========+ ; | Bugfixes: | ; +===========+ ; ! a zero-byte file is not always a DIR! ; - rare but needed fixing (e.g., GNU/DJGPP sed: SED415S.ZIP) ; - also! needed extra PUSH/POP for my XP (P4 2.52 Ghz) cpu ; - seems to be needed only on Win XP Home SP2 (Dell A05 BIOS) ; - DR-DOS 7.03 (P166), MS-DOS 6.22 (486 Sx/25) both work ; with or without it ; ! the .BAT was broken (oops, doh, oy, eek, wah) ; - it was sometimes wrongly reporting success! ;-( ; ; +===========+ ; | Features: | ; +===========+ ; + small (duh, that's the whole point!) ; + written in FASM (which is FOSS/good/fast/small, etc.) ; - TODO: write sed scripts to convert to NASM, Octasm, etc. ; + written in pure 8086 asm (no 386+ required) ; + liberal license (or lack thereof ... (ab)use for whatever!) ; + outputs names & sizes (w/ commas!) to STDOUT (redirectable) ; + preserves filenames' case (upper, lower, mixed, whatever) ; + now prints the .ZIP file's name itself first (hi, Dex!) ; + always exits with errorlevel of zero (just to be nice) ; - only reads local headers (not "Central Dir Structure") ; - doesn't handle data descriptor (oh well, that's rare anyways) ; - that's all! it doesn't do anything else! ; ; +==============+ ; | Misc. Notes: | ; +==============+ ; = to find *only* directories: ; c02 myfile.zip | sed -n "/\/$/{N;p;}" ; ; = to count files and dirs: ; c02 myfile.zip | sed -n "1,2d;n;p;" | sed -n "$=" ; ; +=========+ ; | Caveat: | ; +=========+ ; = if optimizing this further, use this .BAT to make sure ; the resulting info outputted is the same): ; ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; @echo off ; REM Tested on DR-DOS 7.03 Lite ; REM ; REM !!! FIXED !!! ; ; if "%1"=="/fc" goto test ; ; for %%a in (*.zip) do call %0 /fc %%a ; goto end ; ; :test ; shift ; c02-old.com %1>old ; c02.com %1>new ; fc old new ; ; :end ; for %%f in (old new) do if exist %%f del %%f ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ;short equ byte ; uncomment for FASM < 1.65.20 ; (this prevents 386+ jumps) CR=13 ; carriage return LF=10 ; line feed TAB=9 COMMA=',' SLASH='/' org 100h Komenco: mov ax,3D00h mov si,81h cmp byte [si],CR ; end of cmdline jz short FinoFino xor bh,bh mov bl,[si-1] ; cmdline length (ignores CR) mov byte [si+bx],bh ; change CR to 0 for int 21h,3Dh lea dx,[si+1] ; (makes argv[1] into ASCIIZ) lea cx,[bx-1] ; CX = length - 1 (' ' after 'c02') int 21h ; open file for reading jc short FinoFino push ax ; save file handle mov si,dx call eldonu ; output .ZIP file's name call crlf call crlf ; output '\n' twice pop bx ; restore handle (for read_file) Cxerpu: mov cx,local_header_size mov dx,local_header call read_file ; read in local header mov di,filesize_compressed cmp word [di-18],'PK' ; verify if is a .ZIP file jnz short FinoFino ; cmp word [di-16],0201h ; if reached CDS, then quit ; jz short Fino cmp word [di-16],0403h ; if not local header, then quit jnz short FinoFino mov cx,[di+8] push cx ; save filename length add cx,[di+10] ; CX = fname len + extra field len mov dx,buffer call read_file ; read in filename and extra field ; (to buffer) push dx mov ah,2 mov dl,TAB ; output TAB (to ease readability) int 21h pop si ; SI = location of filename pop cx ; restore filename length call eldonu ; output filename mov cx,[di+2] mov dx,[di] ; CX:DX = size of compressed data test dx,dx jnz short Bonege test cx,cx ; is size of compressed data == 0 ? jnz short Bonege cmp al,SLASH ; if fname ends in '/', it's a DIR jnz short Bonege Dosierujo: mov cx,dir_msg_size mov si,dir_msg+dir_msg_size-1 ; SI = offset of 'D' in 'DIR!' string clc ; clear carry flag pushf ; save flags for later jmp short Diru FinoFino: jmp short Fino ; midway to Fino ; (short jump range is exceeded) CxerpuCxerpu: jmp short Cxerpu ; midway to Cxerpu ; (short jump range exceeded) Bonege: mov ax,4201h ; move file pointer int 21h ; (skip over compressed data, jc short Fino ; if not a DIR) pushf Grandeco: mov ax,[di+4] mov dx,[di+6] ; DX:AX = uncompressed file size push bx ; save file handle bin2dec: mov cx,10 ; output number in base 10 (decimal) mov di,buffer ; put ASCIIZ decimal string ; mov si,di ; w/ commas in buffer (backwards) xor bp,bp bin2dec_start: xchg ax,dx push dx xor dx,dx ; convert word in AX to DX:AX (dword) div cx xchg ax,bx pop ax div cx xchg dx,bx or bl,'0' ; this only works for dec numbers! ; push ax ; this works for dec or hex nums ; xchg bl,al ; mov bx,asciihex ; xlatb ; translate digit to ASCII ; xchg bl,al ; pop ax inc bp mov byte [di],bl cmp bp,3 jb short bin2dec_no_comma ; comma_number = 3 (dec) or 4 (hex) inc di mov byte [di],COMMA xor bp,bp bin2dec_no_comma: inc di test dx,dx jnz short bin2dec_start test ax,ax jnz short bin2dec_start dec di ; now DX:AX = 0 cmp byte [di],COMMA ; this will allow 3-digit numbers jz short bin2dec_bye ; not to be outputted w/ a comma inc di bin2dec_bye: stosb bin2dec_ret: pop bx ; restore file handle lea si,[di-2] ; SI = first digit in number lea cx,[di-buffer-1] ; CX = size of number string Diru: call crlf call eldonu_rev ; output number ("buffer" in reverse) Crlf_it: call crlf ; output \n popf ; restore flags jnc short CxerpuCxerpu ; if not carry, get next header Fino: ; mov ax,4C00h ; closes files, returns errorlevel 0 ; int 21h int 20h ; thanks for your help, ATV ; read_file read_file: mov ah,3Fh ; BX = handle, CX = # bytes to read int 21h ; DX = buffer to read into jc short Fino ; carry flag means error cmp ax,cx jnz short Fino ; quit if # bytes read in != # bytes read_file_ret: ; requested to be read in ret ; crlf crlf: ; outputs \n to STDOUT mov ah,2 mov dl,CR int 21h mov dl,LF int 21h crlf_ret: ret ; eldonu_rev eldonu_rev: ; outputs string at SI in reverse std ; (redirectable) ; CX = size of string ; eldonu eldonu: ; outputs string at SI (redirectable) mov ah,2 ; CX = size of string eldonu_denove: lodsb mov dl,al ; DL = char to output push ax ; * (need to save this on my XP cpu) int 21h pop ax ; * (PUSH/POP not needed on my P166) loop eldonu_denove ; loop while CX is > 0 cld ; clear direction flag eldonu_ret: ret ;asciihex db '0123456789ABCDEF',0 dir_msg db '!RID' dir_msg_size = $-dir_msg local_header: id rb 4 version rb 2 bitfield rb 2 compression rb 2 filetime rb 2 filedate rb 2 crc rb 4 filesize_compressed rb 4 filesize_uncompressed rb 4 filename_length rb 2 extra_field_length rb 2 local_header_size = $-local_header buffer: ; EOF
Last edited by rugxulo on 02 Aug 2007, 23:17; edited 3 times in total |
|||||||||||
05 Nov 2006, 23:56 |
|
rugxulo 06 Nov 2006, 21:11
Hey ATV, nice job! Yeah, I know there are a few dumb things in AV19.ASM, but I was too lazy/busy to fix 'em all (in particular, I discovered the mul thing recently in another program of mine).
It's (apparently) TOO easy for me to make such silly mistakes, and I'm always correcting them, heh. <EDIT> Oops! Looks like you mistakenly changed int 21h,4Ch into int 20h. That would be fine except int 21h,4Ch also closes open files! <EDIT #2> Actually, the file still seems to be closed (at least in DOSBOX 0.65 and Win XP Home SP2 ... why?? Needs further testing, probably). </EDIT #2> </EDIT> |
|||
06 Nov 2006, 21:11 |
|
polygon7 06 Nov 2006, 23:07
rugxulo wrote: <EDIT> If you popped all things from stack, then you could even try to use "ret" instead "int 20". On clean stack "ret" in *.com files jumps to PSP:0h (if i remember correctly) which contains "int 20h" opcode. (Its something similar like in Windows executables) _________________ best regards p7 |
|||
06 Nov 2006, 23:07 |
|
ATV 07 Nov 2006, 11:41
rugxulo, I have been testing 286 (DOS 3.3) and 486 (DOS 6.22) and P166 (Win95) and all will close files with int 20h. I was little suprise that 286 and 486 starts without any problem, even floppy drive was working (only BIOS clock was wrong). Now I need couple hours fresh air, because those computers was covered in a thick layer of dust.
|
|||
07 Nov 2006, 11:41 |
|
Tomasz Grysztar 07 Nov 2006, 11:58
polygon7 wrote: If you popped all things from stack, then you could even try to use "ret" instead "int 20". On clean stack "ret" in *.com files jumps to PSP:0h (if i remember correctly) which contains "int 20h" opcode. (Its something similar like in Windows executables) You may find details on it here. |
|||
07 Nov 2006, 11:58 |
|
Madis731 08 Nov 2006, 10:32
...and then comes the time when I stop believing that 7-Zip is increadibly small
|
|||
08 Nov 2006, 10:32 |
|
polygon7 08 Nov 2006, 19:18
Tomasz Grysztar wrote:
_________________ best regards p7 |
|||
08 Nov 2006, 19:18 |
|
Tomasz Grysztar 08 Nov 2006, 19:23
However you may not be the only one that is reading it.
|
|||
08 Nov 2006, 19:23 |
|
rugxulo 09 Nov 2006, 01:14
ATV, you're just ridiculously talented, that's all. I've noticed that about you (and people on this board in general). Thanks for the tips!
Madis, I'm not sure I understand you here, but 7-Zip is definitely worthwhile. Even PKWARE uses(?) LZMA as compression method #14 in .ZIP according to their latest APPNOTE.TXT (6.3.1, Apr. 11, 2007). Last edited by rugxulo on 18 Jul 2007, 23:05; edited 3 times in total |
|||
09 Nov 2006, 01:14 |
|
ATV 09 Nov 2006, 10:12
I was looking little more deeper and found next text in chapter.004 from archive dosref33.zip
Quote: Issue int 20h to exit from a program. This vector transfers to the Then I tested write file with DOS 3.3/6.22 and file size/date/time was updated. So I don't know which version of DOS can't handle int 20h with dir entry update if file has changed. I should stop programming, because my near memory is very bad and I have made silly errors too, but it's so difficult give up after over 20 year programming. (VIC 20 was so good 1.1MHz 8bit computer) |
|||
09 Nov 2006, 10:12 |
|
Madis731 09 Nov 2006, 13:03
by that I meant that there were times when I thought that *other* zippers are bloat and 7-zip is small (as a program, not as a compression method).
Now when I see that you can really unzip around 100 bytes wow - 7-zip feels bloat... To throw another curveball: ...then there's the speed optimization issue. |
|||
09 Nov 2006, 13:03 |
|
Dex4u 09 Nov 2006, 15:01
Madis731 wrote: by that I meant that there were times when I thought that *other* zippers are bloat and 7-zip is small (as a program, not as a compression method). This is a zipped file viewer, not a unzipper . |
|||
09 Nov 2006, 15:01 |
|
Madis731 09 Nov 2006, 15:07
:$ oh, okay - its all logical then, NOT
But impressive still! I admire these small things... |
|||
09 Nov 2006, 15:07 |
|
Dex4u 09 Nov 2006, 17:24
I agree its still impressive, rugxulo did a good job, so impressed i converted it to run in Dex4u OS (soon to be dexOS)
http://jas2o.forthworks.com/dexforum/index.php?topic=172.0 PS: A unzipper in less than 2k would be very impressive. |
|||
09 Nov 2006, 17:24 |
|
rugxulo 09 Nov 2006, 17:58
I've seen at least two unzippers in < 3k (PKUNZJR, TUNZ), so it definitely can be done. But, neither is open source, and I'm NOT inclined to disassemble 'em (and definitely don't recommend doing so) for fear of breaking some law or whatever. Besides, writing my own would probably be easier and more fun, anyways.
EDIT: I now actually think that TUNZ is based on / hacked from PKUNZJR. Like I said in PM to Dex, there is lots of Unzip code out there (DJTAR, UZ, UnzipAda, Unzip in Pascal, Info-Zip, ZLIB, OctaOS, etc.), so anybody is welcome to try their hand at it. P.S. These mini proggies of mine are not that impressive. I've seen better (tet, bd3, inv, selfdasm, wolf, smile256). Last edited by rugxulo on 18 Jul 2007, 23:08; edited 4 times in total |
|||
09 Nov 2006, 17:58 |
|
Dex4u 09 Nov 2006, 19:10
Quote:
CdPod and MiniDos are my mini efforts |
|||
09 Nov 2006, 19:10 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.