Friday, December 18, 2015

Quick Nasm/Assembly Tutorial One-liner! =)

alias quickasm64='_() { cd /tmp; outfile="helloworld.asm"; echo "Writing ${outfile} ..."; echo -en "section     .text\nglobal      _start                              ;must be declared for linker (ld)\n\n_start:                                         ;tell linker entry point\n\n    mov     rdx,len                             ;message length\n    mov     rcx,msg                             ;message to write\n    mov     rbx,1                               ;file descriptor (stdout)\n    mov     rax,4                               ;system call number (sys_write)\n    int     0x80                                ;call kernel\n\n    mov     rax,1                               ;system call number (sys_exit)\n    int     0x80                                ;call kernel\n\nsection     .data\n\nmsg     db  \x27Hello, world\x21\x27,0xa                 ;our dear string\nlen     equ \$ - msg                             ;length of our dear string\n\n" > "${outfile}"; echo "Compiling assembler: nasm -felf64 \"${outfile}\"..."; nasm -felf64 "${outfile}"; echo "Linking object helloworld.o: ld -melf_x86_64 -o helloworld helloworld.o ..."; ld -melf_x86_64 -o helloworld helloworld.o; echo "Displaying ${outfile} asm source: "; cat "${outfile}"; echo "Executing linked helloworld executable! ./helloworld | figlet .."; ./helloworld | figlet; file ./helloworld;}; _' 
alias quickasm='_() { cd /tmp; outfile="helloworld.asm"; echo "Writing ${outfile} ..."; echo -en "section     .text\nglobal      _start                              ;must be declared for linker (ld)\n\n_start:                                         ;tell linker entry point\n\n    mov     edx,len                             ;message length\n    mov     ecx,msg                             ;message to write\n    mov     ebx,1                               ;file descriptor (stdout)\n    mov     eax,4                               ;system call number (sys_write)\n    int     0x80                                ;call kernel\n\n    mov     eax,1                               ;system call number (sys_exit)\n    int     0x80                                ;call kernel\n\nsection     .data\n\nmsg     db  \x27Hello, world\x21\x27,0xa                 ;our dear string\nlen     equ \$ - msg                             ;length of our dear string\n\n" > "${outfile}"; echo "Compiling assembler: nasm -felf \"${outfile}\"..."; nasm -felf "${outfile}"; echo "Linking object helloworld.o: ld -melf_i386 -o helloworld helloworld.o ..."; ld -melf_i386 -o helloworld helloworld.o; echo "Displaying ${outfile} asm source: "; cat "${outfile}"; echo "Executing linked helloworld executable! ./helloworld | figlet .."; ./helloworld | figlet; file ./helloworld;}; _' 

No comments:

Post a Comment