Attribute VB_Name = "CloneInfo"
'Made By: ZeR0/0cm4n for HackHound.org
'Thanks to: Noble (C++ Source Code), Cobein (mDelRes Module)
Option Explicit

Private Const RT_VERSION      As Long = 16

Private Const VS_VERSION_INFO As Long = 1

Private Declare Function BeginUpdateResource _
                Lib "KERNEL32" _
                Alias "BeginUpdateResourceA" (ByVal pFileName As String, _
                                              ByVal bDeleteExistingResources As Long) As Long

Private Declare Function EndUpdateResource _
                Lib "KERNEL32" _
                Alias "EndUpdateResourceA" (ByVal lUpdate As Long, _
                                            ByVal fDiscard As Long) As Long

Private Declare Function UpdateResource _
                Lib "KERNEL32" _
                Alias "UpdateResourceA" (ByVal lUpdate As Long, _
                                         ByVal lpType As Long, _
                                         ByVal lpName As Long, _
                                         ByVal wLanguage As Long, _
                                         lpData As Any, _
                                         ByVal cbData As Long) As Long

Private Declare Function GetFileVersionInfo _
                Lib "Version.dll" _
                Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, _
                                             ByVal dwhandle As Long, _
                                             ByVal dwlen As Long, _
                                             lpData As Any) As Long

Private Declare Function GetFileVersionInfoSize _
                Lib "Version.dll" _
                Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, _
                                                 lpdwHandle As Long) As Long

Private Declare Function VerQueryValue _
                Lib "Version.dll" _
                Alias "VerQueryValueA" (pBlock As Any, _
                                        ByVal lpSubBlock As String, _
                                        lplpBuffer As Any, _
                                        puLen As Long) As Long

Private Declare Sub CopyMemory _
                Lib "KERNEL32" _
                Alias "RtlMoveMemory" (dest As Any, _
                                       source As Any, _
                                       ByVal Length As Long)

Public Sub CloneFileInformation(ByVal source As String, ByVal Destination As String)
    Dim lLenSource      As Long
    Dim lLenDestination As Long
    Dim lHandle         As Long
    Dim hRes            As Long
    Dim lVerPointer     As Long
    Dim lLangId         As Long
    Dim iVal            As Long
    Dim lSize           As Long
    Dim bFileInfo()     As Byte
    Dim bDestination()  As Byte
    lLenSource = GetFileVersionInfoSize(source, lHandle)
    ReDim bFileInfo(lLenSource)
    Call GetFileVersionInfo(source, 0&, lLenSource, bFileInfo(0))
    lLenDestination = GetFileVersionInfoSize(Destination, lHandle)
    ReDim bDestination(lLenDestination)
    Call GetFileVersionInfo(Destination, 0&, lLenDestination, bDestination(0))
    Call VerQueryValue(bDestination(0), "\\VarFileInfo\\Translation", lVerPointer, lSize)
    hRes = BeginUpdateResource(Destination, False)
    CopyMemory lLangId, ByVal lVerPointer, 2
    Call UpdateResource(hRes, RT_VERSION, VS_VERSION_INFO, lLangId, bFileInfo(0), lLenSource)
    Call EndUpdateResource(hRes, False)

End Sub
