Sign in to follow this  
Followers 0
snify

ResourceUpdate

4 posts in this topic

Hey out there,

I really got it to update Resources. I just want to Update the FileVersion Resource (16) with a .res file. The Problem is, I dont know how to make .res File. I tried it with a selfrwitten .rc File. But it doesnt work :)

I need to change:

FileVersion

FileDesciption

LegalCopyright

Comments

CompanyName

InternalName

LegalTrademarks

OriginalFilename

ProductName

ProductVersion

Contact

PS.: I looked in the AutoIT Wrapper Source and found the resstring function. But this is only for a few things... But I need to update all.

So is there a .rc to .res compiler/converter? or a function, that creates a 100% Full Version Info.res?

Please Help

Thank you.

Greetz Snify

Share this post


Link to post
Share on other sites



PS.: I looked in the AutoIT Wrapper Source and found the resstring function. But this is only for a few things... But I need to update all.

Everything is defined in the AutoIt3Wrapper resource update functions as long as you use the proper resource field names.... etc since the UDFs build the total resource block for FileVersion. :)

Anyways... you can use the RC.EXE program the comes with the Microsoft SDK to generate a RC from a RES.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Does this help?

#include-once

; #INDEX# =======================================================================================================================
; Title .........: FileSetVersion
; AutoIt Version: 3.2.10++
; Language:     English
; Description ...: Updating the StringFileInfo section.
; ===============================================================================================================================

; Example
;#include <_FileSetVersion.au3>

; Use Notepad as example...
FileCopy(@WindowsDir & "\Notepad.exe", @ScriptDir)
$FineName = @ScriptDir & "\OutPutFile.exe"
$FineName = @ScriptDir & "\Notepad.exe"

; save old field information
$OldCompanyName = FileGetVersion($FineName, "CompanyName")
MsgBox(4096, "Old Company name", $OldCompanyName)

; set new field information
If _FileSetVersion($FineName, "CompanyName", "_FileSetVersion ;-)") = 1 Then
    $NewCompanyName = FileGetVersion($FineName, "CompanyName")
    MsgBox(4096, "New Company name", $NewCompanyName)
    ; Restore old field information
    _FileSetVersion($FineName, "CompanyName", $OldCompanyName)
Else
    MsgBox(4096, "Error!", "Can not set the field CompanyName!")
EndIf

