Sign in to follow this  
Followers 0
H3rdell

Search and replace in a binary file

3 posts in this topic

Hi everyone. I'm a game translator and i'm looking for a script the let me search for a determinate string inside a binary file, and replace the entries with another entrie with same number of bytes. Example: search in a binary file for any entrie: .subb and replace with .tdr0. I need it to force a game to load my translation MOD from folder, instead the original file. I have a script but it have 2 problems. First, it search and replace only the first entrie found, and I need a script to search in the whole file and replace all found entries. Second problem is memory allocating. The one of the files that I need to search and replace inside of it has more than 500 mb. Anyway to do this without load the whole file in ram?

Here my fail script:

$sInFile = @ScriptDir & "\COMMON0.POD" ; Original in file
$sFind = "2e73756262" ; .subb hex to find
$sReplace = "2e74647230" ; .tdr0 hex to replace
$sOutFile = @ScriptDir & "\NEW_COMMON.POD" ; New edited out file
 
_BinaryReplace($sInFile, $sFind, $sReplace, $sOutFile)
 
Func _BinaryReplace($sInFile, $sFind, $sReplace, $sOutFile)
    Local $FO, $FR
    $FO = FileOpen($sInFile, 16) ; Open the file in binary read mode
    $FR = FileRead($FO) ; Read the opened file into a variable
    FileClose($FO) ; Close the opened file now we've read it
    $FR = StringReplace($FR, $sFind, $sReplace, 1); find and replace the hex string
    $FO = FileOpen($sOutFile, 18) ; Open a new empty file in binary write mode
    FileWrite($FO, $FR) ; Write the data to the new opened file
    FileClose($FO) ; Close the newly created file.
EndFunc

If anyone can write me a better script with command line options, it will be great. In the command line I can put the text to find and the text to replace making the script a universal script to search and replace.

Thank you in advance...

Share this post


Link to post
Share on other sites



Hmmm... I wonder if you might be better off with a hex editor like XVI32? It wil open big files n you can search/edit ascii.

I know it's not AutoIT but it might be an easy solution without reinventing the wheel.

Share this post


Link to post
Share on other sites

Yes, but I need a tool to auto do it in installation time. Because of this i'm asking here for help. My translation are distributed with installer, and no way to put inside of it a 500 mb file. But if anyone can help, no problem.

Thank you.

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