Skrip Posted August 27, 2008 Share Posted August 27, 2008 How can you write to the first line inside...say... a picture file? Like so if you open it in a hex editor, it will show the text on the first line. [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 27, 2008 Share Posted August 27, 2008 How can you write to the first line inside...say... a picture file? Like so if you open it in a hex editor, it will show the text on the first line.You would just write it in binary mode, but the change may cause the rest of the file format to be unrecognized. So you would have to know what can be changed and still preserve normal operation of the file. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Skrip Posted September 2, 2008 Author Share Posted September 2, 2008 Can I get an example on how to use binary mode..? [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
cppman Posted September 2, 2008 Share Posted September 2, 2008 (edited) Binary files don't exactly have "lines". And all hex editors are different in the length of the "lines" that are displayed. Some will display the data in lines of 16 bytes, and others will display it in lines of 8 bytes. I'm not sure how you would actually write a specifically sized value to a binary file in AutoIt, but to write a value (of unknown size?) you would do something like this: $hFile = FileOpen("test.bin", BitOR(16, 1)) FileWrite($hFile, Binary(547)) ;should write 4 bytes FileClose($hFile) Edited September 2, 2008 by cppman Miva OS Project Link to comment Share on other sites More sharing options...
Skrip Posted September 2, 2008 Author Share Posted September 2, 2008 (edited) How do I know the value for like..letters? Er...would it be something like this? $bin = StringToBinary("Test") $hFile = FileOpen("test.bin", BitOR(16, 1)); Okay. What exactly is the BitOR for? I think I know, but not sure. FileWrite($hFile, $bin);should write 4 bytes FileClose($hFile) EDIT: Yes..This worked perfectly actually. Now how exactly could I write it to the top of the file, and not at the end? Edited September 2, 2008 by Firestorm [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
cppman Posted September 2, 2008 Share Posted September 2, 2008 BitOR(16, 1) is combining the "Binary" and "Write" flags, which tells AutoIt how to open the file. Its basically saying, I want to write to this binary file. As for the value of letters, you simply get the ASCII (or Unicode) value (that is what StringToBinary does). The size of the file will be: size of character * length of string So, if you are using unicode, and each character is 2 bytes, what you just wrote to the file would be 8 bytes. If you used ASCII, the size of the file would be 4 bytes. Miva OS Project Link to comment Share on other sites More sharing options...
Skrip Posted September 2, 2008 Author Share Posted September 2, 2008 Okay. I understand. The examples above seem to work perfectly. Now how exactly could I write it to the top of the file, and not at the end? [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
cppman Posted September 2, 2008 Share Posted September 2, 2008 Look at _WinAPI_CreateFile, and _WinAPI_SetFilePointer. _WinAPI_SetFilePointer isn't part of the WinAPI lib in AutoIt, so here it is below:Func _WinAPI_SetFilePointer($hFile, $nDistance, $nMethod = 0) $nRet = DllCall("kernel32.dll", "dword", "SetFilePointer", "ptr", $hFile, "long", $nDistance, "ptr", 0, "dword", $nMethod) return $nRet[0] EndFuncBasically, just open the file with the fist function, then set the position you would like to start writing to with the second function. Miva OS Project Link to comment Share on other sites More sharing options...
Skrip Posted September 2, 2008 Author Share Posted September 2, 2008 Thank you. [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
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