Outils pour utilisateurs

Outils du site


tech:notes_langage_c

Ceci est une ancienne révision du document !


Notes langage C

Voir :

Voir aussi :

#include <stdio.h>
#include <string.h>
#include <malloc.h>
 
main(int argc, char **argv)
{
    int i, size;
 
 
#define SEPARATEUR " "
 
    char *cmdline;
 
    for (i=1; i < argc; i++)
       size +=  strlen(SEPARATEUR) + strlen(argv[i]);
 
    cmdline = malloc(size);
 
    if (cmdline ) {
        memset(cmdline, 0, size);
        for (i=1; i < argc; i++) {
            strcat(cmdline, argv[i]);
            strcat(cmdline, SEPARATEUR);
        }
    }
 
    printf("-- %s --", cmdline);
 
    system(cmdline);
 
}

Surcharger un symbole

Voir : https://stackoverflow.com/questions/2146059/limiting-syscall-access-for-a-linux-application

Is the application linked statically?

If not, you may override some symbols, for example, let's redefine socket:

int socket(int domain, int type, int protocol) {

      write(1,"Error\n",6);
      return -1;

}

Then build a shared library:

gcc -fPIC -shared test.c -o libtest.so

Let's run:

nc -l -p 6000

Ok.

And now:

$ LD_PRELOAD=./libtest.so nc -l -p 6000 Error Can't get socket

What happens when you run with variable LD_PRELOAD=./libtest.so? It overrides with symbols defined in libtest.so over those defined in the C library.

tech/notes_langage_c.1759429836.txt.gz · Dernière modification : de Jean-Baptiste

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki