Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
Hello World [ASM] Standard & shared lib's
  • Sh3llc0d3
    Posts: 1,910
    Well I'm working on getting some more coding time in with ASM, hopefully it's coming along nicely, just finished learning about shared lib's...

    ...anyway below is my hello world-type program's in asm.

    The first uses pure ASM as standard.
    # Hello_world.s
    # Semtex-Primed
    .section .data
    helloworld:
    .ascii \"Hello iExploit\n\"
    helloworld_end:
    .equ helloworld_len, helloworld_end - helloworld

    .equ STDOUT, 1
    .equ EXIT, 1
    .equ WRITE, 4
    .equ SYSCALL, 0x80
    .section .text
    .globl _start
    _start:
    movl $STDOUT, %ebx
    movl $helloworld, %ecx
    movl $helloworld_len, %edx
    movl $WRITE, %eax
    int $SYSCALL

    movl $0, %ebx
    movl $EXIT, %eax
    int $SYSCALL


    The below hello iexploit program uses shared library's. This code is lighter however it is obviously incomplete and needs the dynamically linked lib's.
    # hello_world-lib.s
    # Semtex-Primed
    .section .data
    helloworld:
    .ascii \"Hello iExploit\n\"
    .section .text
    .globl _start
    _start:
    pushl $helloworld
    call printf

    pushl $0
    call exit


    Compiling the second file needs extra parameter's dynamically linking the file the linux lib's.

    I prefer the long-hand way but I can see the advantage of shared lib's.
  • Xin
    Posts: 3,251
    I think this is one of the examples your gonna have to comment your code as i have no clue whats going on for most of it not being an ASM coder. :P
    Xin
  • Sh3llc0d3
    Posts: 1,910
    Commented code:

    # Hello_world.s
    # Semtex-Primed
    .section .data #start of data section
    helloworld: #variable to hold hello world
    .ascii \"Hello iExploit\n\" #variable contents - ascii data-type
    helloworld_end:
    # CONSTANT's #
    .equ helloworld_len, helloworld_end - helloworld #calculates the length of the value in helloworld
    #System Calls - I could write an entire book on this,
    # http://asm.sourceforge.net/syscall.html
    # Basically were putting the system calls into constants avoiding using the number calls.
    .equ STDOUT, 1
    .equ EXIT, 1
    .equ WRITE, 4
    .equ SYSCALL, 0x80
    .section .text #text section
    .globl _start #declares the start of \"_start\"
    #start of the main block of code
    _start:
    ### Print hello iexploit
    movl $STDOUT, %ebx #tells *nix we want to output (loaded into ebx register)
    movl $helloworld, %ecx #gives the value/variable we want to output (loaded into ecx register)
    movl $helloworld_len, %edx #give the length of hello world variable being output (loaded into edx reg)
    movl $WRITE, %eax
    int $SYSCALL #initiates the previous block of code.

    ### Exit
    movl $0, %ebx #return code to the OS: similar to \"return 0;\" in C
    movl $EXIT, %eax #$EXIT contains 1 which is the syscall for exit. (sys_exit).
    int $SYSCALL
    #initiates the last block of code (exit's program)[/code]

    Hope that helps