; #INTERNAL_USE_ONLY#============================================================================================================
; __NullEntryPoint
; __NullRepeat
; __Binary
;================================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........:  _FileSetVersion
; Description ...:  Updating the StringFileInfo section.
; Syntax.........:  _FileSetVersion( FileName, "StringName", "StringText" )
; Parameters ....:  FileName - Path and filename.
;                   StringName- name of the field info, default is "FileVersion".
;                   StringText- string to fill the field info, default is @AutoItVersion.
; Return values .:  Success - Returns 1 and set @error to 0
;       Failure - Returns 0 and set @error to 1
; Author ........:  jscript "FROM BRAZIL"
; Modified.......:
; Remarks .......:  The information contained in the StringFileInfo section is not necessarily more difficult
;                   to change, but it does have the constraint that the new information be the same size or smaller
;                   than the old information. Extra characters would inevitably write on something important.
; Related .......:  FileGetVersion
; Link ..........;
; Example .......;  Yes
; ===============================================================================================================================
Func _FileSetVersion($hFileName, $sStringName = "FileVersion", $sStringText = @AutoItVersion)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $iResourceSize, $hFileOpen, $bFileRead, $bSearch, $bReplace, $bHex, $NewResSize, $iPos
    Local $aStrSplit, $iResFieldSize, $bBinStrName, $sBinStrText, $sFileGetInfo, $iValue, $iCont
    Local $bHeader = "34000000560053005f00560045005200530049004f004e005f0049004e0046004f"
    Local $bEndHeader = "5400720061006e0073006c006100740069006f006e0000000000"
    ;
    ; If not file found return 0 and set @error to 1
    If Not FileExists($hFileName) Then Return SetError(1, 0, 0)
    ;
    ; First open file in only binary read mode and close
    $hFileOpen = FileOpen($hFileName, 16)
    $bFileRead = FileRead($hFileOpen)
    FileClose($hFileOpen)
    ;
    ; Get resource info, if no version information found, return 0 and set @error to 1
    If FileGetVersion($hFileName) = "0.0.0.0" Then Return SetError(1, 0, 0)
    #cs
        ;
        ; Determine the size of the resource information
        $bSearch = StringMid($bFileRead, StringInStr($bFileRead, $bHeader, 0, -1) - 4, 4)
        ; Invert and return value in bytes
        $iResourceSize = Dec(StringRight($bSearch, 2) & StringLeft($bSearch, 2))
    #ce
    ;
    ; Update Resource information
    If $sStringName = "FILEVERSION" Or $sStringName = "PRODUCTVERSION" Then
        ;
        ; Split FileVersion, format is: 00.00.0000.0000
        $aStrSplit = StringSplit($sStringText, ".")
        ; If wrong FileVersion format, return 0 and set @error to 1
        If $aStrSplit[0] > 4 Then Return SetError(1, 0, 0)
        ;
        ; Convert to Hex and Invert data
        Dim $bReplace[5] = [5, Hex(0, 4), Hex(0, 4), Hex(0, 4), Hex(0, 4)]
        For $i = 1 To $aStrSplit[0]
            $bHex = Hex($aStrSplit[$i], 4)
            $bReplace[$i] = StringRight($bHex, 2) & StringLeft($bHex, 2)
        Next
        ;
        ; Set FILEVERSION / PRODUCTVERSION
        If $sStringName = "FILEVERSION" Then $iPos = StringInStr($bFileRead, "bd04effe00000100", 0, -1) + 16
        If $sStringName = "PRODUCTVERSION" Then $iPos = StringInStr($bFileRead, "bd04effe00000100", 0, -1) + 32
        $bFileRead = StringReplace($bFileRead, $iPos, $bReplace[2] & $bReplace[1] & $bReplace[4] & $bReplace[3])
        ; free the memory
        $aStrSplit = 0
        $bReplace = 0
        ;
        ; If error found, return 0 and set @error to 1
        If @error Then Return SetError(1, 0, 0)
    Else
        ; If FileGetVersion returns error then
        If @error Then Return SetError(1, 0, 0)
        ;
        ; Set the length of $sStringName resource field
        $bBinStrName = __Binary(__NullEntryPoint($sStringName))
        $iPos = StringInStr($bFileRead, $bBinStrName)
        $iValue = StringMid($bFileRead, $iPos + StringLen($bBinStrName), 10)
        For $i = 1 To 10
            $iCont = StringMid($iValue, $i, 2)
            If $iCont = "00" Then $bBinStrName &= __Binary(Chr("00"))
            If $iCont <> "00" Then ExitLoop
            $i += 1
        Next
        ;
        ; Get the resource field size
        $iValue = StringMid($bFileRead, $iPos + StringLen($bBinStrName), 400)
        For $i = 1 To 400
            If StringMid($iValue, $i, 6) = "000000" Then
                $iValue = Int($i / 2) + 3
                ExitLoop
            EndIf
            $i += 1
        Next
        $iResFieldSize = Dec(StringMid($bFileRead, $iPos - 8, 2))
        If $iValue > $iResFieldSize Then $iResFieldSize = $iValue
        ;
        If $iResFieldSize <= 1 Then Return SetError(1, 0, 0)
        ;
        ; fix $sStringText length
        $sBinStrText = __Binary(StringMid(__NullEntryPoint(__NullRepeat($sStringText, $iResFieldSize, 32)), 1, $iResFieldSize - 3))
        ;
        ; Replace resource
        $bFileRead = StringReplace($bFileRead, $iPos + StringLen($bBinStrName), $sBinStrText)
        ; If error found, return 0 and set @error to 1
        If @error Then Return SetError(1, 0, 0)
        ;
        ; Update resource field size
        $bHex = Hex($iResFieldSize, 2)
        $bFileRead = StringReplace($bFileRead, StringInStr($bFileRead, $bBinStrName, 0, -1) - 8, $bHex, 1)
        ; If error found, return 0 and set @error to 1
        If @error Then Return SetError(1, 0, 0)
    EndIf
    #cs
        ;
        ; Get new resource size
        $bSearch = StringMid($bFileRead, StringInStr($bFileRead, $bHeader, 0, 1) - 4)
        $bSearch = StringMid($bSearch, 1, StringInStr($bSearch, $bEndHeader, 0, -1) + 60)
        $iResourceSize = Int(BinaryLen($bSearch) / 2)
        ; Convert to Hex, invert and set new resource size
        $bHex = Hex($iResourceSize, 4)
        $iResourceSize = StringRight($bHex, 2) & StringLeft($bHex, 2)
        $bFileRead = StringReplace($bFileRead, StringInStr($bFileRead, $bHeader, 0, -1) - 4, $iResourceSize, 1)
        ;
        ; If error found, return 0 and set @error to 1
        If @error Then Return SetError(1, 0, 0)
    #ce
    ;
    ; Open file in binary write mode, save modified data and close
    $hFileOpen = FileOpen($hFileName, 18)
    ; If error found, return 0 and set @error to 1
    If $hFileOpen = -1 Then Return SetError(1, 0, 0)
    FileWrite($hFileOpen, $bFileRead)
    FileClose($hFileOpen)
    ;
    ; Set @error to 0 and return 1
    Return SetError(0, 0, 1)
