tebasuna51 Posted Tuesday at 11:02 AM Posted Tuesday at 11:02 AM I want modify some bytes in one big file, there are a way to do that? There are: $FO_APPEND (1) = Write mode (append to end of file) $FO_OVERWRITE (2) = Write mode (erase previous contents) But not a Read/Write mode to go to a position, modify some bytes and leave the rest intact. The $FO_BINARY (16) = Force binary mode, don't help.
Nine Posted Tuesday at 11:55 AM Posted Tuesday at 11:55 AM Maybe this : #include <Constants.au3> Local $hFile = FileOpen("Test.txt", $FO_APPEND) FileSetPos($hFile, 5, $FILE_BEGIN) FileWrite($hFile, "12345") FileClose($hFile) TheSaint 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Solution Musashi Posted Tuesday at 03:43 PM Solution Posted Tuesday at 03:43 PM (edited) Or maybe this : #include <Constants.au3> Global $bInsert = "0xFFFFFF" Global $hFile = FileOpen("mslogo.jpg", BitOR($FO_APPEND, $FO_BINARY)) FileSetpos($hFile, 20, $FILE_BEGIN ) ; Pos = 20 FileWrite($hfile, $bInsert) FileClose($hFile) ==> Info : A better way to work with binary data is to use a struct ! I would advise you to always create a backup of the file before you change it - safety first Edited Tuesday at 03:47 PM by Musashi pixelsearch and TheSaint 2 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
TheSaint Posted Tuesday at 04:33 PM Posted Tuesday at 04:33 PM And you can also use other methods, especially if this is just a text file. A very simple approach if you know your insertion point, and it is based on unique text, is to FileRead your file, then use StringSplit with the unique text, then add all three parts together and then FileWrite back to the file with that, overwriting it. The only tricky bit, is if you are not familiar with an array, which is what StringSplit creates. But as suggested, back your file up first, just in case. Have a play, and any further questions, keep asking here. Musashi 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
tebasuna51 Posted yesterday at 07:39 AM Author Posted yesterday at 07:39 AM Thanks all. Since my file isn't a text file, I need to open it as $FO_APPEND+$FO_BINARY. If it opens as a text file by default, writing adds an unwanted extra chr(15) (?). I use this to change the channel mask (4 bytes) of a wav file (maybe larger than 10 GB). Rewriting the entire file takes time and space. TheDcoder 1
tebasuna51 Posted yesterday at 08:42 AM Author Posted yesterday at 08:42 AM Code used: $fh = FileOpen($wav_file, 17) ; $FO_APPEND (1) + $FO_BINARY (16) = 17 FileSetPos($fh, $pos_mask, 0) ; $FILE_BEGIN (0) = Beginning of the file. FileWrite($fh, number($mask,1)) ; $NUMBER_32BIT (1) = 32bit integer (to be sure always 4 bytes) FileClose($fh) TheSaint 1
TheSaint Posted 17 hours ago Posted 17 hours ago Goodo. I remember having issues once upon a time (some years ago) with surround sound (multiple channel) wav files not being recognized as such, due to some header issue etc. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now