News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

File Shredder

Started by Bieb, January 19, 2005, 10:57:41 PM

Previous topic - Next topic

Ramon Sala

#15
Hi Bieb,

No, the Dec instruction only decrements a 32-bit value (register or variable). If you deal with a QWord value, decrement and check the low-order DWord. Each time its value is 0FFFFFFFFH, you have to decrement the high-order DWord and then repeat this operation until they both, high and low DWords are zero.

Ramon
Greetings from Catalonia

Relvinian

Bieb,

Attached is a very simple program to take a file and "munge" it.  You can use this code to your liking for your own purposes.  I have included a build.bat so you can test out my code. In the .const section, there is a default filename the exe looks for.

Hope this helps you with your efforts.

Relvinian


[attachment deleted by admin]

Bieb

Thanks for all the help.  The utility will be freeware, and I'll put y'alls names in the comments section of the EXE.

Bieb

Okay, I think I have a nearly complete version of the code.  But I'm getting three compile errors that don't seem to make any sense.  I put the errors in as comments on the lines that the errors were for.  If anyone can figure out the problem, it would be a great help.
This version is meant to go through thirty passes, rotating the garbage byte it uses right one bit each pass.


.Const

.Data?
FileBoxHandle HWND ?
hDWord DWord ?
lDWord DWord ?
ByteWrite DWord ?
.Data
FilePath Byte 257 Dup (0)
DataByte Byte 01010101B
mbText DB "The file has been shredded", 0
mbCaption DB "Done", 0
mbError DB "Error", 0
.Code

ShredFile Proto

Window1Procedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
.If uMsg == WM_CREATE
;Retrieve and store handle to the edit box
Invoke GetWindowItem, hWnd, IDC_WINDOW1_FILEBOX
Mov FileBoxHandle, Eax

.ElseIf uMsg == WM_COMMAND
Mov Eax, wParam
.If Ax == IDC_WINDOW1_SHREDBUTTON
Shr Eax, 16
.If Ax == BN_CLICKED
;Code to execute if the shred button has been clicked
Invoke GetWindowText, FileBoxHandle, Addr FilePath, 256
Invoke ShredFile
.EndIf
.EndIf

.ElseIf uMsg == WM_CLOSE
Invoke IsModal, hWnd
.If Eax
Invoke EndModal, hWnd, IDCANCEL
Return TRUE
.EndIf
.Endif
Return FALSE
Window1Procedure EndP

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ShredFile Proc Private
Local lDWORD:DWord
Local hDWORD:DWord
Local hFile:DWord
Local Pass:Byte
Local BytesLeft:Byte
Invoke CreateFile, Addr FilePath, GENERIC_READ Or GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
Cmp Eax, INVALID_HANDLE_VALUE
Je ExitProcError
Mov hFile, Eax
Invoke GetFileSize, hFile, Addr hDWORD
Cmp Eax, INVALID_HANDLE_VALUE
Je ExitProcError
Cmp Eax, 0
Je ExitProcError
Mov lDWORD, Eax
Mov Pass, 31
Mov Ecx, lDWORD
Mov BytesLeft, Ecx ;Window1.asm(78) : error A2070: invalid instruction operands?
PassLabel:
Dec Pass
ByteLabel:
Invoke WriteFile, hFile, Addr DataByte, 1, Addr ByteWrite, NULL
Dec BytesLeft
Ror DataByte ;Window1.asm(71) : error A2008: syntax error : in instruction?
Cmp BytesLeft, 0
Jne ByteLabel
Cmp Pass, 0
Je ExitProc
Invoke SetFilePointer, hFile, 0, NULL, FILE_BEGIN
Mov Ecx, lDWORD
Mov BytesLeft, Ecx ;Window1.asm(78) : error A2070: invalid instruction operands?
Jmp PassLabel
Invoke CloseHandle, hFile
Invoke MessageBox, NULL, Addr mbText, Addr mbCaption, MB_OK
Jmp ExitProc
ExitProcError:
Invoke MessageBox, NULL, Addr mbError, NULL, MB_OK
ExitProc:
Ret
ShredFile EndP

Relvinian

Bieb,

The compiling errors you are receiving are because you are trying to move a DWORD into a BYTE location.

mov BytesLeft, ecx


BytesLeft is defined as a BYTE.  Change this define to a DWORD or move CL instead of ECX.

The ROR instruction needs a extra param to tell how many bits to rotate to the right.

Relvinian

Bieb


Bieb

Yay!  It's working now.  Just a few UI tweaks, support for bigger files, and an implementation of the Gutmann Algorithm, and I'll have finished my first complete project in Win32 ASM!   :bg

pbrennick

Bieb,
Congratulations!  It is a good feeling when you stick to it through to the end, is it not?  BTW:  Thank you for your support of Easy Code.  Since it is freeware and it is such a useful project, why don't you consider adding it to the Easy Code project.

Paul

pbrennick

Bieb,
Don't forget to change CREATE_ALWAYS to OPEN_EXISTING in the CreateFile line.  That was something that Ramon had done for testing purposes and when you think about it, no sense creating a file just to delete it.  He had told you this but with everything going on you might have missed it.  He already included the trap code to exit the procedure if the file doesn't exist.  It just keeps the housekeeping up to date.

Paul

Ramon Sala

#24
Hi Bieb,

Congratulations! Thanks for using Easy Code and all your support of the project. As Paul suggested, why don't you consider to add it to the Easy Code project? It would be included as an example project.

Regards,

Ramon


BTW: When testing your program, I changed OPEN_EXISTING to CREATE_ALWAYS in order to avoid deleting any file, but as Paul said you should change it to OPEN_EXISTING again.
Greetings from Catalonia

Bieb

I'd be glad to let y'all use it as an example.  I should have the time to finish it all up in a few days. 

Bieb

#26
Okay, it's complete now.  I've added progress bars and a slider bar to control the number of passes it goes through.  You can do whatever you want with the code now.  If you're using it as example code, you might want to replace some of my cmp/conditional jump sequences with .if's.

Edit - Someone showed me a bug in the error handling I hadn't noticed before.  I've updated the attachment with the bug fixed.

[attachment deleted by admin]

pbrennick

Bieb,
Very nicely done.  I am confused by the Passes thing, though.  I moved it halfway up and then shredded a file.  I got some activity in the Overall progressbar but it never emptied and the Pass progressbar repeated a little more than three times.  Is this expected behavior?

It does do the job, though.
Paul

Ramon Sala

#28
Hi Bieb,

I've been testing your File Shredder program and it really works! Congratulations! Anyway, I made some little changes in order the progress bar to work properly. You must take into account that the MinValue and MaxValue properties for a progress bar are two-byte values, that is, from 0 to 65535. As files are usually larger than 65535, the best you can do is working with the percentage done.

Also, if you specified a file name that didn't exist, and after the error message box appeared, the shredder button remained disabled. I fixed that in the ExitProcError label, by enabling the button again.

Finally, I added a call to DoEvents method inside the loop writing the file. This Easy Code method makes the message queue to be checked and allows the application to be repainted when it becomes active (if you switch to other tasks and come back to file shredder). In fact, it only would be necessary, for example, if you added a cancel button allowing the user to interrupt the deleting process. If not, you can remove it.

I attached the modified project. Thanks for using Easy Code.

Good work!

Ramon


[attachment deleted by admin]
Greetings from Catalonia

pbrennick

Ramon,
That definitely clears up the 'Passes' problem.  I really like this app, it can be an excellent addition to anyone's toolbox and is already in mine.  Thanks Bieb!
Paul