EndFunc ;==>_FileSetVersion

Func _UnHexEntry($t)
    ;Return _StringReverse(_HexToString($t))
EndFunc ;==>_UnHexEntry

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: __NullEntryPoint
; Description ...: Adding the Chr("00") enter each char.
; Syntax.........: __NullEntryPoint( $sString )
; Parameters ....: $sString - String to pass.
; Return values .: Success - Returns Chr("00") enter each char
;   Failure -
; Author ........: jscript "FROM BRAZIL"
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func __NullEntryPoint($sString)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $iLen = StringLen($sString), $bNullString = "";Chr("00")
    ;
    For $i = 1 To $iLen
        $bNullString &= StringMid($sString, $i, 1)
        If $i = $iLen Then ExitLoop
        $bNullString &= Chr("00")
    Next
    Return $bNullString
EndFunc ;==>__NullEntryPoint

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........:  __NullRepeat
; Description ...:  Adding the Chr("00") at the end of the string
; Syntax.........:  __NullRepeat( $sString, $iValue, $vChar = 0 )
; Parameters ....:  $sString- String to pass.
;                   $iValue - Number of times to repeat
;                   $vChar  - Char type, default is 00
; Return values .:  Success - Returns Chr("00") enter each char
;       Failure -
; Author ........:  jscript "FROM BRAZIL"
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func __NullRepeat($sString, $iValue, $vChar = 0)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $sRepeat = ""
    ;
    $iValue = $iValue - StringLen($sString)
    If $iValue > 0 Then
        For $i = 1 To $iValue
            $sRepeat &= Chr($vChar)
        Next
    EndIf
    Return $sString & $sRepeat
EndFunc ;==>__NullRepeat

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: __Binary
; Description ...: Returns the binary representation of an expression.
; Syntax.........: __Binary( $sExpression )
; Parameters ....: $sExpression - An expression to convert into binary/byte data.
; Return values .: Success - Returns a Binary variant without: 0x
;   Failure -
; Author ........: jscript "FROM BRAZIL"
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func __Binary($sExpression)
    Return StringTrimLeft(Binary($sExpression), 2)
EndFunc ;==>__Binary

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Does this help?

#include-once

; #INDEX# =======================================================================================================================
; Title .........: FileSetVersion
; AutoIt Version: 3.2.10++
; Language:     English
; Description ...: Updating the StringFileInfo section.
; ===============================================================================================================================

; Example
;#include <_FileSetVersion.au3>

; Use Notepad as example...
FileCopy(@WindowsDir & "\Notepad.exe", @ScriptDir)
$FineName = @ScriptDir & "\OutPutFile.exe"
$FineName = @ScriptDir & "\Notepad.exe"

; save old field information
$OldCompanyName = FileGetVersion($FineName, "CompanyName")
MsgBox(4096, "Old Company name", $OldCompanyName)

; set new field information
If _FileSetVersion($FineName, "CompanyName", "_FileSetVersion ;-)") = 1 Then
    $NewCompanyName = FileGetVersion($FineName, "CompanyName")
    MsgBox(4096, "New Company name", $NewCompanyName)
    ; Restore old field information
    _FileSetVersion($FineName, "CompanyName", $OldCompanyName)
Else
    MsgBox(4096, "Error!", "Can not set the field CompanyName!")
EndIf

