Friday, January 14, 2011

[MIPS/C] Tiny little search function

I thought I would share this, since I'm sure someone else might be able to use it. Some1 asked me to write a function to search for a string and return its location, in order to find functions in a PSP VSH exploit. The function is simple enough, it searches for the first letter of your null-terminated string, and once it does, loops through the string to test if the next characters are the same, if not, it goes back and looks for the first character again. It returns 0 if nothing was found.

Here is the MIPS:

Note that for this to work, you need a constant address, meaning you need to add a .org to your code.

Here is the C:

I'm sure there may be a better way to do it in C, but I was trying to get it to behave as close to the original as possible.

No comments:

Post a Comment