News:

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

Need help to read documents in the right direction..

Started by travism, October 28, 2008, 11:39:32 PM

Previous topic - Next topic

travism

Im not really looking for a answer how to, I really want to learn how to write disk images to a floppy etc.. I want to write a program like rawwritewin but using assembler and ofcourse myself writing it, But im not sure if its as easy as opening a voume like \\.\C: and writing to it or sector copying or what... So basically what im asking is what docs and api's (if any) should I be studying. I hope you all dont think im stupid for asking this type of question. Thanks!  :bg

MichaelW

For a diskette I would just use the Interrupt 13h functions from a DOS app.
eschew obfuscation

travism

I was thinking more along the lines of win32 based app.

Tedd

Don't worry, it actually is as simple as opening "\\.\A:" and then writing the image.
If you want to do anything more complex, like writing to specific sectors, then you need to calculate the offset into the disk image then move the file-pointer and write from there - it's still straightforward though,
No snowflake in an avalanche feels responsible.

travism

Ive always hated writing files in any language Ive coded in heres my code snippet that isnt working, Im sure someone can spot whats wrong :P Don't make fun of it please :\
hVolume is the drive so its "\\.\A:" and strFile is the path the the image file.

invoke CreateFile,addr hVolume,GENERIC_WRITE,FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
              .IF eax!=INVALID_HANDLE_VALUE
                  mov hDevice,eax
                 
                  invoke CreateFile,addr strFile,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
                  .IF eax!=INVALID_HANDLE_VALUE
                      mov fHandle,eax
                      ; --------------------------------------------------------------
                      ; Write our image file to the floppy
                      invoke GetFileSize,fHandle,NULL
                      invoke ReadFile,fHandle,addr iBytes,eax,addr wBytes,0
                      .IF eax!=0
                          invoke WriteFile,hDevice,addr iBytes,eax,addr tBytes,0
                      .ENDIF
                      ; --------------------------------------------------------------
                      ; clean up everything
                      invoke CloseHandle,hDevice
                      invoke CloseHandle,fHandle
                      invoke SetDlgItemText,hWnd,IDC_STC8,addr strDone
                  .ENDIF
              .ELSE
                  ; --------------------------------------------------------------
                  ; Let them know we are finished
                  invoke SetDlgItemText,hWnd,IDC_STC8,addr strNoVolume
              .ENDIF
              .ELSE
                  invoke SetDlgItemText,hWnd,IDC_STC8,addr strError
              .ENDIF



travism

any input? still can't figure this out :\ i dont get errors opening anything so im guessing its the read/write file part.

sinsi

You need to save the return value of GetFileSize somewhere, since EAX gets trashed after using an API - even using ADDR with INVOKE will trash EAX if the variable is local.

                      ; Write our image file to the floppy
                      invoke GetFileSize,fHandle,NULL
                      mov esi,eax
                      invoke ReadFile,fHandle,addr iBytes,esi,addr wBytes,0
                      .IF eax!=0
                          invoke WriteFile,hDevice,addr iBytes,esi,addr tBytes,0
                      .ENDIF

Light travels faster than sound, that's why some people seem bright until you hear them.

travism

Ah, well changed that, It still doesn't write anything though :\

sinsi

So which call returns the error? Run it through a debugger.
Light travels faster than sound, that's why some people seem bright until you hear them.

travism

Im not receiving an error, it finishes like it should it just doesnt write the file to the floppy..

Tedd

The first thing I see is that you're opening the volume with only FILE_SHARE_WRITE, you do need FILE_SHARE_READ as well (even if you're only writing, or only reading).
Then also save the filesize if you intend to use it more than once - though you wouldn't really need to, since you're only writing the same number of bytes read (which will be stored in wBytes.) However, you're assuming that a single read and a single write will do it all in one go - it may not; loop over it until filesize number of bytes have been transferred.
Note: the return value from ReadFile is NOT the number of bytes read.
How big is iBytes?
No snowflake in an avalanche feels responsible.

travism

ah, ok I got the program working finally... I had to change iBytes :) so everything works great now thanks for all the help!