News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Determining if file exists

Started by Magnum, November 30, 2012, 12:30:59 PM

Previous topic - Next topic

Magnum

I decided to check that my batch file exists.

GetFileAttributes worked fine when run by itself in a simpler program.

I loaded the program below in Olly, ran it, and inserted a thumbdrive.

It said the file was not present when it was.

I could not see that anything changed in Olly.

Is there a certain way I have to load my program in it ?

Andy


main proc
LOCAL msg:MSG

   
    mov edi,rv(CreateWindowEx,0,"button",0,0,-100,-100,10,10,0,0,hInstance,0)
    mov pcbWndProc,rv(SetWindowLong,edi,GWL_WNDPROC,OFFSET WndProc)

    .while 1
        invoke GetMessage,ADDR msg,0,0,0
    .endw
   
    invoke ExitProcess,0
   
main endp

WndProc proc uses edi hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL sui:STARTUPINFO
LOCAL pi:PROCESS_INFORMATION

    .if uMsg == WM_DEVICECHANGE
        .if wParam == DBT_DEVICEARRIVAL
            mov edi,lParam
            .if [edi].DEV_BROADCAST_HDR.dbch_devicetype == DBT_DEVTYP_VOLUME
                .if ![edi].DEV_BROADCAST_VOLUME.dbcv_flags
                    mov eax,[edi].DEV_BROADCAST_VOLUME.dbcv_unitmask
                    bsf eax,eax
                    lea edx,[eax+'A']
                    .if edx == 'E' ; LINE 73 Drive letter of thumbdrive
                        invoke RtlZeroMemory,ADDR sui,sizeof sui
                        mov sui.cb,sizeof sui

                        invoke GetFileAttributes, addr FileName
                        .if eax==0FFFFFFFFh
                        jmp FileNotExist
                        .endif
                       
                        fn CreateProcess,0,OFFSET szCmd,0,0,0,CREATE_NEW_CONSOLE,0,0,ADDR sui,ADDR pi
                        .if EAX == 0
                        invoke  MessageBox, NULL, addr szError, addr szAppName,MB_OK

                        FileNotExist:
                        invoke  MessageBox, NULL, addr Error, addr szAppName,MB_OK

                        .endif
                    .endif
                .endif
            .endif
        .endif
    .else
        invoke CallWindowProc,pcbWndProc,hWnd,uMsg,wParam,lParam
        ret
    .endif

    xor eax,eax
    ret   
   
WndProc endp
end main
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

not sure you need the GetMessage loop thingy

anyways....
                        invoke GetFileAttributes, addr FileName
                        .if eax==0FFFFFFFFh
                        jmp FileNotExist
                        .endif
                       
                        fn CreateProcess,0,OFFSET szCmd,0,0,0,CREATE_NEW_CONSOLE,0,0,ADDR sui,ADDR pi
                        .if EAX == 0
                        invoke  MessageBox, NULL, addr szError, addr szAppName,MB_OK

                        FileNotExist:
                        invoke  MessageBox, NULL, addr Error, addr szAppName,MB_OK

                        .endif


you will get the "not exist" message box if the file does not exist
you will also get it if there is an error creating the process

why not...
                        invoke GetFileAttributes, addr FileName
                        .if eax==0FFFFFFFFh
                        invoke  MessageBox, NULL, addr Error, addr szAppName,MB_OK
                        .else
                            fn CreateProcess,0,OFFSET szCmd,0,0,0,CREATE_NEW_CONSOLE,0,0,ADDR sui,ADDR pi
                            .if EAX == 0
                            invoke  MessageBox, NULL, addr szError, addr szAppName,MB_OK
                            .endif
                        .endif

qWord

Quote from: Magnum on November 30, 2012, 12:30:59 PM    .while 1
        invoke GetMessage,ADDR msg,0,0,0 ; you get the message into MSG and then???
    .endw
    ; dead code ;-)
    invoke ExitProcess,0
 

Using Messages and Message Queues
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

i guess i see that now
that's a strange way to do things - lol
it may as well be
label0: jmp label0
just create a dialog box with a button in it   :biggrin:

Farabi

Did not MASM already have it? Are you going to make it your own?
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Magnum

qWord,

Thanks for pointing out that I had code not being used.

Farabi,

This is my bak.bat file.

:: Used by USB_Watcher.exe !!
::
color 1f
@echo off
cls
echo.
echo.
echo.
echo Backing up files to Thumbdrive
echo.
echo.
echo.
"C:\Program Files\7-Zip\"7z.exe u f:\z_keep\Wrd_Backup.zip *.doc *.rtf *.bat *.jpg *.reg *.txt
"C:\Program Files\7-Zip\"7z.exe u f:\z_keep\SS_Files.zip c:\z_keep\ScanImage*.jpg
"C:\Program Files\7-Zip\"7z.exe u f:\z_keep\16_Bit_Source.zip c:\tasm\*.*
cd\
cd c:\masm32\SOURCE
"C:\Program Files\7-Zip\"7z.exe u c:\masm32\SOURCE\source.zip *.asm *.rc *.ico *.inc

xcopy /y c:\masm32\SOURCE\source.zip f:\z_keep
F:
cd\
cd f:\z_keep
"C:\Program Files\7-Zip\"7z.exe u bookmarks.zip "C:\Documents and Settings\kennedyc.LP\Application Data\Mozilla\Firefox\Profiles\wdsfo6nc.FixIt\bookmarks.html
if exist C:\masm32\SOURCE\"*.udd *.obj del C:\masm32\SOURCE\"*.udd *.obj
if exist e:\backup\ xcopy /y f:\z_keep\*.zip /d e:\backup
if exist e:\backup\ xcopy /y source.zip /d e:\backup
if exist e:\backup\ xcopy /y f:\z_keep\SS_Files.zip /d e:\backup
if exist e:\backup dir e:\backup
PING localhost -n 4 > nul
dir f:\z_keep\source
exit

Dave,
               
                ;
                 ; Make sure batch file is there so files get copied to thumbdrive
                 ;
                 invoke GetFileAttributes, addr FileName ; Make sure batch file is there so files get copied to thumbdrive
                 .if eax==0FFFFFFFFh
                 invoke  MessageBox, NULL, addr NoFile, addr szAppName,MB_OK
                 .endif
                  fn CreateProcess,0,OFFSET szCmd,0,0,0,CREATE_NEW_CONSOLE,0,0,ADDR sui,ADDR pi
                  .if EAX == 0
                   invoke  MessageBox, NULL, addr szError, addr szAppName,MB_OK
                  .endif
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org