Author Topic: Would like input for improvements to my script!!  (Read 1743 times)

0 Members and 1 Guest are viewing this topic.

Offline DerpyTurtle

  • Peasant
  • *
  • Posts: 80
  • Cookies: -12
    • View Profile
Would like input for improvements to my script!!
« on: November 01, 2013, 12:52:55 am »
So I am thinking of taking on the task of learning Assembly, was bored one night and decided to write a shell script to compile and build my assembly files. What I am asking of you fine folks is to provide some helpful criticism and give me your input on this script and your ideas on what I could do to make it better. Feel free to use it and modify it as you wish. I have tested it and it does indeed work!


Here is the script
Code: [Select]

#!/bin/bash
#: Title :asm2exe (Assembly to Executable)
#: Date :(C)2013
#: Author :derpyturtle
#: Version :1.0
#: Description :A small script to compile and build .asm files with ease.
#: Options :


echo "            _____ __  __ ___  ________   ________
     /\    / ____|  \/  |__ \|  ____\ \ / /  ____|
    /  \  | (___ | \  / |  ) | |__   \ V /| |__   
   / /\ \  \___ \| |\/| | / /|  __|   > < |  __| 
  / ____ \ ____) | |  | |/ /_| |____ / . \| |____
 /_/    \_\_____/|_|  |_|____|______/_/ \_\______|" #display ascii art logo
 echo #skip a line
 echo #skip a line
 echo "This is a program to make compiling"
 echo " and building your .asm files a breeze!\c" #display message to user
 echo #skip a line
 echo "Enter the name of the file you would like to compile"
 echo "(Please use the full path if it applies):" #prompt user to enter filename
 read filename #read input and save it in filename
 echo "You want to compile $filename, correct? (y/n)" #prompt user again to be sure
 read answer
 if test "$answer" = y
 then
echo #skip a line
echo "Compilation will begin shortly..." #display message to user
nasm -f elf $filename #begin building process
echo "Ready to begin with step 2!"
echo "Please enter the new file name" #prompt user for .o file
read file2
echo "\n"
echo "Finalizing compilation..."
gcc $file2 -o final

else
echo "Please re-enter the name of the file you would like to use: " #prompt user to re-enter initial file name
read filename #re-check user input
fi
echo "Your file is ready!"
echo "Thank you for using asm2exe"
exit 0

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Would like input for improvements to my script!!
« Reply #1 on: November 01, 2013, 09:33:48 am »
I don't really see the advantage. It's ok for having a little bash exercise, but using this script will take much longer than just executing the commands on command line or using a make file.
So why not just create a make file?
« Last Edit: November 01, 2013, 09:33:58 am by Deque »

Offline DerpyTurtle

  • Peasant
  • *
  • Posts: 80
  • Cookies: -12
    • View Profile
Re: Would like input for improvements to my script!!
« Reply #2 on: November 02, 2013, 02:29:37 am »
Honestly I was quite bored and I wanted to do something, but I couldnt think of anything really until this came to mind but its just something I decided to do. Just thought it would be useful in some way. As far as the Make file, I am not too experienced with them, I've used them but never actually made one myself.

Offline SkiddieBastard

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -1338
    • View Profile
Re: Would like input for improvements to my script!!
« Reply #3 on: November 02, 2013, 05:04:53 am »
Stupidest script ever.

Can type the commands in less time than it takes to look at the artwork on your script.

Go home.

Spacecow

  • Guest
Re: Would like input for improvements to my script!!
« Reply #4 on: November 02, 2013, 06:20:54 am »
Couple of aliases in .bashrc would speed up the process more then using the script but useless programs are a quality time killer when you're bored IMO.

Offline d4rkcat

  • Knight
  • **
  • Posts: 287
  • Cookies: 115
  • He who controls the past controls the future. He who controls the present controls the past.
    • View Profile
    • Scripts
