home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / NO.ASM < prev    next >
Assembly Source File  |  1986-02-14  |  11KB  |  312 lines

  1. ;    NO.ASM -- Hides specified files from command that follows
  2. ;    ======
  3.  
  4. CSEG        Segment
  5.         Assume    CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
  6.         Org    002Ch
  7. Environment    Label    Word        ; Segment of Environment is here
  8.         Org    0080h
  9. Parameter    Label    Byte        ; Parameter is here
  10.         Org    0100h
  11. Entry:        Jmp    Begin        ; Entry Point
  12.  
  13. ;    Most Data (some more at end of program)
  14. ;    ---------------------------------------
  15.  
  16.         db    "Copyright 1986 Ziff-Davis Publishing Co.",1Ah
  17.         db    " Programmed by Charles Petzold ",1Ah
  18. SyntaxMsg    db    "Syntax: NO filespec command [parameters]$"
  19. DosVersMsg    db    "NO: Needs DOS 2.0 +$"
  20. FileSpecMsg    db    "NO: Incorrect File Spec$"
  21. TooManyMsg    db    "NO: Too many files to hide$"
  22. MemAllocMsg    db    "NO: Allocation Problem$"
  23. CommandMsg    db    "NO: COMMAND Problem$"
  24. Delimiters    db    9,' ,;='
  25. FileList    dw    ?        ; Storage of found files
  26. FileCount    dw    0        ; Count of found files
  27. FileListEnd    dw    ?        ; End of storage of found files
  28. BreakState    db    ?        ; Store original break state here
  29. Comspec        db    'COMSPEC='    ; String for Environment search
  30. ParamBlock    dw    ?        ; Parameter block for EXEC call
  31.         dw    ?, ?
  32.         dw    5Ch, ?
  33.         dw    6Ch, ?
  34. StackPointer    dw    ?        ; Save SP during EXEC call
  35.  
  36. ;    Check DOS Version
  37. ;    -----------------
  38.  
  39. Begin:        Mov    AH, 30h            ; Check for DOS Version
  40.         Int    21h            ;   through DOS call
  41.         Cmp    AL, 2            ; See if it's 2.0 or above
  42.         Jae    DosVersOK        ; If so, continue
  43.  
  44.         Mov    DX, Offset DosVersMsg    ; Error message
  45. ErrorExit:    Mov    AH, 9            ; Print String function call
  46.         Int    21h            ; Do it
  47.         Int    20h            ; And exit prematurely
  48.  
  49. ;    Parse Command Line to get NO File specification
  50. ;    -----------------------------------------------
  51.  
  52. ScanParam:    Lodsb                ; SUBROUTINE: Get byte
  53.         Cmp    AL, 13            ; See if end of parameter
  54.         Je    ErrorExit        ; If so, exit
  55.         Mov    DI, Offset Delimiters    ; Check if delimiter
  56.         Mov    CX, 5            ; There are 5 of them
  57.         Repne    Scasb            ; Scan the string
  58.         Ret                ; And return
  59.  
  60. DosVersOK:    Mov    DX, Offset SyntaxMsg    ; Possible error msg 
  61.         Mov    SI, 1+Offset Parameter    ; NO Parameter string
  62.         Cld                ; Directions forward
  63.  
  64. BegSearch:    Call    ScanParam        ; Check byte in subroutine
  65.         Je    BegSearch        ; If delimiter, keep searching
  66.         Mov    BX, SI            ; Save pointer in BX
  67.         Dec    BX            ; BX points to NO file spec
  68.  
  69. EndSearch:    Call    ScanParam        ; Check byte in subroutine
  70.         Jne    EndSearch        ; If not delimiter, keep going
  71.  
  72. ;    Construct full FilePath and save down at end of program
  73. ;    -------------------------------------------------------
  74.  
  75.         Dec    SI            ; Points after NO file spec
  76.         Xchg    SI, BX            ; SI points to beg, BX to end
  77.         Mov    DI, Offset FullPath    ; Points to destination
  78.         Cmp    Byte Ptr [SI + 1], ':'    ; See if drive spec included
  79.         Jnz    GetDrive        ; If not, must get the drive
  80.         Lodsw                ; Otherwise, grab drive spec
  81.         And    AL, 0DFh        ; Capitalize drive letter
  82.         Jmp    Short SaveDrive        ; And skip next section
  83.  
  84. GetDrive:    Mov    AH, 19h            ; Get current drive
  85.         Int    21h            ;   through DOS
  86.         Add    AL, 'A'            ; Convert to letter
  87.         Mov    AH, ':'            ; Colon after drive letter
  88.  
  89. SaveDrive:    Stosw                ; Save drive spec and colon
  90.         Mov    AL, '\'            ; Directory divider byte
  91.         Cmp    [SI], AL        ; See if spec starts at root
  92.         Jz    HaveFullPath        ; If so, no need to get path
  93.         Stosb                ; Store that character
  94.         Push    SI            ; Save pointer to parameter
  95.         Mov    SI, DI            ; Destination of current path
  96.         Mov    DL, [SI - 3]        ; Drive letter specification
  97.         Sub    DL, '@'            ; Convert to number
  98.         Mov    AH, 47h            ; Get current directory
  99.         Int    21h            ;   through DOS
  100.         Mov    DX, Offset FileSpecMsg    ; Possible error message
  101.         Jc    ErrorExit        ; Exit if error
  102.         Sub    AL, AL            ; Search for terminating zero
  103.         Cmp    [SI], AL        ; Check if Root Directory
  104.         Jz    RootDir            ; If so, don't use it
  105.         Mov    CX, 64            ; Number of bytes to search
  106.         Repnz    Scasb            ; Do the search
  107.         Dec    DI            ; DI points to last zero
  108.         Mov    AL, '\'            ; Put a backslash in there
  109.         Stosb                ; So filespec can follow
  110. RootDir:    Pop    SI            ; Get back SI
  111.  
  112. HaveFullPath:    Mov    CX, BX            ; End of NO file spec
  113.         Sub    CX, SI            ; Number of bytes to transfer
  114.         Rep    Movsb            ; Transfer them
  115.         Sub    AL, AL            ; Terminating zero
  116.         Stosb                ; Save it
  117.         Mov    [FileList], DI        ; Repository for found files
  118.  
  119. ;    Fix up parameter and ParamBlock for eventual COMMAND load
  120. ;    ---------------------------------------------------------
  121.  
  122.         Sub    BX, 4            ; Points to new param begin
  123.         Mov    AL, [Parameter]        ; Old byte count of parameter
  124.         Add    AL, 80h            ; Add beginning of old param
  125.         Sub    AL, BL            ; Subtract beginning of new
  126.         Mov    AH, ' '            ; Space separator
  127.         Mov    Word Ptr [BX], AX    ; Store it
  128.         Mov    Word Ptr [BX + 2], 'C/'    ; Add /C to beginning of rest
  129.         Mov    AX, [Environment]    ; Get environment segment
  130.         Mov    [ParamBlock], AX    ; Save it    
  131.         Mov    [ParamBlock + 2], BX    ; Save parameter pointer
  132.         Mov    [ParamBlock + 4], CS    ; Save segment of ParamBlock
  133.         Mov    [ParamBlock + 8], CS
  134.         Mov    [ParamBlock + 10], CS
  135.  
  136. ;    Find Files from NO File Specification
  137. ;    -------------------------------------
  138.  
  139.         Mov    DX, Offset DTABuffer    ; Set File Find buffer
  140.         Mov    AH, 1Ah            ;   by calling DOS
  141.         Int    21h
  142.  
  143.         Mov    DI, [FileList]        ; Address of destination
  144.         Mov    DX, Offset FullPath    ; Search string
  145.         Sub    CX, CX            ; Search Normal files only
  146.         Mov    AH, 4Eh            ; Find first file 
  147.  
  148. FindFile:    Int    21h            ; Call DOS to find file
  149.         Jnc    Continue        ; If no error continue
  150.         Cmp    AX, 18            ; If no more files
  151.         Jz    NoMoreFiles        ;   get out of the loop
  152.         Mov    DX, Offset FileSpecMsg    ; Error message otherwise
  153.         Jmp    ErrorExit        ; Exit and print message
  154.  
  155. Continue:    Mov    AX, DI            ; Address of destination
  156.         Add    AX, 512            ; See if near top of segment
  157.         Jc    TooManyFiles         ; If so, too many files
  158.         Cmp    AX, SP            ; See if getting too many 
  159.         Jb    StillOK            ; If not, continue
  160.  
  161. TooManyFiles:    Mov    DX, Offset TooManyMsg    ; Otherwise error message
  162.         Jmp    ErrorExit        ; And terminate
  163.  
  164. StillOK:    Mov    SI, 30+Offset DTABuffer    ; Points to filename
  165.         Call    AsciizTransfer        ; Transfer it to list
  166.         Inc    [FileCount]        ; Kick up counter 
  167.         Mov    AH, 4Fh            ; Find next file
  168.         Jmp    FindFile        ; By looping around
  169.  
  170. NoMoreFiles:    Mov    [FileListEnd], DI    ; Points after last file
  171.         Mov    DI, [FileList]        ; Points to end of find string
  172.         Mov    CX, 64            ; Search up to 64 bytes
  173.         Mov    AL, '\'            ; For the backslash
  174.         Std                ; Search backwards
  175.         Repnz    Scasb            ; Do the search
  176.         Mov    Byte Ptr [DI + 2], 0    ; Stick zero in there
  177.         Cld                ; Fix up direction flag
  178.  
  179. ;    Stop Ctrl-Break Exits and Hide the files
  180. ;    ----------------------------------------
  181.  
  182.         Mov    AX,3300h        ; Get Break State
  183.         Int    21h            ; By calling DOS
  184.         Mov    [BreakState],DL        ; Save it
  185.         Sub    DL,DL            ; Set it to OFF
  186.         Mov    AX,3301h        ; Set Break State
  187.         Int    21h            ; By calling DOS
  188.         Mov    BL, 0FFh        ; Value to AND attribute
  189.         Mov    BH, 02h            ; Value to OR attribute
  190.         Call    ChangeFileMode        ; Hide all the files
  191.  
  192. ;    Un-allocate rest of memory 
  193. ;    --------------------------
  194.  
  195.         Mov    BX, [FileListEnd]    ; Beyond this we don't need
  196.         Add    BX, 512            ; Allow 512 bytes for stack
  197.         Mov    SP, BX            ; Set new stack pointer
  198.         Add    BX, 15            ; Prepare for truncation
  199.         Mov    CL,4            ; Prepare for shift
  200.         Shr    BX,CL            ; Convert to segment form
  201.         Mov    AH,4Ah            ; Shrink allocated memory
  202.         Int    21h            ; By calling DOS
  203.         Mov    DX,Offset MemAllocMsg    ; Possible Error Message
  204.         Jc    ErrorExit2        ; Print it and terminate
  205.  
  206. ;    Search for Comspec in Environment
  207. ;    ---------------------------------
  208.  
  209.         Push    ES            ; We'll be changing this
  210.         Mov    ES, [Environment]    ; Set ES to Environment
  211.         Sub    DI, DI            ; Start at the beginning
  212.         Mov    SI, Offset ComSpec    ; String to search for
  213.         Mov    DX, Offset CommandMsg    ; Possible error message
  214.  
  215. TryThis:    Cmp    Byte Ptr ES:[DI], 0    ; See if points to zero
  216.         Jz    ErrorExit2        ; If so, we can't go on
  217.         Push    SI            ; Temporarily save these
  218.         Push    DI
  219.         Mov    CX, 8            ; Search string has 8 chars
  220.         Repz    Cmpsb            ; Do the string compare
  221.         Pop    DI            ; Get back the registers
  222.         Pop    SI
  223.         Jz    LoadCommand        ; If equals, we've found it
  224.         Sub    AL, AL            ; Otherwise search for zero
  225.         Mov    CX, -1            ; For 'infinite' bytes 
  226.         Repnz    Scasb            ; Do the search
  227.         Jmp    TryThis            ; And try the next string
  228.  
  229. ;     Load COMMAND.COM
  230. ;     -----------------
  231.         
  232. LoadCommand:    Add    DI, 8            ; so points after 'COMSPEC='
  233.         Push    DS            ; Switch DS and ES registers
  234.         Push    ES
  235.         Pop    DS
  236.         Pop    ES
  237.         Mov    [StackPointer],SP    ; Save Stack Pointer
  238.         Mov    DX, DI            ; DS:DX = Asciiz of COMMAND
  239.         Mov    BX, Offset ParamBlock    ; ES:BX = parameter block
  240.         Mov    AX, 4B00h        ; EXEC function call
  241.         Int    21h            ; Load command processor
  242.  
  243. ;     Return from COMMAND.COM
  244. ;    -----------------------
  245.  
  246.         Mov    AX, CS            ; Current code segment
  247.         Mov    DS, AX            ; Reset DS to this segment
  248.         Mov    ES, AX            ; Reset ES to this segment
  249.         Mov    SS, AX            ; Reset stack segment to it
  250.         Mov    SP, [StackPointer]    ; Reset SP
  251.         Pushf                ; Save error flag
  252.         Sub    DL,DL            ; Set Ctrl Break to OFF
  253.         Mov    AX,3301h
  254.         Int    21h            ; By calling DOS
  255.         Popf                ; Get back error flag    
  256.         Mov    DX,Offset CommandMsg    ; Set up possible error msg
  257.         Jnc    Terminate        ; And print if EXEC error
  258.  
  259. ;    Unhide the Files, restore Ctrl-Break state, and exit
  260. ;    ----------------------------------------------------
  261.  
  262. ErrorExit2:    Mov    AH,9            ; Will print the string
  263.         Int    21h            ; Print it
  264. Terminate:    Mov    BL, 0FDh        ; AND value for change
  265.         Mov    BH, 00h            ; OR value for change
  266.         Call    ChangeFileMode        ; Change file attributes
  267.         Mov    DL,[BreakState]        ; Original break-state
  268.         Mov    AX,3301h        ; Change the break-state
  269.         Int    21h            ;   by calling DOS
  270.         Int    20h            ; Terminate
  271.  
  272. ;    SUBROUTINE: Change File Mode (All files, BL = AND, BH = OR)
  273. ;    -----------------------------------------------------------
  274.  
  275. ChangeFileMode:    Mov    CX, [FileCount]        ; Number of files
  276.         Jcxz    EndOfChange        ; If no files, do nothing
  277.         Mov    SI, [FileList]        ; Beginning of list
  278.         Mov    DX, [FileListEnd]    ; End of List
  279. ChangeLoop:    Push    SI            ; Save pointer
  280.         Mov    SI, Offset FullPath    ; Preceeding path string
  281.         Mov    DI, DX            ; Destination of full name
  282.         Call    AsciizTransfer        ; Transfer it
  283.         Dec    DI            ; Back up to end zero
  284.         Pop    SI            ; Get back pointer to filename
  285.         Call    AsciizTransfer        ; Transfer it
  286.         Push    CX            ; Save the counter
  287.         Mov    AX, 4300h        ; Get attribute
  288.         Int    21h            ;   by calling DOS
  289.         And    CL, BL            ; AND with BL
  290.         Or    CL, BH            ; OR with BH
  291.         Mov    AX, 4301h        ; Now set attribute    
  292.         Int    21h            ;   by calling DOS
  293.         Pop    CX            ; Get back counter
  294.         Loop    ChangeLoop        ; And do it again if necessary
  295. EndOfChange:    Ret                ; End of subroutine
  296.  
  297. ;    SUBROUTINE: Asciiz String Transfer (SI, DI in, returned incremented)
  298. ;    --------------------------------------------------------------------
  299.  
  300. AsciizTransfer:    Movsb                ; Transfer Byte
  301.         Cmp    Byte Ptr [DI - 1], 0    ; See if it was end
  302.         Jnz    AsciizTransfer        ; If not, loop
  303.         Ret                ; Or leave subroutine
  304.  
  305. ;    Variable length data stored at end
  306. ;    ----------------------------------
  307.  
  308. DTABuffer    Label    Byte            ; For file find calls
  309. FullPath    equ    DTABuffer + 43        ; For file path and names 
  310. CSEG        EndS                ; End of the segment
  311.         End    Entry            ; Denotes entry point
  312.