flat assembler
Message board for the users of flat assembler.
Index
> DOS > tiny ATTRIB clones (171 or 955 / 810 bytes) -- reupdated! |
How lousy is this? | |||||||||||||||||||||
|
|||||||||||||||||||||
Total Votes : 10 |
Author |
|
rugxulo 28 Jun 2007, 07:42
It's not like I majorly needed to write this (I mean, FreeDOS' attrib.com is only 5,044 bytes). Anyways, at least it's small and doesn't need megs of compiler crud to make.
REUPDATED! Code: ; ------------------------------------------------------------------------ ; ; ATTR.ASM -- tiny DOS attrib clone (w/ .ASM src) ; ; written with FASM 1.67.21 http://board.flatassembler.net ; public domain, free for any use ("nenies proprajxo") ; ; rugxulo CXE gmail PUNKTO com (bug reports welcome) ; ; Monday, August 27, 2007 6:32pm ; ; ------------------------------------------------------------------------ ; ; +==========+ ; | HISTORY: | ; +==========+ ; ; 0.6 : 955 (810) bytes, fixed "attr" to show +H +S files like "attr *.*", ; .ZIP now includes a 624'd .COM (b/c AVG Free resident / heuristics ; whines FALSELY, scan online at http://virustotal.com if in doubt) ; 0.5 : 939 (794) bytes, fixed "attr /d -r" to not act unnecessarily on ; dirs, now keeps going if GET_ATTRIB failed (WinXP: "attr \*.*"), ; plus lists attribs from before / after change ("????" = failed) ; 0.4 : 895 bytes, fixed the new "attr whatever\*.*" (aka, "attr ..\*.*") ; bug, plus now assembles to only 750 bytes if TINYHELP > 0 ; 0.3 : 899 bytes, "attr /d" bugfix, fixed accidental 386+ jumps ; (doh! sorry ...), plus it's MUCH faster on ignorable files ; (see "speed" section below) ; 0.2 : 900 bytes, supports wildcards (default '*.*'), says fname + attrib, ; options /Q (quiet), /D (dirs in wildcards), and /H /? (help ; screen), plus some basic error checking ; 0.1 : 168 bytes, first release, only very VERY minimum functionality ; ; ------------------------------------------------------------------------ ; ; +==========+ ; | THANKS : | ) B-) =o) ; +==========+ ; ; - Thanks to Jesus Christ for his help (in this and everything)! ; - Mom? Dad? Beyond words ... so much kindness and patience. ; - FASM forum r0x0rz! ^_^ ; ; - greets to Octavio Vega Fernandez, Jason Hood, David Lindauer, ; Eric Auer, and Stefan Weber (among many others ...). ; ; ------------------------------------------------------------------------ ; ; +=========+ ; | NOTES : | ; +=========+ ; ; If this doesn't work fully for you, please contact me, and tell me ; what happened, what specific OS (PTS-DOS? OS/2? Win NT?) and version ; that you used it on, and how / if you can duplicate the problem, etc. ; ; - I used the FASM dialect of assembly language and did a few minor (heh) ; annoying things, so you may find it harder to translate to NASM (or ; whatever) than usual. If you can't understand the code, disassemble it ; or just e-mail me asking me to translate it to NASM, Octasm, etc. ; ; - Usage: 'attr +sa a*.*' or 'attr /q -Rh t:*.asm' or 'attr /q /d -S' ; ; - the following filespecs should work correctly: ; ; "t:*.*" "c:\utils\*.com" "\*.bat" "*.bk?" "" ; ; ------------------------------------------------------------------------ ; ; +=========+ ; | SPEED : | ; +=========+ ; ; [ DR-DOS ] Thu 7-19-2007>attr +r u:attr*.com ; A..R u:attr1.com ; A..R u:attr.com ; ; [ DR-DOS ] Thu 7-19-2007>attr +r u:v.com ; A..R u:v.com ; ; [ DR-DOS ] Thu 7-19-2007>runtime fdattrib -r u:\*.com | find "seconds" ; 01.70 seconds elapsed ; ; [ DR-DOS ] Thu 7-19-2007>attr +r u:v.com ; A..R u:v.com ; ; [ DR-DOS ] Thu 7-19-2007>attr +r u:attr*.com ; A..R u:attr1.com ; A..R u:attr.com ; ; [ DR-DOS ] Thu 7-19-2007>runtime attr3 -r u:\*.com ; A... u:\v.com ; A... u:\attr1.com ; A... u:\attr.com ; 00.11 seconds elapsed ; ; [ DR-DOS ] Thu 7-19-2007>scrndump ; ; ------------------------------------------------------------------------ ; ; +========+ ; | TODO : | ; +========+ ; ; 1). make usage of PLEX strlens conditional (if ~ UNDOC, use normal getlen) ; = would be nice, just in case ... ; 2). report "Not found" if attr changes nothing (but be silent if /Q) ; = so far, it's always silent if no change (slightly confusing??) ; 3). LFN support (int 21h,71..h), which FreeDOS ATTRIB also lacks ; = shouldn't be hard, see my LFNDIR ; 4). perhaps "attr =ar" to set / unset in one invocation ?? ; ; - lacks the following features (not very important for me): ; ; - set and unset in one cmd 'attr -s +r *.asm' ; - set/unset after fname 'attr *.asm -sr' ; - set/unset on multiple filespecs 'attr +r *.asm *.txt' ; - set/unset in subdirs 'attr /s +r c:\code\*.asm' ; ; - Not a huge deal, IMO, since I *very* seldomly use such. Use the ; 'for' keyword in COMMAND.COM to simulate some of those. ; ; - Or get FreeDOS' ATTRIB instead if you must have such abilities ; (only 5,044-byte .COM, aPACK'd; GPL, written in C). ; ; - Or get Charles Dye's nice clone (5,107-byte .COM, UPX'd; GPL, NASM): ; http://www.highfiber.com/~raster/freeware.htm ; ; ------------------------------------------------------------------------ TINYHELP=0 ; set %INCLUDE% or put "Include=" in your FASMW.INI file (under Environment) include 'only8086.inc' ; not needed, just a precaution ; (I didn't write this, only ; found it on FASM's forum) VERSION equ '0.6' EMAIL equ 'rugxulo AT gmail DOT com' ; (anti-spam trick for forum) DEFAULT=0 ; default options OPT_Q=1 ; quiet (no attrib + fname reporting) OPT_D=2 ; don't ignore dirs in wildcards CR=13 LF=10 CRLF=0A0Dh TAB=9 ARCHIVE=32 DIRECTORY=16 VOLUME=8 SYSTEM=4 HIDDEN=2 READONLY=1 ALL=ARCHIVE or DIRECTORY or SYSTEM or HIDDEN or READONLY and not VOLUME SET_DTA=1Ah FINDFIRST=4Eh FINDNEXT=4Fh GET_ATTRIB=4300h SET_ATTRIB=4301h FILEATTR equ dta+15h FILENAME equ dta+1Eh DOS equ int 21h PLEX equ int 2Fh macro zero reg { xor reg,reg } macro uppercase whatever { and whatever,0FFh and not 20h } macro lowercase whatever { or whatever,20h } org 100h Komenco: mov ah,SET_DTA mov dx,dta ; change DTA to avoid PSP:80h clash DOS mov si,80h lodsb cbw xchg ax,bp ; BP = length of cmdline used mov byte [si+bp],0 ; make filename ASCIIZ cmp byte [si],CR jz FinoFino mov di,si call skip_space call find_options mov dx,filespec cmp byte [di-2],'/' jz Zero_it cmp byte [di],0 jnz @f cmp byte [di-1],0 jnz @f mov cx,ALL test byte [options],OPT_D jz .maskoff jmp Find .maskoff: and cl,not DIRECTORY jmp Find @@: mov al,byte [di-1] test al,al jz Before cmp al,'+' jz @f cmp al,'-' jz @f dec di jmp Get_filename @@: mov byte [flag],al ; save plus '+' or minus '-' Zero_it: zero dx ; start w/ clear attribute Search: zero bx .begin: cmp byte [di],' ' jz Get_filename cmp byte [di],0 jz Get_filename mov al,byte [attrib_list+bx] uppercase byte [di] cmp byte [di],al ; is valid attribute symbol found? jz Found inc bx ; if not, goto next symbol cmp bx,attrib_list.size-1 ja Get_filename ; > means we've tried all attribs jmp .begin ; with no luck! Found: call modify_value ; tweak value (set or unset) inc di jmp Search FinoFino: jmp Fino Get_filename: mov byte [attrib],dl ; save final attribute call skip_space dec di mov word [file_with_path],di mov ax,1212h ; DOS 3.0+ (undocumented) PLEX ; get length of ASCIIZ in ES:DI mov si,di mov di,filespec push si cx cmp byte [si],0 jz @f rep movsb @@: pop cx di mov bx,di add di,cx std mov al,'\' repnz scasb cld ; \mydir ; t:myfiles*.com ; t:\*.asm cmp bx,di pushf inc di inc di popf jnz Before cmp byte [bx],'\' jz .fix2 cmp byte [bx+1],':' jz Before .fix: dec di .fix2: dec di Before: push di push bx mov dx,filespec mov bx,ALL push dx mov di,dx mov ax,1212h PLEX mov al,'?' @@: push cx repnz scasb test cx,cx pop cx jnz .wildcard_found cmp al,'*' jz .no_wildcard pop di push di mov dx,di mov al,'*' jmp @b .wildcard_found: and bl,not DIRECTORY .no_wildcard: mov cx,bx ; setup attribs to search for pop dx ; restore filespec pop bx pop di Find: mov ah,FINDFIRST ; find matching files (via wildcards) test byte [options],OPT_D jz @f or cl,DIRECTORY @@: DOS jc Fino Change: mov si,FILENAME cmp byte [si],'.' ; skip '.' and '..' (useless filenames) jz Next push di mov ax,1225h ; DOS 3.0+ (undocumented) PLEX ; get length of ASCII in DS:SI rep movsb mov dx,word [file_with_path] pop di mov cl,byte [FILEATTR] .okay: and cl,not DIRECTORY mov bx,cx @@: mov ax,SET_ATTRIB call adjust_attrib cmp byte [flag],' ' jz @f cmp bx,cx ; skip files which don't need changing jz Next ; for better speed @@: DOS .output: call output_info jc Fino Next: mov ah,FINDNEXT mov dx,filespec DOS jc Clear mov si,FILENAME cmp byte [si],'.' jz Next jmp Change Clear: zero al Fino: test byte [options],OPT_Q jnz Adios push ax cmp al,3 jnz @f mov si,no_path call error_msg @@: cmp al,15 jnz @f mov si,no_drive call error_msg @@: cmp al,18 jnz @f mov si,no_file call print_str @@: pop ax Adios: mov ah,4Ch DOS ; output_info output_info: lahf mov bx,cx test byte [options],OPT_Q jnz .ret push dx push ax bx mov cl,byte [FILEATTR] call print_attrib pop bx ax cmp byte [flag],' ' jz .mark_dir push ax mov ax,GET_ATTRIB DOS pop ax jnc .after mov cx,bx sahf jnc .after mov ax,'??' call fill_attrib_str call print_attrib.print jmp .mark_dir .after: call print_attrib .mark_dir: mov dl,'[' call is_dir mov si,word [file_with_path] call print_str2 ; print fname (lowercase if not DIR) ; and \n mov dl,']' call is_dir .crlf: call print_crlf pop dx .ret: ret ; print_attrib print_attrib: mov bx,-1 .test: inc bx cmp bl,attrib_list.size-1 ja .print test cl,[values+bx] jz .test .okay: mov dl,[attrib_list+bx] mov [attrib_str+bx],dl jmp .test .print: mov si,attrib_str call print_str ; print file's attribute string, .clear: mov ax,'__' call fill_attrib_str .ret: ret ; error_msg error_msg: call print_str mov si,not_found call print_str .ret: ret ; fill_attrib_str fill_attrib_str: push di ; then clear string for later mov di,attrib_str stosw stosw pop di .ret: ret ; find_options find_options: cmp byte [di-1],'/' jnz .ret mov al,byte [di] cmp al,'?' jnz @f jmp .help @@: call toupper cmp al,'H' jnz @f .help: mov si,help_msg call print_str jmp Clear @@: cmp al,'Q' jnz @f xor byte [options],OPT_Q @@: cmp al,'D' jnz .next xor byte [options],OPT_D .next: cmp byte [di+1],0 jnz .okay inc di ret .okay: mov cx,bp mov al,' ' repnz scasb dec di mov cx,bp rep scasb jmp find_options .ret: ret ; print_str2 print_str2: lodsb test al,al jz .ret test byte [FILEATTR],DIRECTORY jnz @f call tolower @@: xchg ax,dx call print_char jmp print_str2 .ret: ret ; print_str print_str: push ax .begin: lodsb test al,al jz .bye cmp al,LF jnz @f call print_crlf jmp .begin @@: xchg ax,dx call print_char jmp .begin .bye: pop ax .ret: ret ; print_crlf print_crlf: mov dl,CR call print_char mov dl,LF DOS .ret: ret ; print_char print_char: mov ah,2 DOS .ret: ret ; toupper toupper: cmp al,'a' jb .ret cmp al,'z' ja .ret uppercase al .ret: ret ; tolower tolower: cmp al,'A' jb .ret cmp al,'Z' ja .ret lowercase al .ret: ret ; is_dir is_dir: test byte [FILEATTR],DIRECTORY jz .ret call print_char .ret: ret ; skip_space skip_space: mov al,' ' mov cx,bp inc cx rep scasb .ret: ret ; modify_value modify_value: cmp byte [flag],'+' jnz .unset or dl,byte [values+bx] ret .unset: cmp byte [flag],'-' jnz .ret push ax mov al,byte [values+bx] not al and al,ARCHIVE or SYSTEM or HIDDEN or READONLY test dl,dl jnz .and or dl,al jmp .bye .and: and dl,al .bye: pop ax .ret: ret ; adjust_attrib adjust_attrib: cmp byte [flag],'+' jnz .unset or cl,byte [attrib] ret .unset: cmp byte [flag],'-' jnz .ret and cl,byte [attrib] .ret: ret if ~ TINYHELP help_msg db LF,'ATTR ',VERSION,' -- tiny DOS attrib (w/ .ASM src)',LF db TAB,' -- ',EMAIL,LF,LF db '/q',TAB,'Quiet (don''t show attribs & fnames)',LF db '/d',TAB,'don''t ignore Dirs in wildcard',LF db '/h /?',TAB,'this Help',LF,0 else help_msg db LF,'ATTR ',VERSION,' : /q /d',LF,0 end if no_path db LF,'Path',0 no_drive db LF,'Drive',0 no_file db LF,'File' if ~ TINYHELP not_found db ' not found!',LF,0 else not_found db ' ??',LF,0 end if attrib_str db '____ ',0 attrib_list db 'ASHR' .size=$-attrib_list values db ARCHIVE,SYSTEM,HIDDEN,READONLY flag db ' ' ; set '+' (plus) or unset '-' (minus) options db DEFAULT file_with_path dw FILENAME filespec: db '*.*',0 .len=$-filespec filespec_data rb 128-filespec.len attrib rb 1 dta rb 43 ; EOF
Last edited by rugxulo on 28 Aug 2007, 23:21; edited 9 times in total |
|||||||||||
28 Jun 2007, 07:42 |
|
vid 28 Jun 2007, 13:44
Their version has error handling. For realworld use it is more important than saving kilobyte.
Anyway, it's nice as a demo |
|||
28 Jun 2007, 13:44 |
|
rugxulo 30 Jun 2007, 03:42
Well, both MS-DOS and DR-DOS have a bloatier ATTRIB than FreeDOS. Plus, the one in DR-DOS doesn't like changing dir attributes (for some odd reason, bug??). Granted, the whole idea of attributes in DOS is inconsistently handled at best.
Seriously though, floppies can fill up quite fast, so having a small and simple ATTRIB clone can indeed be useful (even if only a subset of functionality is supported so far). Maybe one day someone (Dex? me? you?) will port it to MiniDOS. |
|||
30 Jun 2007, 03:42 |
|
Japheth 30 Jun 2007, 09:04
Wildcards aren't handled in the filename argument. That's a too severe restriction IMO. Much space for improvement!
|
|||
30 Jun 2007, 09:04 |
|
Picnic 30 Jun 2007, 09:21
Added to my fasm scripts collection rugxulo.
|
|||
30 Jun 2007, 09:21 |
|
DOS386 02 Jul 2007, 23:11
rugxulo wrote:
Quote: FreeDOS' attrib.com is only 5,044 bytes UPX'd NO http://board.flatassembler.net/topic.php?t=7278 It's APACK'ed and the correct size (uncompressed) is 7306 bytes ... Last edited by DOS386 on 03 Jul 2007, 22:45; edited 1 time in total |
|||
02 Jul 2007, 23:11 |
|
prino 03 Jul 2007, 18:43
Charles Petzold's ATTR.COM was 626 bytes way back in 1986, with support for wildcards and elementaty help. Despite PC Magazines no-dist policy it's still around, with source.
|
|||
03 Jul 2007, 18:43 |
|
rugxulo 12 Jul 2007, 19:13
prino wrote: Charles Petzold's ATTR.COM was 626 bytes way back in 1986, with support for wildcards and elementaty help. Despite PC Magazines no-dist policy it's still around, with source. Yeah, uh, with a license like that, er, I don't think that would be quite as useful. |
|||
12 Jul 2007, 19:13 |
|
rugxulo 14 Jul 2007, 23:36
Okay, I finished the new version (see updated first post). No LFN support (yet). But at least it's "free" and small (WinXP, MS-DOS, and DR-DOS all have 11k or 12k attribs). Enjoy! (heh, yeah right)
Last edited by rugxulo on 20 Jul 2007, 18:49; edited 1 time in total |
|||
14 Jul 2007, 23:36 |
|
rugxulo 18 Jul 2007, 23:01
(post removed because AVG still complains, doh!)
Last edited by rugxulo on 20 Jul 2007, 18:53; edited 1 time in total |
|||
18 Jul 2007, 23:01 |
|
Rahsennor 19 Jul 2007, 10:33
Nice work.
What about other DOS commands, like COPY? |
|||
19 Jul 2007, 10:33 |
|
vador 19 Jul 2007, 11:12
yeah, nice piece of code
|
|||
19 Jul 2007, 11:12 |
|
Dex4u 19 Jul 2007, 14:22
Nice work rugxulo, if i get time i will port it to MiniDos, i will also port it to DexOS.
|
|||
19 Jul 2007, 14:22 |
|
rugxulo 20 Jul 2007, 01:01
SLIGHTLY IMPROVED!
AVG Free Resident Shield (with heuristics enabled) still whines, so if you download the .ZIP, the .COM is (still) 907 bytes because it's "packed" by 624 so that AVG won't notice it. (Sheesh, annoying, hope they fix that.) Anyways, now I made it 895 so you'd know I updated it. It's faster if files don't need changing (but not with "attr /d -r", doh, needs fixing). Fixed the "attr ..\*.*" bug (FYI, if anyone followed this thread, the bug was actually due to my use of anonymous labels, heh). P.S. Since 0.2 had an accidental long 386+ jump in there, I've now started using ONLY8086.INC (but you don't need it to reassemble, you could even just make a blank .INC file or put "TINYHELP=1" or whatever in there.) EDIT: Bah, I really kludged it up in some ways, so there are more bugs ("attr \*.*" on XP stops after only 4 files for me b/c "Access denied" error #5 on HIBERFIL.SYS). Sorry, peeps, I'll have to fix it eventually (so don't port it yet, heh). Last edited by rugxulo on 02 Aug 2007, 23:09; edited 2 times in total |
|||
20 Jul 2007, 01:01 |
|
DOS386 22 Jul 2007, 22:37
Quote: Even my dumb, wimpy (buggy?) DOS ATTR.COM is (still) detected as "suspicious unknown EXE / COM virus" by AVG Free. (And it doesn't even open / read / create / modify / write / close / delete any files or stay resident!!) 4 : Don't use AVG "Free" - it IIRC doesn't work on FreeDOS anyway It's NOT your bug Quote: are more bugs ("attr \*.*" on XP stops after only 4 files for me b/c "Access denied" error #5 on HIBERFIL.SYS) I don't get this "bug" on DOS - maybe not a bug at all Is much better now. Remaining issues: - Display attr before and after change (as APACK'ed bloat does) - ATTRIB /*.* +s is buggy - should accept /*.* +s as well as +s /*.* _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
22 Jul 2007, 22:37 |
|
rugxulo 25 Jul 2007, 02:33
NTOSKRNL_VXE wrote:
Well, if neither XP's nor FreeDOS' attrib does it, mine must be broken. (It should just ignore what can't change and keep going instead of stopping cold. On my XP HD, stopping at file #4 skips files #5-13, so that's not optimal, IMO.) NTOSKRNL_VXE wrote:
Yes, that first suggestion is already considered (as well as a few other things) though I may put it off until a later version (once I get rid of the obvious bugs). As far as "attrib *.* +s" is concerned, I never use that syntax, so I don't support it. It wouldn't be impossible to implement, obviously, but it would require a rewritten cmdline parser (and would bloat up a bit more). I've already (barely) considered it, but I hope you don't need that too badly / soon. |
|||
25 Jul 2007, 02:33 |
|
rugxulo 02 Aug 2007, 23:12
Fixed remaining bugs (AFAIK). Now 939 bytes (but .ZIP includes 949-byte packed .COM because AVG Free still whines despite a clean slate from http://www.virustotal.com ).
P.S. I had totally forgotten about Charles Dye's DOS attrib clone (very very nice even if no LFN support). It's GPL, written in NASM, and is only 5k UPX'd (and adjustable for features, so you can get it to like 3.5k or whatever). Be sure to consider his if you don't like mine or FreeDOS'. |
|||
02 Aug 2007, 23:12 |
|
rugxulo 28 Aug 2007, 23:25
Reupdated (but only minor changes). Still, may as well get the latest!
|
|||
28 Aug 2007, 23:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.