Skip to content

Instantly share code, notes, and snippets.

@0x75
Created June 29, 2013 15:24
Show Gist options
  • Save 0x75/5891532 to your computer and use it in GitHub Desktop.
Save 0x75/5891532 to your computer and use it in GitHub Desktop.
exc
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <spawn.h>
#include <sys/wait.h>
#ifndef _POSIX_SPAWN_DISABLE_ASLR
#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
#endif
int
main(int argc, char* argv[], char* env[])
{
pid_t pid;
int err;
posix_spawnattr_t attr;
if ( argc == 0 )
{
printf("Please specify the full path to an executable.\n”");
exit(1);
}
if ( posix_spawnattr_init(&attr) )
{
perror("Couldn’t initialize attributes for posix_spawn");
exit(1);
}
if ( posix_spawnattr_setflags(&attr, _POSIX_SPAWN_DISABLE_ASLR) )
{
perror("Couldn’t add _POSIX_SPAWN_DISABLE_ASLR to attributes");
exit(1);
}
if ( posix_spawn(&pid, argv[1], NULL, &attr, argv, env) )
{
perror("posix_spawn failed");
exit(1);
}
/* Wait for the spawned process to exit */
(void)wait(NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment