News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Error_Acess_Denied

Started by Magnum, December 05, 2014, 04:10:44 PM

Previous topic - Next topic

dedndave

well - ADDR works for either in an INVOKE argument
but,
    mov     eax,addr dwGlobal
may not work - i don't recall, because i don't use that form - lol

certainly,
    mov     eax,addr dwLocal
is bad form - it should be
    lea     eax,dwLocal

Magnum

It gives Error_Invalid_Parameter.

I can't tell which api is throwing that error.

.data

file          db  "test.txt",0

.data?

hFile      HANDLE ?
fCRTime    dd     ?   ; creation time
fACTime    dd     ?   ; access time
fWRTime    dd     ?   ; write time
systime     SYSTEMTIME <>

.code

; notice that SetFileTime wants 3 pointers to FILETIME structures
;
; i suggest:
; creation time: NULL - leave it as is
; access time: pointer to current FILETIME structure
; modify time: same pointer as access time


start:

invoke CreateFile, addr file, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL

.IF eax==INVALID_HANDLE_VALUE

invoke ExitProcess,0

.endif

mov     hFile,eax

invoke GetFileTime,hFile, addr fCRTime, addr fACTime, addr fWRTime

invoke GetSystemTimeAsFileTime,ADDR systime

invoke SetFileTime, hFile, addr fCRTime, offset fACTime, offset fWRTime

invoke CloseHandle, hFile ; Release handle fails if return value is 0

invoke ExitProcess,0

end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

fCRTime FILETIME <> ; creation time
fACTime FILETIME <> ; access time
fWRTime FILETIME <> ; write time


FILETIME structures are essentially QWORD's

dedndave

also...
GetSystemTimeAsFileTime wants a pointer to a FILETIME structure, not a SYSTEMTIME structure

dedndave

your .if/.endif structure is a little clumsy
.IF eax!=INVALID_HANDLE_VALUE

;do stuff

.endif

invoke ExitProcess,0

Tedd

The example I posted does work - I tested it, obviously.
If it does not work for you, the problem lies elsewhere and thus you should focus your efforts on finding why, not on reproducing the same code with minor variations as if that's going to magically make it work.
Potato2

dedndave

as a final thought....

you don't need to get the current file times

get the current time as FILETIME (use a single structure, ftime)
set the access and mod times using that single structure
invoke SetFileTime,hFile,NULL,offset ftime,offset ftime

Magnum

Quote from: Tedd on December 17, 2014, 07:23:25 AM
The example I posted does work - I tested it, obviously.
If it does not work for you, the problem lies elsewhere and thus you should focus your efforts on finding why, not on reproducing the same code with minor variations as if that's going to magically make it work.

Your code did NOT work on my system.

My posts are designed to find out what is wrong.

Maybe spend more time helping than criticizing ??



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

you may want to watch the file sharing flags, Andy
if some other process may be accessing the file, use the appropriate flag set in both programs

Tedd

Quote from: Magnum on December 17, 2014, 09:18:17 AM
Your code did NOT work on my system.

My posts are designed to find out what is wrong.

Maybe spend more time helping than criticizing ??
Let me just get this straight.
At 4:20pm, you copied and assembled the example code, created a file named "test.txt", and then ran the program. The modified time of the file is now 10:20am.
This is all just guessing, but I'm going to say that the file time has definitely changed.

Admittedly, the time is not the current time in your locale, but a difference of exactly 6 hours (your UTC offset) is a change nonetheless. That fault is mine -- I used GetLocalTime instead of GetSystemTime -- but other than that, the code clearly does change the modification time on your system.

So, go ahead and replace GetLocalTime with GetSystemTime, re-assemble, and re-test.

Maybe spend more time checking details than crying foul of supposed victimization.
Potato2

Magnum

There is no other program accessing the file.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

Thanks a lot Tedd.

That change got it to working. :-)

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org