; #INTERNAL_USE_ONLY#============================================================================================================
; __NullEntryPoint
; __NullRepeat
; __Binary
;================================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........:  _FileSetVersion
; Description ...:  Updating the StringFileInfo section.
; Syntax.........:  _FileSetVersion( FileName, "StringName", "StringText" )
; Parameters ....:  FileName - Path and filename.
;                   StringName- name of the field info, default is "FileVersion".
;                   StringText- string to fill the field info, default is @AutoItVersion.
; Return values .:  Success - Returns 1 and set @error to 0
;       Failure - Returns 0 and set @error to 1
; Author ........:  jscript "FROM BRAZIL"
; Modified.......:
; Remarks .......:  The information contained in the StringFileInfo section is not necessarily more difficult
;                   to change, but it does have the constraint that the new information be the same size or smaller
;                   than the old information. Extra characters would inevitably write on something important.
; Related .......:  FileGetVersion
; Link ..........;
; Example .......;  Yes
; ===============================================================================================================================
Func _FileSetVersion($hFileName, $sStringName = "FileVersion", $sStringText = @AutoItVersion)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $iResourceSize, $hFileOpen, $bFileRead, $bSearch, $bReplace, $bHex, $NewResSize, $iPos
    Local $aStrSplit, $iResFieldSize, $bBinStrName, $sBinStrText, $sFileGetInfo, $iValue, $iCont
    Local $bHeader = "34000000560053005f00560045005200530049004f004e005f0049004e0046004f"
    Local $bEndHeader = "5400720061006e0073006c006100740069006f006e0000000000"
    ;
    ; If not file found return 0 and set @error to 1
    If Not FileExists($hFileName) Then Return SetError(1, 0, 0)
    ;
    ; First open file in only binary read mode and close
    $hFileOpen = FileOpen($hFileName, 16)
    $bFileRead = FileRead($hFileOpen)
    FileClose($hFileOpen)
    ;
    ; Get resource info, if no version information found, return 0 and set @error to 1
    If FileGetVersion($hFileName) = "0.0.0.0" Then Return SetError(1, 0, 0)
    #cs
        ;
        ; Determine the size of the resource information
        $bSearch = StringMid($bFileRead, StringInStr($bFileRead, $bHeader, 0, -1) - 4, 4)
        ; Invert and return value in bytes
        $iResourceSize = Dec(StringRight($bSearch, 2) & StringLeft($bSearch, 2))
    #ce
    ;
    ; Update Resource information
    If $sStringName = "FILEVERSION" Or $sStringName = "PRODUCTVERSION" Then
        ;
        ; Split FileVersion, format is: 00.00.0000.0000
        $aStrSplit = StringSplit($sStringText, ".")
        ; If wrong FileVersion format, return 0 and set @error to 1
        If $aStrSplit[0] > 4 Then Return SetError(1, 0, 0)
        ;
        ; Convert to Hex and Invert data
        Dim $bReplace[5] = [5, Hex(0, 4), Hex(0, 4), Hex(0, 4), Hex(0, 4)]
        For $i = 1 To $aStrSplit[0]
            $bHex = Hex($aStrSplit[$i], 4)
            $bReplace[$i] = StringRight($bHex, 2) & StringLeft($bHex, 2)
        Next
        ;
        ; Set FILEVERSION / PRODUCTVERSION
        If $sStringName = "FILEVERSION" Then $iPos = StringInStr($bFileRead, "bd04effe00000100", 0, -1) + 16
        If $sStringName = "PRODUCTVERSION" Then $iPos = StringInStr($bFileRead, "bd04effe00000100", 0, -1) + 32
        $bFileRead = StringReplace($bFileRead, $iPos, $bReplace[2] & $bReplace[1] & $bReplace[4] & $bReplace[3])
        ; free the memory
        $aStrSplit = 0
        $bReplace = 0
        ;
        ; If error found, return 0 and set @error to 1
        If @error Then Return SetError(1, 0, 0)
    Else
        ; If FileGetVersion returns error then
        If @error Then Return SetError(1, 0, 0)
        ;
        ; Set the length of $sStringName resource field
        $bBinStrName = __Binary(__NullEntryPoint($sStringName))
        $iPos = StringInStr($bFileRead, $bBinStrName)
        $iValue = StringMid($bFileRead, $iPos + StringLen($bBinStrName), 10)
        For $i = 1 To 10
            $iCont = StringMid($iValue, $i, 2)
            If $iCont = "00" Then $bBinStrName &= __Binary(Chr("00"))
            If $iCont <> "00" Then ExitLoop
            $i += 1
        Next
        ;
        ; Get the resource field size
        $iValue = StringMid($bFileRead, $iPos + StringLen($bBinStrName), 400)
        For $i = 1 To 400
            If StringMid($iValue, $i, 6) = "000000" Then
                $iValue = Int($i / 2) + 3
                ExitLoop
            EndIf
            $i += 1
        Next
        $iResFieldSize = Dec(StringMid($bFileRead, $iPos - 8, 2))
        If $iValue > $iResFieldSize Then $iResFieldSize = $iValue
        ;
        If $iResFieldSize <= 1 Then Return SetError(1, 0, 0)
        ;
        ; fix $sStringText length
        $sBinStrText = __Binary(StringMid(__NullEntryPoint(__NullRepeat($sStringText, $iResFieldSize, 32)), 1, $iResFieldSize - 3))
        ;
        ; Replace resource
        $bFileRead = StringReplace($bFileRead, $iPos + StringLen($bBinStrName), $sBinStrText)
        ; If error found, return 0 and set @error to 1
        If @error Then Return SetError(1, 0, 0)
        ;
        ; Update resource field size
        $bHex = Hex($iResFieldSize, 2)
        $bFileRead = StringReplace($bFileRead, StringInStr($bFileRead, $bBinStrName, 0, -1) - 8, $bHex, 1)
        ; If error found, return 0 and set @error to 1
        If @error Then Return SetError(1, 0, 0)
    EndIf
    #cs
        ;
        ; Get new resource size
        $bSearch = StringMid($bFileRead, StringInStr($bFileRead, $bHeader, 0, 1) - 4)
        $bSearch = StringMid($bSearch, 1, StringInStr($bSearch, $bEndHeader, 0, -1) + 60)
        $iResourceSize = Int(BinaryLen($bSearch) / 2)
        ; Convert to Hex, invert and set new resource size
        $bHex = Hex($iResourceSize, 4)
        $iResourceSize = StringRight($bHex, 2) & StringLeft($bHex, 2)
        $bFileRead = StringReplace($bFileRead, StringInStr($bFileRead, $bHeader, 0, -1) - 4, $iResourceSize, 1)
        ;
        ; If error found, return 0 and set @error to 1
        If @error Then Return SetError(1, 0, 0)
    #ce
    ;
    ; Open file in binary write mode, save modified data and close
    $hFileOpen = FileOpen($hFileName, 18)
    ; If error found, return 0 and set @error to 1
    If $hFileOpen = -1 Then Return SetError(1, 0, 0)
    FileWrite($hFileOpen, $bFileRead)
    FileClose($hFileOpen)
    ;
    ; Set @error to 0 and return 1
    Return SetError(0, 0, 1)
