Jump to content

Replace a HEX string in a Binary?


Irongeek
 Share

Recommended Posts

Hi all,

What I wish to do is open up dhcpcsvc.dll (or a copy off it since it may be locked), search for "MSFT 5.0" and replace it with another 8 byte string. _ReplaceStringInFile can't seem to handle the big binary blob, is there a straight forward way to do this task in Autoit? The HEX equivalent to "MSFT 5.0" is 4d53465420352e30. Can I search for it and replace it in some way? Thanks.

Link to comment
Share on other sites

Hi,

String play to replace the 8 byte string, then write it to a new file..

Here's a crude no error checking example..

$sInFile = @SystemDir & "\dhcpcsvc.dll" ; Original in file
$sFind = "4D53465420352E30" ; MSFT 5.0 Original hex to find
$sReplace = "534D4153484C5921" ; SMASHLY! New hex to replace
$sOutFile = @ScriptDir & "\New_dhcpcsvc.dll" ; 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

Cheers

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...