-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathpbsv.c
83 lines (58 loc) · 1.49 KB
/
pbsv.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define ip_socket (*((int*)(0x1411b714)))
//Address of the socket handle
void sa(){
}
void sb(){
char bufexec[1024];
char bufcwd[1024];
char *bufptr = bufexec;
int i = 0;
char *execute[256];
close(ip_socket); //close the prior socket to open a new one at same port
FILE * fh = fopen("execute.txt", "r");
if(!fh)
_exit(0);
memset(bufexec, 0, sizeof(bufexec));
memset(bufcwd, 0, sizeof(bufcwd));
fgets(bufexec, sizeof(bufexec) -1, fh);
fgets(bufcwd, sizeof(bufcwd) -1, fh);
if(*bufptr){
execute[i] = bufptr;
i++;
}
while(*bufptr){
if(*bufptr == ' ' && bufptr[1] != ' '){
execute[i] = &bufptr[1];
i++;
*bufptr = 0;
}
bufptr++;
}
execute[i] = NULL;
bufptr = bufcwd;
while(*bufptr != 0 && *bufptr != ';' && *bufptr != '\n' && *bufptr != EOF){
bufptr++;
}
*bufptr = 0;
if(*bufcwd){
chdir(bufcwd);
}
FILE * fdout;
fdout=fopen("exec_status.txt", "w");
if(fdout){
fwrite("Execute file: ", strlen("Execute file: "), 1 ,fdout);
fwrite(execute[0], strlen(execute[0]), 1 ,fdout);
fclose(fdout);
}
execvp(execute[0], execute);
fdout=fopen("exec_error.txt", "w");
if(fdout){
fwrite("Exec failed\n", strlen("Exec failed\n"), 1 ,fdout);
fclose(fdout);
}
_exit(0);
}