EndFunc ;==>_FileSetVersion

Func _UnHexEntry($t)
    ;Return _StringReverse(_HexToString($t))
EndFunc ;==>_UnHexEntry

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: __NullEntryPoint
; Description ...: Adding the Chr("00") enter each char.
; Syntax.........: __NullEntryPoint( $sString )
; Parameters ....: $sString - String to pass.
; Return values .: Success - Returns Chr("00") enter each char
;   Failure -
; Author ........: jscript "FROM BRAZIL"
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func __NullEntryPoint($sString)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $iLen = StringLen($sString), $bNullString = "";Chr("00")
    ;
    For $i = 1 To $iLen
        $bNullString &= StringMid($sString, $i, 1)
        If $i = $iLen Then ExitLoop
        $bNullString &= Chr("00")
    Next
    Return $bNullString
EndFunc ;==>__NullEntryPoint

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........:  __NullRepeat
; Description ...:  Adding the Chr("00") at the end of the string
; Syntax.........:  __NullRepeat( $sString, $iValue, $vChar = 0 )
; Parameters ....:  $sString- String to pass.
;                   $iValue - Number of times to repeat
;                   $vChar  - Char type, default is 00
; Return values .:  Success - Returns Chr("00") enter each char
;       Failure -
; Author ........:  jscript "FROM BRAZIL"
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func __NullRepeat($sString, $iValue, $vChar = 0)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $sRepeat = ""
    ;
    $iValue = $iValue - StringLen($sString)
    If $iValue > 0 Then
        For $i = 1 To $iValue
            $sRepeat &= Chr($vChar)
        Next
    EndIf
    Return $sString & $sRepeat
EndFunc ;==>__NullRepeat

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: __Binary
; Description ...: Returns the binary representation of an expression.
; Syntax.........: __Binary( $sExpression )
; Parameters ....: $sExpression - An expression to convert into binary/byte data.
; Return values .: Success - Returns a Binary variant without: 0x
;   Failure -
; Author ........: jscript "FROM BRAZIL"
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func __Binary($sExpression)
    Return StringTrimLeft(Binary($sExpression), 2)
EndFunc ;==>__Binary

I used this, but its not working with all these FileVersions.

I used now brc32.exe (from Borland Delphi7) the resource compiler.

Thanks :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0