-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac.c
81 lines (63 loc) · 1.52 KB
/
ac.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>
#define A "nasm -f elf ./"
#define B ".asm"
#define C "ld -m elf_i386 -o ./"
#define D " ./"
#define E ".o"
int main(int argc, char * argv[]){
if(argc < 2){
printf("Usage\n %s <filename(without .asm)>\n", argv[0]);
exit(-1);
}
int status;
int size = 0;
char *command;
size += sizeof(A) * sizeof(char);
size += sizeof(B) * sizeof(char);
size += sizeof(argv[1]) * sizeof(char);
size += sizeof(char);
command = (char *)malloc(size);
if(!command){
printf("\n\n Error on nasm command malloc\n");
exit(-1);
}
strcpy(command, A);
strcat(command, argv[1]);
strcat(command, B);
strcat(command, "\x00");
printf("\n\n Assemble command is : %s \n\n", command);
status = system(command);
if(status != 0){
printf("\n\nError on assemble!\nExit code is %d\n", status);
exit(-1);
}
free(command);
size = 0;
size += sizeof(C) * sizeof(char);
size += sizeof(D) * sizeof(char);
size += sizeof(E) * sizeof(char);
size += sizeof(argv[1]) * sizeof(char) * 2;
size += sizeof(char);
command = (char *)malloc(size);
if(!command){
printf("\n\n Error on ld command malloc\n");
exit(-1);
}
strcpy(command, C);
strcat(command, argv[1]);
strcat(command, D);
strcat(command, argv[1]);
strcat(command, E);
strcat(command, "\x00");
printf("\n\n ld command is : %s \n\n", command);
status = system(command);
if(status != 0){
printf("\n\nError on linking!\nExit code is %d\n", status);
exit(-1);
}
free(command);
puts("\n\nSuccess!\n");
exit(0);
}