I have an application that have to replace certain byte arrays (all occurences) in a 4gb file (like HxD), and i would like help in that search of offsets, i need a function that search (fast) in the big file (4gb) and return the decimal offset of this byte array so i can replace it (i already have the replace method, i just need to get the decimal offset of each byte arrays). Thanks for reading this! PS: Sorry for my english.
Asked
Active
Viewed 534 times
-2
-
1Consult [How to read file over 2GB](https://stackoverflow.com/questions/52861230/). – Dour High Arch Nov 05 '18 at 21:07
-
@DourHighArch too long.... (120 seconds for one byte array searching) – darkshoz Nov 06 '18 at 18:53
-
Get it working before you start worrying about how long it takes. Why do you think 120 seconds is too long for a multi-GB file? If it really is, consider using `BinaryReader(BufferedStream(...))` but only after you have it working. – Dour High Arch Nov 07 '18 at 01:17
-
The problem is that the program is replacing byte array normally but i want to avoid updating the offset each time, i need to find a way to get the offset automatically. – darkshoz Nov 07 '18 at 13:52
-
130 seconds is too long because the idea of the program is the speed, so if i can’t be faster tell me.. – darkshoz Nov 07 '18 at 13:52
1 Answers
0
I'd have a look at MemoryMappedFile.CreateFromFile
Method - you can then create a MemoryMappedViewStream
, and create a buffered stream to use to help find the array. This post has some suggestions on doing the last part: Best way to find position in the Stream where given byte sequence starts.

Dylan Nicholson
- 1,301
- 9
- 23
-
What problems did you have trying to use MemoryMappedFile.CreateFromFile? – Dylan Nicholson Nov 06 '18 at 22:14