Proof of suckage, early 2008
anomit | September 2, 2009
I applied for the Etherboot project in the 2008 edition of GSoC. Looking back it doesn’t look like a wise decision at all since my C skills sucked hairy camel balls back then.
Today I was reading through some shellcode and buffer overflow attack basics and just about an hour ago from now I happened to remember this certain question that a couple of developers from the Etherboot project asked me during the IRC screening of potential candidates. Right now it took me less than 5 minutes to come up with a hopefully correct solution. Back then I was absolutely at a loss how to even begin coding the problem. The logic of the problem is really simple but I had no idea how to put it down in concrete code. Take a look at the problem and the solution below and laugh at me.
/**
* Search memory for a 32-bit pattern match on a 32-bit boundary
*
* @v start Start address of region to search
* @v len Length of region, in bytes
* @v pattern Pattern to search for
* @v mask Mask of which bits in the pattern we care about
* @ret found First address at which pattern is found
*
*
* The mask is used to indicate that we care about only part of the
* pattern matching. For example, suppose we wanted to search the
* region for words of the form
*
* 0xabcdXXXX
*
* where X indicates that we don't care about that digit (i.e. that we
* would want to match on 0xabcd0000, or 0xabcd1234, or 0xabcdffff,
* etc.). We would then call memsearch() as
*
* memsearch ( start, len, 0xabcd0000, 0xffff0000 );
*/
#include <stdint.h>
#include <stdio.h>
uint32_t *memsearch ( uint32_t *start, size_t len, uint32_t pattern, uint32_t mask )
{
uint32_t s = (uint32_t)start;
while(len--)
{
s++;
if ( (s & mask) == (pattern & mask) )
return (uint32_t *)s;
}
return NULL;
}
int main()
{
uint32_t result;
printf("Result is: %x", (result=(uint32_t)memsearch ( 0x00000000, 4294967295u,\
0x000000df, 0x000000ff ))?result:0);
return 0;
}







Remember you asked me the solution and I gave such
Manish Sinha | September 2, 2009Remember you asked me the solution and I gave such a dumb solution which wouldn’t have worked ever. I should have been ashamed at the solution which I proposed.
Hehe. Of course I remember
anomit | September 2, 2009Hehe. Of course I remember
This seems correct enough — at least in concept. Help
Aditya Mukherjee | September 9, 2009This seems correct enough — at least in concept. Help me out?
Er..help you out with? If you are talking about my
anomit | September 9, 2009Er..help you out with? If you are talking about my solution, it _is_ correct