-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmvh.c
62 lines (46 loc) · 1.57 KB
/
mvh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "mvh.h"
#include "common.h"
#include <stdlib.h>
#include <unistd.h>
#define SIZE_COMMAND 256
const char * version= VERSION;
const char * usage = USAGE;
void run_preocess(char * const argv[], const char * ip,
const char * port, const char * visibility )
{
// set the IP of the server
if (ip)
setenv(MVH_SERVER_IP, ip, OVERWRITE);
// set the server port
if (port)
setenv(MVH_SERVER_PORT, port, OVERWRITE);
//set the visibility of the process
if (visibility)
setenv(MVH_PROCESS_VISIBILITY, visibility, OVERWRITE);
// load the shared object within the new process enviroment
if (putenv("LD_PRELOAD=./preload.so") < 0)
die("Failed putenv (LD_PRELOAD)");
// execute the application
if (execv(argv[0], argv) < 0)
die("Failed execv");
}
/*
* Verify the binary file has the verify dynamic symbol
* __lib_start_main
*/
void verify_dynamic_symbol( const char * application){
char command[SIZE_COMMAND]={0};
FILE * fp=NULL;
int nread=0;
snprintf(command, sizeof(command),
"objdump -T %s | grep __libc_start_main", application);
fp = popen((const char *)command, "r");
DPRINT(DEBUG_INFO, "Running : %s\n", command);
memset(command, 0, SIZE_COMMAND);
INTR_RES(fread(command, 1, SIZE_COMMAND, fp), nread);
pclose(fp);
if(strstr(command, "__libc_start_main") == NULL || nread == 0)
irreversible_error("Symbol __libc_start_main not found");
DPRINT(DEBUG_INFO, "Result retrivied from objdump : %s", command);
return;
}