Learn to share

Compile ELF on Windows: Islxss

| Comments

With recent bash addition on windows, I simply love the hybrid environment. In this post, we will create Linux executuable (islxss) which is compiled on Windows bash. The function of this exectuable (islxss) is to verify, whether I am running inside LXSS or not.

Step-1) Write a c program, which detects whether I am running inside LXSS or not

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <dirent.h>
#include <string.h>

int main() {
        DIR *d;
        struct dirent *de;
        d = opendir("/dev");
        while((de = readdir(d)) != NULL)
                if(!strcmp(de->d_name, "lxss")) {
                        printf("I'm running inside LXSS!\n");
                        closedir(d);
                        return 0;
                }
        closedir(d);
        printf("LXSS not detected\n");
        return 1;
}

Step-2) Compile the code with static flag

1
gcc -static -o islxss islxss.c

Finally, I move islxss executable to /usr/local/bin on my windows and other cloud servers.

Comments