A 86 version, Zero out not working for cshred.asm
From: Andrew Kennedy (andrewkennedy2_at_LOGev1.net)
Date: 02/12/04
- Previous message: Robert Wessel: "Re: Divide by constant"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 11 Feb 2004 23:55:53 +0000 (UTC)
; cshred.asm This version written to assemble with A86 by QvasiMode
; COMMAND LINE VERSION
; email: andrewkennedy2@LOGev1.net (Remove LOG)
; Tasm code (c) Andrew Kennedy Jan 2004 ->
;
; Works in Win XP in a DOS box, with short or long filenames
;
; Overwrite a file with zero bytes, Zero_out is currently NOT working
; truncates it to zero bytes and
;
; Set file time and date to 12:59:58 pm 1/1/80,
; renames it and then deletes it.
; Single files only. (For Safety)
; Long File Name support
;
; Use SHORT path when not in current directory Ex. C:\PROGRA~1\VERYLO~1.ASM
;
; Works across drives, handles periods in the path names
;
; Help from Stealth, Raymond, Bitrake, Rudy Weiser, Frank Kotler,
; Fauzan Mirza, Robert Redelmeier, QvasiModo
; Win 98 + Long File Name support
; |------------------------------------------|
; | Feel free to use sections of the code |
; | but please credit me somewhere. |
; |------------------------------------------|
;
; Works across drives, handles periods in the path names
;
; USE SHORT NAME path if not in current directory
;
MODEL TINY
.386
DATASEG
NO_PARMS db 13,10,9,'No File Specified.',13,10
db 13,10,9,'Usage: CSHRED <filename> (c) Andrew
Kennedy',13,10
db 13,10,9,'Use Quotes around path if not in current directory
!!',13,10
db 13,10,9,'Ex. "C:\PROGRAMFILES\VERYLONGFILENAME.ASM"',13,10
db 13,10,9,'This file will be UNRECOVERABLY erased !!',13,10,'$'
file_name db 129 dup(0)
storage db 150 dup(0)
handle dw ?
file_size dd ?
name_size dw ?
not_there db 13,10,13,10,'File not present.',13,10,'$'
emsg2 db 13,10,13,10,'Error moving file pointer.',13,10,'$'
emsg3 db 13,10,13,10,'Error writing to file.',13,10,'$'
done_msg db 13,10,13,10,'File has been shredded.',13,10,'$'
eraser_name db '_.',0
e_name_length equ $ - eraser_name
UDATASEG ;<<Any uninitialized data is defined here>>
random db 64000 dup(?) ; whatever is in memory at the time
CODESEG
STARTUPCODE
mov ah,15 ; clear the screen
int 10h
mov ah,0
int 10h
mov si,80h
mov cl,[si] ; Move byte count to CL
xor ch,ch ; Zero CH
mov [name_size],cx ; store command line length, this
; includes the 0dh
lea di,file_name
cld
lodsb ; any command line present?
or al,al ; return error status if not.
jz noparms
infile1: ; scan over leading blanks
lodsb ; to file name
cmp al,0dh ; if we hit carriage return
jz noparms ; filename is missing.
cmp al,20h ; is this a blank?
jz infile1 ; if so keep scanning.
infile24:
stosb ; move last char. to output
; file name buffer.
lodsb ; check next character, found
cmp al,0dh ; carriage return yet?
je short change ; yes,exit with success code
infile26:
cmp al,20h ; is this a blank?
jne infile24 ; if not keep moving chars.
jmp short change
noparms:
lea dx, NO_PARMS
mov ah,9
int 21h
mov ax,4c01h
int 21h
zero_out: ; Set memory to zero ( NOT Working )
mov [random + bx],00h
inc bx
cmp bx,64000
jnz zero_out
change: ; remove all file attributes
lea dx,file_name
mov ax,7143h
mov bl,01h
mov cx,0 ; remove any read-only attributes
int 21h
;INT 21 - Windows95 - LONG FILENAME - CREATE OR OPEN FILE
; AX = 716Ch
; BX = access mode and sharing flags
; CX = attributes
; DX = action (see #01781)
; DS:SI -> ASCIZ filename
mov ax,716Ch ; create file
xor cx,cx ; file attributes
; file access modes (bits)
; 000 read-only
; 001 write-only
; 010 read-write
; 100 read-only, do not modify file's last-access time
mov bx,00000001b ; access mode
mov dx,00000001b ; open file
lea si,file_name ; sets the file name
int 21h
mov [handle],ax ; Save file handle
jnc short get_size ; No errors, go on
no_file:
lea dx,not_there ; Get error message
jmp error ; and go display/exit
get_size:
mov ax,4202h ; Set file pointer
mov bx,[handle] ; for this file
xor cx,cx ; relative to end of file
xor dx,dx ; offset 0 bytes
int 21h
jnc save_size
err2:
lea dx,emsg2 ; Get error message
jmp error ; and go display/exit
save_size:
mov word ptr [file_size],ax ; Save low word of file
size
mov word ptr [file_size + 2],dx ; Save high word
mov ax,4200h ; Move file pointer
mov bx,[handle] ; for this file
xor cx,cx ; relative to beginning of file
xor dx,dx ; offset 0 bytes
int 21h
jc err2 ; Errors: go handle
next_bunch:
mov cx,64000 ; Assume 64,000 bytes or more
; left to do
sub word ptr [file_size],cx ; Is there ? - subtract it
sbb word ptr [file_size + 2],0 ; from saved file size
jae wipe ; There were 64,000 bytes or
; more left
mov cx,word ptr [file_size] ; Get number of bytes left
add cx,64000 ; back CX (undo subtraction)
wipe:
mov ah,40h ; Write file
mov bx,[handle] ; Handle
lea dx, random ; Write the random bytes,
int 21h ; whatever was in memory
jnc check_size ; No errors, go on
err3:
lea dx,emsg3 ; Get appropriate error message
jmp error ; and go display/exit
check_size:
cmp ax,cx
jnz err3
cmp ax,64000 ; Full 64,000 bytes written,
je next_bunch ; yes, go check for more
jmp SHORT $+2 ; short delay cuz sometimes
; file isn't renamed
mov bx,[handle] ; close file
mov ah,3eh
int 21h
; Store the path
scan:
lea si,[file_name]
xor cx,cx
mov di,si
mov cx,[name_size]
mov al,'\' ;
add di,cx
std ; scan from right to left
dec di
repne scasb
jnz short no_path ; No slash is present
add cx,1 ;
no_path:
lea di,storage
cld ; change directions and scan
rep movsb ; from left to right
mov al,00
stosb ; make path ASCIZ
; Add on eraser_name to end of storage
add_eraser:
mov cx,[name_size]
mov si,cx
lea di,storage
mov al,00 ; stops at the byte after the "00"
repnz scasb
dec di ; backup one
xor cx,cx
lea si, eraser_name
mov cx,e_name_length ; # of characters in eraser name
rep movsb
; Rename and delete file (LFN)
rename:
lea dx,file_name ; old file name
lea di,storage ; new file name
mov ax,7156h ; LFN support
int 21h
; Change file date and time
mov ax,716Ch ; open file
xor cx,cx ; file attributes
mov bx,100000000000010b ; access mode (R/W) and commit
; file after every write
mov dx,1 ; open file
lea si,storage ; sets the file name
int 21h
mov bx,ax ; save file handle
push bx
mov ax,5701h ; change file date
; BITS 5-10 are minutes,
; 11-15 are hours, 0-4 seconds/2
mov cx,677dh ; 12:59:58 pm 110011101111101b
;
; BITS 0-4 are day, 5-8 are month,
; 9-15 (year - 1980)
mov dx,021h ; 1/1/80 0000000000100001b
int 21h
pop bx
mov ah,6ah ; DOS 4.0+ - COMMIT FILE
int 21h
mov ah,3eh ; close file
int 21h
; INT 21 - Windows95 - LONG FILENAME - DELETE FILE
; AX = 7141h
; DS:DX -> ASCIZ long name of file to delete
lea dx,storage ; delete file
mov ax,7141h
xor si,si
int 21h
finito:
mov ah,9
lea dx,done_msg
int 21h
mov ax,4c00h ; Set errorlevel to 0
int 21h
error:
mov ah,9
int 21h
mov ax,4c01h ; Set errorlevel to 1
int 21h
END
- Previous message: Robert Wessel: "Re: Divide by constant"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|