Thread: Null bytes in code

  1. #1
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528

    Null bytes in code

    I have the following piece of code(Which is not necessarily correct )

    Code:
    /* gcc main.s -o main */
    
    .global main
    main:
      movq %rax, 1
      movq %rdi, 1
      movq %rsi, 3
      movq %rdx, 13
      syscall
      movq %rax, 13
      movq %rdi, 0
      syscall
    I have the following dissassembly.

    Code:
    /* objdump -d main */
    
    00000000004004b6 <main>:
      4004b6:       48 89 04 25 01 00 00    mov    %rax,0x1
      4004bd:       00
      4004be:       48 89 3c 25 01 00 00    mov    %rdi,0x1
      4004c5:       00
      4004c6:       48 89 34 25 03 00 00    mov    %rsi,0x3
      4004cd:       00
      4004ce:       48 89 14 25 0d 00 00    mov    %rdx,0xd
      4004d5:       00
      4004d6:       0f 05                   syscall
      4004d8:       48 89 04 25 0d 00 00    mov    %rax,0xd
      4004df:       00
      4004e0:       48 89 3c 25 00 00 00    mov    %rdi,0x0
      4004e7:       00
      4004e8:       0f 05                   syscall
      4004ea:       66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)
    Just the main function - anyway - the rest are the C library setup routine so no need going over them

    any ideas why am I am getting the null bytes its probably something silly am missing out ?

  2. #2
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by Aslaville View Post
    any ideas why am I am getting the null bytes its probably something silly am missing out ?
    Ehm..

    No, they're not null bytes. The mov mnemonics are just eight bytes long, and the disassembly format was chosen when seven bytes were thought to suffice for any mnemonic. So, the output wraps to the next line...

  3. #3
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Nominal Animal View Post
    Ehm..

    No, they're not null bytes. The mov mnemonics are just eight bytes long, and the disassembly format was chosen when seven bytes were thought to suffice for any mnemonic. So, the output wraps to the next line...
    Arrg, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting a stream of non-null terminated bytes
    By sockets12 in forum C Programming
    Replies: 3
    Last Post: 10-10-2014, 12:19 PM
  2. Arrays with NULL bytes
    By Yawney in forum C Programming
    Replies: 7
    Last Post: 04-17-2013, 01:21 PM
  3. Replies: 8
    Last Post: 01-18-2008, 04:06 AM
  4. Sending null-bytes over a socket?
    By Siphon in forum C Programming
    Replies: 2
    Last Post: 10-08-2007, 03:21 PM
  5. Char size (in bytes) independent code
    By JoshR in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2005, 07:33 PM