• Welcome to Valhalla Legends Archive.
 

[Solved]VB6 Battle.Net FILETIME help please!

Started by Ringo, January 21, 2006, 04:24 AM

Previous topic - Next topic

Ringo

Can anyone please explain how battle.net's "FILETIME" works?
After downloading tos_usa.txt from BNFTP and copying the file time in the responce packet, im not sure what to do next.
Iv tryed converting it to a number of differnt time structures, but non of them match the one in the packet.
any ideas?


Packet = 00 DF 77 0F 6C E8 C0 01
Packet High = 29419628
Packet Low  = 259514112

CreateFile() = 676

GetFileTime() = 1
1 High = 29761120
1 Low  = 256759730
1        B2 D7 4D 0F 60 1E C6 01
2 High = 29761120
2 Low  = -1052582566
2        5A DD 42 C1 60 1E C6 01
3 High = 29761120
3 Low  = 396134730
3        4A 89 9C 17 60 1E C6 01





Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
Private Declare Function GetFileTime Lib "kernel32" _
                        (ByVal hFile As Long, _
                        lpCreationTime As FILETIME, _
                        lpLastAccessTime As FILETIME, _
                        lpLastWriteTime As FILETIME) As Long

Private Declare Function CreateFileA Lib "kernel32" _
                         (ByVal lpFileName As String, _
                         ByVal dwDesiredAccess As Long, _
                         ByVal dwShareMode As Long, _
                         lpSecurityAttributes As Long, _
                         ByVal dwCreationDisposition As Long, _
                         ByVal dwFlagsAndAttributes As Long, _
                         ByVal hTemplateFile As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
                         (ByVal hObject As Long) As Long

Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const FO_DELETE = &H3

Public Sub FuckingFile()
    Dim Ft1 As FILETIME
    Dim Ft2 As FILETIME
    Dim Ft3 As FILETIME
    Dim R&, hdl&
    Ft1 = GetQWORD(HexToStr("00 DF 77 0F 6C E8 C0 01"))
    Debug.Print "Packet = " & StrToHex(MakeQWORD(Ft1))
    Debug.Print "Packet High = " & Ft1.dwHighDateTime
    Debug.Print "Packet Low  = " & Ft1.dwLowDateTime
    Debug.Print " "
    hdl = CreateFileA(App.Path & "\tos_usa.txt", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
    Debug.Print "CreateFile() = " & hdl
    Debug.Print " "
    R = GetFileTime(hdl, Ft1, Ft2, Ft3)
    Debug.Print "GetFileTime() = " & R
    Debug.Print "1 High = " & Ft1.dwHighDateTime
    Debug.Print "1 Low  = " & Ft1.dwLowDateTime
    Debug.Print "1        " & StrToHex(MakeQWORD(Ft1))
    Debug.Print "2 High = " & Ft2.dwHighDateTime
    Debug.Print "2 Low  = " & Ft2.dwLowDateTime
    Debug.Print "2        " & StrToHex(MakeQWORD(Ft2))
    Debug.Print "3 High = " & Ft3.dwHighDateTime
    Debug.Print "3 Low  = " & Ft3.dwLowDateTime
    Debug.Print "3        " & StrToHex(MakeQWORD(Ft3))
    Call CloseHandle(hdl)
End Sub




Private Function GetQWORD(Data As String) As FILETIME
    CopyMemory GetQWORD, ByVal Data, 8
End Function
Private Function MakeQWORD(F As FILETIME) As String
    MakeQWORD = String(8, 0)
    CopyMemory ByVal MakeQWORD, F, 8
End Function
Public Function StrToHex(ByVal Data As String, Optional Splitter As String = " ") As String
    For i = 1 To Len(Data)
        StrToHex = StrToHex & Right("00" & Hex(Asc(Mid(Data, i, 1))), 2) & Splitter
    Next i
End Function
Public Function HexToStr(ByVal Data As String) As String
    For i = 1 To Len(Data) Step 3
        HexToStr = HexToStr & Chr("&H" & Mid(Data, i, 2))
    Next i
End Function




[EDIT]: Oh...
I just tryed SetFileTime() and its all good!
I spose that how its ment to be done after downloading and creating the file?


    Ft3 = GetQWORD(HexToStr("00 DF 77 0F 6C E8 C0 01"))
    R = SetFileTime(hdl, Ft1, Ft2, Ft3)
    Debug.Print "SetFileTime() = " & R
    Debug.Print "1 High = " & Ft1.dwHighDateTime
    Debug.Print "1 Low  = " & Ft1.dwLowDateTime
    Debug.Print "1        " & StrToHex(MakeQWORD(Ft1))
    Debug.Print "2 High = " & Ft2.dwHighDateTime
    Debug.Print "2 Low  = " & Ft2.dwLowDateTime
    Debug.Print "2        " & StrToHex(MakeQWORD(Ft2))
    Debug.Print "3 High = " & Ft3.dwHighDateTime
    Debug.Print "3 Low  = " & Ft3.dwLowDateTime
    Debug.Print "3        " & StrToHex(MakeQWORD(Ft3))
    Call CloseHandle(hdl)

gave me:

SetFileTime() = 1
1 High = 29761120
1 Low  = 256759730
1        B2 D7 4D 0F 60 1E C6 01
2 High = 29761120
2 Low  = -1052582566
2        5A DD 42 C1 60 1E C6 01
3 High = 29419628
3 Low  = 259514112
3        00 DF 77 0F 6C E8 C0 01

MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.