Jump to content

binary data replace by offset

Recommended Posts


Hi, im new there and trying to learn how autoit works.

I have files that contains some data (hex) i want to one-click replace , looks like:

FF F0 0F FF F0 0F 06 00 06 00 AE 08 2A 1A 5A 2B 
FC 33 00 00 00 00 00 00 00 00 B8 4D 45 00 FF FF 
C8 00 00 FF 96 00 00 FF 96 00 00 FF 00 00 00 FF 
00 00 00 FF FF FF FF FF 00 00 00 FF 00 00 00 00 
EF E0 1F D8 D7 28 FF F0 0F FF F0 0F CC C3 3C 41

script must replace string from 0x24 till 0x2F ( 960000FF960000FF000000FF )  with  FFF00FFFF00FFFF00FFFF00F.

each file have different data, before and after mentioned adresses , there is no rows etc. so editing possible only by offset.

Ive been trying to use FileOpen but it erases  data before setted position or after

 $FO_APPEND (1) = Write mode (append to end of file)
    $FO_OVERWRITE (2) = Write mode (erase previous contents)

help please

Share this post

Link to post
Share on other sites

Did you try the FileOpen with the Binary option?

$FO_BINARY (16) = Force binary mode (See Remarks).


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>


Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = @ScriptDir & '\test.txt'

    ; Open the file for read/write access.
    Local $hFileOpen = FileOpen($sFilePath, $FO_BINARY)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading/writing the file.")
        Return False

    ; Retrieve the current position in the file.
    Local $iFilePos = FileGetPos($hFileOpen)

    ; Now, adjust the position to the beginning.
    FileSetPos($hFileOpen, 33, $FILE_BEGIN)

   ; Write some data.
    FileWrite($hFileOpen, "ZZZZZZZZZZZZZZZZZZZ" & @CRLF)

    ; Display the contents of the file.
    MsgBox($MB_SYSTEMMODAL, "", FileRead($hFileOpen))

    ; Now, adjust the position back to the previous position.
    FileSetPos($hFileOpen, 0, $iFilePos)

    ; Close the handle returned by FileOpen.

    ; Delete the temporary file.

    Return True
EndFunc   ;==>Example

With $FO_BINARY nothing happens with targeted file at all

Share this post

Link to post
Share on other sites

16+2 erases data before adress and cuts all after

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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.