; cshred.asm Not working correctly yet
; COMMAND LINE VERSION
; email:http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2c4c23c18218165825da5354af8828e8 (Remove LOG)
; Tasm code (c) Andrew Kennedy Jan 2004
;
; Overwrite a file with random bytes,
; truncates it to zero bytes,
;
; 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,
; 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 SHORT path if not in current directory!!',13,10
db 13,10,9,'Ex. C:\PROGRA~1\VERYLO~1.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, ; Move byte count to CL
xor ch,ch ; Zero CH
mov ,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
mov ,00h
inc bx
cmp bx,64000
jnz zero_out

change: ; remove all file attributes
;int 3
lea dx,file_name
mov ax,7143h
mov bl,01h
mov cx,0 ; remove any read-only attributes
;int 3
int 21h
;int 3
;INT 21 - Windows95 - LONG FILENAME - CREATE OR OPEN FILE
; AX = 716Ch
; BX = access mode and sharing flags (see #01782,also AX=6C00h);
; 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 ,ax ; Save file handle
int 3 ; GETTING AN ACCESS DENIED ERROR HERE
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, ; 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 ,ax ; Save low word of file size
mov word ptr ,dx ; Save high word

mov ax,4200h ; Move file pointer
mov bx, ; 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 ,cx ; Is there ? - subtract it
sbb word ptr ,0 ; from saved file size

jae wipe ; There were 64,000 bytes or
; more left

mov cx,word ptr ; Get number of bytes left
add cx,64000 ; back CX (undo subtraction)

wipe:
mov ah,40h ; Write file
mov bx, ; 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

mov bx, ; close file
mov ah,3eh
int 21h
int 3
; Store the path

scan:
lea si,
xor cx,cx
mov di,si
mov cx,

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,
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
Posted on 2004-02-10 15:43:02 by skywalker
Hi.
A suggestion: if you use quotes at your command line parsing routine you can support long pathnames.
I'll try debugging it when I get back home, if I find out anything I'll post it :)
Posted on 2004-02-10 17:03:06 by QvasiModo

Hi.
A suggestion: if you use quotes at your command line parsing routine you can support long pathnames.
I'll try debugging it when I get back home, if I find out anything I'll post it :)


The code is working. Sometimes I'll make changes in one file and assemble another with the same name except for a 1 in the name.

A poster at Programmer' Heaven verified that the code works in a DOS window and uses short or long
filenames in Win XP. That was nice to know.

Thanks.
Posted on 2004-02-10 21:18:07 by skywalker
Yes, it worked on my computer too. Glad to know the problem's solved. :)

Since I didn't have TASM I had to adapt it for A86, I'm posting it in case you're interested.

BTW, I noticed that the code at the label "zero_out" never seems to get executed. And it would be safer to fill "random" with actual random data, rather than relying on the previous contents of the RAM. :)
Posted on 2004-02-11 11:19:03 by QvasiModo

Yes, it worked on my computer too. Glad to know the problem's solved. :)

Since I didn't have TASM I had to adapt it for A86, I'm posting it in case you're interested.

BTW, I noticed that the code at the label "zero_out" never seems to get executed. And it would be safer to fill "random" with actual random data, rather than relying on the previous contents of the RAM. :)


Thanks for writing it for A86. I'll post it on one of the assembly newsgroups.

I'll have to check out the zero_out. I know it works with my shred program that actually prompts for the file
name. I put on a single 1.68 MB file on a floopy that contained x's and used a disk editor to see that only
zeros were on the disk.

I also added a jmp $ + 2 after the file overwrite section because of what someone called Windows lazy-ness
in writing files. Sometimes the file would be overwritten correctly but the renamimg part would fail.

Thanks.
Posted on 2004-02-11 17:33:41 by skywalker