Heaventools

   English English  Deutsch Deutsch

home  products  resource tuner console  sample scripts library

Replacing Data Types That Stored As Custom Resources

This code shows how to modify common data types that are stored as custom resources, including major graphic files (.GIF, .PNG, .JPG), sound (.WAV, .MIDI) and video (.AVI) files, and binary files (.CAB, TYPELIB, etc).

The ChangeCustomResource procedure allows you to replace any custom resource. In this script, it replaces a GIF resource in DemoApp1.exe with an animated GIF file from the "Src" folder.

Additionally, the script demonstrates how to replace the standard cursor with another xhair2.cur file using the ChangeCursor procedure.

To avoid conflicts when loading multiple DLLs with the same base address, the script sets the ImageBase value in the PE Optional Header manually with the RebaseImage procedure. This operation is optional and can be commented out if not needed.

The resulting modified files will be saved to the directory named "Release".

Note: when copying out the script code, please make sure there's no line breaks. This is a requirement of VBScript: the entire command must be on one line.

Edit Custom GIF

'------------------------------------------------------------------------------
'
' This script demonstrates how to modify common data types that are stored as 
' custom resources: major graphic files (.GIF, .PNG, .JPG), sound (.WAV, .MIDI),
' video (.AVI) files, or binary files (.CAB, TYPELIB, etc.).
'
' The resulting files will be created in the directory named "\Release".
' Check the log file to see the Resource Tree built.
'
'------------------------------------------------------------------------------

Sub Main
      
  PEFileProxy.PostDebugString "PE file header checksum updating is enabled." 
  PEFileProxy.UpdateCheckSum = True

  PEFileProxy.PostDebugString "The creation of a backup copy is disabled." 
  PEFileProxy.CreateBackUp = False

  PEFileProxy.PostDebugString "Open the file for editing..."
  PEFileProxy.OpenFile ".\src\DemoApp1.exe"
  if (PEFileProxy.Terminated) then
    'Issue a warning in case of error
    PEFileProxy.PostDebugString "Error when opening this file."
  else
    PEFileProxy.PostDebugString "File opened OK."
    if (not PEFileProxy.HasResources) then
      PEFileProxy.PostDebugString "The file contains no resources."
    else
      PEFileProxy.PostDebugString "The file contains resources."      

      'This specifies the default language      
      LangID = 0 ' Default 

      ' Replace the "GIF" file in the "DEMO_GIF" custom resource
      ' (resource name = "DEMO_GIF", resource id = "GIF")
      PEFileProxy.PostDebugString "Change/add Custom Resource..."
      ResourcesProxy.ChangeCustomResource "DEMO_GIF", "GIF", LangID, 
CREATE_IF_NOT_EXIST, ".\src\replaced_ani_gif.gif"

      'Replace the cursor (for demo purposes)
      PEFileProxy.PostDebugString "Change/add Cursor..."
      ResourcesProxy.ChangeCursor "32761", LangID, CREATE_IF_NOT_EXIST, 
REPLACE_IF_ITEM_EXISTS_ELSE_ADD, ".\src\xhair2.cur"

      'Build and output the Resource Tree to a log file.
      'Check the log file to see the Resource Tree built. 
      PEFileProxy.PostDebugString ""
      PEFileProxy.PostDebugString "Resource Tree built by RTC:"
      ResourcesProxy.ResourceTreeToLog
      PEFileProxy.PostDebugString ""

'--- Set the ImageBase value in the PE Optional Header to the desired address ---

' Note: This is an optional operation for demo purposes. It lets your files have
' their image base set manually to avoid conflicts when your application loads 
' quite a few DLLs having the same base address.
' This operation is optional and can be commented out if not needed.

      PEFileProxy.PostDebugString "Set new ImageBase..."
      if (not PEFileProxy.RebaseImage(&H00500000)) then
        'Issue a warning in case of error
        PEFileProxy.PostDebugString "Can't rebase file"
      end if

'--------------------------------------------------------------------------------

      'Save the file      
      PEFileProxy.PostDebugString "Saving the file..."
      PEFileProxy.SaveAsNewImage ".\release\DemoApp1.exe"

    end if
    PEFileProxy.PostDebugString "Closing this file..."
    PEFileProxy.CloseFile
  end if
end Sub

To view the changes made to the test EXE file, you can open it using Resource Tuner GUI.


SAMPLE SCRIPTS LIBRARY

Once installed Resorce Tuner Console, you will find the Demo Scripts folder nested within the directory where RTC has been installed. Within this Demo folder, there are 12 subdirectories containing script examples and sample executable files.

All sample scripts are ready to run. Select one of the .BAT files located within the Demo Scripts folders to execute the sample script. The script will make changes in the test EXE file. The resulting file will be created in the directory named Release under the directory containing the script.

The Complete Illustrated Step-by-Step Guide To Using Scripts

 Download Resource Tuner Console and learn how it can make you more productive.