-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgem-compiler.pl
72 lines (57 loc) · 1.48 KB
/
gem-compiler.pl
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
#!/usr/bin/perl
package gem_compiler;
use strict;
use warnings;
print "Iterkocze Gem Compiler 0.0.0.00....00.00000.18\n";
my $file = $ARGV[0] or die "You have to provide the source code file.";
open my $info, $file or die "Could not open $file: $!";
#my $feet
my $OUTFILE = substr($ARGV[0], -4) = "";
$OUTFILE .= ".asm";
my $output_string = "";
$output_string .= "
section .data\n
";
while( my $line = <$info>) {
if (rindex($line, "Remember", 0) == 0) {
my @def = split(' ', $line);
my $string = $def[1];
my $var_name = $def[3];
$output_string .= "
${var_name}: db ${string},10\n
${var_name}Len equ \$ - ${var_name}\n
";
}
last if $. == 2;
}
$output_string .= "
global _start\n
section .text\n
_start:\n
";
open my $info2, $file or die "Could not open $file: $!";
while( my $line = <$info2>) {
if (rindex($line, "Write", 0) == 0) {
my @def = split(' ', $line);
my $var_name = $def[1];
$output_string .= "
mov eax, 4\n
mov ebx, 1\n
mov ecx, ${var_name}\n
mov edx, ${var_name}Len\n
int 0x80 \n
";
}
last if $. == 2;
}
$output_string .= "
mov eax, 1\n
int 0x80\n
";
close $info;
close $info2;
open(FH, '>', $OUTFILE) or die $!;
print FH $output_string;
system("nasm", "-f elf64", $OUTFILE, "-o out.o");
system("ld", "out.o", "-o", "program");
system("rm", "out.o");