Searching/patching binary file


#1

I have to patch binary file. Also have to find a pattern/string in the file, to determine proper position/offset for patching.

What is the best way to do it with JUCE ? I was thinking to load file into MemoryBlock - is this the right approach ?

Are there any JUCE functions to search memory block for a pattern ?

Sorry for rookie questions :)


#2

Anyone ?

Thank you !!!


#3


Here's how to find the position using plain C++, provided that you have the data inside any kind of container offering a pointer to the data and/or iterators:

auto offset = std::distance (​
    data.begin(), 
    std::search (data.begin(), data.end(), pattern.begin(), pattern.end()));

(Replace begin/end with ptr/ptr+size if you have plain pointers instead of iterators)


#4

Thank you - simple & elegant solution ... have to check this standard library more often :)