Jump to content

replace hex value in a file


 Share

Recommended Posts

Cattura.thumb.PNG.25bf352df15018ec68f46c

I want to replace this value with autoit, usually I do that with HxD editor and replace selection utility.

I'm able to find the exact value but I do not understand how to replace it, can someone explain me how to do it?

Thx.

My code

#include <String.au3>
#include <Array.au3>
$file = "myfile" 
$read = FileRead($file)
$filhex = _StringToHex($read)
$split = StringRegExp($filhex, "(?s).{1,2}", 3)

$kb = 0
$sp = ""
$val = ""
$row = 0

For $i = 0 To UBound($split) - 1
    $kb += 1
    If $kb < 16 Then
        $sp = "  "
        $val &= $split[$i] & $sp

    ElseIf $kb = 16 Then
        $sp = @CRLF
        $val &= $split[$i] & $sp
        $kb = 0
        $row += 1
    EndIf
Next

ConsoleWrite($split[53]&@LF)

 

Link to comment
Share on other sites

local $hFile=FileOpen("1.exe",512)
Local $sData=FileRead($hFile)
FileClose($hFile)

Local $hFile2=FileOpen("2.exe",514)
FileWrite($hFile2,StringReplace($sData,Chr(0x2B),Chr(0x2A),1))
FileClose($hFile2)

That change the first found 2B for 2A.

 

Saludos

Link to comment
Share on other sites

local $hFile=FileOpen("1.exe",512)
Local $sData=FileRead($hFile)
FileClose($hFile)

Local $hFile2=FileOpen("2.exe",514)
FileWrite($hFile2,StringReplace($sData,Chr(0x2B),Chr(0x2A),1))
FileClose($hFile2)

That change the first found 2B for 2A.

 

Saludos

Thx one step forward...

I used one array because I need to replace a lot of values dynamically without knowing the value inside the file but only the exactly position.

For example at the position of the Array [12][22].......N replace with [AE][2B] ....N

In your example the target is the first occurrence... but I need to replace multiples values in one loop. Usually I used _FileReadToArray but Im not sure with Hex values the right way to do it.

:>

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

×
×
  • Create New...