Jump to content

Change VersionInfo in executables


Recommended Posts

Hi,

I tried today to change VersionInfo without ResHacker command-line, with pure AutoIT code. So, i wrote this code :

#Include <String.au3>

Const   $STR_TO_REPLACE="I g o r  P a v l o v" ;this is how string looks like in the executable
Const   $REPLACE_STR="I u l i" ;the new string i want in the executable

;Select file for modifing
$file=FileOpenDialog("Open file","","")

;Open file and convert to HEX
$fo=FileOpen($file,16)
$cont=Hex(FileRead($fo))
FileClose($fo)

;Replace string
$cont=StringReplace($cont,_StringToHex($STR_TO_REPLACE),_StringToHex($REPLACE_STR))

;Select file to save to
$files=FileSaveDialog("Save file","","")

;Save file
$fw=FileOpen($files,2)
FileWrite($fw,Binary("0x" & $cont))
FileClose($fw)

;Exit
Exit

The problem seems to be with ReplaceString. So, i converted "I g o r P a v l o v" to HEX, then i searched in the HEX converted file with Notepad, finding nothing. Am i missing something ? If that string is in the executable, shouldn't it be in the HEX converted file too, under HEX form ?

EDIT : I remember that JScript had kinda'of UDF on the forums, but i cannot find it.

Thanks,

Iuli.

Edited by Iuli
[size="2"]SFXMaker[/size] - The most complete switchless installer creator software[indent][/indent]
Link to comment
Share on other sites

Look for the Resource Hacker UDF in example scripts.

It looks like you are probably going to be breaking copyright laws here. As far as I'm aware Igor has nothing that isn't copyrighted including 7zip

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Look for the Resource Hacker UDF in example scripts.

It looks like you are probably going to be breaking copyright laws here. As far as I'm aware Igor has nothing that isn't copyrighted including 7zip

Actually, i'm not breaking any copyright laws. I'm using 7-zip to make a SFX installer (SFXMaker) and i want to change the VersionInfo of SFX Installer Executable.

Are you talking about this post ?

Edited by Iuli
[size="2"]SFXMaker[/size] - The most complete switchless installer creator software[indent][/indent]
Link to comment
Share on other sites

  • 1 month later...

(...)

The problem seems to be with ReplaceString. So, i converted "I g o r P a v l o v" to HEX, then i searched in the HEX converted file with Notepad, finding nothing. Am i missing something ? If that string is in the executable, shouldn't it be in the HEX converted file too, under HEX form ?

EDIT : I remember that JScript had kinda'of UDF on the forums, but i cannot find it.

Thanks,

Iuli.

Hello,

Try this:_FileSetVersion.au3

If the link is broken...

#include-once

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

; Example
;#include <_FileSetVersion.au3>
#cs
; 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
#ce

; #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 $bVS_VERSION_INFO = "34000000560053005f00560045005200530049004f004e005f0049004e0046004f"
    Local $bSTRINGFILEINFO = "53007400720069006e006700460069006c00650049006e0066006f"
    Local $bTRANSLATION = "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 Not StringInStr($bFileRead, $bVS_VERSION_INFO, 0, -1) Then Return SetError(1, 0, 0)
    #cs
        ;
        ; Determine the size of the resource information
        $bSearch = StringMid($bFileRead, StringInStr($bFileRead, $bVS_VERSION_INFO, 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)
        ;
    ElseIf $sStringName = "DefaultLanguage" Then
        ;
        ; Verify if $sStringText is in Hex
        If StringInStr($sStringText, "0x") Then
            $sStringText = StringRight($sStringText, 4)
        Else
            $sStringText = Hex($sStringText, 4)
        EndIf
        ; Set Translation
        $iPos = StringInStr($bFileRead, $bTRANSLATION, 0, -1) + 52
        $bFileRead = StringReplace($bFileRead, $iPos, StringRight($sStringText, 2) & StringLeft($sStringText, 2))
        ; Set StringFileInfo
        $sStringText = __Binary(__NullEntryPoint($sStringText))
        $iPos = StringInStr($bFileRead, $bSTRINGFILEINFO, 0, -1) + 72
        $bFileRead = StringReplace($bFileRead, $iPos, $sStringText)
    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, $bVS_VERSION_INFO, 0, 1) - 4)
        $bSearch = StringMid($bSearch, 1, StringInStr($bSearch, $bTRANSLATION, 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, $bVS_VERSION_INFO, 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

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...