News:

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

Main Menu

Error_Acess_Denied

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

Previous topic - Next topic

Magnum

Eax shows zero as it would if no error had occured.

It apparently worked once today.

I ran the program at 6:34 and 6:35 and refreshed explorer.

As the pictures shows, the file date and time were not changed.

Guess it is one of those mysteries. :-)

Maybe I will see if CreateFileEx does the same thing.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Tedd

#16
There's no mystery.

This took all of 3 minutes to write.
.586
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib

.const
fname       db "test.txt",0

.data?
hFile       HANDLE ?
systime     SYSTEMTIME <>
ftime       FILETIME <>

.code
start:
    invoke CreateFile, ADDR fname,GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
    .IF (eax != INVALID_HANDLE_VALUE)
        mov hFile,eax

        ;;;invoke GetLocalTime, ADDR systime;;;
        invoke GetSystemTime, ADDR systime
        invoke SystemTimeToFileTime, ADDR systime,ADDR ftime
        invoke SetFileTime, hFile,NULL,NULL,ADDR ftime       ;update modified time to current time

        invoke CloseHandle, hFile
    .ENDIF
    invoke ExitProcess, NULL
end start



Edit: used GetSystemTime instead; silly mistake caused by rushing out code.
Potato2

adeyblue

Windows has 'touch' to update the timestamp built-in, though it's a bizarre incantation

jj2007

Quote from: adeyblue on December 16, 2014, 06:27:27 AM
Windows has 'touch' to update the timestamp built-in, though it's a bizarre incantation

Bizarre is an understatement:
QuoteThe following MS-DOS command updates the date and time stamps of a file named "EXAMPLE" without altering the contents of the file. This is similar to the TOUCH utility found in XENIX and in some third-party MS-DOS toolkits.

   COPY /B EXAMPLE +,,
Oh Redmond :redface:

There is a Touch command in MasmBasic, and it can take xmm0 as a second parameter to set an arbitrary FILETIME. Here is an exotic use for the instruction PAVGW - it sets the timestamp of Pic2.png to the average of Pic1 and Pic3:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Touch "Pic2.png"                  ; set to current date and time
  .if Exist("Pic2.png")
      MsgBox 0, Cat$("Pic2 was modified on "+GfDate$()+", "+GfTime$()+\
      CrLf$+"Verify the date now in Explorer"), "Touché:", MB_OK
      .if Exist("Pic1.png")
            sub esp, 4*16
            mov edi, esp
            lea esi, [esp+16]
            movups [edi+SYSTEMTIME], GfGetInfo(m)
            lea edx, [edi+SYSTEMTIME]
            invoke FileTimeToSystemTime, edx, edi
            .if Exist("Pic3.png")
                  movups [esi+SYSTEMTIME], GfGetInfo(m)
                  lea edx, [esi+SYSTEMTIME]
                  invoke FileTimeToSystemTime, edx, esi
                  movups xmm0, [edi]
                  movups xmm1, [esi]
                  pavgw xmm0, xmm1            ; Use AVERAGE to touch Pic2
                  lea edx, [edi+SYSTEMTIME]
                  movups [edx], xmm0
                  invoke SystemTimeToFileTime, edx, edi
                  movups xmm0, [edi]
                  Touch "Pic2.png", xmm0
                  void Exist("Pic2.png")
                  PrintLine "Modified ", GfDate$(), ", ", GfTime$()
            .endif
            add esp, 4*16
      .endif
  .endif
  Inkey "OK?"
  Exit
end start


WinAPI fans who know their SYSTEMTIME know why pavgw works in this case :bgrin:

hutch--

Quote
There's no mystery.
This took all of 3 minutes to write.
What happened, are you getting slow in your old age ?  :biggrin:

Magnum

Quote from: adeyblue on December 16, 2014, 06:27:27 AM
Windows has 'touch' to update the timestamp built-in, though it's a bizarre incantation

Thanks adeyblue.

I wanted to learn to do it using assembly.

I have been out of it for a while.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

Quote from: Tedd on December 16, 2014, 12:21:49 AM
There's no mystery.

This took all of 3 minutes to write.


It failed.

I went with this.

cd\
COPY /B Windows_XP_Partition +,,

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org


Magnum

Tedd used SetFileTime is his code.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

I found this and am working on it.

' First, open the file C:\MyApp\test.txt for both read-level and
' write-level access, since we need to do both.
hFile = CreateFile("C:\MyApp\test.txt", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
If hFile = -1 Then
  Debug.Print "Could not open the file successfully -- aborting."
  End  ' terminate the program
End If

' Next, get the creation, last-access, and last-modification times.
retval = GetFileTime(hFile, ctime, atime, mtime)

' Get the system time (already in UTC) as a FILETIME structure.
GetSystemTimeAsFileTime mtime
' Set the retrieved creation and access times and the new modification
' time as the file's times.
retval = SetFileTime(hFile, ctime, atime, mtime)

' Close the file to free up resources.
retval = CloseHandle(hFile)
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

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

Magnum

I don't understand how to make a pointer to current FILETIME structure.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

if it's a local, use ADDR
if it's a global, use OFFSET

pointer = address

dedndave

people will tell you that ADDR works for either
and that may be so, but i prefer to differentiate so that i know at a glance which i am using   :t

Gunther

Quote from: dedndave on December 17, 2014, 06:51:51 AM
people will tell you that ADDR works for either
and that may be so, but i prefer to differentiate so that i know at a glance which i am using   :t

Yes ADDR works in both cases. But your practice is okay and well thought out.

Gunther
You have to know the facts before you can distort them.