Skip to content

Commit

Permalink
Merge branch 'stable' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
heapcrash committed Jun 30, 2020
2 parents fcfce6c + 8d07456 commit 6443d82
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pwnlib/shellcraft/templates/aarch64/pushstr_array.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pwnlib import shellcraft
from pwnlib.context import context as ctx
from pwnlib.util.iters import group
from six import text_type, binary_type
from six import text_type, binary_type, ensure_binary
%>
<%docstring>
Pushes an array/envp-style array of pointers onto the stack.
Expand All @@ -16,16 +16,18 @@ Arguments:
ends with exactly one NULL byte.

Example:

>>> assembly = shellcraft.execve("/bin/sh", ["sh", "-c", "echo Hello $WORLD"], {"WORLD": "World!"})
>>> assembly = shellcraft.execve("/bin/sh", ["sh", "-c", "echo Hello string $WORLD"], {"WORLD": "World!"})
>>> ELF.from_assembly(assembly).process().recvall()
b'Hello, World!''
b'Hello string World!\n'
</%docstring>
<%page args="reg, array, register1='x14', register2='x15'"/>
<%
if isinstance(array, (binary_type, text_type)):
array = [array]

# Convert all items to strings
array = [ensure_binary(x) for x in array]

# Normalize line endings for each item
array = [arg.rstrip(b'\x00') + b'\x00' for arg in array]

Expand All @@ -50,7 +52,6 @@ if len(array) * 8 > 4095:
add ${register1}, sp, ${register1}
str ${register1}, [sp, #-8]! /* ${array[-i]} */
%endfor
%if len(array[-1] != 'sp')

/* set ${reg} to the current top of the stack */
${shellcraft.mov(reg,'sp')}

0 comments on commit 6443d82

Please sign in to comment.