Jump to content

How can you change hex values in a bin file or any file?


wkeeter
 Share

Recommended Posts

I've been searching and trying things for days and i'm here

to tell you im confused as heck and cant get nothing to work.

Senario:

FileName = test.bin

In a hex editor i can goto offset 0x350 and i see example "Please Change Me Now"

But i want it changed to "Changed" or what ever.

Ok 2 delimas i'm running into is one changing this hex value, and the other is when

you wright "Changed" it leaves "Change Me Now" still in the test.bin file.

I would also like to know how to change these values to null or 00's in the hex value

becuase they are no longer needed.

Really what i'm looking for is some sample code if at all possible because i really am confused.

And the closest i've found in the forums is this post http://www.autoitscript.com/forum/index.php?showtopic=12604

But that even confuses me more. :P

I'd even be happy if someone knew of a commandline utility that would accomplish the same thing but googling for days hasn't brought much help either.

Any help would be appreciated.

Thanks

Link to comment
Share on other sites

I would Zedna

If i could read it. :P

I tried to spend some time with a translator but even a translator dont even know what a lot of these words are.

Any chance u can convert that to english?

Thanks

Try something like this you can simplicify it even more...

#NoTrayIcon
#include "APIFileReadWrite.au3"

Global $def_rows, $count

; 00000073: 65 FC
_FileReadToArray('c:\file_def.txt', $def_rows)

$count = $def_rows[0]
Dim $values[$count + 1][3]
$values[0][0] = $count

For $i = 1 To $count
    $line = StringStripWS($def_rows[$i],3)
   
    $line = StringSplit($line, ' ') ; 00000073: 65 FC
    If $line[0] <> 3 Then
        MsgBox(48,"Error","Definition file contains bad data")
        Exit
    EndIf
   
    $line[1] = StringTrimRight($line[1], 1) ; remove char :
    $values[$i][0] = $line[1]
    $values[$i][1] = $line[2]
    $values[$i][2] = $line[3]
Next

$f = _APIFileOpen('c:\file_to_patch.exe')

For $i = 1 To $values[0][0]
    _APIFileSetPos($f, Dec($values[$i][0]))
    $written = _APIFileWrite($f, $values[$i][2], 1)
    If $written <> 1 Then
        MsgBox(48,"Error","Error in writing data")
        Exit
    EndIf
Next

_APIFileClose($f)

Func _FileReadToArray($sFilePath, ByRef $aArray)
    Local $hFile
   
    $hFile = FileOpen($sFilePath, 0)
   
    If $hFile = -1 Then
        SetError(1)
        Return 0
    EndIf
   
    $aArray = StringStripCR( FileRead($hFile, FileGetSize($sFilePath)))
   
    ; remove last @CRLF to avoid empty last line in array of definition values
    If StringRight($aArray,1) = @LF Then $aArray = StringTrimRight($aArray,1)
    $aArray = StringSplit( $aArray, @LF)
   
    FileClose($hFile)
    Return 1
EndFunc
Link to comment
Share on other sites

Try something like this you can simplicify it even more...

#NoTrayIcon
#include "APIFileReadWrite.au3"

Global $def_rows, $count

; 00000073: 65 FC
_FileReadToArray('c:\file_def.txt', $def_rows)

$count = $def_rows[0]
Dim $values[$count + 1][3]
$values[0][0] = $count

For $i = 1 To $count
    $line = StringStripWS($def_rows[$i],3)
   
    $line = StringSplit($line, ' ') ; 00000073: 65 FC
    If $line[0] <> 3 Then
        MsgBox(48,"Error","Definition file contains bad data")
        Exit
    EndIf
   
    $line[1] = StringTrimRight($line[1], 1) ; remove char :
    $values[$i][0] = $line[1]
    $values[$i][1] = $line[2]
    $values[$i][2] = $line[3]
Next

$f = _APIFileOpen('c:\file_to_patch.exe')

For $i = 1 To $values[0][0]
    _APIFileSetPos($f, Dec($values[$i][0]))
    $written = _APIFileWrite($f, $values[$i][2], 1)
    If $written <> 1 Then
        MsgBox(48,"Error","Error in writing data")
        Exit
    EndIf
Next

_APIFileClose($f)

Func _FileReadToArray($sFilePath, ByRef $aArray)
    Local $hFile
   
    $hFile = FileOpen($sFilePath, 0)
   
    If $hFile = -1 Then
        SetError(1)
        Return 0
    EndIf
   
    $aArray = StringStripCR( FileRead($hFile, FileGetSize($sFilePath)))
   
    ; remove last @CRLF to avoid empty last line in array of definition values
    If StringRight($aArray,1) = @LF Then $aArray = StringTrimRight($aArray,1)
    $aArray = StringSplit( $aArray, @LF)
   
    FileClose($hFile)
    Return 1
EndFunc
Thank You Much!
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...