richietheprogrammer Posted April 7, 2011 Share Posted April 7, 2011 Hello, I am trying to delete every 840 bytes from a file, and keep the rest. How would I do that? Thanks for any help Link to comment Share on other sites More sharing options...
trancexx Posted April 7, 2011 Share Posted April 7, 2011 Hello, I am trying to delete every 840 bytes from a file, and keep the rest. How would I do that? Thanks for any help But if you delete every 840 bytes then you'll delete all. Or you mean every other? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
richietheprogrammer Posted April 7, 2011 Author Share Posted April 7, 2011 But if you delete every 840 bytes then you'll delete all. Or you mean every other?Haha good point. Well basically I want to delete "3A" bytes every 840 bytes. So start by deleting 3A bytes, then jump 840 bytes, delete 3A bytes, jump another 840 bytes... Thanks for requiring clarification! Link to comment Share on other sites More sharing options...
jchd Posted April 7, 2011 Share Posted April 7, 2011 Read your input as binary then repeatedly use BinaryMid to grab parts you need and rewrite that back to wherever you want. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
richietheprogrammer Posted April 7, 2011 Author Share Posted April 7, 2011 Read your input as binary then repeatedly use BinaryMid to grab parts you need and rewrite that back to wherever you want.Thank you. Can you please provide a sample code? I'd appreciate it Link to comment Share on other sites More sharing options...
jchd Posted April 7, 2011 Share Posted April 7, 2011 (edited) Sorry for delay, had to taxi kids around, eat, etc. If your input is a file, then this should work (no much time to test it really). #include <Constants.au3) Local $hInpf = FileOpen("myinpfile.bin", 16) If $hInpf <> -1 Then Local $hOutf = FileOpen("myoutfile.bin", 2 + 16) If $hOutf <> -1 Then Local $ret, $data, $done Do $ret = FileSetPos($hInpf, 58, $FILE_CURRENT) If Not $ret Then ExitLoop $data = FileRead($hInpf, 840) $done = (@error = -1) ; read incomplete (EOF reached) but maybe something to write anyway FileWrite($hOutf, $data) ; process write error until $done FileClose($hInpf) FileClose($hOutf) Else ; process error EndIf ; process error EndIf Edited April 7, 2011 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
richietheprogrammer Posted April 7, 2011 Author Share Posted April 7, 2011 (edited) Sorry for delay, had to taxi kids around, eat, etc. If your input is a file, then this should work (no much time to test it really). #include <Constants.au3) Local $hInpf = FileOpen("myinpfile.bin", 16) If $hInpf <> -1 Then Local $hOutf = FileOpen("myoutfile.bin", 2 + 16) If $hOutf <> -1 Then Local $ret, $data, $done Do $ret = FileSetPos($hInpf, 58, $FILE_CURRENT) If Not $ret Then ExitLoop $data = FileRead($hInpf, 840) $done = (@error = -1) ; read incomplete (EOF reached) but maybe something to write anyway FileWrite($hOutf, $data) ; process write error until $done FileClose($hInpf) FileClose($hOutf) Else ; process error EndIf ; process error EndIf No worries, and thanks a lot for this! However, I cannot get it to function the way I want it to. It is deleting the first 58 bytes correctly, but then it is not jumping and deleting the rest correctly. it seems like it is miscounting. Also, the 840 is in hex, so really I want it 2112, assuming the script counts in dec? But anyways, maybe there is something wrong with counting 2112 every time, because if we remove the first 58, then shouldn't we count (2112 minus 58) from the new file so we can get to the next set? Thanks again for your help!!! (I think if we just add 2054 it will jump correctly.) Do you agree? Edited April 7, 2011 by richietheprogrammer Link to comment Share on other sites More sharing options...
jchd Posted April 7, 2011 Share Posted April 7, 2011 OK I misunderstood your "jump" offset. Try this working( for me) example: #include <Constants.au3> Local $htest = FileOpen(@ScriptDir & "\myinpfile.bin", 2 + 16) Local $ch = Asc('a') For $i = 1 To 10 For $j = 1 To 58 FileWrite($htest, Chr($ch)) Next $ch += 1 For $j = 1 To 2112 - 58 FileWrite($htest, Chr($ch)) Next $ch += 1 Next FileClose($htest) Local $hInpf = FileOpen(@ScriptDir & "\myinpfile.bin", 16) If $hInpf <> -1 Then Local $hOutf = FileOpen(@ScriptDir & "\myoutfile.bin", 2 + 16) If $hOutf <> -1 Then Local $ret, $data, $done Do $ret = FileSetPos($hInpf, 58, $FILE_CURRENT) If Not $ret Then ExitLoop $data = FileRead($hInpf, 2112 - 58) $done = (@error = -1) ; read incomplete (EOF reached) but maybe something to write anyway FileWrite($hOutf, $data) ; process write error until $done FileClose($hInpf) FileClose($hOutf) Else ; process error EndIf ; process error EndIf This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
richietheprogrammer Posted April 7, 2011 Author Share Posted April 7, 2011 Thanks a lot ! 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