robmcmullen / omnivore

Hex editor and debugging emulator, sponsored by the Player/Missile Podcast
Mozilla Public License 2.0
53 stars 7 forks source link

Remove use of strcasestr from libudis/libudis.pyx #260

Open TikiBill opened 4 years ago

TikiBill commented 4 years ago

Should you want to support Windows, the use of strcasestr needs to be removed from libudis.pyx as that function is not (easily, at all?) available in Windows. Not sure this is the best alternative (or if it even works as I did not test it), but here are how I changed search() to get it to compile:

from libc.string cimport strstr, strlen
...
    cdef search(...)
        ...
        cdef char lc_text[4096];
        cdef char lc_search[4096];
        ...
            if match_case:
                found = strstr(text, search)
            else:
                # strcasestr is libc only and not (easily) available in Windows.
                #   and no #ifdef support in cython.
                # found = strcasestr(text, search)
                if strlen(text) <= 4096 and strlen(search) <= 4096:
                    lc_text = text.lower()
                    lc_search = search.lower()
                    found = strstr(lc_text, lc_search)
                else:
                    found = NULL