Re: Would like input for improvements to my script!!
« Reply #5 on: November 02, 2013, 01:52:19 pm »
Hi DerpyTurtle,
Please see below some corrections to your script. Its a good script, but you can definitely learn some tricks from my corrections. Mostly how to use read and echo correctly.  ;)   (also in bash we always make VARIABLES capitals.
Good Luck!

Code: [Select]
#!/bin/bash
#: Title    :asm2exe (Assembly to Executable)
#: Date        :(C)2013
#: Author    :derpyturtle
#: Version    :1.0
#: Description :A small script to compile and build .asm files with ease.
#: Options    :


echo """            _____ __  __ ___  ________   ________
     /\    / ____|  \/  |__ \|  ____\ \ / /  ____|
    /  \  | (___ | \  / |  ) | |__   \ V /| |__   
   / /\ \  \___ \| |\/| | / /|  __|   > < |  __| 
  / ____ \ ____) | |  | |/ /_| |____ / . \| |____
 /_/    \_\_____/|_|  |_|____|______/_/ \_\______|


"
 read -e -p """This is a program to make compiling
and building your .asm files a breeze!

Enter the name of the file you would like to compile
(Please use the full path if it applies):" FILENAME
read -p "You want to compile $FILENAME, correct? (y/n)" ANSWER

 if  [ $ANSWER = 'y' ] 2> /dev/null
 then
    echo """
    Compilation will begin shortly..."
    nasm -f elf $FILENAME
    read -p """Ready to begin with step 2!
    Please enter the new file name" FILE2
    echo """
    Finalizing compilation..."
    gcc $FILE2 -o final
   
else
    read -p "Please re-enter the name of the file you would like to use: " FILENAME
fi
echo """Your file is ready!
Thank you for using asm2exe"
exit 0
« Last Edit: November 04, 2013, 01:42:44 pm by d4rkcat »
Jabber (OTR required): thed4rkcat@einfachjabber.de    Email (PGP required): thed4rkcat@yandex.com    PGP Key: here and here     Blog

<sofldan> not asking for anyone to hold my hand uber space shuttle door gunner guy.


Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: Would like input for improvements to my script!!
« Reply #6 on: November 02, 2013, 03:57:23 pm »
Ehh, what about 32/64 bit ELF mode, also why gcc? why not just link it?
~Factionwars

Offline DerpyTurtle

  • Peasant
  • *
  • Posts: 80
  • Cookies: -12
    • View Profile
Re: Would like input for improvements to my script!!
« Reply #7 on: November 03, 2013, 04:38:23 am »
Hi DerpyTurtle,
Please see below some corrections to your script. Its a good script, but you can definitely learn some tricks from my corrections. Mostly how to use read and echo correctly.  ;)   (also in bash we always make VARIABLES capitals.
Good Luck!

Code: [Select]
#!/bin/bash
#: Title    :asm2exe (Assembly to Executable)
#: Date        :(C)2013
#: Author    :derpyturtle
#: Version    :1.0
#: Description :A small script to compile and build .asm files with ease.
#: Options    :


echo """            _____ __  __ ___  ________   ________
     /\    / ____|  \/  |__ \|  ____\ \ / /  ____|
    /  \  | (___ | \  / |  ) | |__   \ V /| |__   
   / /\ \  \___ \| |\/| | / /|  __|   > < |  __| 
  / ____ \ ____) | |  | |/ /_| |____ / . \| |____
 /_/    \_\_____/|_|  |_|____|______/_/ \_\______|


"
 read -e -p """This is a program to make compiling"
and building your .asm files a breeze!

Enter the name of the file you would like to compile
(Please use the full path if it applies):" FILENAME
read -p "You want to compile $FILENAME, correct? (y/n)" ANSWER

 if  [ $ANSWER = 'y' ] 2> /dev/null
 then
    echo """
    Compilation will begin shortly..."
    nasm -f elf $FILENAME
    read -p """Ready to begin with step 2!
    Please enter the new file name" FILE2
    echo """
    Finalizing compilation..."
    gcc $FILE2 -o final
   
else
    read -p "Please re-enter the name of the file you would like to use: " FILENAME
fi
echo """Your file is ready!
Thank you for using asm2exe"
exit 0


Thanks! Ill take a look at it!


Ehh, what about 32/64 bit ELF mode, also why gcc? why not just link it?


The book I am using to learn assembly uses gcc. Im still new to this whole process so linking is something I will look into!

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: Would like input for improvements to my script!!
« Reply #8 on: November 03, 2013, 02:40:09 pm »

Thanks! Ill take a look at it!



The book I am using to learn assembly uses gcc. Im still new to this whole process so linking is something I will look into!

Well you should look at it because using gcc and libc functions is kinda cheating in ASM :P
~Factionwars

Offline DerpyTurtle

  • Peasant
  • *
  • Posts: 80
  • Cookies: -12
    • View Profile
Re: Would like input for improvements to my script!!
« Reply #9 on: November 04, 2013, 06:26:12 am »
This is the book Im using to start out


http://www.amazon.com/Assembly-Language-Step---step-Programming/dp/0471375233/ref=sr_1_3?ie=UTF8&qid=1383542586&sr=8-3&keywords=assembly+language+step+by+step


Then I plan to move on to this book


http://www.amazon.com/Professional-Assembly-Language-Richard-Blum/dp/0764579010/ref=sr_1_1?ie=UTF8&qid=1383542627&sr=8-1&keywords=professional+assembly+language


The first says to use nasm and then compile with gcc. So hopefully the other book will cover the topic of linking or maybe this one will later on.