0

I have been only programming in assembly for 2 weeks now so I am kind of new to assembly and I need some help.

I need to watch a directory and all sub directories for changes. The only changes I need to be notified of are file creation and when a file is edited, but if you include others that is fine.

I need to be notified of the file who made the changes to a message box. I do not need to know what change the file made, I just need the file path to a message box. I tried to search the web but cant find anything for how to do this in assembly particular masm.
The only stuff I could find was this code that I think was written for masm and I tried it but it message boxes A or other letters and that is it and it blocks me from changing the name of any file in that directory, and i do not want it to do that.

.data
FolderPath3 db "C:\users",0
.data ?
hFile dd ?
FileBuffer        DB 200 DUP(?)

ThreadProc PROC uses edi esi Param:DWORD
    LOCAL lpBytesReturned:dword

    invoke CreateFile,addr FolderPath3,GENERIC_READ,FILE_SHARE_DELETE or FILE_SHARE_READ,0,\
                OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,0
    mov hFile,eax
    invoke ReadDirectoryChangesW,hFile,addr FileBuffer,sizeof FileBuffer,TRUE,FILE_NOTIFY_CHANGE_LAST_ACCESS,\
                addr lpBytesReturned,0,0
    .if eax==0
        invoke MessageBoxA,0,0,0,MB_OK
    .else
        xor ecx,ecx
@@:
        add edi,ecx
        lea edi,FileBuffer
        mov esi,[edi].FILE_NOTIFY_INFORMATION.Action
        .if esi==FILE_ACTION_MODIFIED
                    invoke MessageBoxA, NULL, addr [edi].FILE_NOTIFY_INFORMATION.FileName, offset BoxCaption, NULL 

                    .elseif esi==0
            invoke CloseHandle,hDir
            ret
        .endif
        mov ecx,[edi].FILE_NOTIFY_INFORMATION.NextEntryOffset
        .if ecx==0
            invoke RtlZeroMemory,addr FileBuffer,sizeof FileBuffer
            jmp ThreadProc
        .endif
        jmp @B
    .endif

    ret
ThreadProc ENDP

if anyone can fix the above code or show me different code that works it would be great, thank you

4

1 回答 1

1

The essence of the task is the operating system specific services and handling the notifications.

If you are lost doing this in assembly, code it in a high level language (C, C++, Perl, etc.) and get that working. It should not be hard to find examples of doing just this from MSDN. Once you have learned how to do that, it will then be pretty clear what the assembly language has to do.

于 2013-04-01T21:22:04.097 回答