flat assembler
Message board for the users of flat assembler.

Index > Linux > Simple Perl Script, unistd2asm.pl

Author
Thread Post new topic Reply to topic
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer
Turns the #define __NR_(system call) (number)
into fasm format:

sys.(system call) = (number)

Code:
#!/usr/bin/perl

use warnings;

while (<>){
        if ($_ =~ s/#define __NR_(\w*)\s*(\d*)/sys.$1 =\t$2/){
                $_ =~ s/\/\*.*\*\///; #removes C comments
                $_ =~ s/__NR_/sys./; #removes extra NR stuff and turns into sys.
                print $_;
        }
}
    


And I am still workin gon this one, sys2macro.pl, but currently itturns sys.(system call) = (number) into

macro SYS.(system call) arg1, arg2, arg3{
mov eax, (number)
if arg1 eq
else
mov ebx, arg1
end if
if arg2 eq
else
mov ecx, arg2
end if
if arg3 eq
else
mov edx, arg3
end if
}

Not perfect, but what can you do? Here is what i have so far in my perl code:

Code:
#!/usr/bin/perl

use warnings;

while (<>){
        if ($_ =~ /sys\.(\w*) =\t(\d*)/){
                print "\nmacro SYS.$1 arg1, arg2, arg3{\n";
                print "\tmov eax, $2\n";
                print "\tif arg1 eq \nelse\n";
                print "\t\tmov ebx, arg1\n";
                print "\tend if\n";
                print "\tif arg2 eq \nelse\n";
                print "\t\tmov ecx, arg2\n";
                print "\tend if\n";
                print "\tif arg3 eq \nelse\n";
                print "\t\tmov edx, arg3\n";
                print "\tend if\n";
                print "\tint 80h\n}\n";
        }
}

    


Just incase anyone wants to use them... There they are. Note that they are not perfect, but they seem to make almost working code (just off by 2 lines max)


Last edited by Dragontamer on 22 Jul 2004, 04:20; edited 1 time in total
Post 22 Jul 2004, 03:37
View user's profile Send private message Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer
Oh, and some sample code that uses these auto-generated macros

Code:
format ELF executable
entry start

include 'unistdm.inc'

section executable
start:
 SYS.write 1, string, stringlength
 SYS.exit 0

section writeable readable
string db 'Hello World!',0xa
stringlength = $-string
    
Post 22 Jul 2004, 04:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.