Skip to content

Fix issue with extension check - #1

Open
klezVirus wants to merge 1 commit into
S4ntiagoP:syscallsfrom
klezVirus:patch-1
Open

Fix issue with extension check#1
klezVirus wants to merge 1 commit into
S4ntiagoP:syscallsfrom
klezVirus:patch-1

Conversation

@klezVirus

Copy link
Copy Markdown

Hi man, the syscall version was not working because the file check against the binary was not working when compiled with MSVC. Indeed, when MSVC is used, the unistd function strcasecmp is replaced by stricmp. However, completely unexpectedely, while strcasecmp return 0 when the two strings are equal, the custom implementation stricmp return 0 when they are different. Indeed, following through the definition in donut.h:

#if defined(_MSC_VER)
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")
#define strcasecmp stricmp

And if we go and ivestigate in in clib.c, we can see that the stricmp implementation is:

int stricmp(const char *str1, const char *str2) {
    while (*str1 && *str2) {
      if ((*str1 | 0x20) != (*str2 | 0x20)) {
        return 0;
      }
      str1++; str2++;
    }
    return *str2 == 0;
}

Which evidentely return 0 if the two strings are different.

Hi man, the syscall version was not working because the file check against the binary was not working when compiled with MSVC.  Indeed, when MSVC is used, the unistd function strcasecmp is replaced by stricmp. However, completely unexpectedely, while `strcasecmp` return 0 when the two strings are equal, the custom implementation `stricmp` return 0 when they are different. Indeed, following through the definition in `donut.h`:

```
#if defined(_MSC_VER)
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")
#define strcasecmp stricmp
```

And if we go and ivestigate in in `clib.c`, we can see that the `stricmp` implementation is:

```
int stricmp(const char *str1, const char *str2) {
    while (*str1 && *str2) {
      if ((*str1 | 0x20) != (*str2 | 0x20)) {
        return 0;
      }
      str1++; str2++;
    }
    return *str2 == 0;
}
```
Which evidentely return 0 if the two strings are different.
@klezVirus

Copy link
Copy Markdown
Author

This is just a workaround for MSVC, actually. I think it would be better to change the stricmp implementation and re-change all of its occurrencies in the code when required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant