Those are "slices", and the +
simply concatenates them. This is the simplest case of slicing, [start:end]
creates a subsequence of a sequence, starting from position start
inclusive, ending at position end
, exclusive. If one of them is missing (but the :
is there), it is considered to be the beginning/end of the complete sequence. Indices are zero based.
Examples with string:
'Hello World'[1:5]
: 'ello'
'Hello World'[:5]
: 'Hello'
'Hello World'[1:]
: 'ello World'
'Hello World'[:1]+'Hello World'[5:]
: 'H World'
Your loop steps through your data in 4-byte steps, comparing the 4-byte chunk at the current position with the sequence you have in ROB
, and it returns a new sequence without it when it is found (so the f=...
part does not actually modify the existing sequence).
In C you could do that with memcmp
, then malloc
and a pair of memcpy
calls, as you correctly noticed that this data is binary (contains null-characters), so string functions would likely break it.
Hopefully I did not messed up the indices, and then it could look like this:
void* my_function(const void* f, int len){
for(int i=0;i<len;i+=4)
if(memcmp(f+i,ROB,4)==0){
void* ret=malloc(len-4);
memcpy(ret,f,i);
memcpy(ret+i,f+i+4,len-i-4);
return ret;
}
return NULL; // or have it die somehow
}