Files
perfect/tools/no_aslr.cpp
Carl Pearson 3a86aef546 Squashed commit of the following:
commit 3007df0d153ade6d328321dad8f88d63869159c8
Merge: 7557851 cd14d68
Author: Carl Pearson <pearson@illinois.edu>
Date:   Wed Sep 25 09:59:54 2019 -0500

    Merge branch 'master' into feature/aslr

commit 7557851508f0e1c2d75244267c5f78fb3d1ca303
Author: Carl Pearson <pearson@illinois.edu>
Date:   Tue Sep 24 07:50:15 2019 -0500

    wish list

commit 0bbbac31f354c16ae1942dbfe4683a66ec260498
Author: Carl Pearson <pearson@illinois.edu>
Date:   Tue Sep 24 07:49:36 2019 -0500

    ASLR documentation

commit f1ae37e057792696a739e30ecdbd09e071b8a7d4
Author: Carl Pearson <pearson@illinois.edu>
Date:   Tue Sep 24 07:45:54 2019 -0500

    add ASLR interface
2019-09-25 10:03:32 -05:00

78 lines
1.6 KiB
C++

#include <iostream>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <cstring>
#include <vector>
#include "perfect/aslr.hpp"
using namespace perfect;
int main(int argc, char **argv) {
using namespace perfect;
PERFECT(init());
pid_t pid;
int status;
pid = fork();
if (pid == -1) {
// pid == -1 means error occured
std::cerr << "can't fork, error occured\n";
exit(EXIT_FAILURE);
} else if (pid == 0) {
// in the child process
// skip the first argument, which is this program
std::vector<char*> args;
for (int i = 1; i < argc; ++i) {
args.push_back(argv[i]);
}
assert(args.size() > 0);
args.push_back(nullptr);
PERFECT(disable_aslr());
// the execv() only return if error occured.
// The return value is -1
return execvp(args[0], args.data());
} else {
// parent process
if (waitpid(pid, &status, 0) > 0) {
if (WIFEXITED(status) && !WEXITSTATUS(status)) {
// success
exit(status);
}
else if (WIFEXITED(status) && WEXITSTATUS(status)) {
if (WEXITSTATUS(status) == 127) {
// execv failed
std::cerr << "execv failed\n";
exit(status);
} else {
std::cerr << "program terminated normally, but returned a non-zero status\n";
exit(status);
}
} else {
printf("program didn't terminate normally\n");
exit(status);
}
} else {
// waitpid() failed
printf("waitpid() failed\n");
exit(EXIT_FAILURE);
}
exit(0);
}
return 0;
}